"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@vived/core");
const LabelDropRepo_1 = require("../Entities/LabelDropRepo");
const LabelDropEditingIDPM_1 = require("./LabelDropEditingIDPM");
function makeTestRig() {
    const appObjects = (0, core_1.makeAppObjectRepo)();
    const registerSpy = jest.spyOn(appObjects, "registerSingleton");
    const appObj = appObjects.getOrCreate("appObj");
    const labelDrop = (0, LabelDropRepo_1.makeLabelDropRepo)(appObj);
    const pm = (0, LabelDropEditingIDPM_1.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_1.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