"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@vived/core");
const FeatureFlagEntity_1 = require("./FeatureFlagEntity");
function makeTestRig() {
    const appObjects = (0, core_1.makeAppObjectRepo)();
    const registerSingletonSpy = jest.spyOn(appObjects, "registerSingleton");
    const entity = (0, FeatureFlagEntity_1.makeFeatureFlagsEntity)(appObjects.getOrCreate("FeatureFlags"));
    const observer = jest.fn();
    entity.addChangeObserver(observer);
    return { appObjects, registerSingletonSpy, entity, observer };
}
describe("Feature Flags Entity", () => {
    it("Gets the singleton", () => {
        const { appObjects, entity } = makeTestRig();
        expect(FeatureFlagEntity_1.FeatureFlagsEntity.get(appObjects)).toEqual(entity);
    });
    it("Registers the singleton", () => {
        const { entity, registerSingletonSpy } = makeTestRig();
        expect(registerSingletonSpy).toHaveBeenCalledWith(entity);
    });
    it("Adds a flag", () => {
        const { entity } = makeTestRig();
        expect(entity.hasFlag("someFlag")).toEqual(false);
        entity.addFlag("someFlag");
        expect(entity.hasFlag("someFlag")).toEqual(true);
    });
    it("Notifies the first time a flag is added", () => {
        const { entity, observer } = makeTestRig();
        entity.addFlag("someFlag");
        entity.addFlag("someFlag");
        entity.addFlag("someFlag");
        entity.addFlag("someFlag");
        expect(observer).toHaveBeenCalledTimes(1);
    });
    it("Removes a flag", () => {
        const { entity } = makeTestRig();
        entity.addFlag("someFlag");
        expect(entity.hasFlag("someFlag")).toEqual(true);
        entity.removeFlag("someFlag");
        expect(entity.hasFlag("someFlag")).toEqual(false);
    });
    it("Notifies when a flag is removed", () => {
        const { entity, observer } = makeTestRig();
        entity.addFlag("someFlag");
        observer.mockClear();
        entity.removeFlag("someFlag");
        entity.removeFlag("someFlag");
        entity.removeFlag("someFlag");
        entity.removeFlag("someFlag");
        expect(observer).toHaveBeenCalledTimes(1);
    });
    it("Gets the flags", () => {
        const { entity } = makeTestRig();
        entity.addFlag("someFlag");
        expect(entity.flags).toEqual(["someFlag"]);
    });
});
//# sourceMappingURL=FeatureFlagEntity.test.js.map