mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-20 18:14:29 -07:00
Fix(accessibility): add screen reader support to RewindViewer (#20750)
This commit is contained in:
committed by
GitHub
parent
0452f787b2
commit
d97eaf3420
@@ -4,7 +4,7 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import { describe, it, expect, vi, afterEach } from 'vitest';
|
||||
import { describe, it, expect, vi, afterEach, beforeEach } from 'vitest';
|
||||
import { act } from 'react';
|
||||
import { renderWithProviders } from '../../test-utils/render.js';
|
||||
import { RewindViewer } from './RewindViewer.js';
|
||||
@@ -14,6 +14,11 @@ import type {
|
||||
MessageRecord,
|
||||
} from '@google/gemini-cli-core';
|
||||
|
||||
vi.mock('ink', async () => {
|
||||
const actual = await vi.importActual<typeof import('ink')>('ink');
|
||||
return { ...actual, useIsScreenReaderEnabled: vi.fn(() => false) };
|
||||
});
|
||||
|
||||
vi.mock('./CliSpinner.js', () => ({
|
||||
CliSpinner: () => 'MockSpinner',
|
||||
}));
|
||||
@@ -71,6 +76,35 @@ describe('RewindViewer', () => {
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
|
||||
describe('Screen Reader Accessibility', () => {
|
||||
beforeEach(async () => {
|
||||
const { useIsScreenReaderEnabled } = await import('ink');
|
||||
vi.mocked(useIsScreenReaderEnabled).mockReturnValue(true);
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
const { useIsScreenReaderEnabled } = await import('ink');
|
||||
vi.mocked(useIsScreenReaderEnabled).mockReturnValue(false);
|
||||
});
|
||||
|
||||
it('renders the rewind viewer with conversation items', async () => {
|
||||
const conversation = createConversation([
|
||||
{ type: 'user', content: 'Hello', id: '1', timestamp: '1' },
|
||||
]);
|
||||
const { lastFrame, waitUntilReady, unmount } = renderWithProviders(
|
||||
<RewindViewer
|
||||
conversation={conversation}
|
||||
onExit={vi.fn()}
|
||||
onRewind={vi.fn()}
|
||||
/>,
|
||||
);
|
||||
await waitUntilReady();
|
||||
expect(lastFrame()).toContain('Rewind');
|
||||
expect(lastFrame()).toContain('Hello');
|
||||
unmount();
|
||||
});
|
||||
});
|
||||
|
||||
describe('Rendering', () => {
|
||||
it.each([
|
||||
{ name: 'nothing interesting for empty conversation', messages: [] },
|
||||
@@ -400,3 +434,31 @@ describe('RewindViewer', () => {
|
||||
unmount2();
|
||||
});
|
||||
});
|
||||
it('renders accessible screen reader view when screen reader is enabled', async () => {
|
||||
const { useIsScreenReaderEnabled } = await import('ink');
|
||||
vi.mocked(useIsScreenReaderEnabled).mockReturnValue(true);
|
||||
|
||||
const messages: MessageRecord[] = [
|
||||
{ type: 'user', content: 'Hello world', id: '1', timestamp: '1' },
|
||||
{ type: 'user', content: 'Second message', id: '2', timestamp: '2' },
|
||||
];
|
||||
const conversation = createConversation(messages);
|
||||
const onExit = vi.fn();
|
||||
const onRewind = vi.fn();
|
||||
|
||||
const { lastFrame, waitUntilReady, unmount } = renderWithProviders(
|
||||
<RewindViewer
|
||||
conversation={conversation}
|
||||
onExit={onExit}
|
||||
onRewind={onRewind}
|
||||
/>,
|
||||
);
|
||||
await waitUntilReady();
|
||||
|
||||
const frame = lastFrame();
|
||||
expect(frame).toContain('Rewind - Select a conversation point:');
|
||||
expect(frame).toContain('Stay at current position');
|
||||
|
||||
vi.mocked(useIsScreenReaderEnabled).mockReturnValue(false);
|
||||
unmount();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user