import { makeAppObjectRepo } from "@vived/core";
import { UndoRedoEditSlideText } from "./UndoRedoEditSlideText";
import { MockUndoRedo } from "../../UndoRedo/Mocks/MockUndoRedo";
import { makeMockDispatchStateChange } from "../../Dispatcher";
import { makeBaseAppState } from "../Entity/BaseAppState";
function makeTestRig() {
    const appObjects = makeAppObjectRepo();
    const ao = appObjects.getOrCreate("App");
    const mockUndo = new MockUndoRedo(ao);
    // Override the submitAction with a jest.fn()
    mockUndo.submitAction = jest.fn();
    const mockDispatcher = makeMockDispatchStateChange(appObjects);
    const doDispatchMock = jest.fn();
    mockDispatcher.doDispatch = doDispatchMock;
    const baseApp = makeBaseAppState(ao);
    return { mockUndo, mockDispatcher, doDispatchMock, baseApp, appObjects };
}
describe("Edit slide text Undo Redo action", () => {
    it("Submits itself to the entity", () => {
        const { mockUndo, appObjects, baseApp } = makeTestRig();
        baseApp.slideText = "Final Text";
        const action = new UndoRedoEditSlideText("Initial Text", appObjects);
        expect(mockUndo.submitAction).toHaveBeenCalledWith(action);
    });
    it("Does not submit if there is no change", () => {
        const { mockUndo, appObjects, baseApp } = makeTestRig();
        baseApp.slideText = "Final Text";
        new UndoRedoEditSlideText("Final Text", appObjects);
        expect(mockUndo.submitAction).not.toHaveBeenCalled();
    });
    it("Undo sets the text to the initial text", () => {
        const { appObjects, baseApp } = makeTestRig();
        baseApp.slideText = "Final Text";
        const action = new UndoRedoEditSlideText("Initial Text", appObjects);
        action.undoAction();
        expect(baseApp.slideText).toEqual("Initial Text");
    });
    it("Redo sets the text to the final text", () => {
        const { appObjects, baseApp } = makeTestRig();
        baseApp.slideText = "Final Text";
        const action = new UndoRedoEditSlideText("Initial Text", appObjects);
        action.undoAction();
        action.redoAction();
        expect(baseApp.slideText).toEqual("Final Text");
    });
    it("Dispatches state changes for both the undo and redo action", () => {
        const { appObjects, baseApp, doDispatchMock } = makeTestRig();
        baseApp.slideText = "Final Text";
        const action = new UndoRedoEditSlideText("Initial Text", appObjects);
        action.undoAction();
        expect(doDispatchMock).toHaveBeenCalledTimes(1);
        action.redoAction();
        expect(doDispatchMock).toHaveBeenCalledTimes(2);
    });
});
//# sourceMappingURL=UndoRedoEditSlideText.test.js.map