"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 MockUndoRedo_1 = require("../../UndoRedo/Mocks/MockUndoRedo");
const Entities_1 = require("../Entities");
const MoveTransformUndoRedo_1 = require("./MoveTransformUndoRedo");
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 transform = (0, Entities_1.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 core_2.Vector3(-1, -2, -3),
            endPosition: new core_2.Vector3(1, 2, 3),
            startRotation: core_2.Quaternion.FromEuler(core_2.Angle.FromDegrees(-10), core_2.Angle.FromDegrees(-20), core_2.Angle.FromDegrees(-30)),
            endRotation: core_2.Quaternion.FromEuler(core_2.Angle.FromDegrees(10), core_2.Angle.FromDegrees(20), core_2.Angle.FromDegrees(30)),
        };
        const action = new MoveTransformUndoRedo_1.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 core_2.Vector3(-1, -2, -3),
            endPosition: new core_2.Vector3(-1, -2, -3),
            startRotation: core_2.Quaternion.FromEuler(core_2.Angle.FromDegrees(-10), core_2.Angle.FromDegrees(-20), core_2.Angle.FromDegrees(-30)),
            endRotation: core_2.Quaternion.FromEuler(core_2.Angle.FromDegrees(-10), core_2.Angle.FromDegrees(-20), core_2.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 core_2.Vector3(-1, -2, -3),
            endPosition: new core_2.Vector3(1, 2, 3),
            startRotation: core_2.Quaternion.FromEuler(core_2.Angle.FromDegrees(-10), core_2.Angle.FromDegrees(-20), core_2.Angle.FromDegrees(-30)),
            endRotation: core_2.Quaternion.FromEuler(core_2.Angle.FromDegrees(10), core_2.Angle.FromDegrees(20), core_2.Angle.FromDegrees(30)),
        };
        const action = new MoveTransformUndoRedo_1.MoveTransformUndoRedo(dto, transform, appObjects);
        action.undoAction();
        expect(transform.localPosition).toEqual(dto.startPosition);
        expect(core_2.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 core_2.Vector3(-1, -2, -3),
            endPosition: new core_2.Vector3(1, 2, 3),
            startRotation: core_2.Quaternion.FromEuler(core_2.Angle.FromDegrees(-10), core_2.Angle.FromDegrees(-20), core_2.Angle.FromDegrees(-30)),
            endRotation: core_2.Quaternion.FromEuler(core_2.Angle.FromDegrees(10), core_2.Angle.FromDegrees(20), core_2.Angle.FromDegrees(30)),
        };
        const action = new MoveTransformUndoRedo_1.MoveTransformUndoRedo(dto, transform, appObjects);
        action.redoAction();
        expect(transform.localPosition).toEqual(dto.endPosition);
        expect(core_2.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 core_2.Vector3(-1, -2, -3),
            endPosition: new core_2.Vector3(1, 2, 3),
            startRotation: core_2.Quaternion.FromEuler(core_2.Angle.FromDegrees(-10), core_2.Angle.FromDegrees(-20), core_2.Angle.FromDegrees(-30)),
            endRotation: core_2.Quaternion.FromEuler(core_2.Angle.FromDegrees(10), core_2.Angle.FromDegrees(20), core_2.Angle.FromDegrees(30)),
        };
        const action = new MoveTransformUndoRedo_1.MoveTransformUndoRedo(dto, transform, appObjects);
        action.undoAction();
        expect(doDispatchMock).toHaveBeenCalledTimes(1);
        action.redoAction();
        expect(doDispatchMock).toHaveBeenCalledTimes(2);
    });
});
//# sourceMappingURL=MoveTransformUndoRedo.test.js.map