import { makeAppObjectRepo } from "@vived/core";
import { LabelDropRepo, makeLabelDropRepo } from "../Entities/LabelDropRepo";
import { LabelDropListPM, makeLabelDropListPM, } from "./LabelDropListPM";
function makeTestRig() {
    const appObjects = makeAppObjectRepo();
    const registerSpy = jest.spyOn(appObjects, "registerSingleton");
    const appObj = appObjects.getOrCreate("appObj");
    const labelDrop = makeLabelDropRepo(appObj);
    const pm = makeLabelDropListPM(appObj);
    const view = jest.fn();
    pm.addView(view);
    return { appObj, appObjects, labelDrop, pm, view, registerSpy };
}
describe("Label Drop List Presentation Manager", () => {
    it("Gets the singleton", () => {
        const { appObjects, pm } = makeTestRig();
        expect(LabelDropListPM.get(appObjects)).toEqual(pm);
    });
    it("Registers as the singleton", () => {
        const { registerSpy, pm } = makeTestRig();
        expect(registerSpy).toHaveBeenCalledWith(pm);
    });
    it("Sets the last vm on construction", () => {
        const { pm } = makeTestRig();
        expect(pm.lastVM).not.toBeUndefined();
    });
    it("Updates the view when the entity changes", () => {
        const { pm, labelDrop } = makeTestRig();
        expect(pm.lastVM?.answerItemIds).toEqual([]);
        labelDrop.makeLabelDropItem("obj1");
        expect(pm.lastVM?.answerItemIds).toEqual(["obj1"]);
    });
    it("Sets the validation message", () => {
        const { pm, labelDrop } = makeTestRig();
        expect(pm.lastVM?.challengeValidationMessage).toEqual(LabelDropRepo.LABEL_DROP_ANSWER_REQUIRED);
        labelDrop.makeLabelDropItem("obj1");
        expect(pm.lastVM?.challengeValidationMessage).toEqual("");
    });
    it("Returns true if the VMs are the same", () => {
        const { pm } = makeTestRig();
        const vm1 = {
            answerItemIds: ["id1"],
            challengeValidationMessage: "error",
        };
        const vm2 = { ...vm1 };
        expect(pm.vmsAreEqual(vm1, vm2)).toEqual(true);
    });
    it("Returns false if id is different", () => {
        const { pm } = makeTestRig();
        const vm1 = {
            answerItemIds: ["id1"],
            challengeValidationMessage: "error",
        };
        const vm2 = { ...vm1, answerItemIds: ["CHANGED"] };
        expect(pm.vmsAreEqual(vm1, vm2)).toEqual(false);
    });
    it("Returns false if a id is added", () => {
        const { pm } = makeTestRig();
        const vm1 = {
            answerItemIds: ["id1"],
            challengeValidationMessage: "error",
        };
        const vm2 = { ...vm1, answerItemIds: ["id1", "id2"] };
        expect(pm.vmsAreEqual(vm1, vm2)).toEqual(false);
    });
    it("Returns false if a id is removed", () => {
        const { pm } = makeTestRig();
        const vm1 = {
            answerItemIds: ["id1"],
            challengeValidationMessage: "error",
        };
        const vm2 = { ...vm1, answerItemIds: [] };
        expect(pm.vmsAreEqual(vm1, vm2)).toEqual(false);
    });
    it("Returns false if validation message is different", () => {
        const { pm } = makeTestRig();
        const vm1 = {
            answerItemIds: ["id1"],
            challengeValidationMessage: "error",
        };
        const vm2 = { ...vm1, challengeValidationMessage: "" };
        expect(pm.vmsAreEqual(vm1, vm2)).toEqual(false);
    });
});
//# sourceMappingURL=LabelDropListPM.test.js.map