"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@vived/core");
const core_2 = require("@vived/core");
const Babylon_1 = require("../../Babylon");
const Dispatcher_1 = require("../../Dispatcher");
const Entities_1 = require("../Entities");
const DragScaleSceneRoot_1 = require("./DragScaleSceneRoot");
class MockPick extends Babylon_1.ScenePixelPickUC {
    constructor() {
        super(...arguments);
        this.scenePixelPick = jest.fn();
    }
}
function makeTestRig() {
    const appObjects = (0, core_1.makeAppObjectRepo)();
    const sceneRootAO = appObjects.getOrCreate("sceneRoot");
    const sceneRoot = (0, Entities_1.makeSceneRootEntity)(sceneRootAO);
    const mockDispatch = (0, Dispatcher_1.makeMockDispatchStateChange)(appObjects);
    const doDispatchMock = jest.fn();
    mockDispatch.doDispatch = doDispatchMock;
    const scaleUC = (0, DragScaleSceneRoot_1.makeDragScaleSceneRootUC)(sceneRootAO);
    const appAO = appObjects.getOrCreate("appAO");
    const mockPick = new MockPick(appAO, Babylon_1.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(core_2.Vector2.Zero());
        scaleUC.doScale(new core_2.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(core_2.Vector2.Zero());
        scaleUC.doScale(new core_2.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: core_2.ParametricLine.Forward(),
        };
        mockPick.scenePixelPick.mockReturnValue(pick);
        scaleUC.initializeScale(core_2.Vector2.Zero());
        scaleUC.doScale(new core_2.Vector2(0, 10));
        const pickPoint = mockEntityBump.mock.calls[0][1];
        expect(pickPoint).toEqual(core_2.Vector3.Zero());
    });
    it("Scales around the pick point", () => {
        const { scaleUC, mockEntityBump, mockPick } = makeTestRig();
        const pick = {
            hit: true,
            sceneRay: core_2.ParametricLine.Forward(),
            worldPickPoint: new core_2.Vector3(1, 2, 3),
        };
        mockPick.scenePixelPick.mockReturnValue(pick);
        scaleUC.initializeScale(core_2.Vector2.Zero());
        scaleUC.doScale(new core_2.Vector2(0, 10));
        const pickPoint = mockEntityBump.mock.calls[0][1];
        expect(pickPoint).toEqual(new core_2.Vector3(1, 2, 3));
    });
    it("Dispatches state change", () => {
        const { scaleUC, doDispatchMock, sceneRoot } = makeTestRig();
        sceneRoot.scale = 1;
        scaleUC.initializeScale(core_2.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(core_2.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: core_2.ParametricLine.Forward(),
        };
        mockPick.scenePixelPick.mockReturnValue(pick);
        scaleUC.doScale(new core_2.Vector2(0, 10));
        expect(mockEntityBump).not.toHaveBeenCalled();
    });
    it("Gets the UC", () => {
        const { scaleUC, appObjects } = makeTestRig();
        expect(DragScaleSceneRoot_1.DragScaleSceneRootUC.get(appObjects)).toEqual(scaleUC);
    });
});
//# sourceMappingURL=DragScaleSceneRoot.test.js.map