|
1 | 1 | import { describe, expect, test } from 'bun:test' |
2 | 2 |
|
3 | | -import { nextFreebuffModelId } from '../freebuff-model-navigation' |
| 3 | +import { |
| 4 | + freebuffModelNavigationDirectionForKey, |
| 5 | + nextFreebuffModelId, |
| 6 | +} from '../freebuff-model-navigation' |
4 | 7 |
|
5 | 8 | describe('nextFreebuffModelId', () => { |
6 | 9 | test('moves to the next model when moving forward', () => { |
@@ -49,3 +52,51 @@ describe('nextFreebuffModelId', () => { |
49 | 52 | ).toBeNull() |
50 | 53 | }) |
51 | 54 | }) |
| 55 | + |
| 56 | +describe('freebuffModelNavigationDirectionForKey', () => { |
| 57 | + test('maps arrow keys to model navigation directions', () => { |
| 58 | + expect(freebuffModelNavigationDirectionForKey({ name: 'down' })).toBe( |
| 59 | + 'forward', |
| 60 | + ) |
| 61 | + expect(freebuffModelNavigationDirectionForKey({ name: 'right' })).toBe( |
| 62 | + 'forward', |
| 63 | + ) |
| 64 | + expect(freebuffModelNavigationDirectionForKey({ name: 'up' })).toBe( |
| 65 | + 'backward', |
| 66 | + ) |
| 67 | + expect(freebuffModelNavigationDirectionForKey({ name: 'left' })).toBe( |
| 68 | + 'backward', |
| 69 | + ) |
| 70 | + }) |
| 71 | + |
| 72 | + test('maps tab and shift-tab to model navigation directions', () => { |
| 73 | + expect(freebuffModelNavigationDirectionForKey({ name: 'tab' })).toBe( |
| 74 | + 'forward', |
| 75 | + ) |
| 76 | + expect( |
| 77 | + freebuffModelNavigationDirectionForKey({ name: 'tab', shift: true }), |
| 78 | + ).toBe('backward') |
| 79 | + }) |
| 80 | + |
| 81 | + test('maps terminal tab sequences to model navigation directions', () => { |
| 82 | + expect(freebuffModelNavigationDirectionForKey({ sequence: '\t' })).toBe( |
| 83 | + 'forward', |
| 84 | + ) |
| 85 | + expect( |
| 86 | + freebuffModelNavigationDirectionForKey({ sequence: '\x1b[9u' }), |
| 87 | + ).toBe('forward') |
| 88 | + expect( |
| 89 | + freebuffModelNavigationDirectionForKey({ sequence: '\x1b[Z' }), |
| 90 | + ).toBe('backward') |
| 91 | + expect( |
| 92 | + freebuffModelNavigationDirectionForKey({ sequence: '\x1b[9;2u' }), |
| 93 | + ).toBe('backward') |
| 94 | + expect( |
| 95 | + freebuffModelNavigationDirectionForKey({ sequence: '\x1b[27;2;9~' }), |
| 96 | + ).toBe('backward') |
| 97 | + }) |
| 98 | + |
| 99 | + test('ignores non-navigation keys', () => { |
| 100 | + expect(freebuffModelNavigationDirectionForKey({ name: 'enter' })).toBeNull() |
| 101 | + }) |
| 102 | +}) |
0 commit comments