"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@vived/core");
const core_2 = require("@vived/core");
const Babylon_1 = require("../../Babylon");
const Dispatcher_1 = require("../../Dispatcher");
const Entities_1 = require("../Entities");
const PanSceneRoot_1 = require("./PanSceneRoot");
class MockPick extends Babylon_1.ScenePixelPickUC {
    constructor() {
        super(...arguments);
        this.scenePixelPick = jest.fn();
    }
}
class MockPixelToRay extends Babylon_1.PixelToSceneRayUC {
    constructor() {
        super(...arguments);
        this.pixelToSceneRay = jest.fn();
    }
}
function makeTestRig() {
    const appObjects = (0, core_1.makeAppObjectRepo)();
    const sceneRootAO = appObjects.getOrCreate("sceneRoot");
    const sceneRoot = (0, Entities_1.makeSceneRootEntity)(sceneRootAO);
    const panUC = (0, PanSceneRoot_1.makePanSceneRootUC)(sceneRootAO);
    const appAO = appObjects.getOrCreate("appAO");
    const mockPick = new MockPick(appAO, Babylon_1.ScenePixelPickUC.type);
    const mockDispatch = (0, Dispatcher_1.makeMockDispatchStateChange)(appObjects);
    const doDispatchMock = jest.fn();
    mockDispatch.doDispatch = doDispatchMock;
    const mockPixelRay = new MockPixelToRay(appAO, Babylon_1.PixelToSceneRayUC.type);
    return {
        panUC,
        sceneRoot,
        mockPick,
        mockDispatch,
        doDispatchMock,
        appObjects,
        mockPixelRay,
    };
}
describe("Pan Scene Root Use Case", () => {
    it("Moves the transform", () => {
        const { sceneRoot, panUC, mockPick, mockPixelRay } = makeTestRig();
        const pick = {
            hit: true,
            sceneRay: core_2.ParametricLine.Forward(),
        };
        mockPick.scenePixelPick.mockReturnValue(pick);
        mockPixelRay.pixelToSceneRay.mockReturnValue(core_2.ParametricLine.FromPointDirection(new core_2.Vector3(1, 2, 3), core_2.Vector3.Forward()));
        panUC.initializePan(core_2.Vector2.Zero());
        panUC.doPan(core_2.Vector2.Zero());
        expect(sceneRoot.position).toEqual(new core_2.Vector3(1, 2, 0));
    });
    it("Moves the transform relative to the initial position", () => {
        const { sceneRoot, panUC, mockPick, mockPixelRay } = makeTestRig();
        const pick = {
            hit: true,
            sceneRay: core_2.ParametricLine.Forward(),
        };
        mockPick.scenePixelPick.mockReturnValue(pick);
        sceneRoot.position = new core_2.Vector3(10, 10, 10);
        mockPixelRay.pixelToSceneRay.mockReturnValue(core_2.ParametricLine.FromPointDirection(new core_2.Vector3(1, 2, 3), core_2.Vector3.Forward()));
        panUC.initializePan(core_2.Vector2.Zero());
        panUC.doPan(core_2.Vector2.Zero());
        expect(sceneRoot.position).toEqual(new core_2.Vector3(11, 12, 10));
    });
    it("Dispatches a state change if the position has changed since init", () => {
        const { sceneRoot, panUC, doDispatchMock, mockPick } = makeTestRig();
        sceneRoot.position = new core_2.Vector3(1, 2, 3);
        const pick = {
            hit: true,
            sceneRay: core_2.ParametricLine.Forward(),
        };
        mockPick.scenePixelPick.mockReturnValue(pick);
        panUC.initializePan(core_2.Vector2.Zero());
        sceneRoot.position = new core_2.Vector3(4, 5, 6);
        panUC.finishPan();
        expect(doDispatchMock).toHaveBeenCalled();
    });
    it("Does not dispatch a state change if the position has not changed", () => {
        const { sceneRoot, panUC, doDispatchMock } = makeTestRig();
        sceneRoot.position = new core_2.Vector3(1, 2, 3);
        panUC.initializePan(core_2.Vector2.Zero());
        panUC.finishPan();
        expect(doDispatchMock).not.toHaveBeenCalled();
    });
    it("Doen not move the transform after cancel", () => {
        const { sceneRoot, panUC, mockPick, mockPixelRay } = makeTestRig();
        const pick = {
            hit: true,
            sceneRay: core_2.ParametricLine.Forward(),
        };
        mockPick.scenePixelPick.mockReturnValue(pick);
        mockPixelRay.pixelToSceneRay.mockReturnValue(core_2.ParametricLine.FromPointDirection(new core_2.Vector3(1, 2, 3), core_2.Vector3.Forward()));
        panUC.initializePan(core_2.Vector2.Zero());
        panUC.cancelPan();
        panUC.doPan(core_2.Vector2.Zero());
        expect(sceneRoot.position).toEqual(core_2.Vector3.Zero());
    });
    it("Gets the UC", () => {
        const { panUC, appObjects } = makeTestRig();
        expect(PanSceneRoot_1.PanSceneRootUC.get(appObjects)).toEqual(panUC);
    });
});
//# sourceMappingURL=PanSceneRoot.test.js.map