import { makeAppObjectRepo } from "@vived/core";
import { ParametricLine, Vector2, Vector3 } from "@vived/core";
import { PixelToSceneRayUC, ScenePixelPickUC, } from "../../Babylon";
import { makeMockDispatchStateChange } from "../../Dispatcher";
import { makeSceneRootEntity } from "../Entities";
import { makePanSceneRootUC, PanSceneRootUC } from "./PanSceneRoot";
class MockPick extends ScenePixelPickUC {
    constructor() {
        super(...arguments);
        this.scenePixelPick = jest.fn();
    }
}
class MockPixelToRay extends PixelToSceneRayUC {
    constructor() {
        super(...arguments);
        this.pixelToSceneRay = jest.fn();
    }
}
function makeTestRig() {
    const appObjects = makeAppObjectRepo();
    const sceneRootAO = appObjects.getOrCreate("sceneRoot");
    const sceneRoot = makeSceneRootEntity(sceneRootAO);
    const panUC = makePanSceneRootUC(sceneRootAO);
    const appAO = appObjects.getOrCreate("appAO");
    const mockPick = new MockPick(appAO, ScenePixelPickUC.type);
    const mockDispatch = makeMockDispatchStateChange(appObjects);
    const doDispatchMock = jest.fn();
    mockDispatch.doDispatch = doDispatchMock;
    const mockPixelRay = new MockPixelToRay(appAO, 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: ParametricLine.Forward(),
        };
        mockPick.scenePixelPick.mockReturnValue(pick);
        mockPixelRay.pixelToSceneRay.mockReturnValue(ParametricLine.FromPointDirection(new Vector3(1, 2, 3), Vector3.Forward()));
        panUC.initializePan(Vector2.Zero());
        panUC.doPan(Vector2.Zero());
        expect(sceneRoot.position).toEqual(new Vector3(1, 2, 0));
    });
    it("Moves the transform relative to the initial position", () => {
        const { sceneRoot, panUC, mockPick, mockPixelRay } = makeTestRig();
        const pick = {
            hit: true,
            sceneRay: ParametricLine.Forward(),
        };
        mockPick.scenePixelPick.mockReturnValue(pick);
        sceneRoot.position = new Vector3(10, 10, 10);
        mockPixelRay.pixelToSceneRay.mockReturnValue(ParametricLine.FromPointDirection(new Vector3(1, 2, 3), Vector3.Forward()));
        panUC.initializePan(Vector2.Zero());
        panUC.doPan(Vector2.Zero());
        expect(sceneRoot.position).toEqual(new 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 Vector3(1, 2, 3);
        const pick = {
            hit: true,
            sceneRay: ParametricLine.Forward(),
        };
        mockPick.scenePixelPick.mockReturnValue(pick);
        panUC.initializePan(Vector2.Zero());
        sceneRoot.position = new 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 Vector3(1, 2, 3);
        panUC.initializePan(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: ParametricLine.Forward(),
        };
        mockPick.scenePixelPick.mockReturnValue(pick);
        mockPixelRay.pixelToSceneRay.mockReturnValue(ParametricLine.FromPointDirection(new Vector3(1, 2, 3), Vector3.Forward()));
        panUC.initializePan(Vector2.Zero());
        panUC.cancelPan();
        panUC.doPan(Vector2.Zero());
        expect(sceneRoot.position).toEqual(Vector3.Zero());
    });
    it("Gets the UC", () => {
        const { panUC, appObjects } = makeTestRig();
        expect(PanSceneRootUC.get(appObjects)).toEqual(panUC);
    });
});
//# sourceMappingURL=PanSceneRoot.test.js.map