import { makeAppObjectRepo } from "@vived/core";
import { makeMockPixelToSceneRayUC, makeMockScenePixelPickUC, } from "../../Babylon";
import { makeTransform3D } from "../Entities";
import { makeBumpTransformScaleAboutPixelPointUC } from "./BumpTransformScaleAboutPixelPoint";
import { makeMockDispatchStateChange } from "../../Dispatcher/Mocks/MockDispatchStateChange";
import { ParametricLine, ParametricPlane, Vector2, Vector3 } from "@vived/core";
function makeTestRig() {
    const appObjects = makeAppObjectRepo();
    const ao = appObjects.getOrCreate("AO");
    const transform = makeTransform3D(ao);
    const bumpUC = makeBumpTransformScaleAboutPixelPointUC(ao);
    const mockDispatch = makeMockDispatchStateChange(appObjects);
    const doDispatchMock = jest.fn();
    mockDispatch.doDispatch = doDispatchMock;
    const mockPick = makeMockScenePixelPickUC(appObjects);
    const mockPixelRay = makeMockPixelToSceneRayUC(appObjects);
    mockPixelRay.pixelToSceneRay = (pos) => {
        return ParametricLine.FromPointDirection(new Vector3(pos.x, pos.y, -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 = Vector3.One();
        bumpUC.bump("OUT", Vector2.Zero());
        expect(transform.worldScale.x).toBeLessThan(1);
    });
    it("Bumps the scale larger with an in", () => {
        const { bumpUC, transform } = makeTestRig();
        transform.worldScale = Vector3.One();
        bumpUC.bump("IN", Vector2.Zero());
        expect(transform.worldScale.x).toBeGreaterThan(1);
    });
    it("Scales around the origin if there is no pick", () => {
        const { bumpUC, transform } = makeTestRig();
        transform.worldPosition = Vector3.Zero();
        bumpUC.bump("IN", Vector2.Zero());
        expect(transform.worldPosition).toEqual(Vector3.Zero());
    });
    it("Scales around the pick point", () => {
        const { bumpUC, mockPick, transform } = makeTestRig();
        transform.worldPosition = Vector3.Zero();
        const pick = {
            hit: true,
            sceneRay: ParametricLine.Forward(),
            worldPickPoint: new Vector3(1, 2, 3),
        };
        mockPick.scenePixelPick.mockReturnValue(pick);
        bumpUC.bump("IN", 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", Vector2.Zero());
        expect(doDispatchMock).toHaveBeenCalled();
    });
    it("Limits the minimum", () => {
        const { bumpUC, transform } = makeTestRig();
        bumpUC.minScale = 0.9;
        transform.worldScale = Vector3.One();
        bumpUC.bump("OUT", Vector2.Zero());
        bumpUC.bump("OUT", Vector2.Zero());
        bumpUC.bump("OUT", Vector2.Zero());
        bumpUC.bump("OUT", Vector2.Zero());
        expect(transform.worldScale.x).toEqual(0.9);
    });
    it("Limits the maximum", () => {
        const { bumpUC, transform } = makeTestRig();
        bumpUC.maxScale = 1.1;
        transform.worldScale = Vector3.One();
        bumpUC.bump("IN", Vector2.Zero());
        bumpUC.bump("IN", Vector2.Zero());
        bumpUC.bump("IN", Vector2.Zero());
        bumpUC.bump("IN", Vector2.Zero());
        expect(transform.worldScale.x).toEqual(1.1);
    });
    it("Does not update if disabled", () => {
        const { bumpUC, transform } = makeTestRig();
        transform.worldScale = Vector3.One();
        bumpUC.enabled = false;
        bumpUC.bump("IN", Vector2.Zero());
        expect(transform.worldScale).toEqual(Vector3.One());
    });
    it("Scales around the pick point on the plane if the plane is supplied", () => {
        const { bumpUC, transform } = makeTestRig();
        transform.worldPosition = Vector3.Zero();
        const pickPlane = ParametricPlane.FromPointNormal(new Vector3(0, 0, -1), Vector3.Forward());
        bumpUC.pickPlane = pickPlane;
        bumpUC.bump("IN", 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