import { makeAppObject, makeAppObjectRepo } from "@vived/core";
import { Hideable } from "../Entities/Hideable";
import { IsHiddenPM, makeIsHiddenPM } from "./IsHiddenPM";
function makeTestRig() {
    const appObjects = makeAppObjectRepo();
    const appObj = makeAppObject("obj1", appObjects);
    const hideable = new Hideable(appObj);
    hideable.isHidden = true;
    const view = jest.fn();
    const pm = makeIsHiddenPM(appObj);
    return { appObjects, hideable, pm, view };
}
describe("Is hidden PM", () => {
    it("Sets the last vm on construction", () => {
        const { pm } = makeTestRig();
        expect(pm.lastVM).toEqual(true);
    });
    it("Updates the view when the state changes", () => {
        const { pm, hideable } = makeTestRig();
        const spy = jest.spyOn(pm, "doUpdateView");
        hideable.isHidden = false;
        expect(spy).toHaveBeenCalledWith(false);
    });
    it("Can be disposed", () => {
        const { pm, hideable } = makeTestRig();
        pm.dispose();
        const spy = jest.spyOn(pm, "doUpdateView");
        hideable.isHidden = false;
        expect(spy).not.toHaveBeenCalled();
    });
    it("Is removed from the app object if the entity gets disposed", () => {
        const { hideable, pm } = makeTestRig();
        const appObj = hideable.appObject;
        expect(appObj.hasComponent(Hideable.type)).toEqual(true);
        hideable.dispose();
        expect(appObj.hasComponent(Hideable.type)).toEqual(false);
    });
    it("Checks for changes in the vm", () => {
        const { pm } = makeTestRig();
        expect(pm.vmsAreEqual(true, true)).toEqual(true);
        expect(pm.vmsAreEqual(false, false)).toEqual(true);
        expect(pm.vmsAreEqual(true, false)).toEqual(false);
        expect(pm.vmsAreEqual(false, true)).toEqual(false);
    });
    it("Gets the PM for and ID", () => {
        const { appObjects, pm } = makeTestRig();
        expect(IsHiddenPM.get("obj1", appObjects)).toEqual(pm);
    });
    it("Returns undefined for an unknownID", () => {
        const { appObjects } = makeTestRig();
        expect(IsHiddenPM.get("Unknown", appObjects)).toBeUndefined();
    });
    it("Returns undefined for an app object without a PM", () => {
        const { appObjects } = makeTestRig();
        appObjects.getOrCreate("newObj");
        expect(IsHiddenPM.get("newObj", appObjects)).toBeUndefined();
    });
});
//# sourceMappingURL=IsHiddenPM.test.js.map