refactor(cli): integrate real config loading into async test utils (#23040)

This commit is contained in:
Tommaso Sciortino
2026-03-19 17:05:33 +00:00
committed by GitHub
parent 7de0616229
commit 23264ced9a
103 changed files with 1806 additions and 1541 deletions
@@ -38,6 +38,17 @@ vi.mock('./useAtCompletion', () => ({
useAtCompletion: vi.fn(),
}));
vi.mock('./usePromptCompletion', () => ({
usePromptCompletion: vi.fn(() => ({
text: '',
isLoading: false,
isActive: false,
accept: vi.fn(),
clear: vi.fn(),
markSelected: vi.fn(),
})),
}));
vi.mock('./useSlashCompletion', () => ({
useSlashCompletion: vi.fn(() => ({
completionStart: 0,
@@ -183,13 +194,13 @@ describe('useCommandCompletion', () => {
return null;
}
const renderCommandCompletionHook = (
const renderCommandCompletionHook = async (
initialText: string,
cursorOffset?: number,
shellModeActive = false,
active = true,
) => {
const renderResult = renderWithProviders(
const renderResult = await renderWithProviders(
<TestComponent
initialText={initialText}
cursorOffset={cursorOffset}
@@ -219,8 +230,8 @@ describe('useCommandCompletion', () => {
describe('Core Hook Behavior', () => {
describe('State Management', () => {
it('should initialize with default state', () => {
const { result } = renderCommandCompletionHook('');
it('should initialize with default state', async () => {
const { result } = await renderCommandCompletionHook('');
expect(result.current.suggestions).toEqual([]);
expect(result.current.activeSuggestionIndex).toBe(-1);
@@ -235,7 +246,7 @@ describe('useCommandCompletion', () => {
atSuggestions: [{ label: 'src/file.txt', value: 'src/file.txt' }],
});
const { result } = renderCommandCompletionHook('@file');
const { result } = await renderCommandCompletionHook('@file');
await waitFor(() => {
expect(result.current.suggestions).toHaveLength(1);
@@ -256,8 +267,8 @@ describe('useCommandCompletion', () => {
});
});
it('should reset all state to default values', () => {
const { result } = renderCommandCompletionHook('@files');
it('should reset all state to default values', async () => {
const { result } = await renderCommandCompletionHook('@files');
act(() => {
result.current.setActiveSuggestionIndex(5);
@@ -274,7 +285,7 @@ describe('useCommandCompletion', () => {
it('should call useAtCompletion with the correct query for an escaped space', async () => {
const text = '@src/a\\ file.txt';
const { result } = renderCommandCompletionHook(text);
const { result } = await renderCommandCompletionHook(text);
await waitFor(() => {
expect(useAtCompletion).toHaveBeenLastCalledWith(
@@ -291,7 +302,7 @@ describe('useCommandCompletion', () => {
const text = '@file1 @file2';
const cursorOffset = 3; // @fi|le1 @file2
renderCommandCompletionHook(text, cursorOffset);
await renderCommandCompletionHook(text, cursorOffset);
await waitFor(() => {
expect(useAtCompletion).toHaveBeenLastCalledWith(
@@ -329,7 +340,7 @@ describe('useCommandCompletion', () => {
slashSuggestions: [{ label: 'clear', value: 'clear' }],
});
const { result } = renderCommandCompletionHook(
const { result } = await renderCommandCompletionHook(
'/',
undefined,
shellModeActive,
@@ -361,10 +372,10 @@ describe('useCommandCompletion', () => {
setupMocks({ slashSuggestions: mockSuggestions });
});
it('should handle navigateUp with no suggestions', () => {
it('should handle navigateUp with no suggestions', async () => {
setupMocks({ slashSuggestions: [] });
const { result } = renderCommandCompletionHook('/');
const { result } = await renderCommandCompletionHook('/');
act(() => {
result.current.navigateUp();
@@ -373,9 +384,9 @@ describe('useCommandCompletion', () => {
expect(result.current.activeSuggestionIndex).toBe(-1);
});
it('should handle navigateDown with no suggestions', () => {
it('should handle navigateDown with no suggestions', async () => {
setupMocks({ slashSuggestions: [] });
const { result } = renderCommandCompletionHook('/');
const { result } = await renderCommandCompletionHook('/');
act(() => {
result.current.navigateDown();
@@ -385,7 +396,7 @@ describe('useCommandCompletion', () => {
});
it('should navigate up through suggestions with wrap-around', async () => {
const { result } = renderCommandCompletionHook('/');
const { result } = await renderCommandCompletionHook('/');
await waitFor(() => {
expect(result.current.suggestions.length).toBe(5);
@@ -401,7 +412,7 @@ describe('useCommandCompletion', () => {
});
it('should navigate down through suggestions with wrap-around', async () => {
const { result } = renderCommandCompletionHook('/');
const { result } = await renderCommandCompletionHook('/');
await waitFor(() => {
expect(result.current.suggestions.length).toBe(5);
@@ -420,7 +431,7 @@ describe('useCommandCompletion', () => {
});
it('should handle navigation with multiple suggestions', async () => {
const { result } = renderCommandCompletionHook('/');
const { result } = await renderCommandCompletionHook('/');
await waitFor(() => {
expect(result.current.suggestions.length).toBe(5);
@@ -447,7 +458,7 @@ describe('useCommandCompletion', () => {
it('should automatically select the first item when suggestions are available', async () => {
setupMocks({ slashSuggestions: mockSuggestions });
const { result } = renderCommandCompletionHook('/');
const { result } = await renderCommandCompletionHook('/');
await waitFor(() => {
expect(result.current.suggestions.length).toBe(
@@ -466,7 +477,7 @@ describe('useCommandCompletion', () => {
slashCompletionRange: { completionStart: 1, completionEnd: 4 },
});
const { result } = renderCommandCompletionHook('/mem');
const { result } = await renderCommandCompletionHook('/mem');
await waitFor(() => {
expect(result.current.suggestions.length).toBe(1);
@@ -484,7 +495,7 @@ describe('useCommandCompletion', () => {
atSuggestions: [{ label: 'src/file1.txt', value: 'src/file1.txt' }],
});
const { result } = renderCommandCompletionHook('@src/fi');
const { result } = await renderCommandCompletionHook('@src/fi');
await waitFor(() => {
expect(result.current.suggestions.length).toBe(1);
@@ -509,7 +520,7 @@ describe('useCommandCompletion', () => {
slashCompletionRange: { completionStart: 1, completionEnd: 5 },
});
const { result } = renderCommandCompletionHook('/resu');
const { result } = await renderCommandCompletionHook('/resu');
await waitFor(() => {
expect(result.current.suggestions.length).toBe(1);
@@ -530,7 +541,7 @@ describe('useCommandCompletion', () => {
atSuggestions: [{ label: 'src/file1.txt', value: 'src/file1.txt' }],
});
const { result } = renderCommandCompletionHook(text, cursorOffset);
const { result } = await renderCommandCompletionHook(text, cursorOffset);
await waitFor(() => {
expect(result.current.suggestions.length).toBe(1);
@@ -550,7 +561,7 @@ describe('useCommandCompletion', () => {
atSuggestions: [{ label: 'src/components/', value: 'src/components/' }],
});
const { result } = renderCommandCompletionHook('@src/comp');
const { result } = await renderCommandCompletionHook('@src/comp');
await waitFor(() => {
expect(result.current.suggestions.length).toBe(1);
@@ -570,7 +581,7 @@ describe('useCommandCompletion', () => {
],
});
const { result } = renderCommandCompletionHook('@src\\comp');
const { result } = await renderCommandCompletionHook('@src\\comp');
await waitFor(() => {
expect(result.current.suggestions.length).toBe(1);
@@ -595,7 +606,7 @@ describe('useCommandCompletion', () => {
},
});
const { result } = renderCommandCompletionHook(
const { result } = await renderCommandCompletionHook(
text,
text.length,
true, // shellModeActive
@@ -624,7 +635,7 @@ describe('useCommandCompletion', () => {
},
});
const { result } = renderCommandCompletionHook(
const { result } = await renderCommandCompletionHook(
text,
text.length,
true, // shellModeActive
@@ -642,7 +653,7 @@ describe('useCommandCompletion', () => {
const text = 'ls ';
const cursorOffset = text.length;
const { result } = renderCommandCompletionHook(
const { result } = await renderCommandCompletionHook(
text,
cursorOffset,
true, // shellModeActive
@@ -668,7 +679,7 @@ describe('useCommandCompletion', () => {
},
});
const { result } = renderCommandCompletionHook(
const { result } = await renderCommandCompletionHook(
textWithoutSpace,
textWithoutSpace.length,
true, // shellModeActive
@@ -733,7 +744,7 @@ describe('useCommandCompletion', () => {
hookResult = { ...completion, textBuffer };
return null;
}
renderWithProviders(<TestComponent />);
await renderWithProviders(<TestComponent />);
// Should not trigger prompt completion for comments
await waitFor(() => {
@@ -768,7 +779,7 @@ describe('useCommandCompletion', () => {
hookResult = { ...completion, textBuffer };
return null;
}
renderWithProviders(<TestComponent />);
await renderWithProviders(<TestComponent />);
// Should not trigger prompt completion for comments
await waitFor(() => {
@@ -803,7 +814,7 @@ describe('useCommandCompletion', () => {
hookResult = { ...completion, textBuffer };
return null;
}
renderWithProviders(<TestComponent />);
await renderWithProviders(<TestComponent />);
// This test verifies that comments are filtered out while regular text is not
await waitFor(() => {
@@ -823,7 +834,7 @@ describe('useCommandCompletion', () => {
const text = '/mycommand @src/fi';
const cursorOffset = text.length;
renderCommandCompletionHook(text, cursorOffset);
await renderCommandCompletionHook(text, cursorOffset);
await waitFor(() => {
expect(useAtCompletion).toHaveBeenLastCalledWith(
@@ -843,7 +854,7 @@ describe('useCommandCompletion', () => {
const text = '/mycom';
const cursorOffset = text.length;
const { result } = renderCommandCompletionHook(text, cursorOffset);
const { result } = await renderCommandCompletionHook(text, cursorOffset);
await waitFor(() => {
expect(result.current.suggestions).toHaveLength(1);
@@ -859,7 +870,7 @@ describe('useCommandCompletion', () => {
const text = '/command @';
const cursorOffset = text.length;
renderCommandCompletionHook(text, cursorOffset);
await renderCommandCompletionHook(text, cursorOffset);
await waitFor(() => {
expect(useAtCompletion).toHaveBeenLastCalledWith(
@@ -879,7 +890,7 @@ describe('useCommandCompletion', () => {
const text = '/diff @src/foo.ts @src/ba';
const cursorOffset = text.length;
renderCommandCompletionHook(text, cursorOffset);
await renderCommandCompletionHook(text, cursorOffset);
await waitFor(() => {
expect(useAtCompletion).toHaveBeenLastCalledWith(
@@ -896,7 +907,7 @@ describe('useCommandCompletion', () => {
atSuggestions: [{ label: 'src/file.txt', value: 'src/file.txt' }],
});
const { result } = renderCommandCompletionHook('/cmd @src/fi');
const { result } = await renderCommandCompletionHook('/cmd @src/fi');
await waitFor(() => {
expect(result.current.suggestions.length).toBe(1);
@@ -915,7 +926,7 @@ describe('useCommandCompletion', () => {
});
const text = '/help ';
renderCommandCompletionHook(text);
await renderCommandCompletionHook(text);
await waitFor(() => {
expect(useSlashCompletion).toHaveBeenLastCalledWith(