mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-22 11:04:42 -07:00
test(cli): refactor tests for async render utilities (#23252)
This commit is contained in:
committed by
GitHub
parent
86a3a913b5
commit
6c78eb7a39
@@ -30,7 +30,7 @@ describe('useLoadingIndicator', () => {
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
|
||||
const renderLoadingIndicatorHook = (
|
||||
const renderLoadingIndicatorHook = async (
|
||||
initialStreamingState: StreamingState,
|
||||
initialShouldShowFocusHint: boolean = false,
|
||||
initialRetryStatus: RetryAttemptPayload | null = null,
|
||||
@@ -60,7 +60,7 @@ describe('useLoadingIndicator', () => {
|
||||
});
|
||||
return null;
|
||||
}
|
||||
const { rerender } = render(
|
||||
const { rerender } = await render(
|
||||
<TestComponent
|
||||
streamingState={initialStreamingState}
|
||||
shouldShowFocusHint={initialShouldShowFocusHint}
|
||||
@@ -92,16 +92,16 @@ describe('useLoadingIndicator', () => {
|
||||
};
|
||||
};
|
||||
|
||||
it('should initialize with default values when Idle', () => {
|
||||
it('should initialize with default values when Idle', async () => {
|
||||
vi.spyOn(Math, 'random').mockImplementation(() => 0.5); // Always witty
|
||||
const { result } = renderLoadingIndicatorHook(StreamingState.Idle);
|
||||
const { result } = await renderLoadingIndicatorHook(StreamingState.Idle);
|
||||
expect(result.current.elapsedTime).toBe(0);
|
||||
expect(result.current.currentLoadingPhrase).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should show interactive shell waiting phrase when shouldShowFocusHint is true', async () => {
|
||||
vi.spyOn(Math, 'random').mockImplementation(() => 0.5); // Always witty
|
||||
const { result, rerender } = renderLoadingIndicatorHook(
|
||||
const { result, rerender } = await renderLoadingIndicatorHook(
|
||||
StreamingState.Responding,
|
||||
false,
|
||||
);
|
||||
@@ -125,7 +125,9 @@ describe('useLoadingIndicator', () => {
|
||||
|
||||
it('should reflect values when Responding', async () => {
|
||||
vi.spyOn(Math, 'random').mockImplementation(() => 0.5); // Always witty for subsequent phrases
|
||||
const { result } = renderLoadingIndicatorHook(StreamingState.Responding);
|
||||
const { result } = await renderLoadingIndicatorHook(
|
||||
StreamingState.Responding,
|
||||
);
|
||||
|
||||
// Initial phrase on first activation will be a tip, not necessarily from witty phrases
|
||||
expect(result.current.elapsedTime).toBe(0);
|
||||
@@ -142,7 +144,7 @@ describe('useLoadingIndicator', () => {
|
||||
});
|
||||
|
||||
it('should show waiting phrase and retain elapsedTime when WaitingForConfirmation', async () => {
|
||||
const { result, rerender } = renderLoadingIndicatorHook(
|
||||
const { result, rerender } = await renderLoadingIndicatorHook(
|
||||
StreamingState.Responding,
|
||||
);
|
||||
|
||||
@@ -169,7 +171,7 @@ describe('useLoadingIndicator', () => {
|
||||
|
||||
it('should reset elapsedTime and use a witty phrase when transitioning from WaitingForConfirmation to Responding', async () => {
|
||||
vi.spyOn(Math, 'random').mockImplementation(() => 0.5); // Always witty
|
||||
const { result, rerender } = renderLoadingIndicatorHook(
|
||||
const { result, rerender } = await renderLoadingIndicatorHook(
|
||||
StreamingState.Responding,
|
||||
);
|
||||
|
||||
@@ -202,7 +204,7 @@ describe('useLoadingIndicator', () => {
|
||||
|
||||
it('should reset timer and phrase when streamingState changes from Responding to Idle', async () => {
|
||||
vi.spyOn(Math, 'random').mockImplementation(() => 0.5); // Always witty
|
||||
const { result, rerender } = renderLoadingIndicatorHook(
|
||||
const { result, rerender } = await renderLoadingIndicatorHook(
|
||||
StreamingState.Responding,
|
||||
);
|
||||
|
||||
@@ -225,14 +227,14 @@ describe('useLoadingIndicator', () => {
|
||||
expect(result.current.elapsedTime).toBe(0);
|
||||
});
|
||||
|
||||
it('should reflect retry status in currentLoadingPhrase when provided', () => {
|
||||
it('should reflect retry status in currentLoadingPhrase when provided', async () => {
|
||||
const retryStatus = {
|
||||
model: 'gemini-pro',
|
||||
attempt: 2,
|
||||
maxAttempts: 3,
|
||||
delayMs: 1000,
|
||||
};
|
||||
const { result } = renderLoadingIndicatorHook(
|
||||
const { result } = await renderLoadingIndicatorHook(
|
||||
StreamingState.Responding,
|
||||
false,
|
||||
retryStatus,
|
||||
@@ -242,14 +244,14 @@ describe('useLoadingIndicator', () => {
|
||||
expect(result.current.currentLoadingPhrase).toContain('Attempt 3/3');
|
||||
});
|
||||
|
||||
it('should hide low-verbosity retry status for early retry attempts', () => {
|
||||
it('should hide low-verbosity retry status for early retry attempts', async () => {
|
||||
const retryStatus = {
|
||||
model: 'gemini-pro',
|
||||
attempt: 1,
|
||||
maxAttempts: 5,
|
||||
delayMs: 1000,
|
||||
};
|
||||
const { result } = renderLoadingIndicatorHook(
|
||||
const { result } = await renderLoadingIndicatorHook(
|
||||
StreamingState.Responding,
|
||||
false,
|
||||
retryStatus,
|
||||
@@ -262,14 +264,14 @@ describe('useLoadingIndicator', () => {
|
||||
);
|
||||
});
|
||||
|
||||
it('should show a generic retry phrase in low error verbosity mode for later retries', () => {
|
||||
it('should show a generic retry phrase in low error verbosity mode for later retries', async () => {
|
||||
const retryStatus = {
|
||||
model: 'gemini-pro',
|
||||
attempt: 2,
|
||||
maxAttempts: 5,
|
||||
delayMs: 1000,
|
||||
};
|
||||
const { result } = renderLoadingIndicatorHook(
|
||||
const { result } = await renderLoadingIndicatorHook(
|
||||
StreamingState.Responding,
|
||||
false,
|
||||
retryStatus,
|
||||
@@ -282,8 +284,8 @@ describe('useLoadingIndicator', () => {
|
||||
);
|
||||
});
|
||||
|
||||
it('should show no phrases when loadingPhrasesMode is "off"', () => {
|
||||
const { result } = renderLoadingIndicatorHook(
|
||||
it('should show no phrases when loadingPhrasesMode is "off"', async () => {
|
||||
const { result } = await renderLoadingIndicatorHook(
|
||||
StreamingState.Responding,
|
||||
false,
|
||||
null,
|
||||
|
||||
Reference in New Issue
Block a user