"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@vived/core");
const MockDispatchStateChange_1 = require("../../Dispatcher/Mocks/MockDispatchStateChange");
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);
    const mockDispatcher = new MockDispatchStateChange_1.MockDispatchStateChange(ao);
    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,
        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, mockDispatcher, landmark } = makeTestRig();
        const action = new DeleteLandmarkUndoRedo_1.DeleteLandmarkUndoRedo(landmark.data, appObjects);
        action.undoAction();
        expect(mockDispatcher.doDispatch).toHaveBeenCalledTimes(1);
        action.redoAction();
        expect(mockDispatcher.doDispatch).toHaveBeenCalledTimes(2);
    });
});
//# sourceMappingURL=DeleteLandmarkUndoRedo.test.js.map