import { makeAppObject, makeAppObjectRepo } from "@vived/core";
import { Transparency } from "./Transparency";
function makeTestRig() {
    const appObjects = makeAppObjectRepo();
    const appObj = makeAppObject("appID", appObjects);
    const transparency = new Transparency(appObj);
    const observer = jest.fn();
    transparency.addChangeObserver(observer);
    return { transparency, observer, appObj, appObjects };
}
describe("Transparency Entity", () => {
    it("Adds itself to the App Object", () => {
        const { transparency, appObj } = makeTestRig();
        expect(appObj.hasComponent(Transparency.type)).toEqual(true);
        expect(appObj.getComponent(Transparency.type)).toEqual(transparency);
    });
    it("Removes itself from the App Object when disposed", () => {
        const { transparency, appObj } = makeTestRig();
        transparency.dispose();
        expect(appObj.hasComponent(Transparency.type)).toEqual(false);
    });
    it("Notifies when the is transparent changes", () => {
        const { transparency, observer } = makeTestRig();
        expect(transparency.isTransparent).toEqual(false);
        transparency.isTransparent = true;
        transparency.isTransparent = true;
        transparency.isTransparent = true;
        expect(observer).toHaveBeenCalledTimes(1);
        expect(transparency.isTransparent).toEqual(true);
    });
    it("Gets the entity from an AO", () => {
        const { transparency, appObjects } = makeTestRig();
        expect(Transparency.get("appID", appObjects)).toEqual(transparency);
    });
    it("Returns the existing when calling add if missing ", () => {
        const { transparency, appObj } = makeTestRig();
        expect(Transparency.addIfMissing(appObj)).toEqual(transparency);
    });
    it("Creates a new one if addIfMissing is called", () => {
        const { appObjects } = makeTestRig();
        const newAO = appObjects.getOrCreate("anotherAO");
        expect(newAO.hasComponent(Transparency.type)).toEqual(false);
        Transparency.addIfMissing(newAO);
        expect(newAO.hasComponent(Transparency.type)).toEqual(true);
    });
});
//# sourceMappingURL=Transparency.test.js.map