import { makeAppObjectRepo } from "@vived/core";
import { ParametricLine, Vector2, Vector3 } from "@vived/core";
import { ScenePixelPickUC } from "../../Babylon";
import { makeSceneRootEntity } from "../Entities";
import { FocusOnPixelUC, makeFocusOnPixelUC } from "./FocusOnPixel";
class MockPick extends ScenePixelPickUC {
    constructor() {
        super(...arguments);
        this.scenePixelPick = jest.fn();
    }
}
function makeTestRig() {
    const appObjects = makeAppObjectRepo();
    const sceneRootAO = appObjects.getOrCreate("sceneRoot");
    const sceneRoot = makeSceneRootEntity(sceneRootAO);
    const centerUC = makeFocusOnPixelUC(sceneRootAO);
    const appAO = appObjects.getOrCreate("appAO");
    const mockPick = new MockPick(appAO, ScenePixelPickUC.type);
    const mockLerpToPoint = jest.fn();
    sceneRoot.centerOnPoint = mockLerpToPoint;
    const mockLerpToDefault = jest.fn();
    sceneRoot.lerpToDefault = mockLerpToDefault;
    return {
        centerUC,
        mockLerpToPoint,
        mockLerpToDefault,
        mockPick,
        appObjects,
    };
}
describe("Center Scene Root Use Case", () => {
    it("Centers on the pick point", () => {
        const { centerUC, mockLerpToPoint, mockPick } = makeTestRig();
        const pick = {
            hit: true,
            sceneRay: ParametricLine.Forward(),
            worldPickPoint: new Vector3(10, 20, 30),
        };
        mockPick.scenePixelPick.mockReturnValue(pick);
        centerUC.centerOnPixel(Vector2.Zero());
        expect(mockLerpToPoint).toHaveBeenCalled();
        const pickPoint = mockLerpToPoint.mock.calls[0][0];
        expect(pickPoint).toEqual(new Vector3(10, 20, 30));
    });
    it("Sends the duration", () => {
        const { centerUC, mockLerpToPoint, mockPick } = makeTestRig();
        centerUC.durationMS = 750;
        const pick = {
            hit: true,
            sceneRay: ParametricLine.Forward(),
            worldPickPoint: new Vector3(10, 20, 30),
        };
        mockPick.scenePixelPick.mockReturnValue(pick);
        centerUC.centerOnPixel(Vector2.Zero());
        expect(mockLerpToPoint).toHaveBeenCalled();
        const sentDuration = mockLerpToPoint.mock.calls[0][1];
        expect(sentDuration).toEqual(750);
    });
    it("Sends the lerp ease", () => {
        const { centerUC, mockLerpToPoint, mockPick } = makeTestRig();
        centerUC.easeFn = (v) => {
            return 0.5 * v;
        };
        const pick = {
            hit: true,
            sceneRay: ParametricLine.Forward(),
            worldPickPoint: new Vector3(10, 20, 30),
        };
        mockPick.scenePixelPick.mockReturnValue(pick);
        centerUC.centerOnPixel(Vector2.Zero());
        expect(mockLerpToPoint).toHaveBeenCalled();
        const sentEase = mockLerpToPoint.mock.calls[0][2];
        expect(sentEase).toEqual(centerUC.easeFn);
    });
    it("If there is no pick it recenters the root", () => {
        const { centerUC, mockLerpToDefault, mockPick } = makeTestRig();
        centerUC.easeFn = (v) => {
            return 0.5 * v;
        };
        centerUC.durationMS = 750;
        const pick = {
            hit: false,
            sceneRay: ParametricLine.Forward(),
        };
        mockPick.scenePixelPick.mockReturnValue(pick);
        centerUC.centerOnPixel(Vector2.Zero());
        expect(mockLerpToDefault).toHaveBeenCalled();
        const sentDuration = mockLerpToDefault.mock.calls[0][0];
        expect(sentDuration).toEqual(centerUC.durationMS);
        const sentEase = mockLerpToDefault.mock.calls[0][1];
        expect(sentEase).toEqual(centerUC.easeFn);
    });
    it("Gets the UC", () => {
        const { centerUC, appObjects } = makeTestRig();
        expect(FocusOnPixelUC.get(appObjects)).toEqual(centerUC);
    });
});
//# sourceMappingURL=FocusOnPixel.test.js.map