import { makeAppObjectRepo } from "@vived/core";
import { makeFeatureFlagsEntity } from "../Entity/FeatureFlagEntity";
import { makeFeatureFlagsPM, FeatureFlagsPM } from "./FeatureFlagsPM";
function makeTestRig() {
    const appObjects = makeAppObjectRepo();
    const registerSingletonSpy = jest.spyOn(appObjects, "registerSingleton");
    const ao = appObjects.getOrCreate("Model List");
    const featureFlagsEntity = makeFeatureFlagsEntity(ao);
    const pm = makeFeatureFlagsPM(ao);
    return {
        featureFlagsEntity,
        pm,
        registerSingletonSpy,
        appObjects,
    };
}
describe("Feature Flag List PM", () => {
    it("Gets the PM", () => {
        const { pm, appObjects } = makeTestRig();
        expect(FeatureFlagsPM.get(appObjects)).toEqual(pm);
    });
    it("Registers as the singleton", () => {
        const { pm, registerSingletonSpy } = makeTestRig();
        expect(registerSingletonSpy).toHaveBeenCalledWith(pm);
    });
    it("Checks for equal VMs", () => {
        const { pm } = makeTestRig();
        const vm1 = ["flag1"];
        const vm2 = [...vm1];
        expect(pm.vmsAreEqual(vm1, vm2)).toEqual(true);
    });
    it("Checks for a flag to be added to the vm", () => {
        const { pm } = makeTestRig();
        const vm1 = ["flag1"];
        const vm2 = [...vm1, "flag2"];
        expect(pm.vmsAreEqual(vm1, vm2)).toEqual(false);
    });
    it("Checks for a flag to be removed from the vm", () => {
        const { pm } = makeTestRig();
        const vm1 = ["flag1"];
        const vm2 = [];
        expect(pm.vmsAreEqual(vm1, vm2)).toEqual(false);
    });
    it("Initializes the VM", () => {
        const { pm } = makeTestRig();
        expect(pm.lastVM).not.toBeUndefined();
    });
    it("Checks for a flag to be changed in the vm", () => {
        const { pm } = makeTestRig();
        const vm1 = ["flag1"];
        const vm2 = ["CHANGED"];
        expect(pm.vmsAreEqual(vm1, vm2)).toEqual(false);
    });
    it("Updates the VM when the flags change", () => {
        const { pm, featureFlagsEntity } = makeTestRig();
        featureFlagsEntity.addFlag("flag1");
        expect(pm.lastVM).toEqual(["flag1"]);
        featureFlagsEntity.addFlag("flag2");
        expect(pm.lastVM).toEqual(["flag1", "flag2"]);
    });
});
//# sourceMappingURL=FeatureFlagsPM.test.js.map