Reapply "feat(accessibility): implement centralized screen reader layout (#9263)

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
This commit is contained in:
christine betts
2025-09-26 21:27:00 -04:00
committed by GitHub
parent 40aa4a5585
commit c6103fc871
8 changed files with 329 additions and 173 deletions
+39 -2
View File
@@ -6,12 +6,19 @@
import { describe, it, expect, vi } from 'vitest';
import { render } from 'ink-testing-library';
import { Text } from 'ink';
import { Text, useIsScreenReaderEnabled } from 'ink';
import { App } from './App.js';
import { UIStateContext, type UIState } from './contexts/UIStateContext.js';
import { StreamingState } from './types.js';
// Mock components to isolate App component testing
vi.mock('ink', async (importOriginal) => {
const original = await importOriginal<typeof import('ink')>();
return {
...original,
useIsScreenReaderEnabled: vi.fn(),
};
});
vi.mock('./components/MainContent.js', () => ({
MainContent: () => <Text>MainContent</Text>,
}));
@@ -32,6 +39,10 @@ vi.mock('./components/QuittingDisplay.js', () => ({
QuittingDisplay: () => <Text>Quitting...</Text>,
}));
vi.mock('./components/Footer.js', () => ({
Footer: () => <Text>Footer</Text>,
}));
describe('App', () => {
const mockUIState: Partial<UIState> = {
streamingState: StreamingState.Idle,
@@ -122,4 +133,30 @@ describe('App', () => {
expect(lastFrame()).toContain('Press Ctrl+D again to exit.');
});
it('should render ScreenReaderAppLayout when screen reader is enabled', () => {
(useIsScreenReaderEnabled as vi.Mock).mockReturnValue(true);
const { lastFrame } = render(
<UIStateContext.Provider value={mockUIState as UIState}>
<App />
</UIStateContext.Provider>,
);
expect(lastFrame()).toContain(
'Notifications\nFooter\nMainContent\nComposer',
);
});
it('should render DefaultAppLayout when screen reader is not enabled', () => {
(useIsScreenReaderEnabled as vi.Mock).mockReturnValue(false);
const { lastFrame } = render(
<UIStateContext.Provider value={mockUIState as UIState}>
<App />
</UIStateContext.Provider>,
);
expect(lastFrame()).toContain('MainContent\nNotifications\nComposer');
});
});