"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@vived/core");
const Entities_1 = require("../Entities");
const QuestionEntity_1 = require("../Entities/QuestionEntity");
const SetAnswerTextUC_1 = require("../UC/SetAnswerTextUC");
const setAnswerText_1 = require("./setAnswerText");
function makeTestRig() {
    const appObjects = (0, core_1.makeAppObjectRepo)();
    const question = appObjects.getOrCreate("Question");
    const questionEntity = (0, QuestionEntity_1.makeQuestionEntity)(question);
    questionEntity.answerFactory = (id) => {
        const index = questionEntity.getAllAnswers().length + 1;
        const ao = appObjects.getOrCreate(id ?? "answer" + index);
        return (0, Entities_1.makeQuestionAnswerEntity)(ao);
    };
    const answer = questionEntity.createNewAnswer();
    const setTextUC = (0, SetAnswerTextUC_1.makeSetAnswerTextUC)(answer.appObject);
    answer.feedbackText = "Hello World";
    return { questionEntity, answer, setTextUC, appObjects };
}
describe("setAnswerText Controller", () => {
    it("Sends the feedback to the UC", () => {
        const { answer, setTextUC, appObjects } = makeTestRig();
        const spy = jest.spyOn(setTextUC, "setText");
        (0, setAnswerText_1.setAnswerText)(answer.id, "Hello World", appObjects);
        expect(spy).toHaveBeenCalledWith("Hello World");
    });
    it("Warns if it can't find the Question Entity", () => {
        const { questionEntity, appObjects, answer } = makeTestRig();
        questionEntity.dispose();
        appObjects.submitWarning = jest.fn();
        (0, setAnswerText_1.setAnswerText)(answer.id, "Hello World", appObjects);
        expect(appObjects.submitWarning).toHaveBeenCalled();
    });
    it("Warns if it can't find the Answer Entity", () => {
        const { appObjects } = makeTestRig();
        appObjects.submitWarning = jest.fn();
        (0, setAnswerText_1.setAnswerText)("some id", "Hello World", appObjects);
        expect(appObjects.submitWarning).toHaveBeenCalled();
    });
    it("Warns if it can't find the UC", () => {
        const { appObjects, setTextUC, answer } = makeTestRig();
        setTextUC.dispose();
        appObjects.submitWarning = jest.fn();
        (0, setAnswerText_1.setAnswerText)(answer.id, "Hello World", appObjects);
        expect(appObjects.submitWarning).toHaveBeenCalled();
    });
});
//# sourceMappingURL=setAnswerText.test.js.map