"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Transform3D_1 = require("../Entities/Transform3D");
const core_1 = require("@vived/core");
const Dispatcher_1 = require("../../Dispatcher");
const StylusEntity_1 = require("../../Stylus/Entity/StylusEntity");
const MockUndoRedo_1 = require("../../UndoRedo/Mocks/MockUndoRedo");
const StylusMoveTransformUC_1 = require("./StylusMoveTransformUC");
function makeTestRig() {
    const appObjects = (0, core_1.makeAppObjectRepo)();
    const stylusAO = appObjects.getOrCreate("Stylus");
    const stylus = (0, StylusEntity_1.makeStylusEntity)(stylusAO);
    const ao = appObjects.getOrCreate("App Object");
    const transform = (0, Transform3D_1.makeTransform3D)(ao);
    const stylusRootMovementUC = (0, StylusMoveTransformUC_1.makeStylusMoveTransformUC)(ao);
    const mockDispatch = (0, Dispatcher_1.makeMockDispatchStateChange)(appObjects);
    const doDispatchMock = jest.fn();
    mockDispatch.doDispatch = doDispatchMock;
    const mockUndo = new MockUndoRedo_1.MockUndoRedo(ao);
    // Override the submitAction with a jest.fn()
    mockUndo.submitAction = jest.fn();
    return {
        appObjects,
        stylusRootMovementUC,
        transform,
        mockDispatch,
        doDispatchMock,
        mockUndo,
    };
}
describe("Stylus Root Movement UC", () => {
    it("Dispatches a state change on stop if there was movement", () => {
        const { stylusRootMovementUC, doDispatchMock } = makeTestRig();
        stylusRootMovementUC.initialize();
        stylusRootMovementUC.move();
        stylusRootMovementUC.stop();
        expect(doDispatchMock).toHaveBeenCalled();
    });
    it("Does not Dispatches a state change on stop if there was no movement", () => {
        const { stylusRootMovementUC, doDispatchMock } = makeTestRig();
        stylusRootMovementUC.initialize();
        stylusRootMovementUC.stop();
        expect(doDispatchMock).not.toHaveBeenCalled();
    });
    it("Submits an undo on stop if requested", () => {
        const { stylusRootMovementUC, mockUndo } = makeTestRig();
        stylusRootMovementUC.initialize();
        stylusRootMovementUC.move();
        stylusRootMovementUC.stop(true);
        expect(mockUndo.submitAction).toHaveBeenCalled();
    });
    it("Does not submit an undo on stop if not requested", () => {
        const { stylusRootMovementUC, mockUndo } = makeTestRig();
        stylusRootMovementUC.initialize();
        stylusRootMovementUC.move();
        stylusRootMovementUC.stop();
        expect(mockUndo.submitAction).not.toHaveBeenCalled();
    });
    it("Does not submit an undo on stop if request is false", () => {
        const { stylusRootMovementUC, mockUndo } = makeTestRig();
        stylusRootMovementUC.initialize();
        stylusRootMovementUC.move();
        stylusRootMovementUC.stop(false);
        expect(mockUndo.submitAction).not.toHaveBeenCalled();
    });
    it("Does not submits an undo on stop if there was no movement", () => {
        const { stylusRootMovementUC, mockUndo } = makeTestRig();
        stylusRootMovementUC.initialize();
        stylusRootMovementUC.stop(true);
        expect(mockUndo.submitAction).not.toHaveBeenCalled();
    });
});
//# sourceMappingURL=StylusMoveTransformUC.test.js.map