import { makeAppObjectRepo } from "@vived/core";
import { ParametricLine, Vector2, Vector3 } from "@vived/core";
import { ScenePixelPickUC } from "../../Babylon";
import { makeMockDispatchStateChange } from "../../Dispatcher";
import { makeSceneRootEntity } from "../Entities";
import { BumpSceneRootScaleAboutPixelPointUC, makeBumpSceneRootScaleAboutPixelPointUC, } from "./BumpSceneRootScaleAboutPixelPoint";
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 bumpUC = makeBumpSceneRootScaleAboutPixelPointUC(sceneRootAO);
    const appAO = appObjects.getOrCreate("appAO");
    const mockDispatch = makeMockDispatchStateChange(appObjects);
    const doDispatchMock = jest.fn();
    mockDispatch.doDispatch = doDispatchMock;
    const mockPick = new MockPick(appAO, ScenePixelPickUC.type);
    const mockEntityBump = jest.fn();
    sceneRoot.bumpScaleAboutPoint = mockEntityBump;
    return {
        bumpUC,
        mockEntityBump,
        mockDispatch,
        doDispatchMock,
        mockPick,
        appObjects,
    };
}
describe("Bumping the scene root scale use case", () => {
    it("Gets the UC", () => {
        const { bumpUC, appObjects } = makeTestRig();
        expect(BumpSceneRootScaleAboutPixelPointUC.get(appObjects)).toEqual(bumpUC);
    });
    it("Warns if it is added to something without a scene root", () => {
        const { appObjects } = makeTestRig();
        appObjects.submitWarning = jest.fn();
        const newAO = appObjects.getOrCreate("newAO");
        makeBumpSceneRootScaleAboutPixelPointUC(newAO);
        expect(appObjects.submitWarning).toHaveBeenCalled();
    });
    it("Bumps the scale smaller with an out", () => {
        const { bumpUC, mockEntityBump } = makeTestRig();
        bumpUC.bump("OUT", Vector2.Zero());
        const bumpAmount = mockEntityBump.mock.calls[0][0];
        expect(bumpAmount).toBeLessThan(0);
    });
    it("Bumps the scale larger with an in", () => {
        const { bumpUC, mockEntityBump } = makeTestRig();
        bumpUC.bump("IN", Vector2.Zero());
        const bumpAmount = mockEntityBump.mock.calls[0][0];
        expect(bumpAmount).toBeGreaterThan(0);
    });
    it("Scales around the origin if there is no pick", () => {
        const { bumpUC, mockEntityBump } = makeTestRig();
        bumpUC.bump("IN", Vector2.Zero()); // Pixel point does not matter since we are setting the picker
        const pickPoint = mockEntityBump.mock.calls[0][1];
        expect(pickPoint).toEqual(Vector3.Zero());
    });
    it("Scales around the pick point", () => {
        const { bumpUC, mockEntityBump, mockPick } = makeTestRig();
        const pick = {
            hit: true,
            sceneRay: ParametricLine.Forward(),
            worldPickPoint: new Vector3(1, 2, 3),
        };
        mockPick.scenePixelPick.mockReturnValue(pick);
        bumpUC.bump("IN", Vector2.Zero()); // Pixel point does not matter since we are setting the picker
        const pickPoint = mockEntityBump.mock.calls[0][1];
        expect(pickPoint).toEqual(new Vector3(1, 2, 3));
    });
    it("Dispatches state change", () => {
        const { bumpUC, doDispatchMock } = makeTestRig();
        bumpUC.bump("IN", Vector2.Zero());
        expect(doDispatchMock).toHaveBeenCalled();
    });
});
//# sourceMappingURL=BumpSceneRootScaleAboutPixelPoint.test.js.map