mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-20 18:14:29 -07:00
refactor(ui): unify keybinding infrastructure and support string initialization (#21776)
This commit is contained in:
committed by
GitHub
parent
b89944c3a3
commit
215f8f3f15
@@ -9,18 +9,12 @@ import { act } from 'react';
|
||||
import { renderHook } from '../../test-utils/render.js';
|
||||
import { useTabbedNavigation } from './useTabbedNavigation.js';
|
||||
import { useKeypress } from './useKeypress.js';
|
||||
import { useKeyMatchers } from './useKeyMatchers.js';
|
||||
import type { KeyMatchers } from '../keyMatchers.js';
|
||||
import type { Key, KeypressHandler } from '../contexts/KeypressContext.js';
|
||||
|
||||
vi.mock('./useKeypress.js', () => ({
|
||||
useKeypress: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock('./useKeyMatchers.js', () => ({
|
||||
useKeyMatchers: vi.fn(),
|
||||
}));
|
||||
|
||||
const createKey = (partial: Partial<Key>): Key => ({
|
||||
name: partial.name || '',
|
||||
sequence: partial.sequence || '',
|
||||
@@ -32,27 +26,10 @@ const createKey = (partial: Partial<Key>): Key => ({
|
||||
...partial,
|
||||
});
|
||||
|
||||
const mockKeyMatchers = {
|
||||
'cursor.left': vi.fn((key) => key.name === 'left'),
|
||||
'cursor.right': vi.fn((key) => key.name === 'right'),
|
||||
'dialog.next': vi.fn((key) => key.name === 'tab' && !key.shift),
|
||||
'dialog.previous': vi.fn((key) => key.name === 'tab' && key.shift),
|
||||
} as unknown as KeyMatchers;
|
||||
|
||||
vi.mock('../keyMatchers.js', () => ({
|
||||
Command: {
|
||||
MOVE_LEFT: 'cursor.left',
|
||||
MOVE_RIGHT: 'cursor.right',
|
||||
DIALOG_NEXT: 'dialog.next',
|
||||
DIALOG_PREV: 'dialog.previous',
|
||||
},
|
||||
}));
|
||||
|
||||
describe('useTabbedNavigation', () => {
|
||||
let capturedHandler: KeypressHandler;
|
||||
|
||||
beforeEach(() => {
|
||||
vi.mocked(useKeyMatchers).mockReturnValue(mockKeyMatchers);
|
||||
vi.mocked(useKeypress).mockImplementation((handler) => {
|
||||
capturedHandler = handler;
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user