"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@vived/core");
const Dispatcher_1 = require("../../Dispatcher");
const UndoRedo_1 = require("../../UndoRedo");
const Entities_1 = require("../Entities");
const DeleteAllLandmarksUndoRedo_1 = require("./DeleteAllLandmarksUndoRedo");
function makeTestRig() {
    const appObjects = (0, core_1.makeAppObjectRepo)();
    const appAO = appObjects.getOrCreate("App");
    const mockDispatcher = (0, Dispatcher_1.makeMockDispatchStateChange)(appObjects);
    const doDispatchMock = jest.fn();
    mockDispatcher.doDispatch = doDispatchMock;
    const mockUndo = (0, UndoRedo_1.makeMockUndoRedo)(appObjects);
    const submitActionMock = jest.fn();
    mockUndo.submitAction = submitActionMock;
    const repo1 = (0, Entities_1.makeLandmarkRepoEntity)(appObjects.getOrCreate("repo1"));
    const repo2 = (0, Entities_1.makeLandmarkRepoEntity)(appObjects.getOrCreate("repo2"));
    const landmark1 = repo1.createLandmark("landmark1");
    const landmark2 = repo2.createLandmark("landmark2");
    const deletedLandmarks = [landmark1.data, landmark2.data];
    repo1.deleteLandmark("landmark1");
    repo2.deleteLandmark("landmark2");
    return {
        appObjects,
        mockUndo,
        submitActionMock,
        landmark1,
        landmark2,
        doDispatchMock,
        deletedLandmarks,
        repo1,
        repo2,
    };
}
describe("Delete All Callouts Undo Redo action", () => {
    it("Submits itself to the entity", () => {
        const { submitActionMock, deletedLandmarks, appObjects } = makeTestRig();
        const action = new DeleteAllLandmarksUndoRedo_1.DeleteAllLandmarksUndoRedo(deletedLandmarks, appObjects);
        expect(submitActionMock).toHaveBeenCalledWith(action);
    });
    it("Undo Creates the deleted landmarks", () => {
        const { repo1, repo2, deletedLandmarks, appObjects } = makeTestRig();
        expect(repo1.hasForAppObject("landmark1")).toEqual(false);
        expect(repo2.hasForAppObject("landmark2")).toEqual(false);
        const action = new DeleteAllLandmarksUndoRedo_1.DeleteAllLandmarksUndoRedo(deletedLandmarks, appObjects);
        action.undoAction();
        expect(repo1.hasForAppObject("landmark1")).toEqual(true);
        expect(repo2.hasForAppObject("landmark2")).toEqual(true);
    });
    it("Redo Delete the callouts", () => {
        const { repo1, repo2, deletedLandmarks, appObjects } = makeTestRig();
        const action = new DeleteAllLandmarksUndoRedo_1.DeleteAllLandmarksUndoRedo(deletedLandmarks, appObjects);
        action.undoAction();
        expect(repo1.hasForAppObject("landmark1")).toEqual(true);
        expect(repo2.hasForAppObject("landmark2")).toEqual(true);
        action.redoAction();
        expect(repo1.hasForAppObject("landmark1")).toEqual(false);
        expect(repo2.hasForAppObject("landmark2")).toEqual(false);
    });
    it("Dispatches state changes for both the undo and redo action", () => {
        const { deletedLandmarks, appObjects, doDispatchMock } = makeTestRig();
        const action = new DeleteAllLandmarksUndoRedo_1.DeleteAllLandmarksUndoRedo(deletedLandmarks, appObjects);
        action.undoAction();
        expect(doDispatchMock).toHaveBeenCalledTimes(1);
        action.redoAction();
        expect(doDispatchMock).toHaveBeenCalledTimes(2);
    });
});
//# sourceMappingURL=DeleteAllLandmarksUndoRedo.test.js.map