"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@vived/core");
const Hideable_1 = require("../Entities/Hideable");
const IsHiddenPM_1 = require("./IsHiddenPM");
function makeTestRig() {
    const appObjects = (0, core_1.makeAppObjectRepo)();
    const appObj = (0, core_1.makeAppObject)("obj1", appObjects);
    const hideable = new Hideable_1.Hideable(appObj);
    hideable.isHidden = true;
    const view = jest.fn();
    const pm = (0, IsHiddenPM_1.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_1.Hideable.type)).toEqual(true);
        hideable.dispose();
        expect(appObj.hasComponent(Hideable_1.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_1.IsHiddenPM.get("obj1", appObjects)).toEqual(pm);
    });
    it("Returns undefined for an unknownID", () => {
        const { appObjects } = makeTestRig();
        expect(IsHiddenPM_1.IsHiddenPM.get("Unknown", appObjects)).toBeUndefined();
    });
    it("Returns undefined for an app object without a PM", () => {
        const { appObjects } = makeTestRig();
        appObjects.getOrCreate("newObj");
        expect(IsHiddenPM_1.IsHiddenPM.get("newObj", appObjects)).toBeUndefined();
    });
});
//# sourceMappingURL=IsHiddenPM.test.js.map