"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 Entities_1 = require("../Entities");
const CenterSceneRootOnPixelPick_1 = require("./CenterSceneRootOnPixelPick");
class MockPick extends Babylon_1.ScenePixelPickUC {
    constructor() {
        super(...arguments);
        this.scenePixelPick = jest.fn();
    }
}
function makeTestRig() {
    const appObjects = (0, core_1.makeAppObjectRepo)();
    const sceneRootAO = appObjects.getOrCreate("sceneRoot");
    const sceneRoot = (0, Entities_1.makeSceneRootEntity)(sceneRootAO);
    const centerUC = (0, CenterSceneRootOnPixelPick_1.makeCenterSceneRootOnPixelPickUC)(sceneRootAO);
    const mockLerpToPoint = jest.fn();
    sceneRoot.centerOnPoint = mockLerpToPoint;
    const appAO = appObjects.getOrCreate("appAO");
    const mockPick = new MockPick(appAO, Babylon_1.ScenePixelPickUC.type);
    return { centerUC, appObjects, mockPick, mockLerpToPoint };
}
describe("Center Scene Root Use Case", () => {
    it("Gets the UC", () => {
        const { centerUC, appObjects } = makeTestRig();
        expect(CenterSceneRootOnPixelPick_1.CenterSceneRootOnPixelPickUC.get(appObjects)).toEqual(centerUC);
    });
    it("Warns if it is added to something without a scene root", () => {
        const { appObjects } = makeTestRig();
        appObjects.submitWarning = jest.fn();
        const newAO = appObjects.getOrCreate("newAO");
        (0, CenterSceneRootOnPixelPick_1.makeCenterSceneRootOnPixelPickUC)(newAO);
        expect(appObjects.submitWarning).toHaveBeenCalled();
    });
    it("Finds and uses the UC", () => {
        const { appObjects, centerUC } = makeTestRig();
        centerUC.centerOnPixel = jest.fn();
        (0, CenterSceneRootOnPixelPick_1.centerOnPixel)(new core_2.Vector2(1, 2), appObjects);
        expect(centerUC.centerOnPixel).toHaveBeenCalledWith(new core_2.Vector2(1, 2));
    });
    it("Warns if it can't find the UC", () => {
        const { centerUC, appObjects } = makeTestRig();
        appObjects.submitWarning = jest.fn();
        centerUC.dispose();
        (0, CenterSceneRootOnPixelPick_1.centerOnPixel)(new core_2.Vector2(1, 2), appObjects);
        expect(appObjects.submitWarning).toHaveBeenCalled();
    });
    it("Centers on the pick point", () => {
        const { centerUC, mockPick, mockLerpToPoint } = makeTestRig();
        const pick = {
            hit: true,
            sceneRay: core_2.ParametricLine.Forward(),
            worldPickPoint: new core_2.Vector3(10, 20, 30),
        };
        mockPick.scenePixelPick.mockReturnValue(pick);
        centerUC.centerOnPixel(core_2.Vector2.Zero());
        expect(mockLerpToPoint).toHaveBeenCalled();
        const pickPoint = mockLerpToPoint.mock.calls[0][0];
        expect(pickPoint).toEqual(new core_2.Vector3(10, 20, 30));
    });
    it("Sends the duration", () => {
        const { centerUC, mockLerpToPoint, mockPick } = makeTestRig();
        centerUC.durationMS = 750;
        const pick = {
            hit: true,
            sceneRay: core_2.ParametricLine.Forward(),
            worldPickPoint: new core_2.Vector3(10, 20, 30),
        };
        mockPick.scenePixelPick.mockReturnValue(pick);
        centerUC.centerOnPixel(core_2.Vector2.Zero());
        centerUC.centerOnPixel(core_2.Vector2.Zero());
        expect(mockLerpToPoint).toHaveBeenCalled();
        const sentDuration = mockLerpToPoint.mock.calls[0][1];
        expect(sentDuration).toEqual(centerUC.durationMS);
    });
    it("Sends the lerp ease", () => {
        const { centerUC, mockLerpToPoint, mockPick } = makeTestRig();
        centerUC.easeFn = (v) => {
            return 0.5 * v;
        };
        const pick = {
            hit: true,
            sceneRay: core_2.ParametricLine.Forward(),
            worldPickPoint: new core_2.Vector3(10, 20, 30),
        };
        mockPick.scenePixelPick.mockReturnValue(pick);
        centerUC.centerOnPixel(core_2.Vector2.Zero());
        centerUC.centerOnPixel(core_2.Vector2.Zero());
        expect(mockLerpToPoint).toHaveBeenCalled();
        const sentEase = mockLerpToPoint.mock.calls[0][2];
        expect(sentEase).toEqual(centerUC.easeFn);
    });
    it("If there is no pick it does not start a lerp", () => {
        const { centerUC, mockLerpToPoint, mockPick } = makeTestRig();
        const pick = {
            hit: false,
            sceneRay: core_2.ParametricLine.Forward(),
        };
        mockPick.scenePixelPick.mockReturnValue(pick);
        centerUC.centerOnPixel(core_2.Vector2.Zero());
        centerUC.centerOnPixel(core_2.Vector2.Zero());
        expect(mockLerpToPoint).not.toHaveBeenCalled();
    });
});
//# sourceMappingURL=CenterSceneRootOnPixelPick.test.js.map