mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-22 19:14:33 -07:00
Improve error messages on failed onboarding (#17357)
This commit is contained in:
@@ -17,6 +17,7 @@ import {
|
||||
} from 'vitest';
|
||||
import { ValidationDialog } from './ValidationDialog.js';
|
||||
import { RadioButtonSelect } from './shared/RadioButtonSelect.js';
|
||||
import type { Key } from '../hooks/useKeypress.js';
|
||||
|
||||
// Mock the child components and utilities
|
||||
vi.mock('./shared/RadioButtonSelect.js', () => ({
|
||||
@@ -41,8 +42,15 @@ vi.mock('@google/gemini-cli-core', async (importOriginal) => {
|
||||
};
|
||||
});
|
||||
|
||||
// Capture keypress handler to test it
|
||||
let mockKeypressHandler: (key: Key) => void;
|
||||
let mockKeypressOptions: { isActive: boolean };
|
||||
|
||||
vi.mock('../hooks/useKeypress.js', () => ({
|
||||
useKeypress: vi.fn(),
|
||||
useKeypress: vi.fn((handler, options) => {
|
||||
mockKeypressHandler = handler;
|
||||
mockKeypressOptions = options;
|
||||
}),
|
||||
}));
|
||||
|
||||
describe('ValidationDialog', () => {
|
||||
@@ -99,6 +107,29 @@ describe('ValidationDialog', () => {
|
||||
expect(lastFrame()).toContain('https://example.com/help');
|
||||
unmount();
|
||||
});
|
||||
|
||||
it('should call onChoice with cancel when ESCAPE is pressed', () => {
|
||||
const { unmount } = render(<ValidationDialog onChoice={mockOnChoice} />);
|
||||
|
||||
// Verify the keypress hook is active
|
||||
expect(mockKeypressOptions.isActive).toBe(true);
|
||||
|
||||
// Simulate ESCAPE key press
|
||||
act(() => {
|
||||
mockKeypressHandler({
|
||||
name: 'escape',
|
||||
ctrl: false,
|
||||
shift: false,
|
||||
alt: false,
|
||||
cmd: false,
|
||||
insertable: false,
|
||||
sequence: '\x1b',
|
||||
});
|
||||
});
|
||||
|
||||
expect(mockOnChoice).toHaveBeenCalledWith('cancel');
|
||||
unmount();
|
||||
});
|
||||
});
|
||||
|
||||
describe('onChoice handling', () => {
|
||||
|
||||
@@ -48,17 +48,17 @@ export function ValidationDialog({
|
||||
},
|
||||
];
|
||||
|
||||
// Handle keypresses during 'waiting' state (ESC to cancel, Enter to confirm completion)
|
||||
// Handle keypresses globally for cancellation, and specific logic for waiting state
|
||||
useKeypress(
|
||||
(key) => {
|
||||
if (keyMatchers[Command.ESCAPE](key) || keyMatchers[Command.QUIT](key)) {
|
||||
onChoice('cancel');
|
||||
} else if (keyMatchers[Command.RETURN](key)) {
|
||||
} else if (state === 'waiting' && keyMatchers[Command.RETURN](key)) {
|
||||
// User confirmed verification is complete - transition to 'complete' state
|
||||
setState('complete');
|
||||
}
|
||||
},
|
||||
{ isActive: state === 'waiting' },
|
||||
{ isActive: state !== 'complete' },
|
||||
);
|
||||
|
||||
// When state becomes 'complete', show success message briefly then proceed
|
||||
|
||||
Reference in New Issue
Block a user