44 * SPDX-License-Identifier: Apache-2.0
55 */
66
7- import { describe , it , expect , vi , afterEach } from 'vitest' ;
7+ import { describe , it , expect , vi , afterEach , beforeEach } from 'vitest' ;
88import { act } from 'react' ;
99import { renderWithProviders } from '../../test-utils/render.js' ;
1010import { RewindViewer } from './RewindViewer.js' ;
@@ -14,6 +14,11 @@ import type {
1414 MessageRecord ,
1515} from '@google/gemini-cli-core' ;
1616
17+ vi . mock ( 'ink' , async ( ) => {
18+ const actual = await vi . importActual < typeof import ( 'ink' ) > ( 'ink' ) ;
19+ return { ...actual , useIsScreenReaderEnabled : vi . fn ( ( ) => false ) } ;
20+ } ) ;
21+
1722vi . mock ( './CliSpinner.js' , ( ) => ( {
1823 CliSpinner : ( ) => 'MockSpinner' ,
1924} ) ) ;
@@ -71,6 +76,35 @@ describe('RewindViewer', () => {
7176 vi . restoreAllMocks ( ) ;
7277 } ) ;
7378
79+ describe ( 'Screen Reader Accessibility' , ( ) => {
80+ beforeEach ( async ( ) => {
81+ const { useIsScreenReaderEnabled } = await import ( 'ink' ) ;
82+ vi . mocked ( useIsScreenReaderEnabled ) . mockReturnValue ( true ) ;
83+ } ) ;
84+
85+ afterEach ( async ( ) => {
86+ const { useIsScreenReaderEnabled } = await import ( 'ink' ) ;
87+ vi . mocked ( useIsScreenReaderEnabled ) . mockReturnValue ( false ) ;
88+ } ) ;
89+
90+ it ( 'renders the rewind viewer with conversation items' , async ( ) => {
91+ const conversation = createConversation ( [
92+ { type : 'user' , content : 'Hello' , id : '1' , timestamp : '1' } ,
93+ ] ) ;
94+ const { lastFrame, waitUntilReady, unmount } = renderWithProviders (
95+ < RewindViewer
96+ conversation = { conversation }
97+ onExit = { vi . fn ( ) }
98+ onRewind = { vi . fn ( ) }
99+ /> ,
100+ ) ;
101+ await waitUntilReady ( ) ;
102+ expect ( lastFrame ( ) ) . toContain ( 'Rewind' ) ;
103+ expect ( lastFrame ( ) ) . toContain ( 'Hello' ) ;
104+ unmount ( ) ;
105+ } ) ;
106+ } ) ;
107+
74108 describe ( 'Rendering' , ( ) => {
75109 it . each ( [
76110 { name : 'nothing interesting for empty conversation' , messages : [ ] } ,
@@ -400,3 +434,31 @@ describe('RewindViewer', () => {
400434 unmount2 ( ) ;
401435 } ) ;
402436} ) ;
437+ it ( 'renders accessible screen reader view when screen reader is enabled' , async ( ) => {
438+ const { useIsScreenReaderEnabled } = await import ( 'ink' ) ;
439+ vi . mocked ( useIsScreenReaderEnabled ) . mockReturnValue ( true ) ;
440+
441+ const messages : MessageRecord [ ] = [
442+ { type : 'user' , content : 'Hello world' , id : '1' , timestamp : '1' } ,
443+ { type : 'user' , content : 'Second message' , id : '2' , timestamp : '2' } ,
444+ ] ;
445+ const conversation = createConversation ( messages ) ;
446+ const onExit = vi . fn ( ) ;
447+ const onRewind = vi . fn ( ) ;
448+
449+ const { lastFrame, waitUntilReady, unmount } = renderWithProviders (
450+ < RewindViewer
451+ conversation = { conversation }
452+ onExit = { onExit }
453+ onRewind = { onRewind }
454+ /> ,
455+ ) ;
456+ await waitUntilReady ( ) ;
457+
458+ const frame = lastFrame ( ) ;
459+ expect ( frame ) . toContain ( 'Rewind - Select a conversation point:' ) ;
460+ expect ( frame ) . toContain ( 'Stay at current position' ) ;
461+
462+ vi . mocked ( useIsScreenReaderEnabled ) . mockReturnValue ( false ) ;
463+ unmount ( ) ;
464+ } ) ;
0 commit comments