import { makeAppObjectRepo } from "@vived/core";
import { makeBaseAppState } from "../../BaseApp/Entity/BaseAppState";
import { SubmitResultResultUC, } from "../../Dispatcher";
import { makeQuestionAnswerEntity, makeQuestionEntity } from "../Entities";
import { makeSubmitQuestionAnswerUC } from "./SubmitQuestionAnswerUC";
class MockSubmitResult extends SubmitResultResultUC {
    constructor() {
        super(...arguments);
        this.submitHitResult = jest.fn();
    }
    submitProgressResult(data) {
        throw new Error("Method not implemented.");
    }
    submitMultiHitResult(data) {
        throw new Error("Method not implemented.");
    }
    submitQualityResult(data) {
        throw new Error("Method not implemented.");
    }
    submitScoreResult(data) {
        throw new Error("Method not implemented.");
    }
}
function makeTestRig() {
    const appObjects = makeAppObjectRepo();
    const app = appObjects.getOrCreate("app");
    const baseApp = makeBaseAppState(app);
    const mockSubmit = new MockSubmitResult(app, SubmitResultResultUC.type);
    const questionAO = appObjects.getOrCreate("Question");
    const questionEnt = makeQuestionEntity(questionAO);
    questionEnt.answerFactory = (id) => {
        const index = questionEnt.getAllAnswers().length + 1;
        const ao = appObjects.getOrCreate(id ?? "answer" + index);
        return makeQuestionAnswerEntity(ao);
    };
    const mockAns = questionEnt.createNewAnswer();
    const uc = makeSubmitQuestionAnswerUC(questionAO);
    baseApp.isAuthoring = false;
    baseApp.slideText = "Hello World!";
    baseApp.isReviewing = false;
    const mockSubmitAnswer = jest.fn();
    questionEnt.submitAnswer = mockSubmitAnswer;
    return {
        mockSubmit,
        appObjects,
        mockAns,
        uc,
        baseApp,
        questionEnt,
        mockSubmitAnswer,
    };
}
describe("Submit Question Answer UC", () => {
    it("Submits answer ID", () => {
        const { mockSubmitAnswer, mockAns, uc } = makeTestRig();
        uc.submitAnswer(mockAns.id);
        expect(mockSubmitAnswer).toHaveBeenCalledWith(mockAns.id);
    });
    it("Doesn't submit answer when authoring", () => {
        const { baseApp, uc, mockSubmitAnswer, mockAns } = makeTestRig();
        baseApp.isAuthoring = true;
        uc.submitAnswer(mockAns.id);
        expect(mockSubmitAnswer).not.toHaveBeenCalled();
    });
    it("Warns if the answer ID is not known", () => {
        const { uc } = makeTestRig();
        uc.warn = jest.fn();
        uc.submitAnswer("unknown");
        expect(uc.warn).toHaveBeenCalled();
    });
    it("Warns if it cannot find the base app", () => {
        const { uc, baseApp, mockAns } = makeTestRig();
        uc.warn = jest.fn();
        baseApp.dispose();
        uc.submitAnswer(mockAns.id);
        expect(uc.warn).toHaveBeenCalled();
    });
    it("Dispatches a submitHitResult", () => {
        const { baseApp, questionEnt, mockAns, uc, mockSubmit } = makeTestRig();
        uc.submitAnswer(mockAns.id);
        expect(mockSubmit.submitHitResult).toHaveBeenCalledWith({
            success: questionEnt.gotItRight,
            description: baseApp.slideText,
        });
    });
    it("Sets the baseApp to Review", () => {
        const { baseApp, mockAns, uc } = makeTestRig();
        uc.submitAnswer(mockAns.id);
        expect(baseApp.isReviewing).toEqual(true);
    });
});
//# sourceMappingURL=SubmitQuestionAnswerUC.test.js.map