@vnejs/compatibility.controls.gamepad-with-controls.cursor 0.1.8 → 0.1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +5 -3
- package/src/tests/controls.cursor.test.ts +65 -0
- package/src/tests/setup.ts +24 -0
- package/tsconfig.json +12 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vnejs/compatibility.controls.gamepad-with-controls.cursor",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.9",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"tsconfig.json"
|
|
19
19
|
],
|
|
20
20
|
"scripts": {
|
|
21
|
-
"test": "
|
|
21
|
+
"test": "npx @vnejs/monorepo test",
|
|
22
22
|
"build": "npx @vnejs/monorepo package",
|
|
23
23
|
"publish:major:plugin": "npm run publish:major",
|
|
24
24
|
"publish:minor:plugin": "npm run publish:minor",
|
|
@@ -37,6 +37,8 @@
|
|
|
37
37
|
"@vnejs/shared": "~0.1.0"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@vnejs/configs.ts-common": "~0.1.0"
|
|
40
|
+
"@vnejs/configs.ts-common": "~0.1.0",
|
|
41
|
+
"@vnejs/configs.vitest": "~0.1.0",
|
|
42
|
+
"@vnejs/test-utils": "~0.1.0"
|
|
41
43
|
}
|
|
42
44
|
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
2
|
+
|
|
3
|
+
import { spyEvent } from "@vnejs/test-utils";
|
|
4
|
+
|
|
5
|
+
import { CompatibilityCursorGamepadControls } from "../index.js";
|
|
6
|
+
import { CONTROLS_EVENTS, createCompatibilityTestModule, CURSOR_EVENTS, GAMEPAD_CONST, registerCompatibilityVne } from "./setup.js";
|
|
7
|
+
|
|
8
|
+
type AxisHandler = (event: { detail: { axis: number; axisMovementValue: number } }) => void;
|
|
9
|
+
|
|
10
|
+
describe("CompatibilityCursorGamepadControls", () => {
|
|
11
|
+
let axisHandlers: AxisHandler[] = [];
|
|
12
|
+
|
|
13
|
+
beforeEach(() => {
|
|
14
|
+
registerCompatibilityVne();
|
|
15
|
+
axisHandlers = [];
|
|
16
|
+
vi.useFakeTimers();
|
|
17
|
+
|
|
18
|
+
globalThis.joypad = {
|
|
19
|
+
set: vi.fn(),
|
|
20
|
+
on: vi.fn((event: string, handler: AxisHandler) => {
|
|
21
|
+
if (event === "axis_move") axisHandlers.push(handler);
|
|
22
|
+
}),
|
|
23
|
+
};
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it("init pushes gamepad controls", async () => {
|
|
27
|
+
const { module, observer } = createCompatibilityTestModule(CompatibilityCursorGamepadControls, { subscribe: false });
|
|
28
|
+
const push = spyEvent(observer, CONTROLS_EVENTS.PUSH);
|
|
29
|
+
|
|
30
|
+
await (module as CompatibilityCursorGamepadControls).init();
|
|
31
|
+
|
|
32
|
+
expect(push).toHaveBeenCalledOnce();
|
|
33
|
+
expect(globalThis.joypad.set).toHaveBeenCalledWith({ axisMovementThreshold: 0.1 });
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it("axis move emits CURSOR.SHIFT and CURSOR.SHOW then CURSOR.HIDE after timeout", async () => {
|
|
37
|
+
const { module, observer } = createCompatibilityTestModule(CompatibilityCursorGamepadControls, { subscribe: false });
|
|
38
|
+
const shift = spyEvent(observer, CURSOR_EVENTS.SHIFT);
|
|
39
|
+
const show = spyEvent(observer, CURSOR_EVENTS.SHOW);
|
|
40
|
+
const hide = spyEvent(observer, CURSOR_EVENTS.HIDE);
|
|
41
|
+
|
|
42
|
+
await (module as CompatibilityCursorGamepadControls).init();
|
|
43
|
+
axisHandlers[0]?.({ detail: { axis: 0, axisMovementValue: 0.5 } });
|
|
44
|
+
|
|
45
|
+
expect(shift).toHaveBeenCalledWith({ x: 0.5, y: 0 });
|
|
46
|
+
expect(show).toHaveBeenCalledOnce();
|
|
47
|
+
|
|
48
|
+
vi.advanceTimersByTime(2000);
|
|
49
|
+
|
|
50
|
+
expect(hide).toHaveBeenCalledOnce();
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it("right trigger keyup emits CURSOR.CLICK", async () => {
|
|
54
|
+
const { module, observer } = createCompatibilityTestModule(CompatibilityCursorGamepadControls, { subscribe: false });
|
|
55
|
+
const click = spyEvent(observer, CURSOR_EVENTS.CLICK);
|
|
56
|
+
const push = spyEvent(observer, CONTROLS_EVENTS.PUSH);
|
|
57
|
+
|
|
58
|
+
await (module as CompatibilityCursorGamepadControls).init();
|
|
59
|
+
|
|
60
|
+
const controls = push.mock.calls[0]?.[0]?.controls as Record<string, () => void>;
|
|
61
|
+
controls[GAMEPAD_CONST.BUTTONS.TRIGGER_RIGHT_KEYUP]();
|
|
62
|
+
|
|
63
|
+
expect(click).toHaveBeenCalledOnce();
|
|
64
|
+
});
|
|
65
|
+
});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { CONSTANTS as CONTROLS_CONST, PLUGIN_NAME as CONTROLS, SUBSCRIBE_EVENTS as CONTROLS_EVENTS } from "@vnejs/contracts.controls";
|
|
2
|
+
import { SUBSCRIBE_EVENTS as CURSOR_EVENTS, PLUGIN_NAME as CURSOR } from "@vnejs/contracts.controls.cursor";
|
|
3
|
+
import { CONSTANTS as GAMEPAD_CONST, PLUGIN_NAME as GAMEPAD } from "@vnejs/contracts.controls.gamepad";
|
|
4
|
+
import { createTestModule as baseCreateTestModule, registerCoreVne, registerVnePlugin, stubSilentEvent } from "@vnejs/test-utils";
|
|
5
|
+
|
|
6
|
+
export const registerCompatibilityVne = () => {
|
|
7
|
+
registerCoreVne();
|
|
8
|
+
registerVnePlugin(CONTROLS, { constants: CONTROLS_CONST, events: CONTROLS_EVENTS });
|
|
9
|
+
registerVnePlugin(CURSOR, { events: CURSOR_EVENTS });
|
|
10
|
+
registerVnePlugin(GAMEPAD, { constants: GAMEPAD_CONST });
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export const createCompatibilityTestModule = <T extends Parameters<typeof baseCreateTestModule>[0]>(
|
|
14
|
+
ModuleClass: T,
|
|
15
|
+
options: Parameters<typeof baseCreateTestModule>[1] = {},
|
|
16
|
+
) => {
|
|
17
|
+
const result = baseCreateTestModule(ModuleClass, options);
|
|
18
|
+
|
|
19
|
+
stubSilentEvent(result.observer, CONTROLS_EVENTS.PUSH);
|
|
20
|
+
|
|
21
|
+
return result;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export { CONTROLS_EVENTS, CURSOR_EVENTS, GAMEPAD_CONST };
|
package/tsconfig.json
CHANGED
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"extends": "@vnejs/configs.ts-common/tsconfig.json",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"rootDir": "src",
|
|
5
|
+
"outDir": "dist"
|
|
6
|
+
},
|
|
7
|
+
"include": [
|
|
8
|
+
"src/**/*.ts"
|
|
9
|
+
],
|
|
10
|
+
"exclude": [
|
|
11
|
+
"dist",
|
|
12
|
+
"node_modules",
|
|
13
|
+
"src/tests"
|
|
14
|
+
]
|
|
6
15
|
}
|