import { makeAppObjectRepo } from "@vived/core";
import { makeMockDispatchStateChange } from "../../Dispatcher";
import { MockUndoRedo } from "../../UndoRedo/Mocks/MockUndoRedo";
import { makeLandmarkRepoEntity } from "../Entities/LandmarkRepo";
import { DeleteLandmarkUndoRedo } from "./DeleteLandmarkUndoRedo";
import { makeLandmarkDTO } from "../Mocks/makeLandmarkDTO";
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 landmarkRepo = makeLandmarkRepoEntity(appObjects.getOrCreate("LandmarkRepo"));
    const landmark = landmarkRepo.createLandmark("landmark1");
    landmark.label.custom = "Custom label";
    landmarkRepo.deleteLandmark("landmark1");
    return {
        mockUndo,
        mockDispatcher,
        doDispatchMock,
        landmarkRepo,
        appObjects,
        landmark,
    };
}
describe("Delete Landmark Undo Redo action", () => {
    it("Submits itself to the entity", () => {
        const { mockUndo, appObjects } = makeTestRig();
        const landmarkDTO = makeLandmarkDTO("landmark1", "LandmarkRepo");
        const action = new DeleteLandmarkUndoRedo(landmarkDTO, appObjects);
        expect(mockUndo.submitAction).toHaveBeenCalledWith(action);
    });
    it("Undo adds the landmark back in", () => {
        const { landmarkRepo, appObjects, landmark } = makeTestRig();
        const action = new DeleteLandmarkUndoRedo(landmark.data, appObjects);
        action.undoAction();
        expect(landmarkRepo.hasForAppObject("landmark1")).toEqual(true);
    });
    it("Redo remvoes added landmark", () => {
        const { landmarkRepo, appObjects, landmark } = makeTestRig();
        const action = new DeleteLandmarkUndoRedo(landmark.data, appObjects);
        action.undoAction();
        action.redoAction();
        expect(landmarkRepo.hasForAppObject("landmark1")).toEqual(false);
    });
    it("Dispatches state changes for both the undo and redo action", () => {
        const { appObjects, doDispatchMock, landmark } = makeTestRig();
        const action = new DeleteLandmarkUndoRedo(landmark.data, appObjects);
        action.undoAction();
        expect(doDispatchMock).toHaveBeenCalledTimes(1);
        action.redoAction();
        expect(doDispatchMock).toHaveBeenCalledTimes(2);
    });
});
//# sourceMappingURL=DeleteLandmarkUndoRedo.test.js.map