"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@vived/core");
const core_2 = require("@vived/core");
const Dispatcher_1 = require("../../Dispatcher");
const OverlayColor_1 = require("../../OverlayColor");
const MockUndoRedo_1 = require("../../UndoRedo/Mocks/MockUndoRedo");
const LandmarkRepo_1 = require("../Entities/LandmarkRepo");
const AddLandmarkUndoRedo_1 = require("./AddLandmarkUndoRedo");
const landmarkRepoID = "landmarkRepo";
function makeDto(id, parentID) {
    const q = core_2.Quaternion.FromYawPitchRoll(core_2.Angle.FromDegrees(10), core_2.Angle.FromDegrees(20), core_2.Angle.FromDegrees(30));
    const dto = {
        id,
        position: new core_2.Vector3(1, 2, 3).dto,
        size: 5,
        parentID,
        rotation: q.dto,
        label: "Callout Label",
        defaultLabel: "Custom Label",
        color: OverlayColor_1.OverlayColorEnums.BLUE,
    };
    return dto;
}
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 landmarkRepoAO = appObjects.getOrCreate(landmarkRepoID);
    const landmarkRepo = (0, LandmarkRepo_1.makeLandmarkRepoEntity)(landmarkRepoAO);
    const landmark = landmarkRepo.createLandmark("landmark1");
    landmark.label.custom = "Custom label";
    landmarkRepo.add(landmark);
    return {
        mockUndo,
        mockDispatcher,
        doDispatchMock,
        landmarkRepo,
        appObjects,
        landmarkRepoAO,
        landmark,
    };
}
describe("Add Landmark Undo Redo action", () => {
    it("Submits itself to the entity", () => {
        const { mockUndo, appObjects } = makeTestRig();
        const landmarkDTO = makeDto("landmark1", landmarkRepoID);
        const action = new AddLandmarkUndoRedo_1.AddLandmarkUndoRedo(landmarkDTO, appObjects);
        expect(mockUndo.submitAction).toHaveBeenCalledWith(action);
    });
    it("Undo removes the landmark", () => {
        const { landmarkRepo, landmark, appObjects } = makeTestRig();
        const action = new AddLandmarkUndoRedo_1.AddLandmarkUndoRedo(landmark.data, appObjects);
        action.undoAction();
        expect(landmarkRepo.hasForAppObject("landmark1")).toEqual(false);
    });
    it("Redo adds the landmark back in", () => {
        const { landmarkRepo, landmarkRepoAO, landmark, appObjects } = makeTestRig();
        const action = new AddLandmarkUndoRedo_1.AddLandmarkUndoRedo(landmark.data, appObjects);
        action.undoAction();
        action.redoAction();
        expect(landmarkRepo.hasForAppObject("landmark1")).toEqual(true);
    });
    it("Dispatches state changes for both the undo and redo action", () => {
        const { appObjects, doDispatchMock, landmark } = makeTestRig();
        const action = new AddLandmarkUndoRedo_1.AddLandmarkUndoRedo(landmark.data, appObjects);
        action.undoAction();
        expect(doDispatchMock).toHaveBeenCalledTimes(1);
        action.redoAction();
        expect(doDispatchMock).toHaveBeenCalledTimes(2);
    });
});
//# sourceMappingURL=AddLandmarkUndoRedo.test.js.map