import { makeAppObjectRepo } from "@vived/core";
import { Angle, Quaternion, Vector3 } from "@vived/core";
import { makeMockDispatchStateChange } from "../../Dispatcher";
import { MockUndoRedo } from "../../UndoRedo/Mocks/MockUndoRedo";
import { makeTransform3D } from "../Entities";
import { MoveTransformUndoRedo, } from "./MoveTransformUndoRedo";
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 transform = makeTransform3D(ao);
    return { mockUndo, mockDispatcher, doDispatchMock, transform, appObjects };
}
describe("Stylus Move Undo Redo action", () => {
    it("Submits itself to the entity", () => {
        const { mockUndo, appObjects, transform } = makeTestRig();
        const dto = {
            startPosition: new Vector3(-1, -2, -3),
            endPosition: new Vector3(1, 2, 3),
            startRotation: Quaternion.FromEuler(Angle.FromDegrees(-10), Angle.FromDegrees(-20), Angle.FromDegrees(-30)),
            endRotation: Quaternion.FromEuler(Angle.FromDegrees(10), Angle.FromDegrees(20), Angle.FromDegrees(30)),
        };
        const action = new MoveTransformUndoRedo(dto, transform, appObjects);
        expect(mockUndo.submitAction).toHaveBeenCalledWith(action);
    });
    it("Does not submits itself to the entity if there is no change", () => {
        const { mockUndo, appObjects, transform } = makeTestRig();
        const dto = {
            startPosition: new Vector3(-1, -2, -3),
            endPosition: new Vector3(-1, -2, -3),
            startRotation: Quaternion.FromEuler(Angle.FromDegrees(-10), Angle.FromDegrees(-20), Angle.FromDegrees(-30)),
            endRotation: Quaternion.FromEuler(Angle.FromDegrees(-10), Angle.FromDegrees(-20), Angle.FromDegrees(-30)),
        };
        expect(mockUndo.submitAction).not.toHaveBeenCalled();
    });
    it("Undo moves it to the start position and rotation", () => {
        const { appObjects, transform } = makeTestRig();
        const dto = {
            startPosition: new Vector3(-1, -2, -3),
            endPosition: new Vector3(1, 2, 3),
            startRotation: Quaternion.FromEuler(Angle.FromDegrees(-10), Angle.FromDegrees(-20), Angle.FromDegrees(-30)),
            endRotation: Quaternion.FromEuler(Angle.FromDegrees(10), Angle.FromDegrees(20), Angle.FromDegrees(30)),
        };
        const action = new MoveTransformUndoRedo(dto, transform, appObjects);
        action.undoAction();
        expect(transform.localPosition).toEqual(dto.startPosition);
        expect(Quaternion.Close(transform.localRotation, dto.startRotation)).toEqual(true);
    });
    it("Redo moves it to the end position and rotation", () => {
        const { appObjects, transform } = makeTestRig();
        const dto = {
            startPosition: new Vector3(-1, -2, -3),
            endPosition: new Vector3(1, 2, 3),
            startRotation: Quaternion.FromEuler(Angle.FromDegrees(-10), Angle.FromDegrees(-20), Angle.FromDegrees(-30)),
            endRotation: Quaternion.FromEuler(Angle.FromDegrees(10), Angle.FromDegrees(20), Angle.FromDegrees(30)),
        };
        const action = new MoveTransformUndoRedo(dto, transform, appObjects);
        action.redoAction();
        expect(transform.localPosition).toEqual(dto.endPosition);
        expect(Quaternion.Close(transform.localRotation, dto.endRotation)).toEqual(true);
    });
    it("Dispatches state changes for both the undo and redo action", () => {
        const { appObjects, transform, doDispatchMock } = makeTestRig();
        const dto = {
            startPosition: new Vector3(-1, -2, -3),
            endPosition: new Vector3(1, 2, 3),
            startRotation: Quaternion.FromEuler(Angle.FromDegrees(-10), Angle.FromDegrees(-20), Angle.FromDegrees(-30)),
            endRotation: Quaternion.FromEuler(Angle.FromDegrees(10), Angle.FromDegrees(20), Angle.FromDegrees(30)),
        };
        const action = new MoveTransformUndoRedo(dto, transform, appObjects);
        action.undoAction();
        expect(doDispatchMock).toHaveBeenCalledTimes(1);
        action.redoAction();
        expect(doDispatchMock).toHaveBeenCalledTimes(2);
    });
});
//# sourceMappingURL=MoveTransformUndoRedo.test.js.map