import { makeAppObjectRepo } from "@vived/core";
import { makeChallengeEntity } from "../Entities/ChallengeEntity";
import { ChallengeMock } from "../Mocks/ChallengeMock";
import { ChallengeAuthorHelpPM, makeChallengeAuthorHelpPM, } from "./ChallengeAuthorHelpPM";
function makeTestRig() {
    const appObjects = makeAppObjectRepo();
    const registerSingletonSpy = jest.spyOn(appObjects, "registerSingleton");
    const ao = appObjects.getOrCreate("AppAO");
    const challengeEntity = makeChallengeEntity(ao);
    const mockChallenge = new ChallengeMock("MOCK_CHALLENGE");
    challengeEntity.registerChallenge(mockChallenge);
    const pm = makeChallengeAuthorHelpPM(ao);
    return {
        appObjects,
        pm,
        challengeEntity,
        registerSingletonSpy,
        mockChallenge,
    };
}
describe("ChallengeHelpAccordion Presentation Manager", () => {
    it("Gets the singleton", () => {
        const { appObjects, pm } = makeTestRig();
        expect(ChallengeAuthorHelpPM.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("Sets the vm heading", () => {
        const { pm, challengeEntity, mockChallenge } = makeTestRig();
        expect(pm.lastVM?.heading).toEqual("None");
        challengeEntity.selectedChallenge = "MOCK_CHALLENGE";
        expect(pm.lastVM?.heading).toEqual(mockChallenge.name);
    });
    it("Sets the vm text", () => {
        const { pm, challengeEntity, mockChallenge } = makeTestRig();
        expect(pm.lastVM?.text).toEqual("");
        challengeEntity.selectedChallenge = "MOCK_CHALLENGE";
        expect(pm.lastVM?.text).toEqual(mockChallenge.authorHelpText);
    });
    it("Checks for equal VMs", () => {
        const { pm } = makeTestRig();
        const vm1 = {
            heading: "hello world",
            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",
            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",
            text: "Some text",
        };
        const vm2 = { ...vm1, text: "Something else" };
        expect(pm.vmsAreEqual(vm1, vm2)).toEqual(false);
    });
});
//# sourceMappingURL=ChallengeAuthorHelpPM.test.js.map