"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@vived/core");
const MockQuestionAnswerEntity_1 = require("../Mocks/MockQuestionAnswerEntity");
const Dispatcher_1 = require("../../Dispatcher");
const SetAnswerFeedbackUC_1 = require("./SetAnswerFeedbackUC");
const jest_mock_1 = require("jest-mock");
const SetAnswerFeedbackUndoRedo_1 = require("./SetAnswerFeedbackUndoRedo");
jest.mock("./SetAnswerFeedbackUndoRedo", () => {
    return {
        SetAnswerFeedbackUndoRedo: jest.fn().mockImplementation(() => {
            return;
        }),
    };
});
function makeTestRig() {
    const appObjects = (0, core_1.makeAppObjectRepo)();
    const ansAO = appObjects.getOrCreate("Ans");
    const mockAns = new MockQuestionAnswerEntity_1.MockQuestionAnswerEntity(ansAO);
    const appAO = appObjects.getOrCreate("App");
    const mockDispatch = (0, Dispatcher_1.makeMockDispatchStateChange)(appObjects);
    const doDispatchMock = jest.fn();
    mockDispatch.doDispatch = doDispatchMock;
    const MockedUndoRedoAction = (0, jest_mock_1.mocked)(SetAnswerFeedbackUndoRedo_1.SetAnswerFeedbackUndoRedo);
    const setFeedbackUC = (0, SetAnswerFeedbackUC_1.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();
        (0, SetAnswerFeedbackUC_1.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