"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@vived/core");
const QuestionAnswerEntity_1 = require("./QuestionAnswerEntity");
function makeTestRig() {
    const appObject = (0, core_1.makeAppObjectRepo)().getOrCreate("answer1");
    const answer = (0, QuestionAnswerEntity_1.makeQuestionAnswerEntity)(appObject);
    const observer = jest.fn();
    answer.addChangeObserver(observer);
    return { answer, observer };
}
describe("Question Answer Entity", () => {
    it("Sets the ID", () => {
        const { answer } = makeTestRig();
        expect(answer.id).toEqual("answer1");
    });
    it("Notifies when the text changes", () => {
        const { answer, observer } = makeTestRig();
        answer.text = "Some Sweet Text";
        expect(observer).toHaveBeenCalled();
        observer.mockClear();
        answer.text = "Some Sweet Text";
        answer.text = "Some Sweet Text";
        answer.text = "Some Sweet Text";
        expect(observer).not.toHaveBeenCalled();
    });
    it("Notifies when the feedback changes", () => {
        const { answer, observer } = makeTestRig();
        answer.feedbackText = "Some sweet feedback";
        expect(observer).toHaveBeenCalled();
        observer.mockClear();
        answer.feedbackText = "Some sweet feedback";
        answer.feedbackText = "Some sweet feedback";
        answer.feedbackText = "Some sweet feedback";
        expect(observer).not.toHaveBeenCalled();
    });
    it("Notifies when the is correct changes", () => {
        const { answer, observer } = makeTestRig();
        answer.isCorrect = true;
        expect(observer).toHaveBeenCalled();
        observer.mockClear();
        answer.isCorrect = true;
        answer.isCorrect = true;
        answer.isCorrect = true;
        expect(observer).not.toHaveBeenCalled();
    });
    it("Validates the text", () => {
        const { answer } = makeTestRig();
        answer.text = "";
        expect(answer.textValidationMessage).toEqual(QuestionAnswerEntity_1.EMPTY_TEXT_VALIDATION_MESSAGE);
        for (let index = 0; index < QuestionAnswerEntity_1.MAX_QUESTION_LENGTH; index++) {
            answer.text += "x";
        }
        expect(answer.textValidationMessage).toBeUndefined();
        answer.text += "x";
        expect(answer.textValidationMessage).toEqual(QuestionAnswerEntity_1.LONG_TEXT_VALIDATION_MESSAGE);
    });
    it("Validates the feedback", () => {
        const { answer } = makeTestRig();
        for (let index = 0; index < QuestionAnswerEntity_1.MAX_FEEDBACK_LENGTH; index++) {
            answer.feedbackText += "x";
        }
        expect(answer.feedbackValidationMessage).toBeUndefined();
        answer.feedbackText += "x";
        expect(answer.feedbackValidationMessage).toEqual(QuestionAnswerEntity_1.LONG_FEEDBACK_VALIDATION_MESSAGE);
    });
});
//# sourceMappingURL=QuestionAnswerEntity.test.js.map