"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 BumpSceneRootScaleAboutPixelPoint_1 = require("./BumpSceneRootScaleAboutPixelPoint");
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 bumpUC = (0, BumpSceneRootScaleAboutPixelPoint_1.makeBumpSceneRootScaleAboutPixelPointUC)(sceneRootAO);
    const appAO = appObjects.getOrCreate("appAO");
    const mockDispatch = (0, Dispatcher_1.makeMockDispatchStateChange)(appObjects);
    const doDispatchMock = jest.fn();
    mockDispatch.doDispatch = doDispatchMock;
    const mockPick = new MockPick(appAO, Babylon_1.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(BumpSceneRootScaleAboutPixelPoint_1.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");
        (0, BumpSceneRootScaleAboutPixelPoint_1.makeBumpSceneRootScaleAboutPixelPointUC)(newAO);
        expect(appObjects.submitWarning).toHaveBeenCalled();
    });
    it("Bumps the scale smaller with an out", () => {
        const { bumpUC, mockEntityBump } = makeTestRig();
        bumpUC.bump("OUT", core_2.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", core_2.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", core_2.Vector2.Zero()); // Pixel point does not matter since we are setting the picker
        const pickPoint = mockEntityBump.mock.calls[0][1];
        expect(pickPoint).toEqual(core_2.Vector3.Zero());
    });
    it("Scales around the pick point", () => {
        const { bumpUC, mockEntityBump, mockPick } = makeTestRig();
        const pick = {
            hit: true,
            sceneRay: core_2.ParametricLine.Forward(),
            worldPickPoint: new core_2.Vector3(1, 2, 3),
        };
        mockPick.scenePixelPick.mockReturnValue(pick);
        bumpUC.bump("IN", core_2.Vector2.Zero()); // Pixel point does not matter since we are setting the picker
        const pickPoint = mockEntityBump.mock.calls[0][1];
        expect(pickPoint).toEqual(new core_2.Vector3(1, 2, 3));
    });
    it("Dispatches state change", () => {
        const { bumpUC, doDispatchMock } = makeTestRig();
        bumpUC.bump("IN", core_2.Vector2.Zero());
        expect(doDispatchMock).toHaveBeenCalled();
    });
});
//# sourceMappingURL=BumpSceneRootScaleAboutPixelPoint.test.js.map