import { makeAppObjectRepo } from "@vived/core";
import { makeLabelDropRepo } from "../Entities/LabelDropRepo";
import { makeRemainingLabelDropListPM, RemainingLabelDropListPM, } from "./RemainingLabelDropListPM";
function makeTestRig() {
    const appObjects = makeAppObjectRepo();
    const registerSpy = jest.spyOn(appObjects, "registerSingleton");
    const appObj = appObjects.getOrCreate("appObj");
    const labelDrop = makeLabelDropRepo(appObj);
    const pm = makeRemainingLabelDropListPM(appObj);
    return { appObj, appObjects, labelDrop, pm, registerSpy };
}
describe("LabelDrop List Presentation Manager", () => {
    it("Gets the singleton", () => {
        const { appObjects, pm } = makeTestRig();
        expect(RemainingLabelDropListPM.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 an item is added", () => {
        const { pm, labelDrop } = makeTestRig();
        const item = labelDrop.makeLabelDropItem("id");
        item.labelEntity.custom = "Item Label";
        expect(pm.lastVM).toEqual([
            {
                id: "id",
                label: "Item Label",
            },
        ]);
    });
    it("Updates the view when an items is answered", () => {
        const { pm, labelDrop } = makeTestRig();
        const item = labelDrop.makeLabelDropItem("id");
        item.labelEntity.custom = "Item Label";
        item.targetIds = ["targetID"];
        expect(pm.lastVM).toEqual([
            {
                id: "id",
                label: "Item Label",
            },
        ]);
        item.submitLabelDrop("targetID");
        expect(pm.lastVM).toEqual([]);
    });
    it("Returns true if the VMs are the same", () => {
        const { pm } = makeTestRig();
        const vm1 = [
            {
                id: "id1",
                label: "label1",
            },
        ];
        const vm2 = [
            {
                id: "id1",
                label: "label1",
            },
        ];
        expect(pm.vmsAreEqual(vm1, vm2)).toEqual(true);
    });
    it("Returns false if id is different", () => {
        const { pm } = makeTestRig();
        const vm1 = [
            {
                id: "id1",
                label: "label1",
            },
        ];
        const vm2 = [
            {
                id: "id2",
                label: "label1",
            },
        ];
        expect(pm.vmsAreEqual(vm1, vm2)).toEqual(false);
    });
    it("Returns false if label is different", () => {
        const { pm } = makeTestRig();
        const vm1 = [
            {
                id: "id1",
                label: "label1",
            },
        ];
        const vm2 = [
            {
                id: "id1",
                label: "label2",
            },
        ];
        expect(pm.vmsAreEqual(vm1, vm2)).toEqual(false);
    });
    it("Returns false if item is removed", () => {
        const { pm } = makeTestRig();
        const vm1 = [
            {
                id: "id1",
                label: "label1",
            },
        ];
        const vm2 = [];
        expect(pm.vmsAreEqual(vm1, vm2)).toEqual(false);
    });
    it("Returns false if item is added", () => {
        const { pm } = makeTestRig();
        const vm1 = [
            {
                id: "id1",
                label: "label1",
            },
        ];
        const vm2 = [
            {
                id: "id1",
                label: "label1",
            },
            {
                id: "id2",
                label: "label2",
            },
        ];
        expect(pm.vmsAreEqual(vm1, vm2)).toEqual(false);
    });
});
//# sourceMappingURL=RemainingLabelDropListPM.test.js.map