import { makeAppObjectRepo } from "@vived/core";
import { makeChallengeEntity } from "../Entities/ChallengeEntity";
import { ChallengeMock } from "../Mocks/ChallengeMock";
import { makeSelectedChallengePM, SelectedChallengePM, } from "./SelectedChallengePM";
function makeTestRig() {
    const appObjects = makeAppObjectRepo();
    const registerSingletonSpy = jest.spyOn(appObjects, "registerSingleton");
    const ao = appObjects.getOrCreate("AO");
    const entity = makeChallengeEntity(ao);
    entity.registerChallenge(new ChallengeMock("Challenge1"));
    entity.registerChallenge(new ChallengeMock("Challenge2"));
    entity.registerChallenge(new ChallengeMock("Challenge3"));
    entity.selectedChallenge = "Challenge1";
    const pm = makeSelectedChallengePM(ao);
    return { pm, ao, appObjects, registerSingletonSpy, entity };
}
describe("Selected Challenge PM", () => {
    it("Gets the singleton", () => {
        const { appObjects, pm } = makeTestRig();
        expect(SelectedChallengePM.get(appObjects)).toEqual(pm);
    });
    it("Register the singleton", () => {
        const { registerSingletonSpy, pm } = makeTestRig();
        expect(registerSingletonSpy).toHaveBeenCalledWith(pm);
    });
    it("Checks for equal VMs", () => {
        const { pm } = makeTestRig();
        const vm1 = {
            selectedChallenge: "Challenge1",
            options: [
                { value: "Challenge1", label: "One" },
                { value: "Challenge2", label: "Two" },
            ],
        };
        const vm2 = { ...vm1 };
        expect(pm.vmsAreEqual(vm1, vm2)).toEqual(true);
    });
    it("Checks for a change in the challenge", () => {
        const { pm } = makeTestRig();
        const vm1 = {
            selectedChallenge: "Challenge1",
            options: [
                { value: "Challenge1", label: "One" },
                { value: "Challenge2", label: "Two" },
            ],
        };
        const vm2 = { ...vm1, selectedChallenge: "NONE" };
        expect(pm.vmsAreEqual(vm1, vm2)).toEqual(false);
    });
    it("Checks for an option to be removed", () => {
        const { pm } = makeTestRig();
        const vm1 = {
            selectedChallenge: "Challenge1",
            options: [
                { value: "Challenge1", label: "One" },
                { value: "Challenge2", label: "Two" },
            ],
        };
        const vm2 = { ...vm1, options: [{ value: "Challenge1", label: "One" }] };
        expect(pm.vmsAreEqual(vm1, vm2)).toEqual(false);
    });
    it("Checks for an option to be added", () => {
        const { pm } = makeTestRig();
        const vm1 = {
            selectedChallenge: "Challenge1",
            options: [
                { value: "Challenge1", label: "One" },
                { value: "Challenge2", label: "Two" },
            ],
        };
        const vm2 = {
            ...vm1,
            options: [
                { value: "Challenge1", label: "One" },
                { value: "Challenge2", label: "Two" },
                { value: "Challenge3", label: "Three" },
            ],
        };
        expect(pm.vmsAreEqual(vm1, vm2)).toEqual(false);
    });
    it("Checks for an option label to be change", () => {
        const { pm } = makeTestRig();
        const vm1 = {
            selectedChallenge: "Challenge1",
            options: [
                { value: "Challenge1", label: "One" },
                { value: "Challenge2", label: "Two" },
            ],
        };
        const vm2 = {
            ...vm1,
            options: [
                { value: "Challenge1", label: "One" },
                { value: "Challenge2", label: "Three" },
            ],
        };
        expect(pm.vmsAreEqual(vm1, vm2)).toEqual(false);
    });
    it("Checks for an option value to be change", () => {
        const { pm } = makeTestRig();
        const vm1 = {
            selectedChallenge: "Challenge1",
            options: [
                { value: "Challenge1", label: "One" },
                { value: "Challenge2", label: "Two" },
            ],
        };
        const vm2 = {
            ...vm1,
            options: [
                { value: "Challenge1", label: "One" },
                { value: "Challenge3", label: "Two" },
            ],
        };
        expect(pm.vmsAreEqual(vm1, vm2)).toEqual(false);
    });
    it("Initialize the VM", () => {
        const { pm } = makeTestRig();
        expect(pm.lastVM).not.toBeUndefined();
    });
    it("Sets up the challenge from the entity", () => {
        const { pm } = makeTestRig();
        const lastVM = pm.lastVM;
        expect(lastVM.selectedChallenge).toEqual("Challenge1");
    });
    it("Updates when the Entity changes", () => {
        const { pm, entity } = makeTestRig();
        expect(entity.selectedChallenge).toEqual("Challenge1");
        entity.selectedChallenge = "Challenge2";
        const lastVM = pm.lastVM;
        expect(lastVM.selectedChallenge).toEqual("Challenge2");
    });
    it("Sets up the options", () => {
        const { pm } = makeTestRig();
        const lastVM = pm.lastVM;
        expect(lastVM.options).toEqual([
            { value: "NONE", label: "None" },
            { value: "Challenge1", label: "Challenge1 Name" },
            { value: "Challenge2", label: "Challenge2 Name" },
            { value: "Challenge3", label: "Challenge3 Name" },
        ]);
    });
});
//# sourceMappingURL=SelectedChallengePM.test.js.map