import { makeAppObjectRepo } from "@vived/core";
import { makeInspectorTabEntity } from "../Entities/InspectorTabEntity";
import { InspectorTabPM, makeInspectorTabPM, } from "./InspectorTabPM";
function makeTestRig() {
    const appObjects = makeAppObjectRepo();
    const registerSpy = jest.spyOn(appObjects, "registerSingleton");
    const app = appObjects.getOrCreate("app");
    const tabEntity = makeInspectorTabEntity(app);
    tabEntity.setInspectorTabs(["Properties", "Challenge"]);
    const pm = makeInspectorTabPM(app);
    return { tabEntity, pm, appObjects, registerSpy };
}
describe("Inspector Tab PM", () => {
    it("Initializes the view", () => {
        const { pm } = makeTestRig();
        expect(pm.lastVM).not.toBeUndefined();
    });
    it("Updates the view", () => {
        const { pm, tabEntity } = makeTestRig();
        expect(tabEntity.activeTab).toEqual("Properties");
        tabEntity.activeTab = "Challenge";
        expect(pm.lastVM?.selectedTab).toEqual("Challenge");
        expect(pm.lastVM?.selectedTabIndex).toEqual(1);
        expect(pm.lastVM?.tabs).toEqual(["Properties", "Challenge"]);
    });
    it("Checks if VMs are equal", () => {
        const { pm } = makeTestRig();
        const vm1 = {
            selectedTab: "selected",
            selectedTabIndex: 0,
            tabs: ["Tab1"],
        };
        const vm2 = {
            ...vm1,
        };
        expect(pm.vmsAreEqual(vm1, vm2)).toEqual(true);
    });
    it("Checks for a change in the selected tab", () => {
        const { pm } = makeTestRig();
        const vm1 = {
            selectedTab: "selected",
            selectedTabIndex: 0,
            tabs: ["Tab1"],
        };
        const vm2 = {
            ...vm1,
            selectedTab: "CHANGED",
        };
        expect(pm.vmsAreEqual(vm1, vm2)).toEqual(false);
    });
    it("Checks for a change in the selected index", () => {
        const { pm } = makeTestRig();
        const vm1 = {
            selectedTab: "selected",
            selectedTabIndex: 0,
            tabs: ["Tab1"],
        };
        const vm2 = {
            ...vm1,
            selectedTabIndex: 1,
        };
        expect(pm.vmsAreEqual(vm1, vm2)).toEqual(false);
    });
    it("Checks for a tab to be added", () => {
        const { pm } = makeTestRig();
        const vm1 = {
            selectedTab: "selected",
            selectedTabIndex: 0,
            tabs: ["Tab1"],
        };
        const vm2 = {
            ...vm1,
            tabs: ["Tab1", "Tab2"],
        };
        expect(pm.vmsAreEqual(vm1, vm2)).toEqual(false);
    });
    it("Checks for a tab to be added", () => {
        const { pm } = makeTestRig();
        const vm1 = {
            selectedTab: "selected",
            selectedTabIndex: 0,
            tabs: ["Tab1"],
        };
        const vm2 = {
            ...vm1,
            tabs: [],
        };
        expect(pm.vmsAreEqual(vm1, vm2)).toEqual(false);
    });
    it("Checks for a tab to be changed", () => {
        const { pm } = makeTestRig();
        const vm1 = {
            selectedTab: "selected",
            selectedTabIndex: 0,
            tabs: ["Tab1"],
        };
        const vm2 = {
            ...vm1,
            tabs: ["CHANGED"],
        };
        expect(pm.vmsAreEqual(vm1, vm2)).toEqual(false);
    });
    it("Gets the PM", () => {
        const { pm, appObjects } = makeTestRig();
        expect(InspectorTabPM.get(appObjects)).toEqual(pm);
    });
    it("Registers as the singleton", () => {
        const { pm, registerSpy } = makeTestRig();
        expect(registerSpy).toHaveBeenCalledWith(pm);
    });
});
//# sourceMappingURL=InspectorTabPM.test.js.map