mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-05-26 19:53:18 -07:00
test(ui): finalize snapshots with CircularSpinner and latest main
This commit is contained in:
@@ -4,9 +4,10 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import { act } from 'react';
|
||||
import { renderWithProviders } from '../../test-utils/render.js';
|
||||
import { GeminiSpinner } from './GeminiSpinner.js';
|
||||
import { describe, it, expect, vi, afterEach } from 'vitest';
|
||||
import { describe, it, expect, vi, afterEach, beforeEach } from 'vitest';
|
||||
import { useIsScreenReaderEnabled } from 'ink';
|
||||
|
||||
vi.mock('ink', async () => {
|
||||
@@ -18,24 +19,55 @@ vi.mock('ink', async () => {
|
||||
});
|
||||
|
||||
describe('<GeminiSpinner />', () => {
|
||||
beforeEach(() => {
|
||||
vi.useFakeTimers();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
vi.restoreAllMocks();
|
||||
vi.useRealTimers();
|
||||
});
|
||||
|
||||
it('should render CircularSpinner when screen reader is disabled', async () => {
|
||||
vi.mocked(useIsScreenReaderEnabled).mockReturnValue(false);
|
||||
const { lastFrame, unmount } = await renderWithProviders(<GeminiSpinner />);
|
||||
// Component renders immediately. The interval updates state, but we don't need to wait for it.
|
||||
|
||||
// We wrap render in act to handle the initial effect
|
||||
let renderResult;
|
||||
await act(async () => {
|
||||
renderResult = await renderWithProviders(<GeminiSpinner />);
|
||||
});
|
||||
|
||||
const { lastFrame, unmount } = renderResult!;
|
||||
|
||||
// Advance timers to trigger at least one state update
|
||||
await act(async () => {
|
||||
vi.advanceTimersByTime(30);
|
||||
});
|
||||
|
||||
// Component renders immediately.
|
||||
expect(lastFrame()).toBeTruthy();
|
||||
unmount();
|
||||
|
||||
await act(async () => {
|
||||
unmount();
|
||||
});
|
||||
});
|
||||
|
||||
it('should render altText when screen reader is enabled', async () => {
|
||||
vi.mocked(useIsScreenReaderEnabled).mockReturnValue(true);
|
||||
const { lastFrame, unmount } = await renderWithProviders(
|
||||
<GeminiSpinner altText="Custom Loading" />,
|
||||
);
|
||||
|
||||
let renderResult;
|
||||
await act(async () => {
|
||||
renderResult = await renderWithProviders(
|
||||
<GeminiSpinner altText="Custom Loading" />,
|
||||
);
|
||||
});
|
||||
|
||||
const { lastFrame, unmount } = renderResult!;
|
||||
|
||||
expect(lastFrame()?.trim()).toBe('Custom Loading');
|
||||
unmount();
|
||||
|
||||
await act(async () => {
|
||||
unmount();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user