"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@vived/core");
const Dispatcher_1 = require("../../Dispatcher");
const MockUndoRedo_1 = require("../../UndoRedo/Mocks/MockUndoRedo");
const LandmarkEntity_1 = require("../Entities/LandmarkEntity");
const SetLandmarkSizeUndoRedo_1 = require("./SetLandmarkSizeUndoRedo");
function makeTestRig() {
    const appObjects = (0, core_1.makeAppObjectRepo)();
    const ao = appObjects.getOrCreate("App");
    const mockUndo = new MockUndoRedo_1.MockUndoRedo(ao);
    // Override the submitAction with a jest.fn()
    mockUndo.submitAction = jest.fn();
    const mockDispatcher = (0, Dispatcher_1.makeMockDispatchStateChange)(appObjects);
    const doDispatchMock = jest.fn();
    mockDispatcher.doDispatch = doDispatchMock;
    const landmark = (0, LandmarkEntity_1.makeLandmarkEntity)(appObjects.getOrCreate("Landmark1"));
    return { landmark, mockUndo, mockDispatcher, doDispatchMock, appObjects };
}
describe("SetLandmarkSize Undo Redo action", () => {
    it("Submits itself to the entity", () => {
        const { mockUndo, landmark, appObjects } = makeTestRig();
        const undoData = {
            landmark,
            undoSize: 5,
            redoSize: 3,
        };
        const action = new SetLandmarkSizeUndoRedo_1.SetLandmarkSizeUndoRedo(undoData, appObjects);
        expect(mockUndo.submitAction).toHaveBeenCalledWith(action);
    });
    it("Undo the size change", () => {
        const { appObjects, landmark } = makeTestRig();
        landmark.size = 1;
        const undoData = {
            landmark,
            undoSize: 5,
            redoSize: 3,
        };
        const action = new SetLandmarkSizeUndoRedo_1.SetLandmarkSizeUndoRedo(undoData, appObjects);
        action.undoAction();
        expect(landmark.size).toEqual(5);
    });
    it("Redo the size change", () => {
        const { appObjects, landmark } = makeTestRig();
        landmark.size = 1;
        const undoData = {
            landmark,
            undoSize: 5,
            redoSize: 3,
        };
        const action = new SetLandmarkSizeUndoRedo_1.SetLandmarkSizeUndoRedo(undoData, appObjects);
        action.redoAction();
        expect(landmark.size).toEqual(3);
    });
    it("Dispatches state changes for both the undo and redo action", () => {
        const { landmark, appObjects, doDispatchMock } = makeTestRig();
        const undoData = {
            landmark,
            undoSize: 5,
            redoSize: 3,
        };
        const action = new SetLandmarkSizeUndoRedo_1.SetLandmarkSizeUndoRedo(undoData, appObjects);
        action.undoAction();
        expect(doDispatchMock).toHaveBeenCalledTimes(1);
        action.redoAction();
        expect(doDispatchMock).toHaveBeenCalledTimes(2);
    });
});
//# sourceMappingURL=SetLandmarkSizeUndoRedo.test.js.map