"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@vived/core");
const Dispatcher_1 = require("../../Dispatcher");
const MockQuestionAnswerEntity_1 = require("../Mocks/MockQuestionAnswerEntity");
const SetAnswerTextUC_1 = require("./SetAnswerTextUC");
const jest_mock_1 = require("jest-mock");
const SetAnswerTextUndoRedo_1 = require("./SetAnswerTextUndoRedo");
jest.mock("./SetAnswerTextUndoRedo", () => {
    return {
        SetAnswerTextUndoRedo: 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)(SetAnswerTextUndoRedo_1.SetAnswerTextUndoRedo);
    const setAnswerText = (0, SetAnswerTextUC_1.makeSetAnswerTextUC)(ansAO);
    return {
        mockAns,
        setAnswerText,
        appObjects,
        mockDispatch,
        doDispatchMock,
        MockedUndoRedoAction,
    };
}
describe("Set Answer Text use case", () => {
    it("Sets the text", () => {
        const { mockAns, setAnswerText } = makeTestRig();
        mockAns.text = "";
        setAnswerText.setText("Hello World");
        expect(mockAns.text).toEqual("Hello World");
    });
    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, SetAnswerTextUC_1.makeSetAnswerTextUC)(appObjects.getOrCreate("AnotherAO"));
        expect(appObjects.submitWarning).toHaveBeenCalled();
    });
    it("Dispatches if there is a change", () => {
        const { mockAns, setAnswerText, doDispatchMock } = makeTestRig();
        mockAns.text = "";
        setAnswerText.setText("Hello World");
        expect(doDispatchMock).toHaveBeenCalled();
    });
    it("Does not dispatch if there is no change", () => {
        const { mockAns, setAnswerText, doDispatchMock } = makeTestRig();
        mockAns.text = "Hello World";
        setAnswerText.setText("Hello World");
        expect(doDispatchMock).not.toHaveBeenCalled();
    });
    it("Creates an Undo Redo action", () => {
        const { setAnswerText, MockedUndoRedoAction, appObjects, mockAns } = makeTestRig();
        MockedUndoRedoAction.mockClear();
        mockAns.text = "Initial text";
        setAnswerText.setText("Hello World");
        expect(MockedUndoRedoAction).toHaveBeenCalledTimes(1);
        expect(MockedUndoRedoAction).toHaveBeenCalledWith("Initial text", mockAns.id, appObjects);
    });
});
//# sourceMappingURL=SetAnswerTextUC.test.js.map