import { makeAppObject, makeAppObjectRepo } from "@vived/core";
import { Transparency } from "../Entities";
import { IsTransparentPM, makeIsTransparentPM } from "./IsTransparentPM";
function makeTestRig() {
    const appObjects = makeAppObjectRepo();
    const appObj = makeAppObject("obj1", appObjects);
    const transparency = new Transparency(appObj);
    transparency.isTransparent = true;
    const view = jest.fn();
    const pm = 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(Transparency.type)).toEqual(true);
        transparency.dispose();
        expect(appObj.hasComponent(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.get("obj1", appObjects)).toEqual(pm);
    });
    it("Returns undefined for an unknownID", () => {
        const { appObjects } = makeTestRig();
        expect(IsTransparentPM.get("Unknown", appObjects)).toBeUndefined();
    });
    it("Returns undefined for an app object without a PM", () => {
        const { appObjects } = makeTestRig();
        appObjects.getOrCreate("newObj");
        expect(IsTransparentPM.get("newObj", appObjects)).toBeUndefined();
    });
});
//# sourceMappingURL=IsTransparentPM.test.js.map