"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@vived/core");
const Babylon_1 = require("../../Babylon");
const Stylus_1 = require("../../Stylus");
const PressAppObjectUCMock_1 = require("../Mocks/PressAppObjectUCMock");
const StylusPressOnAppObjectSC_1 = require("./StylusPressOnAppObjectSC");
function makeTestRig() {
    const appObjects = (0, core_1.makeAppObjectRepo)();
    const ao = appObjects.getOrCreate("stylus");
    const stylus = (0, Stylus_1.makeStylusEntity)(ao);
    const mockRegisterController = jest.fn();
    stylus.registerController = mockRegisterController;
    const selectionAO = appObjects.getOrCreate("selection");
    const mockUC = new PressAppObjectUCMock_1.PressAppObjectUCMock(selectionAO);
    const mockPixelToSceneUC = (0, Babylon_1.makeMockPixelToSceneRayUC)(appObjects);
    const mockPixelToRay = jest.fn().mockReturnValue(core_1.ParametricLine.Forward());
    mockPixelToSceneUC.pixelToSceneRay = mockPixelToRay;
    const controller = new StylusPressOnAppObjectSC_1.StylusPressOnAppObjectSC(selectionAO);
    const mockAllow = jest.fn();
    mockAllow.mockReturnValue(true);
    controller.allow = mockAllow;
    return {
        appObjects,
        controller,
        mockUC,
        mockAllow,
        mockRegisterController,
        stylus,
    };
}
describe("Stylus Press Scene Object On App Controller", () => {
    it("Sends a ray to the UC when pressed", () => {
        const { mockUC, controller } = makeTestRig();
        controller.onButtonDown(0);
        expect(mockUC.tryPressAppObject).toHaveBeenCalledWith(core_1.ParametricLine.Forward());
    });
    it("Does not send a ray to the UC if allow returns false", () => {
        const { controller, mockUC, mockAllow } = makeTestRig();
        mockAllow.mockReturnValue(false);
        controller.onButtonDown(0);
        expect(mockUC.tryPressAppObject).not.toHaveBeenCalled();
    });
    it("Sets pressID to null when the PRIMARY button is released", () => {
        const { mockUC, controller } = makeTestRig();
        const button = 0;
        controller.onButtonUp(button);
        expect(mockUC.pressAppObject).toHaveBeenCalled();
    });
    it("Sets pressID to null when the stylus moves more than 5 pixels while pressed", () => {
        const { stylus, controller, mockUC } = makeTestRig();
        const button = 0;
        const localPosition1 = new core_1.Vector3(0, 0, 0);
        const localPosition2 = new core_1.Vector3(0, 0, StylusPressOnAppObjectSC_1.StylusPressOnAppObjectSC.maxTapDistancePx + 1);
        stylus.transform.localPosition = localPosition1;
        controller.onButtonDown(button);
        stylus.transform.localPosition = localPosition2;
        controller.onStylusMove();
        expect(mockUC.pressAppObject).toHaveBeenCalled();
    });
    it("Does not set pressID to null when the stylus moves less than 5 pixels while pressed", () => {
        const { stylus, controller, mockUC } = makeTestRig();
        const button = 0;
        const localPosition1 = new core_1.Vector3(0, 0, 0);
        const localPosition2 = new core_1.Vector3(0, 0, StylusPressOnAppObjectSC_1.StylusPressOnAppObjectSC.maxTapDistancePx - 1);
        stylus.transform.localPosition = localPosition1;
        controller.onButtonDown(button);
        stylus.transform.localPosition = localPosition2;
        controller.onStylusMove();
        expect(mockUC.pressAppObject).not.toHaveBeenCalled();
    });
    it("Registers itself", () => {
        const { controller, mockRegisterController } = makeTestRig();
        expect(mockRegisterController).toHaveBeenCalledWith(controller);
    });
});
//# sourceMappingURL=StylusPressOnAppObjectSC.test.js.map