import { describe, it, expect } from 'vitest'; import { konamiHandler, KONAMI_SEQUENCE } from '../src/lib/konami.js'; describe('konamiHandler', () => { it('fires once the full sequence is entered', () => { let hits = 0; const step = konamiHandler(() => hits++); KONAMI_SEQUENCE.forEach((k) => step(k)); expect(hits).toBe(1); }); it('is case-insensitive and fires again on a repeat', () => { let hits = 0; const step = konamiHandler(() => hits++); const upper = [ 'ArrowUp', 'ArrowUp', 'ArrowDown', 'ArrowDown', 'ArrowLeft', 'ArrowRight', 'ArrowLeft', 'ArrowRight', 'B', 'A', ]; upper.forEach((k) => step(k)); upper.forEach((k) => step(k)); expect(hits).toBe(2); }); it('a wrong key rewinds, but a stray ↑ starts a fresh attempt', () => { let hits = 0; const step = konamiHandler(() => hits++); step('arrowup'); step('arrowdown'); // wrong (expected another arrowup) -> reset step('x'); // noise KONAMI_SEQUENCE.forEach((k) => step(k)); // clean run expect(hits).toBe(1); }); it('does not fire on a partial sequence', () => { let hits = 0; const step = konamiHandler(() => hits++); KONAMI_SEQUENCE.slice(0, -1).forEach((k) => step(k)); expect(hits).toBe(0); }); });