import { makeAppObjectRepo } from "@vived/core";
import { makeQuestionAnswerEntity } from "../Entities";
import { makeQuestionEntity } from "../Entities/QuestionEntity";
import { makeSetAnswerTextUC } from "../UC/SetAnswerTextUC";
import { setAnswerText } from "./setAnswerText";
function makeTestRig() {
    const appObjects = makeAppObjectRepo();
    const question = appObjects.getOrCreate("Question");
    const questionEntity = makeQuestionEntity(question);
    questionEntity.answerFactory = (id) => {
        const index = questionEntity.getAllAnswers().length + 1;
        const ao = appObjects.getOrCreate(id ?? "answer" + index);
        return makeQuestionAnswerEntity(ao);
    };
    const answer = questionEntity.createNewAnswer();
    const setTextUC = 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");
        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();
        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();
        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();
        setAnswerText(answer.id, "Hello World", appObjects);
        expect(appObjects.submitWarning).toHaveBeenCalled();
    });
});
//# sourceMappingURL=setAnswerText.test.js.map