summaryrefslogtreecommitdiff
path: root/packages/cli/src/ui/components/InputPrompt.test.tsx
diff options
context:
space:
mode:
authorSeydulla Narkulyyev <[email protected]>2025-07-22 01:43:23 +0400
committerGitHub <[email protected]>2025-07-21 21:43:23 +0000
commitf7b4e749326e6e17dcd55d4bc78ae7cd681037bd (patch)
treef91a3131b70fa60a5e70af427a86597e7b5f9a2c /packages/cli/src/ui/components/InputPrompt.test.tsx
parentb4d00ab4fb338631de039dc445936f7af2c5b79e (diff)
feat(cli):suggestion-navigation-shortcut (#3641)
Co-authored-by: N. Taylor Mullen <[email protected]>
Diffstat (limited to 'packages/cli/src/ui/components/InputPrompt.test.tsx')
-rw-r--r--packages/cli/src/ui/components/InputPrompt.test.tsx77
1 files changed, 77 insertions, 0 deletions
diff --git a/packages/cli/src/ui/components/InputPrompt.test.tsx b/packages/cli/src/ui/components/InputPrompt.test.tsx
index 886a6235..3f646cc6 100644
--- a/packages/cli/src/ui/components/InputPrompt.test.tsx
+++ b/packages/cli/src/ui/components/InputPrompt.test.tsx
@@ -221,6 +221,83 @@ describe('InputPrompt', () => {
unmount();
});
+ it('should call completion.navigateUp for both up arrow and Ctrl+P when suggestions are showing', async () => {
+ mockedUseCompletion.mockReturnValue({
+ ...mockCompletion,
+ showSuggestions: true,
+ suggestions: [
+ { label: 'memory', value: 'memory' },
+ { label: 'memcache', value: 'memcache' },
+ ],
+ });
+
+ props.buffer.setText('/mem');
+
+ const { stdin, unmount } = render(<InputPrompt {...props} />);
+ await wait();
+
+ // Test up arrow
+ stdin.write('\u001B[A'); // Up arrow
+ await wait();
+
+ stdin.write('\u0010'); // Ctrl+P
+ await wait();
+ expect(mockCompletion.navigateUp).toHaveBeenCalledTimes(2);
+ expect(mockCompletion.navigateDown).not.toHaveBeenCalled();
+
+ unmount();
+ });
+
+ it('should call completion.navigateDown for both down arrow and Ctrl+N when suggestions are showing', async () => {
+ mockedUseCompletion.mockReturnValue({
+ ...mockCompletion,
+ showSuggestions: true,
+ suggestions: [
+ { label: 'memory', value: 'memory' },
+ { label: 'memcache', value: 'memcache' },
+ ],
+ });
+ props.buffer.setText('/mem');
+
+ const { stdin, unmount } = render(<InputPrompt {...props} />);
+ await wait();
+
+ // Test down arrow
+ stdin.write('\u001B[B'); // Down arrow
+ await wait();
+
+ stdin.write('\u000E'); // Ctrl+N
+ await wait();
+ expect(mockCompletion.navigateDown).toHaveBeenCalledTimes(2);
+ expect(mockCompletion.navigateUp).not.toHaveBeenCalled();
+
+ unmount();
+ });
+
+ it('should NOT call completion navigation when suggestions are not showing', async () => {
+ mockedUseCompletion.mockReturnValue({
+ ...mockCompletion,
+ showSuggestions: false,
+ });
+ props.buffer.setText('some text');
+
+ const { stdin, unmount } = render(<InputPrompt {...props} />);
+ await wait();
+
+ stdin.write('\u001B[A'); // Up arrow
+ await wait();
+ stdin.write('\u001B[B'); // Down arrow
+ await wait();
+ stdin.write('\u0010'); // Ctrl+P
+ await wait();
+ stdin.write('\u000E'); // Ctrl+N
+ await wait();
+
+ expect(mockCompletion.navigateUp).not.toHaveBeenCalled();
+ expect(mockCompletion.navigateDown).not.toHaveBeenCalled();
+ unmount();
+ });
+
describe('clipboard image paste', () => {
beforeEach(() => {
vi.mocked(clipboardUtils.clipboardHasImage).mockResolvedValue(false);