import { makeAppObjectRepo, ParametricLine, Vector3 } from "@vived/core";
import { makeMockPixelToSceneRayUC } from "../../Babylon";
import { makeStylusEntity } from "../../Stylus";
import { PressAppObjectUCMock } from "../Mocks/PressAppObjectUCMock";
import { StylusPressOnAppObjectSC } from "./StylusPressOnAppObjectSC";
function makeTestRig() {
    const appObjects = makeAppObjectRepo();
    const ao = appObjects.getOrCreate("stylus");
    const stylus = makeStylusEntity(ao);
    const mockRegisterController = jest.fn();
    stylus.registerController = mockRegisterController;
    const selectionAO = appObjects.getOrCreate("selection");
    const mockUC = new PressAppObjectUCMock(selectionAO);
    const mockPixelToSceneUC = makeMockPixelToSceneRayUC(appObjects);
    const mockPixelToRay = jest.fn().mockReturnValue(ParametricLine.Forward());
    mockPixelToSceneUC.pixelToSceneRay = mockPixelToRay;
    const controller = new 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(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 Vector3(0, 0, 0);
        const localPosition2 = new Vector3(0, 0, 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 Vector3(0, 0, 0);
        const localPosition2 = new Vector3(0, 0, 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