"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 LandmarkRepo_1 = require("../Entities/LandmarkRepo");
const DeleteLandmarkUndoRedo_1 = require("./DeleteLandmarkUndoRedo");
const makeLandmarkDTO_1 = require("../Mocks/makeLandmarkDTO");
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 landmarkRepo = (0, LandmarkRepo_1.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 = (0, makeLandmarkDTO_1.makeLandmarkDTO)("landmark1", "LandmarkRepo");
        const action = new DeleteLandmarkUndoRedo_1.DeleteLandmarkUndoRedo(landmarkDTO, appObjects);
        expect(mockUndo.submitAction).toHaveBeenCalledWith(action);
    });
    it("Undo adds the landmark back in", () => {
        const { landmarkRepo, appObjects, landmark } = makeTestRig();
        const action = new DeleteLandmarkUndoRedo_1.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_1.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_1.DeleteLandmarkUndoRedo(landmark.data, appObjects);
        action.undoAction();
        expect(doDispatchMock).toHaveBeenCalledTimes(1);
        action.redoAction();
        expect(doDispatchMock).toHaveBeenCalledTimes(2);
    });
});
//# sourceMappingURL=DeleteLandmarkUndoRedo.test.js.map