import { makeAppObjectRepo } from "@vived/core";
import { ParametricLine, Vector3 } from "@vived/core";
import { makeMockSceneRayPickUC } from "../../Babylon";
import { makeMockDispatchStateChange } from "../../Dispatcher/Mocks/MockDispatchStateChange";
import { makeTransform3D } from "../Entities";
import { makeRayPanScaleTransformUC } from "./RayPanScaleTransform";
function makeTestRig() {
    const appObjects = makeAppObjectRepo();
    const ao = appObjects.getOrCreate("ao");
    const transform = makeTransform3D(ao);
    const mockDispatch = makeMockDispatchStateChange(appObjects);
    const doDispatchMock = jest.fn();
    mockDispatch.doDispatch = doDispatchMock;
    const uc = makeRayPanScaleTransformUC(ao);
    const mockPick = makeMockSceneRayPickUC(appObjects);
    return {
        uc,
        appObjects,
        doDispatchMock,
        mockPick,
        transform,
    };
}
describe("Drag Scale Scene Root UC", () => {
    it("Decreases the scale with forward movement", () => {
        const { uc, transform } = makeTestRig();
        transform.worldScale = Vector3.One();
        uc.initialize(ParametricLine.FromPointDirection(new Vector3(0, 0, -5), Vector3.Forward()));
        uc.update(ParametricLine.FromPointDirection(new Vector3(0, 0, -4), Vector3.Forward()));
        expect(transform.worldScale.x).toBeLessThan(1);
    });
    it("Increases the scale with backwards movement", () => {
        const { uc, transform } = makeTestRig();
        transform.worldScale = Vector3.One();
        uc.initialize(ParametricLine.FromPointDirection(new Vector3(0, 0, -4), Vector3.Forward()));
        uc.update(ParametricLine.FromPointDirection(new Vector3(0, 0, -5), Vector3.Forward()));
        expect(transform.worldScale.x).toBeGreaterThan(1);
    });
    it("Dispatches state change", () => {
        const { uc, doDispatchMock } = makeTestRig();
        uc.initialize(ParametricLine.FromPointDirection(new Vector3(0, 0, 5), Vector3.Forward()));
        uc.update(ParametricLine.FromPointDirection(new Vector3(0, 0, 4.5), Vector3.Forward()));
        uc.finish();
        expect(doDispatchMock).toHaveBeenCalled();
    });
    it("Does not dispatches state change if the scale does not change", () => {
        const { uc, doDispatchMock } = makeTestRig();
        uc.initialize(ParametricLine.FromPointDirection(new Vector3(0, 0, 5), Vector3.Forward()));
        uc.finish();
        expect(doDispatchMock).not.toHaveBeenCalled();
    });
    it("Does not dispatches state change if it was not initialized", () => {
        const { uc, doDispatchMock } = makeTestRig();
        uc.finish();
        expect(doDispatchMock).not.toHaveBeenCalled();
    });
    it("Does not scale if it is not initialized", () => {
        const { uc, transform } = makeTestRig();
        transform.worldScale = Vector3.One();
        uc.update(ParametricLine.FromPointDirection(new Vector3(0, 0, 4.5), Vector3.Forward()));
        expect(transform.worldScale.x).toEqual(1);
    });
    it("Limits the minimum scale", () => {
        const { uc, transform } = makeTestRig();
        uc.minScale = 0.5;
        transform.worldScale = Vector3.One();
        uc.initialize(ParametricLine.FromPointDirection(new Vector3(0, 0, -5), Vector3.Forward()));
        uc.update(ParametricLine.FromPointDirection(new Vector3(0, 0, -4), Vector3.Forward()));
        expect(transform.worldScale).toEqual(new Vector3(0.5, 0.5, 0.5));
    });
    it("Limits the maximum scale", () => {
        const { uc, transform } = makeTestRig();
        uc.maxScale = 1.5;
        transform.worldScale = Vector3.One();
        uc.initialize(ParametricLine.FromPointDirection(new Vector3(0, 0, -4), Vector3.Forward()));
        uc.update(ParametricLine.FromPointDirection(new Vector3(0, 0, -5), Vector3.Forward()));
        expect(transform.worldScale).toEqual(new Vector3(1.5, 1.5, 1.5));
    });
    it("Moves the transform", () => {
        const { transform, uc } = makeTestRig();
        uc.initialize(ParametricLine.FromPointDirection(new Vector3(0, 0, -4), Vector3.Forward()));
        uc.update(ParametricLine.FromPointDirection(new Vector3(1, 2, -4), Vector3.Forward()));
        expect(transform.worldPosition).toEqual(new Vector3(1, 2, 0));
    });
    it("Moves the transform relative to the initial position", () => {
        const { transform, uc } = makeTestRig();
        transform.worldPosition = new Vector3(10, 10, 10);
        uc.initialize(ParametricLine.FromPointDirection(new Vector3(0, 0, -4), Vector3.Forward()));
        uc.update(ParametricLine.FromPointDirection(new Vector3(1, 2, -4), Vector3.Forward()));
        expect(transform.worldPosition).toEqual(new Vector3(11, 12, 10));
    });
    it("Limits the minimum X", () => {
        const { transform, uc } = makeTestRig();
        uc.minX = 0;
        uc.initialize(ParametricLine.FromPointDirection(new Vector3(0, 0, -4), Vector3.Forward()));
        uc.update(ParametricLine.FromPointDirection(new Vector3(-1, 2, -4), Vector3.Forward()));
        expect(transform.worldPosition).toEqual(new Vector3(0, 2, 0));
    });
    it("Limits the maximum X", () => {
        const { transform, uc } = makeTestRig();
        uc.maxX = 0;
        uc.initialize(ParametricLine.FromPointDirection(new Vector3(0, 0, -4), Vector3.Forward()));
        uc.update(ParametricLine.FromPointDirection(new Vector3(1, 2, -4), Vector3.Forward()));
        expect(transform.worldPosition).toEqual(new Vector3(0, 2, 0));
    });
    it("Limits the minimum Y", () => {
        const { transform, uc } = makeTestRig();
        uc.minY = 0;
        uc.initialize(ParametricLine.FromPointDirection(new Vector3(0, 0, -4), Vector3.Forward()));
        uc.update(ParametricLine.FromPointDirection(new Vector3(-1, -2, -4), Vector3.Forward()));
        expect(transform.worldPosition).toEqual(new Vector3(-1, 0, 0));
    });
    it("Limits the maximum Y", () => {
        const { transform, uc } = makeTestRig();
        uc.maxY = 0;
        uc.initialize(ParametricLine.FromPointDirection(new Vector3(0, 0, -4), Vector3.Forward()));
        uc.update(ParametricLine.FromPointDirection(new Vector3(1, 2, -4), Vector3.Forward()));
        expect(transform.worldPosition).toEqual(new Vector3(1, 0, 0));
    });
    it("Does not update when disabled", () => {
        const { uc, transform } = makeTestRig();
        uc.enabled = false;
        transform.worldScale = Vector3.One();
        transform.worldPosition = Vector3.Zero();
        uc.initialize(ParametricLine.FromPointDirection(new Vector3(0, 0, -5), Vector3.Forward()));
        uc.update(ParametricLine.FromPointDirection(new Vector3(3, 4, -4), Vector3.Forward()));
        expect(transform.worldScale).toEqual(Vector3.One());
        expect(transform.worldPosition).toEqual(Vector3.Zero());
    });
});
//# sourceMappingURL=RayPanScaleTransform.test.js.map