import { makeAppObjectRepo } from "@vived/core";
import { makeSelectable } from "../Entities/Selectable";
import { makeSelection } from "../Entities/Selection";
import { makeSelectedObjectPM, SelectedObjectPM } from "./SelectedObjectPM";
function makeTestRig() {
    const appObjects = makeAppObjectRepo();
    const registerSpy = jest.spyOn(appObjects, "registerSingleton");
    const appObj = appObjects.getOrCreate("selection");
    const selection = makeSelection(appObj);
    const selectableAO = appObjects.getOrCreate("appObj1");
    const selectable = makeSelectable(selectableAO);
    selection.addSelectable(selectable);
    selection.selectedObjectId = "appObj1";
    const pm = 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.get(appObjects)).toEqual(pm);
    });
    it("Registers as the singleton", () => {
        const { pm, registerSpy } = makeTestRig();
        expect(registerSpy).toHaveBeenCalledWith(pm);
    });
});
//# sourceMappingURL=SelectedObjectPM.test.js.map