"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@vived/core");
const OverlayColor_1 = require("../Entities/OverlayColor");
const OverlayColorPM_1 = require("./OverlayColorPM");
function makeTestRig() {
    const appObjects = (0, core_1.makeAppObjectRepo)();
    const appObj = (0, core_1.makeAppObject)("obj1", appObjects);
    const overlayColor = new OverlayColor_1.OverlayColor(appObj);
    overlayColor.overlayColor = OverlayColor_1.OverlayColorEnums.PINK;
    const view = jest.fn();
    const pm = (0, OverlayColorPM_1.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(OverlayColor_1.OverlayColorEnums.PINK);
    });
    it("Updates the view when the color changes", () => {
        const { pm, overlayColor } = makeTestRig();
        const spy = jest.spyOn(pm, "doUpdateView");
        overlayColor.overlayColor = OverlayColor_1.OverlayColorEnums.ORANGE;
        expect(spy).toHaveBeenCalledWith(OverlayColor_1.OverlayColorEnums.ORANGE);
    });
    it("Can be disposed", () => {
        const { pm, overlayColor } = makeTestRig();
        pm.dispose();
        const spy = jest.spyOn(pm, "doUpdateView");
        overlayColor.overlayColor = OverlayColor_1.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_1.OverlayColor.type)).toEqual(true);
        overlayColor.dispose();
        expect(appObj.hasComponent(OverlayColor_1.OverlayColor.type)).toEqual(false);
    });
    it("Checks for changes in the vm", () => {
        const { pm } = makeTestRig();
        expect(pm.vmsAreEqual(OverlayColor_1.OverlayColorEnums.PINK, OverlayColor_1.OverlayColorEnums.PINK)).toEqual(true);
        expect(pm.vmsAreEqual(OverlayColor_1.OverlayColorEnums.PINK, OverlayColor_1.OverlayColorEnums.ORANGE)).toEqual(false);
    });
    it("Gets the PM for and ID", () => {
        const { appObjects, pm } = makeTestRig();
        expect(OverlayColorPM_1.OverlayColorPM.getForID("obj1", appObjects)).toEqual(pm);
    });
    it("Returns undefined for an unknownID", () => {
        const { appObjects } = makeTestRig();
        expect(OverlayColorPM_1.OverlayColorPM.getForID("Unknown", appObjects)).toBeUndefined();
    });
    it("Returns undefined for an app object without a PM", () => {
        const { appObjects } = makeTestRig();
        appObjects.getOrCreate("newObj");
        expect(OverlayColorPM_1.OverlayColorPM.getForID("newObj", appObjects)).toBeUndefined();
    });
});
//# sourceMappingURL=OverlayColorPM.test.js.map