explodorama / files / test / demoInput.test.ts
demoInput.test.ts
92cc4ee3 2026-11-02 Pavel Safronov | 1 | import { describe, expect, it } from 'vitest' |
| 2 | import { | |
| 3 | DEMO_INPUTS, demoHintText, demoInputFamily, demoInputLabel, effectiveDemoInput, inputForFamily, isKeysInput, isPadInput, nextDemoInput, | |
| 4 | } from '../src/ui/demoInput' | |
| 5 | ||
| 6 | describe('the demo input switcher', () => { | |
| 7 | it('cycles touch, mouse, keyboard, ps5, xbox, switch, generic, and round again', () => { | |
| 8 | expect(DEMO_INPUTS).toEqual(['touch', 'mouse', 'keyboard', 'ps5', 'xbox', 'switch', 'generic']) | |
| 9 | let id = DEMO_INPUTS[0]! | |
| 10 | const seen = [id] | |
| 11 | for (let i = 0; i < DEMO_INPUTS.length; i++) seen.push((id = nextDemoInput(id))) | |
| 12 | expect(seen).toEqual(['touch', 'mouse', 'keyboard', 'ps5', 'xbox', 'switch', 'generic', 'touch']) | |
| 13 | }) | |
| 14 | ||
| 15 | it('labels the button exactly', () => { | |
| 16 | expect(DEMO_INPUTS.map(demoInputLabel)).toEqual([ | |
| 17 | 'Input: touch', 'Input: mouse', 'Input: keyboard', 'Input: controller: ps5', 'Input: controller: xbox', 'Input: controller: switch', 'Input: controller: generic', | |
| 18 | ]) | |
| 19 | }) | |
| 20 | ||
| 21 | it('maps controllers to their picture family, and back; the keyboard is no controller', () => { | |
| 22 | expect(DEMO_INPUTS.map(demoInputFamily)).toEqual([null, null, null, 'playstation', 'xbox', 'nintendo', 'generic']) | |
| 23 | expect(DEMO_INPUTS.map(isKeysInput)).toEqual([false, false, true, false, false, false, false]) | |
| 24 | expect(isPadInput('keyboard')).toBe(false) | |
| 25 | for (const id of DEMO_INPUTS) if (isPadInput(id)) expect(inputForFamily(demoInputFamily(id)!)).toBe(id) | |
| 26 | }) | |
| 27 | ||
| 28 | it('shows the detected input without a pick, and the pick over it', () => { | |
| 29 | expect(effectiveDemoInput(null, false, 'xbox')).toBe('touch') | |
| 30 | expect(effectiveDemoInput(null, true, 'xbox')).toBe('xbox') | |
| 31 | expect(effectiveDemoInput(null, true, 'nintendo')).toBe('switch') | |
| 32 | expect(effectiveDemoInput('mouse', true, 'xbox')).toBe('mouse') | |
| 33 | expect(effectiveDemoInput('ps5', false, 'generic')).toBe('ps5') | |
| 34 | }) | |
| 35 | ||
| 36 | it('words the last line for the input', () => { | |
| 37 | expect(demoHintText('touch')).toBe('Tap anywhere to play') | |
| 38 | expect(demoHintText('mouse')).toBe('Click anywhere to play') | |
| 39 | expect(demoHintText('keyboard')).toBe('Press Enter or Esc to play') | |
| 40 | for (const id of ['ps5', 'xbox', 'switch', 'generic'] as const) expect(demoHintText(id)).toBe('Hold {move} to play') | |
| 41 | }) | |
| 42 | }) |