import { makeAppObjectRepo } from "@vived/core";
import { makeBaseAppState } from "../../BaseApp/Entity/BaseAppState";
import { makeQuestionAnswerEntity } from "../Entities";
import { makeQuestionEntity } from "../Entities/QuestionEntity";
import { makeValidateQuestionChallengeStateUC } from "./ValidateQuestionChallengeStateUC";
function makeMockAnwer(appObjects, answerAoId, isCorrect) {
    const ansAo = appObjects.getOrCreate(answerAoId);
    const ans = makeQuestionAnswerEntity(ansAo);
    ans.text = "Text " + answerAoId;
    ans.isCorrect = isCorrect;
    return ans;
}
function makeTestRig() {
    const appObjects = makeAppObjectRepo();
    const appAo = appObjects.getOrCreate("App");
    const baseAppState = makeBaseAppState(appAo);
    const questionEntity = makeQuestionEntity(appAo);
    const validateStateUC = makeValidateQuestionChallengeStateUC(appAo);
    return {
        appObjects,
        baseAppState,
        questionEntity,
        validateStateUC,
    };
}
describe("Validate QuestionChallenge State UC", () => {
    it("Checks to see if there is a slide test", () => {
        const { baseAppState, validateStateUC } = makeTestRig();
        baseAppState.slideText = "";
        expect(validateStateUC.validate()).toEqual(validateStateUC.SLIDE_TEXT_CANNOT_BE_FALSY);
        baseAppState.slideText = "Slide Text";
        expect(validateStateUC.validate()).not.toEqual(validateStateUC.SLIDE_TEXT_CANNOT_BE_FALSY);
    });
    it("Checks to see if there are at least two answers", () => {
        const { appObjects, baseAppState, validateStateUC, questionEntity, } = makeTestRig();
        baseAppState.slideText = "Hello World";
        expect(validateStateUC.validate()).toEqual(validateStateUC.IF_QUESTION_AT_LEAST_TWO_ANSWERS);
        const ans1 = makeMockAnwer(appObjects, "ans1", true);
        questionEntity.addAnswer(ans1);
        expect(validateStateUC.validate()).toEqual(validateStateUC.IF_QUESTION_AT_LEAST_TWO_ANSWERS);
        const ans2 = makeMockAnwer(appObjects, "ans2", false);
        questionEntity.addAnswer(ans2);
        expect(validateStateUC.validate()).toBeUndefined();
    });
    it("Ensures that at least one answer is correct", () => {
        const { appObjects, baseAppState, validateStateUC, questionEntity, } = makeTestRig();
        baseAppState.slideText = "Hello World";
        const ans1 = makeMockAnwer(appObjects, "ans1", false);
        questionEntity.addAnswer(ans1);
        const ans2 = makeMockAnwer(appObjects, "ans2", false);
        questionEntity.addAnswer(ans2);
        expect(validateStateUC.validate()).toEqual(validateStateUC.QUESTION_CHALLENGE_NO_CORRECT_ANSWER);
        ans2.isCorrect = true;
        expect(validateStateUC.validate()).toBeUndefined();
    });
    it("Validates if the answer text is empty", () => {
        const { appObjects, baseAppState, validateStateUC, questionEntity, } = makeTestRig();
        baseAppState.slideText = "Hello World";
        const ans1 = makeMockAnwer(appObjects, "ans1", true);
        ans1.text = "";
        questionEntity.addAnswer(ans1);
        const ans2 = makeMockAnwer(appObjects, "ans2", false);
        questionEntity.addAnswer(ans2);
        expect(validateStateUC.validate()).toEqual(validateStateUC.ANSWER_STRING_CANNOT_BE_0_CHARACTERS);
    });
    it("Validates if the answer text length is longer than 40", () => {
        const { appObjects, baseAppState, validateStateUC, questionEntity, } = makeTestRig();
        baseAppState.slideText = "Hello World";
        const ans1 = makeMockAnwer(appObjects, "ans1", true);
        questionEntity.addAnswer(ans1);
        const ans2 = makeMockAnwer(appObjects, "ans2", false);
        ans2.text = Array(41).fill(0).join("");
        questionEntity.addAnswer(ans2);
        expect(validateStateUC.validate()).toEqual(validateStateUC.ANSWER_STRING_CANNOT_BE_LONGER_THAN_40_CHARACTERS);
    });
    it("Checks to see if all question feedbacks are less than 200 characters", () => {
        const { appObjects, baseAppState, validateStateUC, questionEntity, } = makeTestRig();
        baseAppState.slideText = "Hello World";
        const ans1 = makeMockAnwer(appObjects, "ans1", true);
        questionEntity.addAnswer(ans1);
        const ans2 = makeMockAnwer(appObjects, "ans2", false);
        ans2.feedbackText = Array(201).fill(0).join("");
        questionEntity.addAnswer(ans2);
        expect(validateStateUC.validate()).toEqual(validateStateUC.FEEDBACK_STRING_CANNOT_BE_LONGER_THAN_200_CHARACTERS);
    });
});
//# sourceMappingURL=ValidateQuestionChallengeStateUC.test.js.map