import { makeAppObjectRepo } from "@vived/core";
import { Angle, Quaternion, Vector3 } from "@vived/core";
import { makeMockDispatchStateChange } from "../../Dispatcher";
import { OverlayColorEnums } from "../../OverlayColor";
import { MockUndoRedo } from "../../UndoRedo/Mocks/MockUndoRedo";
import { makeLandmarkRepoEntity } from "../Entities/LandmarkRepo";
import { AddLandmarkUndoRedo } from "./AddLandmarkUndoRedo";
const landmarkRepoID = "landmarkRepo";
function makeDto(id, parentID) {
    const q = Quaternion.FromYawPitchRoll(Angle.FromDegrees(10), Angle.FromDegrees(20), Angle.FromDegrees(30));
    const dto = {
        id,
        position: new Vector3(1, 2, 3).dto,
        size: 5,
        parentID,
        rotation: q.dto,
        label: "Callout Label",
        defaultLabel: "Custom Label",
        color: OverlayColorEnums.BLUE,
    };
    return dto;
}
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 landmarkRepoAO = appObjects.getOrCreate(landmarkRepoID);
    const landmarkRepo = 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(landmarkDTO, appObjects);
        expect(mockUndo.submitAction).toHaveBeenCalledWith(action);
    });
    it("Undo removes the landmark", () => {
        const { landmarkRepo, landmark, appObjects } = makeTestRig();
        const action = new 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(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(landmark.data, appObjects);
        action.undoAction();
        expect(doDispatchMock).toHaveBeenCalledTimes(1);
        action.redoAction();
        expect(doDispatchMock).toHaveBeenCalledTimes(2);
    });
});
//# sourceMappingURL=AddLandmarkUndoRedo.test.js.map