"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@vived/core");
const Entities_1 = require("../Entities");
const IsTransparentPM_1 = require("./IsTransparentPM");
function makeTestRig() {
    const appObjects = (0, core_1.makeAppObjectRepo)();
    const appObj = (0, core_1.makeAppObject)("obj1", appObjects);
    const transparency = new Entities_1.Transparency(appObj);
    transparency.isTransparent = true;
    const view = jest.fn();
    const pm = (0, IsTransparentPM_1.makeIsTransparentPM)(appObj);
    return { appObjects, transparency, pm, view };
}
describe("Is transparent 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, transparency } = makeTestRig();
        const spy = jest.spyOn(pm, "doUpdateView");
        transparency.isTransparent = false;
        expect(spy).toHaveBeenCalledWith(false);
    });
    it("Can be disposed", () => {
        const { pm, transparency } = makeTestRig();
        pm.dispose();
        const spy = jest.spyOn(pm, "doUpdateView");
        transparency.isTransparent = false;
        expect(spy).not.toHaveBeenCalled();
    });
    it("Is removed from the app object if the entity gets disposed", () => {
        const { transparency, pm } = makeTestRig();
        const appObj = transparency.appObject;
        expect(appObj.hasComponent(Entities_1.Transparency.type)).toEqual(true);
        transparency.dispose();
        expect(appObj.hasComponent(Entities_1.Transparency.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(IsTransparentPM_1.IsTransparentPM.get("obj1", appObjects)).toEqual(pm);
    });
    it("Returns undefined for an unknownID", () => {
        const { appObjects } = makeTestRig();
        expect(IsTransparentPM_1.IsTransparentPM.get("Unknown", appObjects)).toBeUndefined();
    });
    it("Returns undefined for an app object without a PM", () => {
        const { appObjects } = makeTestRig();
        appObjects.getOrCreate("newObj");
        expect(IsTransparentPM_1.IsTransparentPM.get("newObj", appObjects)).toBeUndefined();
    });
});
//# sourceMappingURL=IsTransparentPM.test.js.map