import { makeAppObjectRepo } from "@vived/core";
import { makeBaseAppState } from "../../BaseApp/Entity/BaseAppState";
import { makeQuestionAnswerEntity, makeQuestionEntity } from "../Entities";
import { makeQuestionChallengePM, QuestionChallengePM, SLIDE_TEXT_CANNOT_BE_FALSY, } from "./QuestionChallengePM";
function makeTestRig() {
    const appObjects = makeAppObjectRepo();
    const appAo = appObjects.getOrCreate("App");
    const baseAppState = makeBaseAppState(appAo);
    baseAppState.slideText = "Slide Text";
    const questionAO = appObjects.getOrCreate("Question");
    const questionEntity = makeQuestionEntity(questionAO);
    questionEntity.answerFactory = (id) => {
        const index = questionEntity.getAllAnswers().length + 1;
        const ao = appObjects.getOrCreate(id ?? "answer" + index);
        return makeQuestionAnswerEntity(ao);
    };
    const correctAns = questionEntity.createNewAnswer();
    correctAns.isCorrect = true;
    const incorrectAns = questionEntity.createNewAnswer();
    incorrectAns.isCorrect = false;
    const pm = makeQuestionChallengePM(questionAO);
    return {
        pm,
        questionEntity,
        correctAns,
        incorrectAns,
        baseAppState,
        appObjects,
    };
}
describe("Question Challenge Presentation Manager", () => {
    it("Checks for VMs that are equal", () => {
        const { pm } = makeTestRig();
        const vm1 = {
            answerIds: ["id1", "id2"],
            gotItRight: true,
            reviewFeedback: "Some Feedback",
            validationMessage: "validation message",
        };
        const vm2 = { ...vm1 };
        expect(pm.vmsAreEqual(vm1, vm2)).toEqual(true);
    });
    it("Returns false if got it right doesn't match", () => {
        const { pm } = makeTestRig();
        const vm1 = {
            answerIds: ["id1", "id2"],
            gotItRight: true,
            reviewFeedback: "Some Feedback",
            validationMessage: "validation message",
        };
        const vm2 = { ...vm1, gotItRight: !vm1.gotItRight };
        expect(pm.vmsAreEqual(vm1, vm2)).toEqual(false);
    });
    it("Returns false if validation doesn't match", () => {
        const { pm } = makeTestRig();
        const vm1 = {
            answerIds: ["id1", "id2"],
            gotItRight: true,
            reviewFeedback: "Some Feedback",
            validationMessage: "validation message",
        };
        const vm2 = { ...vm1, validationMessage: "nope" };
        expect(pm.vmsAreEqual(vm1, vm2)).toEqual(false);
    });
    it("Returns false if feedback doesn't match", () => {
        const { pm } = makeTestRig();
        const vm1 = {
            answerIds: ["id1", "id2"],
            gotItRight: true,
            reviewFeedback: "Some Feedback",
            validationMessage: "validation message",
        };
        const vm2 = { ...vm1, reviewFeedback: "nope" };
        expect(pm.vmsAreEqual(vm1, vm2)).toEqual(false);
    });
    it("Returns false if the id's don't match", () => {
        const { pm } = makeTestRig();
        const vm1 = {
            answerIds: ["id1", "id2"],
            gotItRight: true,
            reviewFeedback: "Some Feedback",
            validationMessage: "validation message",
        };
        const vm2 = { ...vm1, answerIds: ["id1"] };
        expect(pm.vmsAreEqual(vm1, vm2)).toEqual(false);
        const vm3 = { ...vm1, answerIds: ["id1", "id3"] };
        expect(pm.vmsAreEqual(vm1, vm3)).toEqual(false);
    });
    it("Sets the VM answer list", () => {
        const { pm, correctAns, incorrectAns } = makeTestRig();
        expect(pm.lastVM?.answerIds).toEqual([correctAns.id, incorrectAns.id]);
    });
    it("Sets the is correct from the Entity", () => {
        const { pm, questionEntity } = makeTestRig();
        expect(pm.lastVM?.gotItRight).toEqual(false);
        jest.spyOn(questionEntity, "gotItRight", "get").mockReturnValue(true);
        questionEntity.notifyOnChange();
        expect(pm.lastVM?.gotItRight).toEqual(true);
    });
    it("Sets the validation from the Entity", () => {
        const { pm, questionEntity } = makeTestRig();
        jest
            .spyOn(questionEntity, "validationMessage", "get")
            .mockReturnValue("Some message");
        questionEntity.notifyOnChange();
        expect(pm.lastVM?.validationMessage).toEqual("Some message");
    });
    it("Sets the validation when slide text is empty", () => {
        const { pm, baseAppState } = makeTestRig();
        baseAppState.slideText = "";
        expect(pm.lastVM?.validationMessage).toEqual(SLIDE_TEXT_CANNOT_BE_FALSY);
    });
    it("Gets the PM", () => {
        const { pm, appObjects } = makeTestRig();
        expect(QuestionChallengePM.get(appObjects)).toEqual(pm);
    });
});
//# sourceMappingURL=QuestionChallengePM.test.js.map