diff --git a/tests/core.test.ts b/tests/core.test.ts index b927f58..94d7c01 100644 --- a/tests/core.test.ts +++ b/tests/core.test.ts @@ -4,6 +4,7 @@ import { EventGpz } from "../src/interface"; const coreJoyMock = (o: any) => core['Joy'](o) const coreBtnMock = (o: any) => core['Btn'](o) +const coreBtn4Mock = (o: any) => core['Btn4'](o) test("core joy: 1100 -> 000 (touch)", () => { const gpz = { @@ -34,3 +35,17 @@ test("core gpz: click on button (touch)", () => { expect(gpz.stateOld).toEqual([false]) expect(gpz.stateNew).toEqual([true]) }) + +test("core btn4: gamepad input updates state", () => { + const gpz = { + from: EventGpz.Gamepad, + buttons: [true, false, true], + stateOld: [false, false, false], + stateNew: [false, false, false], + }; + + coreBtn4Mock(gpz) + + expect(gpz.stateOld).toEqual([false, false, false]) + expect(gpz.stateNew).toEqual([true, false, true]) +}) diff --git a/tests/draw.test.ts b/tests/draw.test.ts index 2a87499..4441301 100644 --- a/tests/draw.test.ts +++ b/tests/draw.test.ts @@ -4,6 +4,7 @@ import { draw, drawCircle } from "../src/draw" const drawJoyMock = (o: any) => draw['Joy'](o) const drawBtnMock = (o: any) => draw['Btn'](o) const drawDpadMock = (o: any) => draw['Dpad'](o) +const drawBtn4Mock = (o: any) => draw['Btn4'](o) const drawCircleMock = (a: any, b: any, c: any, d: any, e: any) => drawCircle(a, b, e, {x: c, y: d}) test("drawCircle should draw a filled circle with the correct attributes", () => { @@ -106,3 +107,23 @@ test("Dpad should draw correctly based on stateNew", () => { expect(gpz.ctx2d.clearRect).toHaveBeenCalledWith(0, 0, 100, 100) }) + +test("Btn4 should draw correctly based on stateNew", () => { + const gpz = { + canvas: { width: 100, height: 100, dataset: { gpzSize: '16', color: '#aaaaaa80' } }, + stateNew: [false, false, true, false], + ctx2d: { + fillStyle: "", + beginPath: jest.fn(), + arc: jest.fn(), + fill: jest.fn(), + stroke: jest.fn(), + closePath: jest.fn(), + clearRect: jest.fn() + }, + } + + drawBtn4Mock(gpz) + + expect(gpz.ctx2d.clearRect).toHaveBeenCalledWith(0, 0, 100, 100) +}) diff --git a/tests/handlers.test.ts b/tests/handlers.test.ts index 17ca087..25d24ea 100644 --- a/tests/handlers.test.ts +++ b/tests/handlers.test.ts @@ -34,6 +34,8 @@ test('handleGamepadAxis should return an array of Vector2d', () => { test('handleGamepadButtons should return an array of pressed button indices', () => { const gamepad = {buttons: [{ pressed: false }, { pressed: false }, { pressed: true }]} const result = handleGamepadButtonsMock(gamepad) - expect(result).toHaveLength(1) - expect(result[0]).toBe(2) + expect(result).toHaveLength(3) + expect(result[0]).toBe(false) + expect(result[1]).toBe(false) + expect(result[2]).toBe(true) })