import { makeAppObjectRepo } from "@vived/core";
import { makeLabelDropRepo } from "../Entities/LabelDropRepo";
import { LabelDropReviewPM, makeLabelDropReviewPM } from "./LabelDropReviewPM";
function makeTestRig() {
    const appObjects = makeAppObjectRepo();
    const registerSpy = jest.spyOn(appObjects, "registerSingleton");
    const appObj = appObjects.getOrCreate("appObj");
    const labelDrop = makeLabelDropRepo(appObj);
    const pm = makeLabelDropReviewPM(appObj);
    return { appObj, appObjects, labelDrop, pm, registerSpy };
}
describe("Label Drop Review Presentation Manager", () => {
    it("Gets the singleton", () => {
        const { appObjects, pm } = makeTestRig();
        expect(LabelDropReviewPM.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 { labelDrop, pm } = makeTestRig();
        const item = labelDrop.makeLabelDropItem("id1");
        item.labelEntity.custom = "label1";
        item.targetIds = ["obj1"];
        item.submitLabelDrop("INCORRECT");
        item.submitLabelDrop("obj1");
        expect(pm.lastVM).toEqual([
            {
                id: "id1",
                label: "label1",
                tries: 2,
            },
        ]);
    });
    it("Returns true if the VMs are the same", () => {
        const { pm } = makeTestRig();
        const vm1 = [
            {
                id: "id1",
                label: "label1",
                tries: 1,
            },
        ];
        const vm2 = [
            {
                id: "id1",
                label: "label1",
                tries: 1,
            },
        ];
        expect(pm.vmsAreEqual(vm1, vm2)).toEqual(true);
    });
    it("Returns false if id is different", () => {
        const { pm } = makeTestRig();
        const vm1 = [
            {
                id: "id1",
                label: "label1",
                tries: 1,
            },
        ];
        const vm2 = [
            {
                id: "id2",
                label: "label1",
                tries: 1,
            },
        ];
        expect(pm.vmsAreEqual(vm1, vm2)).toEqual(false);
    });
    it("Returns false if label is different", () => {
        const { pm } = makeTestRig();
        const vm1 = [
            {
                id: "id1",
                label: "label1",
                tries: 1,
            },
        ];
        const vm2 = [
            {
                id: "id1",
                label: "label2",
                tries: 1,
            },
        ];
        expect(pm.vmsAreEqual(vm1, vm2)).toEqual(false);
    });
    it("Returns false if tries are different", () => {
        const { pm } = makeTestRig();
        const vm1 = [
            {
                id: "id1",
                label: "label1",
                tries: 1,
            },
        ];
        const vm2 = [
            {
                id: "id1",
                label: "label2",
                tries: 2,
            },
        ];
        expect(pm.vmsAreEqual(vm1, vm2)).toEqual(false);
    });
});
//# sourceMappingURL=LabelDropReviewPM.test.js.map