"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@vived/core");
const Selectable_1 = require("../Entities/Selectable");
const Selection_1 = require("../Entities/Selection");
const SelectedObjectPM_1 = require("./SelectedObjectPM");
function makeTestRig() {
    const appObjects = (0, core_1.makeAppObjectRepo)();
    const registerSpy = jest.spyOn(appObjects, "registerSingleton");
    const appObj = appObjects.getOrCreate("selection");
    const selection = (0, Selection_1.makeSelection)(appObj);
    const selectableAO = appObjects.getOrCreate("appObj1");
    const selectable = (0, Selectable_1.makeSelectable)(selectableAO);
    selection.addSelectable(selectable);
    selection.selectedObjectId = "appObj1";
    const pm = (0, SelectedObjectPM_1.makeSelectedObjectPM)(appObj);
    return { pm, appObj, appObjects, selection, registerSpy };
}
describe("Selectable Presentation Manager", () => {
    it("Checks for equal VMs", () => {
        const { pm } = makeTestRig();
        expect(pm.vmsAreEqual("id1", "id1")).toEqual(true);
        expect(pm.vmsAreEqual(null, null)).toEqual(true);
    });
    it("Checks for unequal VMs", () => {
        const { pm } = makeTestRig();
        expect(pm.vmsAreEqual("id1", null)).toEqual(false);
        expect(pm.vmsAreEqual(null, "id1")).toEqual(false);
        expect(pm.vmsAreEqual("id1", "id2")).toEqual(false);
    });
    it("Sets the VM as expected", () => {
        const { pm } = makeTestRig();
        expect(pm.lastVM).toEqual("appObj1");
    });
    it("Updates the view when the selection changes", () => {
        const { pm, selection } = makeTestRig();
        const view = jest.fn();
        pm.addView(view);
        view.mockClear();
        selection.selectedObjectId = null;
        expect(view).toHaveBeenCalled();
    });
    it("Gets the singleton", () => {
        const { pm, appObjects } = makeTestRig();
        expect(SelectedObjectPM_1.SelectedObjectPM.get(appObjects)).toEqual(pm);
    });
    it("Registers as the singleton", () => {
        const { pm, registerSpy } = makeTestRig();
        expect(registerSpy).toHaveBeenCalledWith(pm);
    });
});
//# sourceMappingURL=SelectedObjectPM.test.js.map