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