import { makeAppObjectRepo } from "@vived/core";
import { makeQuestionAnswerEntity, EMPTY_TEXT_VALIDATION_MESSAGE, MAX_QUESTION_LENGTH, LONG_TEXT_VALIDATION_MESSAGE, MAX_FEEDBACK_LENGTH, LONG_FEEDBACK_VALIDATION_MESSAGE, } from "./QuestionAnswerEntity";
function makeTestRig() {
    const appObject = makeAppObjectRepo().getOrCreate("answer1");
    const answer = 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(EMPTY_TEXT_VALIDATION_MESSAGE);
        for (let index = 0; index < MAX_QUESTION_LENGTH; index++) {
            answer.text += "x";
        }
        expect(answer.textValidationMessage).toBeUndefined();
        answer.text += "x";
        expect(answer.textValidationMessage).toEqual(LONG_TEXT_VALIDATION_MESSAGE);
    });
    it("Validates the feedback", () => {
        const { answer } = makeTestRig();
        for (let index = 0; index < MAX_FEEDBACK_LENGTH; index++) {
            answer.feedbackText += "x";
        }
        expect(answer.feedbackValidationMessage).toBeUndefined();
        answer.feedbackText += "x";
        expect(answer.feedbackValidationMessage).toEqual(LONG_FEEDBACK_VALIDATION_MESSAGE);
    });
});
//# sourceMappingURL=QuestionAnswerEntity.test.js.map