import { makeAppObjectRepo } from "@vived/core";
import { MockQuestionAnswerEntity } from "../Mocks/MockQuestionAnswerEntity";
import { makeMockDispatchStateChange } from "../../Dispatcher";
import { makeSetAnswerFeedbackUC } from "./SetAnswerFeedbackUC";
import { mocked } from "jest-mock";
import { SetAnswerFeedbackUndoRedo } from "./SetAnswerFeedbackUndoRedo";
jest.mock("./SetAnswerFeedbackUndoRedo", () => {
    return {
        SetAnswerFeedbackUndoRedo: jest.fn().mockImplementation(() => {
            return;
        }),
    };
});
function makeTestRig() {
    const appObjects = makeAppObjectRepo();
    const ansAO = appObjects.getOrCreate("Ans");
    const mockAns = new MockQuestionAnswerEntity(ansAO);
    const appAO = appObjects.getOrCreate("App");
    const mockDispatch = makeMockDispatchStateChange(appObjects);
    const doDispatchMock = jest.fn();
    mockDispatch.doDispatch = doDispatchMock;
    const MockedUndoRedoAction = mocked(SetAnswerFeedbackUndoRedo);
    const setFeedbackUC = makeSetAnswerFeedbackUC(ansAO);
    return {
        mockAns,
        setFeedbackUC,
        appObjects,
        mockDispatch,
        doDispatchMock,
        MockedUndoRedoAction,
    };
}
describe("Set Answer Feedback use case", () => {
    it("Sets the Feedback", () => {
        const { mockAns, setFeedbackUC } = makeTestRig();
        mockAns.feedbackText = "";
        setFeedbackUC.setFeedback("Hello World");
        expect(mockAns.feedbackText).toEqual("Hello World");
    });
    it("Dispatches if there is a change", () => {
        const { mockAns, setFeedbackUC, doDispatchMock } = makeTestRig();
        mockAns.feedbackText = "";
        setFeedbackUC.setFeedback("Hello World");
        expect(doDispatchMock).toHaveBeenCalled();
    });
    it("Does not dispatch if there is no change", () => {
        const { mockAns, setFeedbackUC, doDispatchMock } = makeTestRig();
        mockAns.feedbackText = "Hello World";
        setFeedbackUC.setFeedback("Hello World");
        expect(doDispatchMock).not.toHaveBeenCalled();
    });
    it("Warns if it is added to an App Object that does not have an Answer Entity", () => {
        const { appObjects } = makeTestRig();
        appObjects.submitWarning = jest.fn();
        makeSetAnswerFeedbackUC(appObjects.getOrCreate("AnotherAO"));
        expect(appObjects.submitWarning).toHaveBeenCalled();
    });
    it("Creates an Undo Redo action", () => {
        const { setFeedbackUC, MockedUndoRedoAction, appObjects, mockAns } = makeTestRig();
        MockedUndoRedoAction.mockClear();
        mockAns.feedbackText = "Initial feedback";
        setFeedbackUC.setFeedback("Hello World");
        expect(MockedUndoRedoAction).toHaveBeenCalledTimes(1);
        expect(MockedUndoRedoAction).toHaveBeenCalledWith("Initial feedback", mockAns.id, appObjects);
    });
});
//# sourceMappingURL=SetAnswerFeedbackUC.test.js.map