"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@vived/core");
const OverlayColor_1 = require("./OverlayColor");
function makeTestRig() {
    const appObjects = (0, core_1.makeAppObjectRepo)();
    const appObj = appObjects.getOrCreate("appObj");
    const color = new OverlayColor_1.OverlayColor(appObj);
    const observer = jest.fn();
    color.addChangeObserver(observer);
    return { appObj, color, observer, appObjects };
}
describe("Overlay Color", () => {
    it("Adds itself to the App Object", () => {
        const { color, appObj } = makeTestRig();
        expect(appObj.hasComponent(OverlayColor_1.OverlayColor.type)).toEqual(true);
        expect(appObj.getComponent(OverlayColor_1.OverlayColor.type)).toEqual(color);
    });
    it("Removes itself from the App Object when disposed", () => {
        const { color, appObj } = makeTestRig();
        color.dispose();
        expect(appObj.hasComponent(OverlayColor_1.OverlayColor.type)).toEqual(false);
    });
    it("Notifies when the color changes", () => {
        const { color, observer } = makeTestRig();
        expect(color.overlayColor).toEqual(OverlayColor_1.OverlayColorEnums.NONE);
        color.overlayColor = OverlayColor_1.OverlayColorEnums.ORANGE;
        color.overlayColor = OverlayColor_1.OverlayColorEnums.ORANGE;
        color.overlayColor = OverlayColor_1.OverlayColorEnums.ORANGE;
        expect(observer).toHaveBeenCalledTimes(1);
        expect(color.overlayColor).toEqual(OverlayColor_1.OverlayColorEnums.ORANGE);
    });
    it("Gets the entity from an AO", () => {
        const { color, appObj } = makeTestRig();
        expect(OverlayColor_1.OverlayColor.get(appObj)).toEqual(color);
    });
    it("Returns the existing when calling add if missing ", () => {
        const { color, appObj } = makeTestRig();
        expect(OverlayColor_1.OverlayColor.addIfMissing(appObj)).toEqual(color);
    });
    it("Creates a new one if addIfMissing is called", () => {
        const { appObjects } = makeTestRig();
        const newAO = appObjects.getOrCreate("anotherAO");
        expect(newAO.hasComponent(OverlayColor_1.OverlayColor.type)).toEqual(false);
        OverlayColor_1.OverlayColor.addIfMissing(newAO);
        expect(newAO.hasComponent(OverlayColor_1.OverlayColor.type)).toEqual(true);
    });
    it("Gets by ID", () => {
        const { appObjects, color } = makeTestRig();
        expect(OverlayColor_1.OverlayColor.getByID("appObj", appObjects)).toEqual(color);
    });
});
//# sourceMappingURL=OverlayColor.test.js.map