2024-06-08 00:33:45 +02:00
|
|
|
import cfg_keyboard_qwerty from "#app/configs/inputs/cfg_keyboard_qwerty";
|
2024-08-22 06:49:33 -07:00
|
|
|
import pad_xbox360 from "#app/configs/inputs/pad_xbox360";
|
2025-02-22 22:52:07 -06:00
|
|
|
import GameManager from "#test/testUtils/gameManager";
|
|
|
|
import InputsHandler from "#test/testUtils/inputsHandler";
|
2024-08-22 06:49:33 -07:00
|
|
|
import Phaser from "phaser";
|
|
|
|
import { afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest";
|
2024-06-08 00:33:45 +02:00
|
|
|
|
|
|
|
|
|
|
|
describe("Inputs", () => {
|
|
|
|
let phaserGame: Phaser.Game;
|
|
|
|
let game: GameManager;
|
|
|
|
let originalDocument: Document;
|
|
|
|
|
|
|
|
beforeAll(() => {
|
|
|
|
originalDocument = window.document;
|
|
|
|
phaserGame = new Phaser.Game({
|
|
|
|
type: Phaser.HEADLESS,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
game.phaseInterceptor.restoreOg();
|
|
|
|
Object.defineProperty(window, "document", {
|
|
|
|
value: originalDocument,
|
|
|
|
configurable: true,
|
|
|
|
writable: true,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
game = new GameManager(phaserGame);
|
|
|
|
game.inputsHandler = new InputsHandler(game.scene);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("Mobile - test touch holding for 1ms - 1 input", async () => {
|
|
|
|
await game.inputsHandler.pressTouch("dpadUp", 1);
|
|
|
|
expect(game.inputsHandler.log.length).toBe(1);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("Mobile - test touch holding for 200ms - 1 input", async () => {
|
|
|
|
await game.inputsHandler.pressTouch("dpadUp", 200);
|
|
|
|
expect(game.inputsHandler.log.length).toBe(1);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("Mobile - test touch holding for 300ms - 2 input", async () => {
|
|
|
|
await game.inputsHandler.pressTouch("dpadUp", 300);
|
|
|
|
expect(game.inputsHandler.log.length).toBe(2);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("Mobile - test touch holding for 1000ms - 4 input", async () => {
|
2024-06-11 19:13:02 +02:00
|
|
|
await game.inputsHandler.pressTouch("dpadUp", 1050);
|
|
|
|
expect(game.inputsHandler.log.length).toBe(5);
|
2024-06-08 00:33:45 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
it("keyboard - test input holding for 200ms - 1 input", async() => {
|
|
|
|
await game.inputsHandler.pressKeyboardKey(cfg_keyboard_qwerty.deviceMapping.KEY_ARROW_UP, 200);
|
|
|
|
expect(game.inputsHandler.log.length).toBe(1);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("keyboard - test input holding for 300ms - 2 input", async() => {
|
|
|
|
await game.inputsHandler.pressKeyboardKey(cfg_keyboard_qwerty.deviceMapping.KEY_ARROW_UP, 300);
|
|
|
|
expect(game.inputsHandler.log.length).toBe(2);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("keyboard - test input holding for 1000ms - 4 input", async() => {
|
2024-06-11 19:13:02 +02:00
|
|
|
await game.inputsHandler.pressKeyboardKey(cfg_keyboard_qwerty.deviceMapping.KEY_ARROW_UP, 1050);
|
|
|
|
expect(game.inputsHandler.log.length).toBe(5);
|
2024-06-08 00:33:45 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
it("gamepad - test input holding for 1ms - 1 input", async() => {
|
|
|
|
await game.inputsHandler.pressGamepadButton(pad_xbox360.deviceMapping.RC_S, 1);
|
|
|
|
expect(game.inputsHandler.log.length).toBe(1);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("gamepad - test input holding for 200ms - 1 input", async() => {
|
|
|
|
await game.inputsHandler.pressGamepadButton(pad_xbox360.deviceMapping.RC_S, 200);
|
|
|
|
expect(game.inputsHandler.log.length).toBe(1);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("gamepad - test input holding for 300ms - 2 input", async() => {
|
|
|
|
await game.inputsHandler.pressGamepadButton(pad_xbox360.deviceMapping.RC_S, 300);
|
|
|
|
expect(game.inputsHandler.log.length).toBe(2);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("gamepad - test input holding for 1000ms - 4 input", async() => {
|
2024-06-11 19:13:02 +02:00
|
|
|
await game.inputsHandler.pressGamepadButton(pad_xbox360.deviceMapping.RC_S, 1050);
|
|
|
|
expect(game.inputsHandler.log.length).toBe(5);
|
2024-06-08 00:33:45 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|