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 { DragScaleSceneRootUC, makeDragScaleSceneRootUC, } from "./DragScaleSceneRoot";
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 mockDispatch = makeMockDispatchStateChange(appObjects);
    const doDispatchMock = jest.fn();
    mockDispatch.doDispatch = doDispatchMock;
    const scaleUC = makeDragScaleSceneRootUC(sceneRootAO);
    const appAO = appObjects.getOrCreate("appAO");
    const mockPick = new MockPick(appAO, ScenePixelPickUC.type);
    const mockEntityBump = jest.fn();
    sceneRoot.bumpScaleAboutPoint = mockEntityBump;
    return {
        scaleUC,
        appObjects,
        mockEntityBump,
        mockDispatch,
        doDispatchMock,
        mockPick,
        sceneRoot,
    };
}
describe("Drag Scale Scene Root UC", () => {
    it("Decreases the scaleUC with down movement", () => {
        const { scaleUC, mockEntityBump } = makeTestRig();
        scaleUC.initializeScale(Vector2.Zero());
        scaleUC.doScale(new Vector2(0, -10));
        const bumpAmount = mockEntityBump.mock.calls[0][0];
        expect(bumpAmount).toBeLessThan(0);
    });
    it("Increases the scaleUC with up movement", () => {
        const { scaleUC, mockEntityBump } = makeTestRig();
        scaleUC.initializeScale(Vector2.Zero());
        scaleUC.doScale(new Vector2(0, 10));
        const bumpAmount = mockEntityBump.mock.calls[0][0];
        expect(bumpAmount).toBeGreaterThan(0);
    });
    it("Scales around the origin if there is no pick", () => {
        const { scaleUC, mockEntityBump, mockPick } = makeTestRig();
        const pick = {
            hit: false,
            sceneRay: ParametricLine.Forward(),
        };
        mockPick.scenePixelPick.mockReturnValue(pick);
        scaleUC.initializeScale(Vector2.Zero());
        scaleUC.doScale(new Vector2(0, 10));
        const pickPoint = mockEntityBump.mock.calls[0][1];
        expect(pickPoint).toEqual(Vector3.Zero());
    });
    it("Scales around the pick point", () => {
        const { scaleUC, mockEntityBump, mockPick } = makeTestRig();
        const pick = {
            hit: true,
            sceneRay: ParametricLine.Forward(),
            worldPickPoint: new Vector3(1, 2, 3),
        };
        mockPick.scenePixelPick.mockReturnValue(pick);
        scaleUC.initializeScale(Vector2.Zero());
        scaleUC.doScale(new Vector2(0, 10));
        const pickPoint = mockEntityBump.mock.calls[0][1];
        expect(pickPoint).toEqual(new Vector3(1, 2, 3));
    });
    it("Dispatches state change", () => {
        const { scaleUC, doDispatchMock, sceneRoot } = makeTestRig();
        sceneRoot.scale = 1;
        scaleUC.initializeScale(Vector2.Zero());
        sceneRoot.scale = 5;
        scaleUC.finishScaling();
        expect(doDispatchMock).toHaveBeenCalled();
    });
    it("Does not dispatches state change if the scale does not change", () => {
        const { scaleUC, doDispatchMock, sceneRoot } = makeTestRig();
        sceneRoot.scale = 1;
        scaleUC.initializeScale(Vector2.Zero());
        scaleUC.finishScaling();
        expect(doDispatchMock).not.toHaveBeenCalled();
    });
    it("Does not dispatches state change if it was not initialized", () => {
        const { scaleUC, mockDispatch } = makeTestRig();
        scaleUC.finishScaling();
        expect(mockDispatch.doDispatch).not.toHaveBeenCalled();
    });
    it("Does not scale if it is not initialized", () => {
        const { scaleUC, mockEntityBump, mockPick } = makeTestRig();
        const pick = {
            hit: false,
            sceneRay: ParametricLine.Forward(),
        };
        mockPick.scenePixelPick.mockReturnValue(pick);
        scaleUC.doScale(new Vector2(0, 10));
        expect(mockEntityBump).not.toHaveBeenCalled();
    });
    it("Gets the UC", () => {
        const { scaleUC, appObjects } = makeTestRig();
        expect(DragScaleSceneRootUC.get(appObjects)).toEqual(scaleUC);
    });
});
//# sourceMappingURL=DragScaleSceneRoot.test.js.map