import { makeAppObjectRepo } from "@vived/core";
import { makeLabelDropRepo } from "../Entities/LabelDropRepo";
import { LabelDropEditingIDPM, makeLabelDropEditingIDPM, } from "./LabelDropEditingIDPM";
function makeTestRig() {
    const appObjects = makeAppObjectRepo();
    const registerSpy = jest.spyOn(appObjects, "registerSingleton");
    const appObj = appObjects.getOrCreate("appObj");
    const labelDrop = makeLabelDropRepo(appObj);
    const pm = makeLabelDropEditingIDPM(appObj);
    return { appObj, appObjects, labelDrop, pm, registerSpy };
}
describe("Label Drop Editing ID Presentation Manager", () => {
    it("Gets the singleton", () => {
        const { appObjects, pm } = makeTestRig();
        expect(LabelDropEditingIDPM.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("Returns true if the VMs are the same", () => {
        const { pm } = makeTestRig();
        const vm1 = {
            editingId: "id1",
            isEditingNewAnswer: false,
        };
        const vm2 = {
            editingId: "id1",
            isEditingNewAnswer: false,
        };
        expect(pm.vmsAreEqual(vm1, vm2)).toEqual(true);
    });
    it("Returns false if editingId is different", () => {
        const { pm } = makeTestRig();
        const vm1 = {
            editingId: "id1",
            isEditingNewAnswer: false,
        };
        const vm2 = {
            editingId: "id2",
            isEditingNewAnswer: false,
        };
        expect(pm.vmsAreEqual(vm1, vm2)).toEqual(false);
    });
    it("Returns false if isEditingNewAnswer is different", () => {
        const { pm } = makeTestRig();
        const vm1 = {
            editingId: "id1",
            isEditingNewAnswer: false,
        };
        const vm2 = {
            editingId: "id1",
            isEditingNewAnswer: true,
        };
        expect(pm.vmsAreEqual(vm1, vm2)).toEqual(false);
    });
    it("Updates the view when the editingId changes", () => {
        const { pm, labelDrop } = makeTestRig();
        const newId = "id2";
        labelDrop.makeLabelDropItem(newId);
        expect(pm.lastVM?.editingId).not.toEqual(newId);
        labelDrop.editingID = newId;
        expect(pm.lastVM?.editingId).toEqual(newId);
    });
    it("Updates the view when isEditingNewAnswer changes", () => {
        const { pm, labelDrop } = makeTestRig();
        labelDrop.isEditingNewAnswer = true;
        expect(pm.lastVM?.isEditingNewAnswer).toEqual(true);
    });
});
//# sourceMappingURL=LabelDropEditingIDPM.test.js.map