import { makeAppObjectRepo } from "@vived/core";
import { LabelDropItemEntity } from "../Entities/LabelDropItemEntity";
import { LabelDropTargetsPM, makeLabelDropTargetsPM, } from "./LabelDropTargetsPM";
function makeTestRig() {
    const appObjects = makeAppObjectRepo();
    const ao = appObjects.getOrCreate("ao");
    const labelDropItem = new LabelDropItemEntity(ao);
    const pm = makeLabelDropTargetsPM(ao);
    return { appObjects, ao, labelDropItem, pm };
}
describe("Label Drop Answer Item Details PM", () => {
    it("Get it PM", () => {
        const { appObjects, pm } = makeTestRig();
        expect(LabelDropTargetsPM.get("ao", appObjects)).toEqual(pm);
    });
    it("Initializes the VM", () => {
        const { pm } = makeTestRig();
        expect(pm.lastVM).not.toBeUndefined();
    });
    it("Updates when a correct ID is added to a label drop", () => {
        const { labelDropItem, pm } = makeTestRig();
        expect(pm.lastVM?.targetIds).toEqual([]);
        labelDropItem.addTargetID("id1");
        expect(pm.lastVM?.targetIds).toEqual(["id1"]);
    });
    it("Returns the target validation message", () => {
        const { labelDropItem, pm } = makeTestRig();
        jest
            .spyOn(labelDropItem, "targetValidationMessage", "get")
            .mockReturnValue("Some Message");
        labelDropItem.notifyOnChange();
        expect(pm.lastVM?.targetValidationMessage).toEqual("Some Message");
    });
    it("Checks for equal vms", () => {
        const { pm } = makeTestRig();
        const vm1 = {
            targetIds: ["id1"],
            targetValidationMessage: undefined,
        };
        const vm2 = {
            ...vm1,
        };
        expect(pm.vmsAreEqual(vm1, vm2)).toEqual(true);
    });
    it("Checks for a change in target validation", () => {
        const { pm } = makeTestRig();
        const vm1 = {
            targetIds: ["id1"],
            targetValidationMessage: undefined,
        };
        const vm2 = {
            ...vm1,
            targetValidationMessage: "SOME MESSAGE",
        };
        expect(pm.vmsAreEqual(vm1, vm2)).toEqual(false);
    });
    it("Checks for a change in the target id", () => {
        const { pm } = makeTestRig();
        const vm1 = {
            targetIds: ["id1"],
            targetValidationMessage: undefined,
        };
        const vm2 = {
            ...vm1,
            targetIds: ["CHANGED"],
        };
        expect(pm.vmsAreEqual(vm1, vm2)).toEqual(false);
    });
    it("Checks for a target to be added", () => {
        const { pm } = makeTestRig();
        const vm1 = {
            targetIds: ["id1"],
            targetValidationMessage: undefined,
        };
        const vm2 = {
            ...vm1,
            targetIds: ["id1", "NEW"],
        };
        expect(pm.vmsAreEqual(vm1, vm2)).toEqual(false);
    });
    it("Checks for a target to be removed", () => {
        const { pm } = makeTestRig();
        const vm1 = {
            targetIds: ["id1"],
            targetValidationMessage: undefined,
        };
        const vm2 = {
            ...vm1,
            targetIds: [],
        };
        expect(pm.vmsAreEqual(vm1, vm2)).toEqual(false);
    });
});
//# sourceMappingURL=LabelDropTargetsPM.test.js.map