"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@vived/core");
const QuestionAnswerEntity_1 = require("../Entities/QuestionAnswerEntity");
const QuestionAnswerPM_1 = require("./QuestionAnswerPM");
function makeTestRig() {
    const appObjects = (0, core_1.makeAppObjectRepo)();
    const answerAO = appObjects.getOrCreate("Answer");
    const answer = (0, QuestionAnswerEntity_1.makeQuestionAnswerEntity)(answerAO);
    answer.text = "The answer";
    answer.feedbackText = "Some feedback";
    answer.isCorrect = true;
    const pm = (0, QuestionAnswerPM_1.makeQuestionAnswerPM)(answerAO);
    return { answer, pm, appObjects };
}
describe("Presentation Manager for a Question Answer PM", () => {
    it("Initializes the VM", () => {
        const { pm, answer } = makeTestRig();
        expect(pm.lastVM?.answerText).toEqual(answer.text);
        expect(pm.lastVM?.feedbackText).toEqual(answer.feedbackText);
        expect(pm.lastVM?.isCorrect).toEqual(answer.isCorrect);
    });
    it("Sends the text validation message", () => {
        const { pm, answer } = makeTestRig();
        jest
            .spyOn(answer, "textValidationMessage", "get")
            .mockReturnValue("A Text Validation message");
        answer.notifyOnChange();
        expect(pm.lastVM?.textValidation).toEqual("A Text Validation message");
    });
    it("Sends the feedback validation message", () => {
        const { pm, answer } = makeTestRig();
        jest
            .spyOn(answer, "feedbackValidationMessage", "get")
            .mockReturnValue("A Feedback Validation message");
        answer.notifyOnChange();
        expect(pm.lastVM?.feedbackValidation).toEqual("A Feedback Validation message");
    });
    it("Check for equal VMs", () => {
        const { pm } = makeTestRig();
        const vm1 = {
            answerText: "an answer",
            feedbackText: "some feedback",
            feedbackValidation: "feedback validation",
            isCorrect: true,
            textValidation: "text validation",
        };
        const vm2 = { ...vm1 };
        expect(pm.vmsAreEqual(vm1, vm2)).toEqual(true);
    });
    it("Check for equal answer text", () => {
        const { pm } = makeTestRig();
        const vm1 = {
            answerText: "an answer",
            feedbackText: "some feedback",
            feedbackValidation: "feedback validation",
            isCorrect: true,
            textValidation: "text validation",
        };
        const vm2 = { ...vm1, answerText: "nope" };
        expect(pm.vmsAreEqual(vm1, vm2)).toEqual(false);
    });
    it("Check for equal feedback text", () => {
        const { pm } = makeTestRig();
        const vm1 = {
            answerText: "an answer",
            feedbackText: "some feedback",
            feedbackValidation: "feedback validation",
            isCorrect: true,
            textValidation: "text validation",
        };
        const vm2 = { ...vm1, feedbackText: "nope" };
        expect(pm.vmsAreEqual(vm1, vm2)).toEqual(false);
    });
    it("Check for equal feedback Validation", () => {
        const { pm } = makeTestRig();
        const vm1 = {
            answerText: "an answer",
            feedbackText: "some feedback",
            feedbackValidation: "feedback validation",
            isCorrect: true,
            textValidation: "text validation",
        };
        const vm2 = { ...vm1, feedbackValidation: "nope" };
        expect(pm.vmsAreEqual(vm1, vm2)).toEqual(false);
    });
    it("Check for equal isCorrect", () => {
        const { pm } = makeTestRig();
        const vm1 = {
            answerText: "an answer",
            feedbackText: "some feedback",
            feedbackValidation: "feedback validation",
            isCorrect: true,
            textValidation: "text validation",
        };
        const vm2 = { ...vm1, isCorrect: !vm1.isCorrect };
        expect(pm.vmsAreEqual(vm1, vm2)).toEqual(false);
    });
    it("Check for equal text Validation", () => {
        const { pm } = makeTestRig();
        const vm1 = {
            answerText: "an answer",
            feedbackText: "some feedback",
            feedbackValidation: "feedback validation",
            isCorrect: true,
            textValidation: "text validation",
        };
        const vm2 = { ...vm1, textValidation: "nope" };
        expect(pm.vmsAreEqual(vm1, vm2)).toEqual(false);
    });
});
//# sourceMappingURL=QuestionAnswerPM.test.js.map