import { makeAppObjectRepo } from "@vived/core";
import { makeInspectorTabEntity } from "./InspectorTabEntity";
function makeTestRig() {
    const appObjects = makeAppObjectRepo();
    const app = appObjects.getOrCreate("App");
    const tabEntity = makeInspectorTabEntity(app);
    const observer = jest.fn();
    tabEntity.addChangeObserver(observer);
    tabEntity.setInspectorTabs(["Challenge", "Properties"]);
    return { tabEntity, observer };
}
describe("Inspector Tab Entity", () => {
    it("Initializes the tab to the first one in the list", () => {
        const { tabEntity } = makeTestRig();
        expect(tabEntity.activeTab).toEqual("Challenge");
    });
    it("Returns the tab list", () => {
        const { tabEntity } = makeTestRig();
        expect(tabEntity.inspectorTabs).toEqual(["Challenge", "Properties"]);
    });
    it("Notifies when the Active Tab changes", () => {
        const { tabEntity, observer } = makeTestRig();
        observer.mockClear();
        expect(tabEntity.activeTab).toEqual("Challenge");
        tabEntity.activeTab = "Properties";
        tabEntity.activeTab = "Properties";
        tabEntity.activeTab = "Properties";
        tabEntity.activeTab = "Properties";
        expect(observer).toHaveBeenCalledTimes(1);
        expect(tabEntity.activeTab).toEqual("Properties");
    });
    it("Warns if an unknown tab is sent in", () => {
        const { tabEntity } = makeTestRig();
        tabEntity.warn = jest.fn();
        tabEntity.activeTab = "Unknown";
        expect(tabEntity.warn).toHaveBeenCalled();
    });
    it("Notifies when the Active Tab Index changes", () => {
        const { tabEntity, observer } = makeTestRig();
        observer.mockClear();
        expect(tabEntity.activeTabIndex).toEqual(0);
        tabEntity.activeTabIndex = 1;
        tabEntity.activeTabIndex = 1;
        tabEntity.activeTabIndex = 1;
        tabEntity.activeTabIndex = 1;
        expect(observer).toHaveBeenCalledTimes(1);
        expect(tabEntity.activeTabIndex).toEqual(1);
        expect(tabEntity.activeTab).toEqual("Properties");
    });
    it("Warns if an invalid index is submitted", () => {
        const { tabEntity } = makeTestRig();
        tabEntity.warn = jest.fn();
        tabEntity.activeTabIndex = -1;
        expect(tabEntity.warn).toHaveBeenCalledTimes(1);
        tabEntity.activeTabIndex = 2;
        expect(tabEntity.warn).toHaveBeenCalledTimes(2);
    });
});
//# sourceMappingURL=InspectorTabEntity.test.js.map