mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-01 17:02:29 -07:00
Fix tests to wrap all calls changing the UI with act. (#12268)
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
*/
|
||||
|
||||
import { renderWithProviders } from '../../test-utils/render.js';
|
||||
import { waitFor } from '../../test-utils/async.js';
|
||||
import { act } from 'react';
|
||||
import type { InputPromptProps } from './InputPrompt.js';
|
||||
import { InputPrompt } from './InputPrompt.js';
|
||||
@@ -240,7 +241,7 @@ describe('InputPrompt', () => {
|
||||
await act(async () => {
|
||||
stdin.write('\u001B[A');
|
||||
});
|
||||
await vi.waitFor(() =>
|
||||
await waitFor(() =>
|
||||
expect(mockShellHistory.getPreviousCommand).toHaveBeenCalled(),
|
||||
);
|
||||
unmount();
|
||||
@@ -252,10 +253,10 @@ describe('InputPrompt', () => {
|
||||
|
||||
await act(async () => {
|
||||
stdin.write('\u001B[B');
|
||||
await waitFor(() =>
|
||||
expect(mockShellHistory.getNextCommand).toHaveBeenCalled(),
|
||||
);
|
||||
});
|
||||
await vi.waitFor(() =>
|
||||
expect(mockShellHistory.getNextCommand).toHaveBeenCalled(),
|
||||
);
|
||||
unmount();
|
||||
});
|
||||
|
||||
@@ -269,7 +270,7 @@ describe('InputPrompt', () => {
|
||||
await act(async () => {
|
||||
stdin.write('\u001B[A');
|
||||
});
|
||||
await vi.waitFor(() => {
|
||||
await waitFor(() => {
|
||||
expect(mockShellHistory.getPreviousCommand).toHaveBeenCalled();
|
||||
expect(props.buffer.setText).toHaveBeenCalledWith('previous command');
|
||||
});
|
||||
@@ -284,7 +285,7 @@ describe('InputPrompt', () => {
|
||||
await act(async () => {
|
||||
stdin.write('\r');
|
||||
});
|
||||
await vi.waitFor(() => {
|
||||
await waitFor(() => {
|
||||
expect(mockShellHistory.addCommandToHistory).toHaveBeenCalledWith(
|
||||
'ls -l',
|
||||
);
|
||||
@@ -300,21 +301,19 @@ describe('InputPrompt', () => {
|
||||
await act(async () => {
|
||||
stdin.write('\u001B[A'); // Up arrow
|
||||
});
|
||||
await vi.waitFor(() =>
|
||||
expect(mockInputHistory.navigateUp).toHaveBeenCalled(),
|
||||
);
|
||||
await waitFor(() => expect(mockInputHistory.navigateUp).toHaveBeenCalled());
|
||||
|
||||
await act(async () => {
|
||||
stdin.write('\u001B[B'); // Down arrow
|
||||
});
|
||||
await vi.waitFor(() =>
|
||||
await waitFor(() =>
|
||||
expect(mockInputHistory.navigateDown).toHaveBeenCalled(),
|
||||
);
|
||||
|
||||
await act(async () => {
|
||||
stdin.write('\r'); // Enter
|
||||
});
|
||||
await vi.waitFor(() =>
|
||||
await waitFor(() =>
|
||||
expect(props.onSubmit).toHaveBeenCalledWith('some text'),
|
||||
);
|
||||
|
||||
@@ -342,14 +341,14 @@ describe('InputPrompt', () => {
|
||||
await act(async () => {
|
||||
stdin.write('\u001B[A'); // Up arrow
|
||||
});
|
||||
await vi.waitFor(() =>
|
||||
await waitFor(() =>
|
||||
expect(mockCommandCompletion.navigateUp).toHaveBeenCalledTimes(1),
|
||||
);
|
||||
|
||||
await act(async () => {
|
||||
stdin.write('\u0010'); // Ctrl+P
|
||||
});
|
||||
await vi.waitFor(() =>
|
||||
await waitFor(() =>
|
||||
expect(mockCommandCompletion.navigateUp).toHaveBeenCalledTimes(2),
|
||||
);
|
||||
expect(mockCommandCompletion.navigateDown).not.toHaveBeenCalled();
|
||||
@@ -374,14 +373,14 @@ describe('InputPrompt', () => {
|
||||
await act(async () => {
|
||||
stdin.write('\u001B[B'); // Down arrow
|
||||
});
|
||||
await vi.waitFor(() =>
|
||||
await waitFor(() =>
|
||||
expect(mockCommandCompletion.navigateDown).toHaveBeenCalledTimes(1),
|
||||
);
|
||||
|
||||
await act(async () => {
|
||||
stdin.write('\u000E'); // Ctrl+N
|
||||
});
|
||||
await vi.waitFor(() =>
|
||||
await waitFor(() =>
|
||||
expect(mockCommandCompletion.navigateDown).toHaveBeenCalledTimes(2),
|
||||
);
|
||||
expect(mockCommandCompletion.navigateUp).not.toHaveBeenCalled();
|
||||
@@ -395,32 +394,29 @@ describe('InputPrompt', () => {
|
||||
showSuggestions: false,
|
||||
});
|
||||
props.buffer.setText('some text');
|
||||
|
||||
const { stdin, unmount } = renderWithProviders(<InputPrompt {...props} />);
|
||||
|
||||
await act(async () => {
|
||||
stdin.write('\u001B[A'); // Up arrow
|
||||
});
|
||||
await vi.waitFor(() =>
|
||||
expect(mockInputHistory.navigateUp).toHaveBeenCalled(),
|
||||
);
|
||||
await waitFor(() => expect(mockInputHistory.navigateUp).toHaveBeenCalled());
|
||||
await act(async () => {
|
||||
stdin.write('\u001B[B'); // Down arrow
|
||||
});
|
||||
await vi.waitFor(() =>
|
||||
await waitFor(() =>
|
||||
expect(mockInputHistory.navigateDown).toHaveBeenCalled(),
|
||||
);
|
||||
await act(async () => {
|
||||
stdin.write('\u0010'); // Ctrl+P
|
||||
});
|
||||
await vi.waitFor(() => {});
|
||||
await act(async () => {
|
||||
stdin.write('\u000E'); // Ctrl+N
|
||||
});
|
||||
await vi.waitFor(() => {});
|
||||
|
||||
expect(mockCommandCompletion.navigateUp).not.toHaveBeenCalled();
|
||||
expect(mockCommandCompletion.navigateDown).not.toHaveBeenCalled();
|
||||
await waitFor(() => {
|
||||
expect(mockCommandCompletion.navigateUp).not.toHaveBeenCalled();
|
||||
expect(mockCommandCompletion.navigateDown).not.toHaveBeenCalled();
|
||||
});
|
||||
unmount();
|
||||
});
|
||||
|
||||
@@ -447,7 +443,7 @@ describe('InputPrompt', () => {
|
||||
await act(async () => {
|
||||
stdin.write('\x16'); // Ctrl+V
|
||||
});
|
||||
await vi.waitFor(() => {
|
||||
await waitFor(() => {
|
||||
expect(clipboardUtils.clipboardHasImage).toHaveBeenCalled();
|
||||
expect(clipboardUtils.saveClipboardImage).toHaveBeenCalledWith(
|
||||
props.config.getTargetDir(),
|
||||
@@ -470,7 +466,7 @@ describe('InputPrompt', () => {
|
||||
await act(async () => {
|
||||
stdin.write('\x16'); // Ctrl+V
|
||||
});
|
||||
await vi.waitFor(() => {
|
||||
await waitFor(() => {
|
||||
expect(clipboardUtils.clipboardHasImage).toHaveBeenCalled();
|
||||
});
|
||||
expect(clipboardUtils.saveClipboardImage).not.toHaveBeenCalled();
|
||||
@@ -489,7 +485,7 @@ describe('InputPrompt', () => {
|
||||
await act(async () => {
|
||||
stdin.write('\x16'); // Ctrl+V
|
||||
});
|
||||
await vi.waitFor(() => {
|
||||
await waitFor(() => {
|
||||
expect(clipboardUtils.saveClipboardImage).toHaveBeenCalled();
|
||||
});
|
||||
expect(mockBuffer.setText).not.toHaveBeenCalled();
|
||||
@@ -518,7 +514,7 @@ describe('InputPrompt', () => {
|
||||
await act(async () => {
|
||||
stdin.write('\x16'); // Ctrl+V
|
||||
});
|
||||
await vi.waitFor(() => {
|
||||
await waitFor(() => {
|
||||
// Should insert at cursor position with spaces
|
||||
expect(mockBuffer.replaceRangeByOffset).toHaveBeenCalled();
|
||||
});
|
||||
@@ -549,7 +545,7 @@ describe('InputPrompt', () => {
|
||||
await act(async () => {
|
||||
stdin.write('\x16'); // Ctrl+V
|
||||
});
|
||||
await vi.waitFor(() => {
|
||||
await waitFor(() => {
|
||||
expect(consoleErrorSpy).toHaveBeenCalledWith(
|
||||
'Error handling clipboard image:',
|
||||
expect.any(Error),
|
||||
@@ -577,7 +573,7 @@ describe('InputPrompt', () => {
|
||||
await act(async () => {
|
||||
stdin.write('\t'); // Press Tab
|
||||
});
|
||||
await vi.waitFor(() =>
|
||||
await waitFor(() =>
|
||||
expect(mockCommandCompletion.handleAutocomplete).toHaveBeenCalledWith(0),
|
||||
);
|
||||
unmount();
|
||||
@@ -601,7 +597,7 @@ describe('InputPrompt', () => {
|
||||
await act(async () => {
|
||||
stdin.write('\t'); // Press Tab
|
||||
});
|
||||
await vi.waitFor(() =>
|
||||
await waitFor(() =>
|
||||
expect(mockCommandCompletion.handleAutocomplete).toHaveBeenCalledWith(1),
|
||||
);
|
||||
unmount();
|
||||
@@ -626,7 +622,7 @@ describe('InputPrompt', () => {
|
||||
await act(async () => {
|
||||
stdin.write('\t'); // Press Tab
|
||||
});
|
||||
await vi.waitFor(() =>
|
||||
await waitFor(() =>
|
||||
// It should NOT become '/show'. It should correctly become '/memory show'.
|
||||
expect(mockCommandCompletion.handleAutocomplete).toHaveBeenCalledWith(0),
|
||||
);
|
||||
@@ -648,7 +644,7 @@ describe('InputPrompt', () => {
|
||||
await act(async () => {
|
||||
stdin.write('\t'); // Press Tab
|
||||
});
|
||||
await vi.waitFor(() =>
|
||||
await waitFor(() =>
|
||||
expect(mockCommandCompletion.handleAutocomplete).toHaveBeenCalledWith(0),
|
||||
);
|
||||
unmount();
|
||||
@@ -668,7 +664,7 @@ describe('InputPrompt', () => {
|
||||
await act(async () => {
|
||||
stdin.write('\r');
|
||||
});
|
||||
await vi.waitFor(() => {
|
||||
await waitFor(() => {
|
||||
// The app should autocomplete the text, NOT submit.
|
||||
expect(mockCommandCompletion.handleAutocomplete).toHaveBeenCalledWith(0);
|
||||
});
|
||||
@@ -700,7 +696,7 @@ describe('InputPrompt', () => {
|
||||
await act(async () => {
|
||||
stdin.write('\t'); // Press Tab for autocomplete
|
||||
});
|
||||
await vi.waitFor(() =>
|
||||
await waitFor(() =>
|
||||
expect(mockCommandCompletion.handleAutocomplete).toHaveBeenCalledWith(0),
|
||||
);
|
||||
unmount();
|
||||
@@ -714,9 +710,10 @@ describe('InputPrompt', () => {
|
||||
await act(async () => {
|
||||
stdin.write('\r'); // Press Enter
|
||||
});
|
||||
await vi.waitFor(() => {});
|
||||
|
||||
expect(props.onSubmit).not.toHaveBeenCalled();
|
||||
await waitFor(() => {
|
||||
expect(props.onSubmit).not.toHaveBeenCalled();
|
||||
});
|
||||
unmount();
|
||||
});
|
||||
|
||||
@@ -733,9 +730,7 @@ describe('InputPrompt', () => {
|
||||
await act(async () => {
|
||||
stdin.write('\r');
|
||||
});
|
||||
await vi.waitFor(() =>
|
||||
expect(props.onSubmit).toHaveBeenCalledWith('/clear'),
|
||||
);
|
||||
await waitFor(() => expect(props.onSubmit).toHaveBeenCalledWith('/clear'));
|
||||
unmount();
|
||||
});
|
||||
|
||||
@@ -752,9 +747,7 @@ describe('InputPrompt', () => {
|
||||
await act(async () => {
|
||||
stdin.write('\r');
|
||||
});
|
||||
await vi.waitFor(() =>
|
||||
expect(props.onSubmit).toHaveBeenCalledWith('/clear'),
|
||||
);
|
||||
await waitFor(() => expect(props.onSubmit).toHaveBeenCalledWith('/clear'));
|
||||
unmount();
|
||||
});
|
||||
|
||||
@@ -772,7 +765,7 @@ describe('InputPrompt', () => {
|
||||
await act(async () => {
|
||||
stdin.write('\r');
|
||||
});
|
||||
await vi.waitFor(() =>
|
||||
await waitFor(() =>
|
||||
expect(mockCommandCompletion.handleAutocomplete).toHaveBeenCalledWith(0),
|
||||
);
|
||||
expect(props.onSubmit).not.toHaveBeenCalled();
|
||||
@@ -790,7 +783,7 @@ describe('InputPrompt', () => {
|
||||
await act(async () => {
|
||||
stdin.write('\r');
|
||||
});
|
||||
await vi.waitFor(() => {
|
||||
await waitFor(() => {
|
||||
expect(props.buffer.backspace).toHaveBeenCalled();
|
||||
expect(props.buffer.newline).toHaveBeenCalled();
|
||||
});
|
||||
@@ -800,13 +793,15 @@ describe('InputPrompt', () => {
|
||||
});
|
||||
|
||||
it('should clear the buffer on Ctrl+C if it has text', async () => {
|
||||
props.buffer.setText('some text to clear');
|
||||
await act(async () => {
|
||||
props.buffer.setText('some text to clear');
|
||||
});
|
||||
const { stdin, unmount } = renderWithProviders(<InputPrompt {...props} />);
|
||||
|
||||
await act(async () => {
|
||||
stdin.write('\x03'); // Ctrl+C character
|
||||
});
|
||||
await vi.waitFor(() => {
|
||||
await waitFor(() => {
|
||||
expect(props.buffer.setText).toHaveBeenCalledWith('');
|
||||
expect(mockCommandCompletion.resetCompletionState).toHaveBeenCalled();
|
||||
});
|
||||
@@ -821,9 +816,10 @@ describe('InputPrompt', () => {
|
||||
await act(async () => {
|
||||
stdin.write('\x03'); // Ctrl+C character
|
||||
});
|
||||
await vi.waitFor(() => {});
|
||||
|
||||
expect(props.buffer.setText).not.toHaveBeenCalled();
|
||||
await waitFor(() => {
|
||||
expect(props.buffer.setText).not.toHaveBeenCalled();
|
||||
});
|
||||
unmount();
|
||||
});
|
||||
|
||||
@@ -922,7 +918,7 @@ describe('InputPrompt', () => {
|
||||
|
||||
const { unmount } = renderWithProviders(<InputPrompt {...props} />);
|
||||
|
||||
await vi.waitFor(() => {
|
||||
await waitFor(() => {
|
||||
expect(mockedUseCommandCompletion).toHaveBeenCalledWith(
|
||||
mockBuffer,
|
||||
['/test/project/src'],
|
||||
@@ -949,7 +945,7 @@ describe('InputPrompt', () => {
|
||||
await act(async () => {
|
||||
stdin.write('i');
|
||||
});
|
||||
await vi.waitFor(() => {
|
||||
await waitFor(() => {
|
||||
expect(props.vimHandleInput).toHaveBeenCalled();
|
||||
});
|
||||
expect(mockBuffer.handleInput).not.toHaveBeenCalled();
|
||||
@@ -965,7 +961,7 @@ describe('InputPrompt', () => {
|
||||
await act(async () => {
|
||||
stdin.write('i');
|
||||
});
|
||||
await vi.waitFor(() => {
|
||||
await waitFor(() => {
|
||||
expect(props.vimHandleInput).toHaveBeenCalled();
|
||||
expect(mockBuffer.handleInput).toHaveBeenCalled();
|
||||
});
|
||||
@@ -982,7 +978,7 @@ describe('InputPrompt', () => {
|
||||
await act(async () => {
|
||||
stdin.write('i');
|
||||
});
|
||||
await vi.waitFor(() => {
|
||||
await waitFor(() => {
|
||||
expect(props.vimHandleInput).toHaveBeenCalled();
|
||||
expect(mockBuffer.handleInput).toHaveBeenCalled();
|
||||
});
|
||||
@@ -1000,7 +996,7 @@ describe('InputPrompt', () => {
|
||||
await act(async () => {
|
||||
stdin.write('\x1B[200~pasted text\x1B[201~');
|
||||
});
|
||||
await vi.waitFor(() => {
|
||||
await waitFor(() => {
|
||||
expect(mockBuffer.handleInput).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
paste: true,
|
||||
@@ -1020,7 +1016,7 @@ describe('InputPrompt', () => {
|
||||
await act(async () => {
|
||||
stdin.write('a');
|
||||
});
|
||||
await vi.waitFor(() => {});
|
||||
await waitFor(() => {});
|
||||
|
||||
expect(mockBuffer.handleInput).not.toHaveBeenCalled();
|
||||
unmount();
|
||||
@@ -1090,7 +1086,7 @@ describe('InputPrompt', () => {
|
||||
<InputPrompt {...props} />,
|
||||
);
|
||||
|
||||
await vi.waitFor(() => {
|
||||
await waitFor(() => {
|
||||
const frame = stdout.lastFrame();
|
||||
expect(frame).toContain(expected);
|
||||
});
|
||||
@@ -1147,7 +1143,7 @@ describe('InputPrompt', () => {
|
||||
<InputPrompt {...props} />,
|
||||
);
|
||||
|
||||
await vi.waitFor(() => {
|
||||
await waitFor(() => {
|
||||
const frame = stdout.lastFrame();
|
||||
expect(frame).toContain(expected);
|
||||
});
|
||||
@@ -1171,7 +1167,7 @@ describe('InputPrompt', () => {
|
||||
<InputPrompt {...props} />,
|
||||
);
|
||||
|
||||
await vi.waitFor(() => {
|
||||
await waitFor(() => {
|
||||
const frame = stdout.lastFrame();
|
||||
const lines = frame!.split('\n');
|
||||
// The line with the cursor should just be an inverted space inside the box border
|
||||
@@ -1203,7 +1199,7 @@ describe('InputPrompt', () => {
|
||||
<InputPrompt {...props} />,
|
||||
);
|
||||
|
||||
await vi.waitFor(() => {
|
||||
await waitFor(() => {
|
||||
const frame = stdout.lastFrame();
|
||||
// Check that all lines, including the empty one, are rendered.
|
||||
// This implicitly tests that the Box wrapper provides height for the empty line.
|
||||
@@ -1241,7 +1237,7 @@ describe('InputPrompt', () => {
|
||||
await act(async () => {
|
||||
stdin.write(`\x1b[200~${pastedText}\x1b[201~`);
|
||||
});
|
||||
await vi.waitFor(() => {
|
||||
await waitFor(() => {
|
||||
// Verify that the buffer's handleInput was called once with the full text
|
||||
expect(props.buffer.handleInput).toHaveBeenCalledTimes(1);
|
||||
expect(props.buffer.handleInput).toHaveBeenCalledWith(
|
||||
@@ -1277,7 +1273,9 @@ describe('InputPrompt', () => {
|
||||
const { stdin, unmount } = renderWithProviders(
|
||||
<InputPrompt {...props} />,
|
||||
);
|
||||
await vi.runAllTimersAsync();
|
||||
await act(async () => {
|
||||
await vi.runAllTimersAsync();
|
||||
});
|
||||
|
||||
// Simulate a paste operation (this should set the paste protection)
|
||||
await act(async () => {
|
||||
@@ -1288,7 +1286,9 @@ describe('InputPrompt', () => {
|
||||
await act(async () => {
|
||||
stdin.write('\r');
|
||||
});
|
||||
await vi.runAllTimersAsync();
|
||||
await act(async () => {
|
||||
await vi.runAllTimersAsync();
|
||||
});
|
||||
|
||||
// Verify that onSubmit was NOT called due to recent paste protection
|
||||
expect(props.onSubmit).not.toHaveBeenCalled();
|
||||
@@ -1304,13 +1304,17 @@ describe('InputPrompt', () => {
|
||||
const { stdin, unmount } = renderWithProviders(
|
||||
<InputPrompt {...props} />,
|
||||
);
|
||||
await vi.runAllTimersAsync();
|
||||
await act(async () => {
|
||||
await vi.runAllTimersAsync();
|
||||
});
|
||||
|
||||
// Simulate a paste operation (this sets the protection)
|
||||
await act(async () => {
|
||||
stdin.write('\x1b[200~pasted text\x1b[201~');
|
||||
});
|
||||
await vi.runAllTimersAsync();
|
||||
await act(async () => {
|
||||
await vi.runAllTimersAsync();
|
||||
});
|
||||
|
||||
// Advance timers past the protection timeout
|
||||
await act(async () => {
|
||||
@@ -1321,7 +1325,9 @@ describe('InputPrompt', () => {
|
||||
await act(async () => {
|
||||
stdin.write('\r');
|
||||
});
|
||||
await vi.runAllTimersAsync();
|
||||
await act(async () => {
|
||||
await vi.runAllTimersAsync();
|
||||
});
|
||||
|
||||
expect(props.onSubmit).toHaveBeenCalledWith('pasted text');
|
||||
expect(props.buffer.newline).not.toHaveBeenCalled();
|
||||
@@ -1349,19 +1355,25 @@ describe('InputPrompt', () => {
|
||||
<InputPrompt {...props} />,
|
||||
{ kittyProtocolEnabled: true },
|
||||
);
|
||||
await vi.runAllTimersAsync();
|
||||
await act(async () => {
|
||||
await vi.runAllTimersAsync();
|
||||
});
|
||||
|
||||
// Simulate a paste operation
|
||||
await act(async () => {
|
||||
stdin.write('\x1b[200~some pasted stuff\x1b[201~');
|
||||
});
|
||||
await vi.runAllTimersAsync();
|
||||
await act(async () => {
|
||||
await vi.runAllTimersAsync();
|
||||
});
|
||||
|
||||
// Simulate an Enter key press immediately after paste
|
||||
await act(async () => {
|
||||
stdin.write('\r');
|
||||
});
|
||||
await vi.runAllTimersAsync();
|
||||
await act(async () => {
|
||||
await vi.runAllTimersAsync();
|
||||
});
|
||||
|
||||
// Verify that onSubmit was called
|
||||
expect(props.onSubmit).toHaveBeenCalledWith('pasted command');
|
||||
@@ -1376,13 +1388,17 @@ describe('InputPrompt', () => {
|
||||
const { stdin, unmount } = renderWithProviders(
|
||||
<InputPrompt {...props} />,
|
||||
);
|
||||
await vi.runAllTimersAsync();
|
||||
await act(async () => {
|
||||
await vi.runAllTimersAsync();
|
||||
});
|
||||
|
||||
// Press Enter without any recent paste
|
||||
await act(async () => {
|
||||
stdin.write('\r');
|
||||
});
|
||||
await vi.runAllTimersAsync();
|
||||
await act(async () => {
|
||||
await vi.runAllTimersAsync();
|
||||
});
|
||||
|
||||
// Verify that onSubmit was called normally
|
||||
expect(props.onSubmit).toHaveBeenCalledWith('normal command');
|
||||
@@ -1404,17 +1420,17 @@ describe('InputPrompt', () => {
|
||||
|
||||
await act(async () => {
|
||||
stdin.write('\x1B');
|
||||
});
|
||||
await vi.waitFor(() => {
|
||||
expect(onEscapePromptChange).toHaveBeenCalledWith(true);
|
||||
await waitFor(() => {
|
||||
expect(onEscapePromptChange).toHaveBeenCalledWith(false);
|
||||
});
|
||||
});
|
||||
|
||||
await act(async () => {
|
||||
stdin.write('\x1B');
|
||||
});
|
||||
await vi.waitFor(() => {
|
||||
expect(props.buffer.setText).toHaveBeenCalledWith('');
|
||||
expect(mockCommandCompletion.resetCompletionState).toHaveBeenCalled();
|
||||
await waitFor(() => {
|
||||
expect(props.buffer.setText).toHaveBeenCalledWith('');
|
||||
expect(mockCommandCompletion.resetCompletionState).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
unmount();
|
||||
});
|
||||
@@ -1431,18 +1447,16 @@ describe('InputPrompt', () => {
|
||||
|
||||
await act(async () => {
|
||||
stdin.write('\x1B');
|
||||
});
|
||||
|
||||
await vi.waitFor(() => {
|
||||
expect(onEscapePromptChange).toHaveBeenCalledWith(true);
|
||||
await waitFor(() => {
|
||||
expect(onEscapePromptChange).toHaveBeenCalledWith(false);
|
||||
});
|
||||
});
|
||||
|
||||
await act(async () => {
|
||||
stdin.write('a');
|
||||
});
|
||||
|
||||
await vi.waitFor(() => {
|
||||
expect(onEscapePromptChange).toHaveBeenCalledWith(false);
|
||||
await waitFor(() => {
|
||||
expect(onEscapePromptChange).toHaveBeenCalledWith(false);
|
||||
});
|
||||
});
|
||||
unmount();
|
||||
});
|
||||
@@ -1457,10 +1471,10 @@ describe('InputPrompt', () => {
|
||||
|
||||
await act(async () => {
|
||||
stdin.write('\x1B');
|
||||
await waitFor(() =>
|
||||
expect(props.setShellModeActive).toHaveBeenCalledWith(false),
|
||||
);
|
||||
});
|
||||
await vi.waitFor(() =>
|
||||
expect(props.setShellModeActive).toHaveBeenCalledWith(false),
|
||||
);
|
||||
unmount();
|
||||
});
|
||||
|
||||
@@ -1479,7 +1493,7 @@ describe('InputPrompt', () => {
|
||||
await act(async () => {
|
||||
stdin.write('\x1B');
|
||||
});
|
||||
await vi.waitFor(() =>
|
||||
await waitFor(() =>
|
||||
expect(mockCommandCompletion.resetCompletionState).toHaveBeenCalled(),
|
||||
);
|
||||
unmount();
|
||||
@@ -1494,12 +1508,16 @@ describe('InputPrompt', () => {
|
||||
<InputPrompt {...props} />,
|
||||
{ kittyProtocolEnabled: false },
|
||||
);
|
||||
await vi.runAllTimersAsync();
|
||||
await act(async () => {
|
||||
await vi.runAllTimersAsync();
|
||||
});
|
||||
|
||||
await act(async () => {
|
||||
stdin.write('\x1B');
|
||||
});
|
||||
await vi.runAllTimersAsync();
|
||||
await act(async () => {
|
||||
await vi.runAllTimersAsync();
|
||||
});
|
||||
|
||||
vi.useRealTimers();
|
||||
unmount();
|
||||
@@ -1514,12 +1532,12 @@ describe('InputPrompt', () => {
|
||||
await act(async () => {
|
||||
stdin.write('\x0C');
|
||||
});
|
||||
await vi.waitFor(() => expect(props.onClearScreen).toHaveBeenCalled());
|
||||
await waitFor(() => expect(props.onClearScreen).toHaveBeenCalled());
|
||||
|
||||
await act(async () => {
|
||||
stdin.write('\x01');
|
||||
});
|
||||
await vi.waitFor(() =>
|
||||
await waitFor(() =>
|
||||
expect(props.buffer.move).toHaveBeenCalledWith('home'),
|
||||
);
|
||||
unmount();
|
||||
@@ -1561,7 +1579,7 @@ describe('InputPrompt', () => {
|
||||
stdin.write('\x12');
|
||||
});
|
||||
|
||||
await vi.waitFor(() => {
|
||||
await waitFor(() => {
|
||||
const frame = stdout.lastFrame();
|
||||
expect(frame).toContain('(r:)');
|
||||
expect(frame).toContain('echo hello');
|
||||
@@ -1580,7 +1598,6 @@ describe('InputPrompt', () => {
|
||||
await act(async () => {
|
||||
stdin.write('\x12');
|
||||
});
|
||||
await vi.waitFor(() => {});
|
||||
await act(async () => {
|
||||
stdin.write('\x1B');
|
||||
});
|
||||
@@ -1588,12 +1605,11 @@ describe('InputPrompt', () => {
|
||||
stdin.write('\u001b[27u'); // Press kitty escape key
|
||||
});
|
||||
|
||||
await vi.waitFor(() => {
|
||||
await waitFor(() => {
|
||||
expect(stdout.lastFrame()).not.toContain('(r:)');
|
||||
expect(stdout.lastFrame()).not.toContain('echo hello');
|
||||
});
|
||||
|
||||
expect(stdout.lastFrame()).not.toContain('echo hello');
|
||||
|
||||
unmount();
|
||||
});
|
||||
|
||||
@@ -1629,7 +1645,7 @@ describe('InputPrompt', () => {
|
||||
});
|
||||
|
||||
// Verify reverse search is active
|
||||
await vi.waitFor(() => {
|
||||
await waitFor(() => {
|
||||
expect(stdout.lastFrame()).toContain('(r:)');
|
||||
});
|
||||
|
||||
@@ -1637,7 +1653,7 @@ describe('InputPrompt', () => {
|
||||
await act(async () => {
|
||||
stdin.write('\t');
|
||||
});
|
||||
await vi.waitFor(() => {
|
||||
await waitFor(() => {
|
||||
expect(mockHandleAutocomplete).toHaveBeenCalledWith(0);
|
||||
expect(props.buffer.setText).toHaveBeenCalledWith('echo hello');
|
||||
});
|
||||
@@ -1665,7 +1681,7 @@ describe('InputPrompt', () => {
|
||||
stdin.write('\x12');
|
||||
});
|
||||
|
||||
await vi.waitFor(() => {
|
||||
await waitFor(() => {
|
||||
expect(stdout.lastFrame()).toContain('(r:)');
|
||||
});
|
||||
|
||||
@@ -1673,7 +1689,7 @@ describe('InputPrompt', () => {
|
||||
stdin.write('\r');
|
||||
});
|
||||
|
||||
await vi.waitFor(() => {
|
||||
await waitFor(() => {
|
||||
expect(stdout.lastFrame()).not.toContain('(r:)');
|
||||
});
|
||||
|
||||
@@ -1708,7 +1724,7 @@ describe('InputPrompt', () => {
|
||||
stdin.write('\x12');
|
||||
});
|
||||
|
||||
await vi.waitFor(() => {
|
||||
await waitFor(() => {
|
||||
expect(stdout.lastFrame()).toContain('(r:)');
|
||||
});
|
||||
|
||||
@@ -1717,7 +1733,7 @@ describe('InputPrompt', () => {
|
||||
stdin.write('\u001b[27u');
|
||||
});
|
||||
|
||||
await vi.waitFor(() => {
|
||||
await waitFor(() => {
|
||||
expect(stdout.lastFrame()).not.toContain('(r:)');
|
||||
expect(props.buffer.text).toBe(initialText);
|
||||
expect(props.buffer.cursor).toEqual(initialCursor);
|
||||
@@ -1740,7 +1756,7 @@ describe('InputPrompt', () => {
|
||||
await act(async () => {
|
||||
stdin.write('\x05'); // Ctrl+E
|
||||
});
|
||||
await vi.waitFor(() => {
|
||||
await waitFor(() => {
|
||||
expect(props.buffer.move).toHaveBeenCalledWith('end');
|
||||
});
|
||||
expect(props.buffer.moveToOffset).not.toHaveBeenCalled();
|
||||
@@ -1759,7 +1775,7 @@ describe('InputPrompt', () => {
|
||||
await act(async () => {
|
||||
stdin.write('\x05'); // Ctrl+E
|
||||
});
|
||||
await vi.waitFor(() => {
|
||||
await waitFor(() => {
|
||||
expect(props.buffer.move).toHaveBeenCalledWith('end');
|
||||
});
|
||||
expect(props.buffer.moveToOffset).not.toHaveBeenCalled();
|
||||
@@ -1793,7 +1809,7 @@ describe('InputPrompt', () => {
|
||||
stdin.write('\x12'); // Ctrl+R
|
||||
});
|
||||
|
||||
await vi.waitFor(() => {
|
||||
await waitFor(() => {
|
||||
const frame = stdout.lastFrame() ?? '';
|
||||
expect(frame).toContain('(r:)');
|
||||
expect(frame).toContain('git commit');
|
||||
@@ -1822,14 +1838,14 @@ describe('InputPrompt', () => {
|
||||
await act(async () => {
|
||||
stdin.write('\x12');
|
||||
});
|
||||
await vi.waitFor(() => {
|
||||
await waitFor(() => {
|
||||
expect(clean(stdout.lastFrame())).toContain('→');
|
||||
});
|
||||
|
||||
await act(async () => {
|
||||
stdin.write('\u001B[C');
|
||||
});
|
||||
await vi.waitFor(() => {
|
||||
await waitFor(() => {
|
||||
expect(clean(stdout.lastFrame())).toContain('←');
|
||||
});
|
||||
expect(stdout.lastFrame()).toMatchSnapshot(
|
||||
@@ -1839,7 +1855,7 @@ describe('InputPrompt', () => {
|
||||
await act(async () => {
|
||||
stdin.write('\u001B[D');
|
||||
});
|
||||
await vi.waitFor(() => {
|
||||
await waitFor(() => {
|
||||
expect(clean(stdout.lastFrame())).toContain('→');
|
||||
});
|
||||
expect(stdout.lastFrame()).toMatchSnapshot(
|
||||
@@ -1871,7 +1887,7 @@ describe('InputPrompt', () => {
|
||||
await act(async () => {
|
||||
stdin.write('\x12');
|
||||
});
|
||||
await vi.waitFor(() => {
|
||||
await waitFor(() => {
|
||||
expect(stdout.lastFrame()).toMatchSnapshot(
|
||||
'command-search-render-collapsed-match',
|
||||
);
|
||||
@@ -1880,7 +1896,7 @@ describe('InputPrompt', () => {
|
||||
await act(async () => {
|
||||
stdin.write('\u001B[C');
|
||||
});
|
||||
await vi.waitFor(() => {
|
||||
await waitFor(() => {
|
||||
expect(stdout.lastFrame()).toMatchSnapshot(
|
||||
'command-search-render-expanded-match',
|
||||
);
|
||||
@@ -1909,7 +1925,7 @@ describe('InputPrompt', () => {
|
||||
await act(async () => {
|
||||
stdin.write('\x12');
|
||||
});
|
||||
await vi.waitFor(() => {
|
||||
await waitFor(() => {
|
||||
const frame = clean(stdout.lastFrame());
|
||||
// Ensure it rendered the search mode
|
||||
expect(frame).toContain('(r:)');
|
||||
@@ -1933,7 +1949,7 @@ describe('InputPrompt', () => {
|
||||
await act(async () => {
|
||||
stdin.write('\u001B[A');
|
||||
});
|
||||
await vi.waitFor(() => expect(mockPopAllMessages).toHaveBeenCalled());
|
||||
await waitFor(() => expect(mockPopAllMessages).toHaveBeenCalled());
|
||||
const callback = mockPopAllMessages.mock.calls[0][0];
|
||||
|
||||
await act(async () => {
|
||||
@@ -1957,7 +1973,7 @@ describe('InputPrompt', () => {
|
||||
await act(async () => {
|
||||
stdin.write('\u001B[A');
|
||||
});
|
||||
await vi.waitFor(() =>
|
||||
await waitFor(() =>
|
||||
expect(mockInputHistory.navigateUp).toHaveBeenCalled(),
|
||||
);
|
||||
expect(mockPopAllMessages).not.toHaveBeenCalled();
|
||||
@@ -1976,7 +1992,7 @@ describe('InputPrompt', () => {
|
||||
await act(async () => {
|
||||
stdin.write('\u001B[A');
|
||||
});
|
||||
await vi.waitFor(() => expect(mockPopAllMessages).toHaveBeenCalled());
|
||||
await waitFor(() => expect(mockPopAllMessages).toHaveBeenCalled());
|
||||
const callback = mockPopAllMessages.mock.calls[0][0];
|
||||
await act(async () => {
|
||||
callback(undefined);
|
||||
@@ -2002,7 +2018,7 @@ describe('InputPrompt', () => {
|
||||
await act(async () => {
|
||||
stdin.write('\u001B[A');
|
||||
});
|
||||
await vi.waitFor(() => expect(mockPopAllMessages).toHaveBeenCalled());
|
||||
await waitFor(() => expect(mockPopAllMessages).toHaveBeenCalled());
|
||||
unmount();
|
||||
});
|
||||
|
||||
@@ -2018,7 +2034,7 @@ describe('InputPrompt', () => {
|
||||
await act(async () => {
|
||||
stdin.write('\u001B[A');
|
||||
});
|
||||
await vi.waitFor(() => expect(mockPopAllMessages).toHaveBeenCalled());
|
||||
await waitFor(() => expect(mockPopAllMessages).toHaveBeenCalled());
|
||||
|
||||
const callback = mockPopAllMessages.mock.calls[0][0];
|
||||
await act(async () => {
|
||||
@@ -2041,7 +2057,7 @@ describe('InputPrompt', () => {
|
||||
await act(async () => {
|
||||
stdin.write('\u001B[A');
|
||||
});
|
||||
await vi.waitFor(() => expect(mockPopAllMessages).toHaveBeenCalled());
|
||||
await waitFor(() => expect(mockPopAllMessages).toHaveBeenCalled());
|
||||
unmount();
|
||||
});
|
||||
|
||||
@@ -2056,7 +2072,7 @@ describe('InputPrompt', () => {
|
||||
await act(async () => {
|
||||
stdin.write('\u001B[A');
|
||||
});
|
||||
await vi.waitFor(() =>
|
||||
await waitFor(() =>
|
||||
expect(mockInputHistory.navigateUp).toHaveBeenCalled(),
|
||||
);
|
||||
unmount();
|
||||
@@ -2074,7 +2090,7 @@ describe('InputPrompt', () => {
|
||||
await act(async () => {
|
||||
stdin.write('\u001B[A');
|
||||
});
|
||||
await vi.waitFor(() => expect(mockPopAllMessages).toHaveBeenCalled());
|
||||
await waitFor(() => expect(mockPopAllMessages).toHaveBeenCalled());
|
||||
|
||||
const callback = mockPopAllMessages.mock.calls[0][0];
|
||||
await act(async () => {
|
||||
@@ -2094,7 +2110,7 @@ describe('InputPrompt', () => {
|
||||
const { stdout, unmount } = renderWithProviders(
|
||||
<InputPrompt {...props} />,
|
||||
);
|
||||
await vi.waitFor(() => expect(stdout.lastFrame()).toMatchSnapshot());
|
||||
await waitFor(() => expect(stdout.lastFrame()).toMatchSnapshot());
|
||||
unmount();
|
||||
});
|
||||
|
||||
@@ -2103,7 +2119,7 @@ describe('InputPrompt', () => {
|
||||
const { stdout, unmount } = renderWithProviders(
|
||||
<InputPrompt {...props} />,
|
||||
);
|
||||
await vi.waitFor(() => expect(stdout.lastFrame()).toMatchSnapshot());
|
||||
await waitFor(() => expect(stdout.lastFrame()).toMatchSnapshot());
|
||||
unmount();
|
||||
});
|
||||
|
||||
@@ -2112,7 +2128,7 @@ describe('InputPrompt', () => {
|
||||
const { stdout, unmount } = renderWithProviders(
|
||||
<InputPrompt {...props} />,
|
||||
);
|
||||
await vi.waitFor(() => expect(stdout.lastFrame()).toMatchSnapshot());
|
||||
await waitFor(() => expect(stdout.lastFrame()).toMatchSnapshot());
|
||||
unmount();
|
||||
});
|
||||
|
||||
@@ -2122,7 +2138,7 @@ describe('InputPrompt', () => {
|
||||
const { stdout, unmount } = renderWithProviders(
|
||||
<InputPrompt {...props} />,
|
||||
);
|
||||
await vi.waitFor(() => {
|
||||
await waitFor(() => {
|
||||
expect(stdout.lastFrame()).not.toContain(`{chalk.inverse(' ')}`);
|
||||
// This snapshot is good to make sure there was an input prompt but does
|
||||
// not show the inverted cursor because snapshots do not show colors.
|
||||
@@ -2140,7 +2156,7 @@ describe('InputPrompt', () => {
|
||||
await act(async () => {
|
||||
stdin.write('a');
|
||||
});
|
||||
await vi.waitFor(() => expect(mockBuffer.handleInput).toHaveBeenCalled());
|
||||
await waitFor(() => expect(mockBuffer.handleInput).toHaveBeenCalled());
|
||||
unmount();
|
||||
});
|
||||
describe('command queuing while streaming', () => {
|
||||
@@ -2184,7 +2200,7 @@ describe('InputPrompt', () => {
|
||||
await act(async () => {
|
||||
stdin.write('\r');
|
||||
});
|
||||
await vi.waitFor(() => {
|
||||
await waitFor(() => {
|
||||
if (shouldSubmit) {
|
||||
expect(props.onSubmit).toHaveBeenCalledWith(bufferText);
|
||||
expect(props.setQueueErrorMessage).not.toHaveBeenCalled();
|
||||
|
||||
Reference in New Issue
Block a user