@@ -32,8 +32,11 @@ describe('SearchResultsList', () => {
3232 const user = userEvent . setup ( { advanceTimers : jest . advanceTimersByTime } ) ;
3333
3434 await renderComponent ( ) ;
35+
36+ const placeholder = Strings . components . searchDefault . base . collapsed . base . inputPlaceholder ;
37+
3538 // focus input to show results
36- const searchInput = screen . getAllByRole ( 'textbox' ) [ 0 ] ;
39+ const searchInput = screen . getAllByPlaceholderText ( placeholder ) [ 0 ] ;
3740 await user . click ( searchInput ) ;
3841 await screen . findByText ( / f l e s h w o u n d / ) ;
3942 expect ( document . body ) . toMatchSnapshot ( ) ;
@@ -48,6 +51,9 @@ describe('SearchResultsList', () => {
4851 const searchInput = screen . getAllByRole ( 'textbox' ) [ 0 ] ;
4952 await user . click ( searchInput ) ;
5053
54+ // Wait for the dropdown to open and results to load
55+ await screen . findByRole ( 'listbox' ) ;
56+
5157 const fleshWound = await screen . findAllByText ( "it's just a flesh wound" ) ;
5258
5359 await user . click ( fleshWound [ 0 ] ) ;
@@ -111,8 +117,11 @@ describe('SearchResultsList', () => {
111117 const user = userEvent . setup ( { advanceTimers : jest . advanceTimersByTime } ) ;
112118
113119 await renderComponent ( ) ;
120+
121+ const placeholder = Strings . components . searchDefault . base . collapsed . base . inputPlaceholder ;
122+
114123 // focus input to show results
115- const searchInput = screen . getAllByRole ( 'textbox' ) [ 1 ] ;
124+ const searchInput = screen . getAllByPlaceholderText ( placeholder ) [ 1 ] ;
116125 await user . click ( searchInput ) ;
117126
118127 const noArmsLeft = await screen . findByText ( / n o a r m s l e f t / ) ;
@@ -139,16 +148,17 @@ describe('SearchResultsList', () => {
139148
140149 it ( 'Should apply dark and light mode styles when theme button is toggled' , async ( ) => {
141150 await renderComponent ( ) ;
151+ const placeholder = Strings . components . searchDefault . base . collapsed . base . inputPlaceholder ;
142152 const user = userEvent . setup ( { advanceTimers : jest . advanceTimersByTime } ) ;
143153 const darkModeToggle = screen . getByRole ( 'checkbox' , {
144154 name : / D a r k m o d e s w i t c h / ,
145155 } ) ;
146156
147157 await user . click ( darkModeToggle ) ;
148158 expect ( screen . getByLabelText ( 'Light mode' ) ) . toBeInTheDocument ( ) ;
149- const searchInput = screen . getAllByRole ( 'textbox' ) [ 0 ] ;
159+ const searchInput = screen . getAllByPlaceholderText ( placeholder ) [ 0 ] ;
150160 await user . click ( searchInput ) ;
151- const resultsList = screen . getByTestId ( 'list-mode ') ;
161+ const resultsList = screen . getByRole ( 'listbox ') ;
152162 expect ( resultsList ) . toMatchSnapshot ( 'after toggling dark mode' ) ;
153163 expect ( resultsList ) . toHaveClass ( 'results-list-dark' ) ;
154164 } ) ;
0 commit comments