explodorama / files / test / padPlaces.test.ts
padPlaces.test.ts
| 1 | import { describe, expect, it } from 'vitest' |
| 2 | import { PAD_LAYOUTS } from '../src/ui/padLayouts' |
| 3 | import { facePosition, layoutOf, padPlaces, type PadSlot } from '../src/ui/padPlaces' |
| 4 | import type { PadFamily } from '../src/ui/padMap' |
| 5 | |
| 6 | const FAMILIES: PadFamily[] = ['xbox', 'playstation', 'nintendo', 'generic'] |
| 7 | const SLOTS: PadSlot[] = ['dpad', 'stick', 'move', 'bomb', 'charge', 'wait', 'l1', 'r1', 'start'] |
| 8 | |
| 9 | describe('padPlaces', () => { |
| 10 | it('places every part on every family, inside the box', () => { |
| 11 | for (const f of FAMILIES) { |
| 12 | const l = layoutOf(f) |
| 13 | const places = padPlaces(f) |
| 14 | for (const s of SLOTS) { |
| 15 | const p = places[s] |
| 16 | expect(p.size, `${f} ${s}`).toBeGreaterThan(0) |
| 17 | expect(p.x).toBeGreaterThanOrEqual(0) |
| 18 | expect(p.x).toBeLessThanOrEqual(l.width) |
| 19 | expect(p.y).toBeGreaterThanOrEqual(0) |
| 20 | expect(p.y).toBeLessThanOrEqual(l.height) |
| 21 | } |
| 22 | expect(l.image).toMatch(/^padart-.*\.png$/) |
| 23 | expect(l.height).toBeGreaterThan(0) |
| 24 | } |
| 25 | }) |
| 26 | |
| 27 | it('puts Move on the right and Wait at the bottom on a Nintendo pad, the standard way elsewhere', () => { |
| 28 | expect(facePosition('nintendo', 'move')).toBe('right') |
| 29 | expect(facePosition('nintendo', 'wait')).toBe('bottom') |
| 30 | for (const f of ['xbox', 'playstation', 'generic'] as const) { |
| 31 | expect(facePosition(f, 'move')).toBe('bottom') |
| 32 | expect(facePosition(f, 'wait')).toBe('right') |
| 33 | expect(facePosition(f, 'bomb')).toBe('left') |
| 34 | expect(facePosition(f, 'charge')).toBe('top') |
| 35 | } |
| 36 | const n = padPlaces('nintendo') |
| 37 | expect(n.move.x).toBe(PAD_LAYOUTS.nintendo.face.right.x) |
| 38 | expect(n.wait.y).toBe(PAD_LAYOUTS.nintendo.face.bottom.y) |
| 39 | }) |
| 40 | |
| 41 | it('uses the Xbox layout for a generic pad', () => { |
| 42 | expect(layoutOf('generic')).toBe(PAD_LAYOUTS.xbox) |
| 43 | expect(padPlaces('generic')).toEqual(padPlaces('xbox')) |
| 44 | }) |
| 45 | }) |