"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@vived/core");
const Hideable_1 = require("./Hideable");
function makeTestRig() {
    const appObjects = (0, core_1.makeAppObjectRepo)();
    const appObj = (0, core_1.makeAppObject)("appID", appObjects);
    const hideable = new Hideable_1.Hideable(appObj);
    const observer = jest.fn();
    hideable.addChangeObserver(observer);
    return { hideable, observer, appObj, appObjects };
}
describe("Hideable Entity", () => {
    it("Adds itself to the App Object", () => {
        const { hideable, appObj } = makeTestRig();
        expect(appObj.hasComponent(Hideable_1.Hideable.type)).toEqual(true);
        expect(appObj.getComponent(Hideable_1.Hideable.type)).toEqual(hideable);
    });
    it("Removes itself from the App Object when disposed", () => {
        const { hideable, appObj } = makeTestRig();
        hideable.dispose();
        expect(appObj.hasComponent(Hideable_1.Hideable.type)).toEqual(false);
    });
    it("Notifies when the is hidden changes", () => {
        const { hideable, observer } = makeTestRig();
        expect(hideable.isHidden).toEqual(false);
        hideable.isHidden = true;
        hideable.isHidden = true;
        hideable.isHidden = true;
        expect(observer).toHaveBeenCalledTimes(1);
        expect(hideable.isHidden).toEqual(true);
    });
    it("Gets the entity from an AO", () => {
        const { hideable, appObjects } = makeTestRig();
        expect(Hideable_1.Hideable.get("appID", appObjects)).toEqual(hideable);
    });
    it("Returns the existing when calling add if missing ", () => {
        const { hideable, appObj } = makeTestRig();
        expect(Hideable_1.Hideable.addIfMissing(appObj)).toEqual(hideable);
    });
    it("Creates a new one if addIfMissing is called", () => {
        const { appObjects } = makeTestRig();
        const newAO = appObjects.getOrCreate("anotherAO");
        expect(newAO.hasComponent(Hideable_1.Hideable.type)).toEqual(false);
        Hideable_1.Hideable.addIfMissing(newAO);
        expect(newAO.hasComponent(Hideable_1.Hideable.type)).toEqual(true);
    });
    it("Has a property called ignoreSerialization that can be set", () => {
        const { hideable } = makeTestRig();
        expect(hideable.ignoreSerialization).toEqual(false);
        hideable.ignoreSerialization = true;
        expect(hideable.ignoreSerialization).toEqual(true);
    });
});
//# sourceMappingURL=Hideable.test.js.map