"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@vived/core");
const UndoRedoEditSlideText_1 = require("./UndoRedoEditSlideText");
const MockUndoRedo_1 = require("../../UndoRedo/Mocks/MockUndoRedo");
const MockDispatchStateChange_1 = require("../../Dispatcher/Mocks/MockDispatchStateChange");
const BaseAppState_1 = require("../Entity/BaseAppState");
function makeTestRig() {
    const appObjects = (0, core_1.makeAppObjectRepo)();
    const ao = appObjects.getOrCreate("App");
    const mockUndo = new MockUndoRedo_1.MockUndoRedo(ao);
    const mockDispatcher = new MockDispatchStateChange_1.MockDispatchStateChange(ao);
    const baseApp = (0, BaseAppState_1.makeBaseAppState)(ao);
    return { mockUndo, mockDispatcher, 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_1.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_1.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_1.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_1.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, mockDispatcher } = makeTestRig();
        baseApp.slideText = "Final Text";
        const action = new UndoRedoEditSlideText_1.UndoRedoEditSlideText("Initial Text", appObjects);
        action.undoAction();
        expect(mockDispatcher.doDispatch).toHaveBeenCalledTimes(1);
        action.redoAction();
        expect(mockDispatcher.doDispatch).toHaveBeenCalledTimes(2);
    });
});
//# sourceMappingURL=UndoRedoEditSlideText.test.js.map