"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@vived/core");
const BaseAppState_1 = require("../../BaseApp/Entity/BaseAppState");
const ChallengeEntity_1 = require("../Entities/ChallengeEntity");
const ChallengeMock_1 = require("../Mocks/ChallengeMock");
const ChallengeConsumerHelpPM_1 = require("./ChallengeConsumerHelpPM");
function makeTestRig() {
    const appObjects = (0, core_1.makeAppObjectRepo)();
    const registerSingletonSpy = jest.spyOn(appObjects, "registerSingleton");
    const ao = appObjects.getOrCreate("AppAO");
    const baseApp = (0, BaseAppState_1.makeBaseAppState)(ao);
    const challengeEntity = (0, ChallengeEntity_1.makeChallengeEntity)(ao);
    const mockChallenge = new ChallengeMock_1.ChallengeMock("Challenge1");
    challengeEntity.registerChallenge(mockChallenge);
    const pm = (0, ChallengeConsumerHelpPM_1.makeChallengeConsumerHelpPM)(ao);
    return {
        appObjects,
        pm,
        baseApp,
        challengeEntity,
        registerSingletonSpy,
        mockChallenge,
    };
}
describe("ChallengeHelpAccordion Presentation Manager", () => {
    it("Gets the singleton", () => {
        const { appObjects, pm } = makeTestRig();
        expect(ChallengeConsumerHelpPM_1.ChallengeConsumerHelpPM.get(appObjects)).toEqual(pm);
    });
    it("Register the singleton", () => {
        const { registerSingletonSpy, pm } = makeTestRig();
        expect(registerSingletonSpy).toHaveBeenCalledWith(pm);
    });
    it("Initializes the VM", () => {
        const { pm } = makeTestRig();
        expect(pm.lastVM).not.toBeUndefined();
    });
    it("Shows if the challenge has some text", () => {
        const { pm, challengeEntity } = makeTestRig();
        challengeEntity.selectedChallenge = "Challenge1";
        expect(pm.lastVM?.show).toEqual(true);
        challengeEntity.selectedChallenge = "NONE";
        expect(pm.lastVM?.show).toEqual(false);
    });
    it("Does not show if reviewing", () => {
        const { pm, baseApp, challengeEntity } = makeTestRig();
        challengeEntity.selectedChallenge = "Challenge1";
        expect(pm.lastVM?.show).toEqual(true);
        baseApp.isReviewing = true;
        expect(pm.lastVM?.show).toEqual(false);
    });
    it("Checks for equal VMs", () => {
        const { pm } = makeTestRig();
        const vm1 = {
            heading: "hello world",
            show: true,
            text: "Some text",
        };
        const vm2 = { ...vm1 };
        expect(pm.vmsAreEqual(vm1, vm2)).toEqual(true);
    });
    it("Checks for a change in the heading", () => {
        const { pm } = makeTestRig();
        const vm1 = {
            heading: "hello world",
            show: true,
            text: "Some text",
        };
        const vm2 = { ...vm1, heading: "Something else" };
        expect(pm.vmsAreEqual(vm1, vm2)).toEqual(false);
    });
    it("Checks for a change in the text", () => {
        const { pm } = makeTestRig();
        const vm1 = {
            heading: "hello world",
            show: true,
            text: "Some text",
        };
        const vm2 = { ...vm1, text: "Something else" };
        expect(pm.vmsAreEqual(vm1, vm2)).toEqual(false);
    });
    it("Checks for a change in the show flag", () => {
        const { pm } = makeTestRig();
        const vm1 = {
            heading: "hello world",
            show: true,
            text: "Some text",
        };
        const vm2 = { ...vm1, show: false };
        expect(pm.vmsAreEqual(vm1, vm2)).toEqual(false);
    });
});
//# sourceMappingURL=ChallengeConsumerHelpPM.test.js.map