"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@vived/core");
const Babylon_1 = require("../../Babylon");
const Entities_1 = require("../Entities");
const BumpTransformScaleAboutPixelPoint_1 = require("./BumpTransformScaleAboutPixelPoint");
const MockDispatchStateChange_1 = require("../../Dispatcher/Mocks/MockDispatchStateChange");
const core_2 = require("@vived/core");
function makeTestRig() {
    const appObjects = (0, core_1.makeAppObjectRepo)();
    const ao = appObjects.getOrCreate("AO");
    const transform = (0, Entities_1.makeTransform3D)(ao);
    const bumpUC = (0, BumpTransformScaleAboutPixelPoint_1.makeBumpTransformScaleAboutPixelPointUC)(ao);
    const mockDispatch = (0, MockDispatchStateChange_1.makeMockDispatchStateChange)(appObjects);
    const doDispatchMock = jest.fn();
    mockDispatch.doDispatch = doDispatchMock;
    const mockPick = (0, Babylon_1.makeMockScenePixelPickUC)(appObjects);
    const mockPixelRay = (0, Babylon_1.makeMockPixelToSceneRayUC)(appObjects);
    mockPixelRay.pixelToSceneRay = (pos) => {
        return core_2.ParametricLine.FromPointDirection(new core_2.Vector3(pos.x, pos.y, -2), core_2.Vector3.Forward());
    };
    return {
        bumpUC,
        transform,
        doDispatchMock,
        mockPick,
        appObjects,
    };
}
describe("Bumping the transform scale use case", () => {
    it("Bumps the scale smaller with an out", () => {
        const { bumpUC, transform } = makeTestRig();
        transform.worldScale = core_2.Vector3.One();
        bumpUC.bump("OUT", core_2.Vector2.Zero());
        expect(transform.worldScale.x).toBeLessThan(1);
    });
    it("Bumps the scale larger with an in", () => {
        const { bumpUC, transform } = makeTestRig();
        transform.worldScale = core_2.Vector3.One();
        bumpUC.bump("IN", core_2.Vector2.Zero());
        expect(transform.worldScale.x).toBeGreaterThan(1);
    });
    it("Scales around the origin if there is no pick", () => {
        const { bumpUC, transform } = makeTestRig();
        transform.worldPosition = core_2.Vector3.Zero();
        bumpUC.bump("IN", core_2.Vector2.Zero());
        expect(transform.worldPosition).toEqual(core_2.Vector3.Zero());
    });
    it("Scales around the pick point", () => {
        const { bumpUC, mockPick, transform } = makeTestRig();
        transform.worldPosition = core_2.Vector3.Zero();
        const pick = {
            hit: true,
            sceneRay: core_2.ParametricLine.Forward(),
            worldPickPoint: new core_2.Vector3(1, 2, 3),
        };
        mockPick.scenePixelPick.mockReturnValue(pick);
        bumpUC.bump("IN", core_2.Vector2.Zero());
        expect(transform.worldPosition.x).toBeCloseTo(-0.1);
        expect(transform.worldPosition.y).toBeCloseTo(-0.2);
        expect(transform.worldPosition.z).toBeCloseTo(-0.3);
    });
    it("Dispatches state change", () => {
        const { bumpUC, doDispatchMock } = makeTestRig();
        bumpUC.bump("IN", core_2.Vector2.Zero());
        expect(doDispatchMock).toHaveBeenCalled();
    });
    it("Limits the minimum", () => {
        const { bumpUC, transform } = makeTestRig();
        bumpUC.minScale = 0.9;
        transform.worldScale = core_2.Vector3.One();
        bumpUC.bump("OUT", core_2.Vector2.Zero());
        bumpUC.bump("OUT", core_2.Vector2.Zero());
        bumpUC.bump("OUT", core_2.Vector2.Zero());
        bumpUC.bump("OUT", core_2.Vector2.Zero());
        expect(transform.worldScale.x).toEqual(0.9);
    });
    it("Limits the maximum", () => {
        const { bumpUC, transform } = makeTestRig();
        bumpUC.maxScale = 1.1;
        transform.worldScale = core_2.Vector3.One();
        bumpUC.bump("IN", core_2.Vector2.Zero());
        bumpUC.bump("IN", core_2.Vector2.Zero());
        bumpUC.bump("IN", core_2.Vector2.Zero());
        bumpUC.bump("IN", core_2.Vector2.Zero());
        expect(transform.worldScale.x).toEqual(1.1);
    });
    it("Does not update if disabled", () => {
        const { bumpUC, transform } = makeTestRig();
        transform.worldScale = core_2.Vector3.One();
        bumpUC.enabled = false;
        bumpUC.bump("IN", core_2.Vector2.Zero());
        expect(transform.worldScale).toEqual(core_2.Vector3.One());
    });
    it("Scales around the pick point on the plane if the plane is supplied", () => {
        const { bumpUC, transform } = makeTestRig();
        transform.worldPosition = core_2.Vector3.Zero();
        const pickPlane = core_2.ParametricPlane.FromPointNormal(new core_2.Vector3(0, 0, -1), core_2.Vector3.Forward());
        bumpUC.pickPlane = pickPlane;
        bumpUC.bump("IN", core_2.Vector2.Zero());
        expect(transform.worldPosition.x).toBeCloseTo(0);
        expect(transform.worldPosition.y).toBeCloseTo(0);
        expect(transform.worldPosition.z).toBeCloseTo(0.1);
    });
});
//# sourceMappingURL=BumpTransformScaleAboutPixelPoint.test.js.map