import { makeAppObjectRepo } from "@vived/core";
import { makeMockDispatchStateChange } from "../../Dispatcher";
import { MockUndoRedo } from "../../UndoRedo/Mocks/MockUndoRedo";
import { makeCalloutEntity } from "../Entities/CalloutEntity";
import { SetCalloutSizeUndoRedo, } from "./SetCalloutSizeUndoRedo";
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 callout = makeCalloutEntity(appObjects.getOrCreate("Landmark1"));
    return { callout, mockUndo, mockDispatcher, doDispatchMock, appObjects };
}
describe("Set Callout Undo Redo action", () => {
    it("Submits itself to the entity", () => {
        const { mockUndo, callout, appObjects } = makeTestRig();
        const undoData = {
            callout,
            undoSize: 0.8,
            redoSize: 1.1,
        };
        const action = new SetCalloutSizeUndoRedo(undoData, appObjects);
        expect(mockUndo.submitAction).toHaveBeenCalledWith(action);
    });
    it("Undo the size change", () => {
        const { appObjects, callout } = makeTestRig();
        callout.size = 1;
        const undoData = {
            callout,
            undoSize: 0.8,
            redoSize: 1.1,
        };
        const action = new SetCalloutSizeUndoRedo(undoData, appObjects);
        action.undoAction();
        expect(callout.size).toEqual(0.8);
    });
    it("Redo the size change", () => {
        const { appObjects, callout } = makeTestRig();
        callout.size = 1;
        const undoData = {
            callout,
            undoSize: 0.8,
            redoSize: 1.1,
        };
        const action = new SetCalloutSizeUndoRedo(undoData, appObjects);
        action.redoAction();
        expect(callout.size).toEqual(1.1);
    });
    it("Dispatches state changes for both the undo and redo action", () => {
        const { callout, appObjects, doDispatchMock } = makeTestRig();
        const undoData = {
            callout,
            undoSize: 0.8,
            redoSize: 1.1,
        };
        const action = new SetCalloutSizeUndoRedo(undoData, appObjects);
        action.undoAction();
        expect(doDispatchMock).toHaveBeenCalledTimes(1);
        action.redoAction();
        expect(doDispatchMock).toHaveBeenCalledTimes(2);
    });
});
//# sourceMappingURL=SetCalloutSizeUndoRedo.test.js.map