@@ -105,34 +105,38 @@ describe("App tests", () => {
105105 debugDiv ?. remove ( ) ;
106106 } ) ;
107107
108- it ( "App renders" , ( ) => {
108+ it ( "App renders" , async ( ) => {
109109 renderApp ( ) ;
110- expect ( screen . getByText ( "Hello, Ansible User" ) ) . toBeInTheDocument ( ) ;
110+ expect ( await screen . findByText ( "Hello, Ansible User" ) ) . toBeInTheDocument ( ) ;
111111 const attachButton = screen . queryByLabelText ( "Attach button" ) ;
112112 expect ( attachButton ) . toBeNull ( ) ;
113113 } ) ;
114114
115115 it ( "Basic chatbot interaction" , async ( ) => {
116116 mockAxios ( 200 ) ;
117117 renderApp ( ) ;
118- const textArea = screen . getByLabelText ( "Send a message..." ) ;
118+ const textArea = await screen . findByLabelText ( "Send a message..." ) ;
119119 await act ( async ( ) => userEvent . type ( textArea , "Hello" ) ) ;
120- const sendButton = screen . getByLabelText ( "Send button" ) ;
120+ const sendButton = await screen . findByLabelText ( "Send button" ) ;
121121 await act ( async ( ) => fireEvent . click ( sendButton ) ) ;
122122 expect (
123- screen . getByText (
123+ await screen . findByText (
124124 "In Ansible, the precedence of variables is determined by the order..." ,
125125 ) ,
126126 ) . toBeInTheDocument ( ) ;
127- expect ( screen . getByText ( "Create variables" ) ) . toBeInTheDocument ( ) ;
127+ expect ( await screen . findByText ( "Create variables" ) ) . toBeInTheDocument ( ) ;
128128
129- const thumbsUpIcon = screen . getByRole ( "button" , { name : "Good response" } ) ;
129+ const thumbsUpIcon = await screen . findByRole ( "button" , {
130+ name : "Good response" ,
131+ } ) ;
130132 await act ( async ( ) => fireEvent . click ( thumbsUpIcon ) ) ;
131133
132- const thumbsDownIcon = screen . getByRole ( "button" , { name : "Bad response" } ) ;
134+ const thumbsDownIcon = await screen . findByRole ( "button" , {
135+ name : "Bad response" ,
136+ } ) ;
133137 await act ( async ( ) => fireEvent . click ( thumbsDownIcon ) ) ;
134138
135- const clearContextButton = screen . getByLabelText ( "Clear context" ) ;
139+ const clearContextButton = await screen . findByLabelText ( "Clear context" ) ;
136140 await act ( async ( ) => fireEvent . click ( clearContextButton ) ) ;
137141 expect (
138142 screen . queryByText (
@@ -141,16 +145,16 @@ describe("App tests", () => {
141145 ) . toBeNull ( ) ;
142146 expect ( screen . queryByText ( "Create variables" ) ) . toBeNull ( ) ;
143147
144- const footNoteLink = screen . getByText (
148+ const footNoteLink = await screen . findByText (
145149 "Lightspeed uses AI. Check for mistakes." ,
146150 ) ;
147151 await act ( async ( ) => fireEvent . click ( footNoteLink ) ) ;
148152 expect (
149- screen . getByText ( "While Lightspeed strives for accuracy," , {
153+ await screen . findByText ( "While Lightspeed strives for accuracy," , {
150154 exact : false ,
151155 } ) ,
152156 ) . toBeVisible ( ) ;
153- const gotItButton = screen . getByText ( "Got it" ) ;
157+ const gotItButton = await screen . findByText ( "Got it" ) ;
154158 await act ( async ( ) => fireEvent . click ( gotItButton ) ) ;
155159 expect (
156160 screen . queryByText ( "While Lightspeed strives for accuracy," , {
@@ -163,21 +167,23 @@ describe("App tests", () => {
163167 const ghIssueLinkSpy = vi . spyOn ( global , "open" ) ;
164168 mockAxios ( 200 ) ;
165169 renderApp ( ) ;
166- const textArea = screen . getByLabelText ( "Send a message..." ) ;
170+ const textArea = await screen . findByLabelText ( "Send a message..." ) ;
167171 await act ( async ( ) => userEvent . type ( textArea , "Hello" ) ) ;
168- const sendButton = screen . getByLabelText ( "Send button" ) ;
172+ const sendButton = await screen . findByLabelText ( "Send button" ) ;
169173 await act ( async ( ) => fireEvent . click ( sendButton ) ) ;
170174 expect (
171- screen . getByText (
175+ await screen . findByText (
172176 "In Ansible, the precedence of variables is determined by the order..." ,
173177 ) ,
174178 ) . toBeInTheDocument ( ) ;
175- expect ( screen . getByText ( "Create variables" ) ) . toBeInTheDocument ( ) ;
179+ expect ( await screen . findByText ( "Create variables" ) ) . toBeInTheDocument ( ) ;
176180
177- const thumbsDownIcon = screen . getByRole ( "button" , { name : "Bad response" } ) ;
181+ const thumbsDownIcon = await screen . findByRole ( "button" , {
182+ name : "Bad response" ,
183+ } ) ;
178184 await act ( async ( ) => fireEvent . click ( thumbsDownIcon ) ) ;
179185
180- const sureButton = screen . getByText ( "Sure!" ) ;
186+ const sureButton = await screen . findByText ( "Sure!" ) ;
181187 await act ( async ( ) => fireEvent . click ( sureButton ) ) ;
182188
183189 expect ( ghIssueLinkSpy . mock . calls . length ) . toEqual ( 1 ) ;
@@ -201,21 +207,23 @@ describe("App tests", () => {
201207 }
202208 mockAxios ( 200 , false , false , lotsOfRefDocs ) ;
203209 renderApp ( ) ;
204- const textArea = screen . getByLabelText ( "Send a message..." ) ;
210+ const textArea = await screen . findByLabelText ( "Send a message..." ) ;
205211 await act ( async ( ) => userEvent . type ( textArea , "Hello" ) ) ;
206- const sendButton = screen . getByLabelText ( "Send button" ) ;
212+ const sendButton = await screen . findByLabelText ( "Send button" ) ;
207213 await act ( async ( ) => fireEvent . click ( sendButton ) ) ;
208214 expect (
209- screen . getByText (
215+ await screen . findByText (
210216 "In Ansible, the precedence of variables is determined by the order..." ,
211217 ) ,
212218 ) . toBeInTheDocument ( ) ;
213- expect ( screen . getByText ( "Create variables" ) ) . toBeInTheDocument ( ) ;
219+ expect ( await screen . findByText ( "Create variables" ) ) . toBeInTheDocument ( ) ;
214220
215- const thumbsDownIcon = screen . getByRole ( "button" , { name : "Bad response" } ) ;
221+ const thumbsDownIcon = await screen . findByRole ( "button" , {
222+ name : "Bad response" ,
223+ } ) ;
216224 await act ( async ( ) => fireEvent . click ( thumbsDownIcon ) ) ;
217225
218- const sureButton = screen . getByText ( "Sure!" ) ;
226+ const sureButton = await screen . findByText ( "Sure!" ) ;
219227 await act ( async ( ) => fireEvent . click ( sureButton ) ) ;
220228
221229 expect ( ghIssueLinkSpy . mock . calls . length ) . toEqual ( 1 ) ;
@@ -228,9 +236,9 @@ describe("App tests", () => {
228236 it ( "Chat service returns 500" , async ( ) => {
229237 mockAxios ( 500 ) ;
230238 const view = renderApp ( ) ;
231- const textArea = screen . getByLabelText ( "Send a message..." ) ;
239+ const textArea = await screen . findByLabelText ( "Send a message..." ) ;
232240 await act ( async ( ) => userEvent . type ( textArea , "Hello" ) ) ;
233- const sendButton = screen . getByLabelText ( "Send button" ) ;
241+ const sendButton = await screen . findByLabelText ( "Send button" ) ;
234242 await act ( async ( ) => fireEvent . click ( sendButton ) ) ;
235243 const alert = view . container . querySelector ( ".pf-v6-c-alert__description" ) ;
236244 const textContent = alert ?. textContent ;
@@ -240,66 +248,75 @@ describe("App tests", () => {
240248 it ( "Chat service returns a timeout error" , async ( ) => {
241249 mockAxios ( - 1 , true , true ) ;
242250 renderApp ( ) ;
243- const textArea = screen . getByLabelText ( "Send a message..." ) ;
251+ const textArea = await screen . findByLabelText ( "Send a message..." ) ;
244252 await act ( async ( ) => userEvent . type ( textArea , "Hello" ) ) ;
245- const sendButton = screen . getByLabelText ( "Send button" ) ;
253+ const sendButton = await screen . findByLabelText ( "Send button" ) ;
246254 await act ( async ( ) => fireEvent . click ( sendButton ) ) ;
247255 expect (
248- screen . getByText (
256+ await screen . findByText (
249257 "Chatbot service is taking too long to respond to your query. " ,
250258 { exact : false } ,
251259 ) ,
252260 ) . toBeInTheDocument ( ) ;
253261 } ) ;
254262
255263 it ( "Chat service returns 429 Too Many Requests error" , async ( ) => {
256- vi . useFakeTimers ( ) ;
257264 mockAxios ( 429 , true ) ;
258265 renderApp ( ) ;
259- const textArea = screen . getByLabelText ( "Send a message..." ) ;
266+ const textArea = await screen . findByLabelText ( "Send a message..." ) ;
260267 await act ( async ( ) => userEvent . type ( textArea , "Hello" ) ) ;
261- const sendButton = screen . getByLabelText ( "Send button" ) ;
262- await act ( async ( ) => fireEvent . click ( sendButton ) ) ;
263- await act ( async ( ) => vi . runAllTimers ( ) ) ;
264- expect (
265- screen . getByText ( "Chatbot service is busy with too many requests. " , {
266- exact : false ,
267- } ) ,
268- ) . toBeInTheDocument ( ) ;
268+ const sendButton = await screen . findByLabelText ( "Send button" ) ;
269+ try {
270+ vi . useFakeTimers ( ) ;
271+ await act ( async ( ) => fireEvent . click ( sendButton ) ) ;
272+ await act ( async ( ) => vi . runAllTimers ( ) ) ;
273+ expect (
274+ await screen . findByText (
275+ "Chatbot service is busy with too many requests. " ,
276+ {
277+ exact : false ,
278+ } ,
279+ ) ,
280+ ) . toBeInTheDocument ( ) ;
281+ } finally {
282+ vi . useRealTimers ;
283+ }
269284 } ) ;
270285
271286 it ( "Chat service returns an unexpected error" , async ( ) => {
272287 mockAxios ( - 1 , true ) ;
273288 const view = renderApp ( ) ;
274- const textArea = screen . getByLabelText ( "Send a message..." ) ;
289+ const textArea = await screen . findByLabelText ( "Send a message..." ) ;
275290 await act ( async ( ) => userEvent . type ( textArea , "Hello" ) ) ;
276- const sendButton = screen . getByLabelText ( "Send button" ) ;
291+ const sendButton = await screen . findByLabelText ( "Send button" ) ;
277292 await act ( async ( ) => fireEvent . click ( sendButton ) ) ;
278293 const alert = view . container . querySelector ( ".pf-v6-c-alert__description" ) ;
279294 const textContent = alert ?. textContent ;
280295 expect ( textContent ) . toEqual (
281- "An unexpected error occured : Error: mocked error" ,
296+ "An unexpected error occurred : Error: mocked error" ,
282297 ) ;
283298 } ) ;
284299
285300 it ( "Feedback API returns 500" , async ( ) => {
286301 mockAxios ( 200 ) ;
287302 const view = renderApp ( ) ;
288- const textArea = screen . getByLabelText ( "Send a message..." ) ;
303+ const textArea = await screen . findByLabelText ( "Send a message..." ) ;
289304 await act ( async ( ) => userEvent . type ( textArea , "Hello" ) ) ;
290- const sendButton = screen . getByLabelText ( "Send button" ) ;
305+ const sendButton = await screen . findByLabelText ( "Send button" ) ;
291306 await act ( async ( ) => fireEvent . click ( sendButton ) ) ;
292307 expect (
293- screen . getByText (
308+ await screen . findByText (
294309 "In Ansible, the precedence of variables is determined by the order..." ,
295310 ) ,
296311 ) . toBeInTheDocument ( ) ;
297- expect ( screen . getByText ( "Create variables" ) ) . toBeInTheDocument ( ) ;
312+ expect ( await screen . findByText ( "Create variables" ) ) . toBeInTheDocument ( ) ;
298313
299314 vi . restoreAllMocks ( ) ;
300315 mockAxios ( 500 ) ;
301316
302- const thumbsUpIcon = screen . getByRole ( "button" , { name : "Good response" } ) ;
317+ const thumbsUpIcon = await screen . findByRole ( "button" , {
318+ name : "Good response" ,
319+ } ) ;
303320 await act ( async ( ) => fireEvent . click ( thumbsUpIcon ) ) ;
304321 const alert = view . container . querySelector ( ".pf-v6-c-alert__description" ) ;
305322 const textContent = alert ?. textContent ;
@@ -309,26 +326,28 @@ describe("App tests", () => {
309326 it ( "Feedback API returns an unexpected error" , async ( ) => {
310327 mockAxios ( 200 ) ;
311328 const view = renderApp ( ) ;
312- const textArea = screen . getByLabelText ( "Send a message..." ) ;
329+ const textArea = await screen . findByLabelText ( "Send a message..." ) ;
313330 await act ( async ( ) => userEvent . type ( textArea , "Hello" ) ) ;
314- const sendButton = screen . getByLabelText ( "Send button" ) ;
331+ const sendButton = await screen . findByLabelText ( "Send button" ) ;
315332 await act ( async ( ) => fireEvent . click ( sendButton ) ) ;
316333 expect (
317- screen . getByText (
334+ await screen . findByText (
318335 "In Ansible, the precedence of variables is determined by the order..." ,
319336 ) ,
320337 ) . toBeInTheDocument ( ) ;
321- expect ( screen . getByText ( "Create variables" ) ) . toBeInTheDocument ( ) ;
338+ expect ( await screen . findByText ( "Create variables" ) ) . toBeInTheDocument ( ) ;
322339
323340 vi . restoreAllMocks ( ) ;
324341 mockAxios ( - 1 , true ) ;
325342
326- const thumbsUpIcon = screen . getByRole ( "button" , { name : "Good response" } ) ;
343+ const thumbsUpIcon = await screen . findByRole ( "button" , {
344+ name : "Good response" ,
345+ } ) ;
327346 await act ( async ( ) => fireEvent . click ( thumbsUpIcon ) ) ;
328347 const alert = view . container . querySelector ( ".pf-v6-c-alert__description" ) ;
329348 const textContent = alert ?. textContent ;
330349 expect ( textContent ) . toEqual (
331- "An unexpected error occured : Error: mocked error" ,
350+ "An unexpected error occurred : Error: mocked error" ,
332351 ) ;
333352 } ) ;
334353
@@ -360,22 +379,24 @@ describe("App tests", () => {
360379 mockAxios ( 200 ) ;
361380
362381 renderApp ( true ) ;
363- const modelSelection = screen . getByText ( "granite3-8b" ) ;
382+ const modelSelection = await screen . findByText ( "granite3-8b" ) ;
364383 await act ( async ( ) => fireEvent . click ( modelSelection ) ) ;
365- expect ( screen . getByRole ( "menuitem" , { name : "granite3-8b" } ) ) . toBeTruthy ( ) ;
384+ expect (
385+ await screen . findByRole ( "menuitem" , { name : "granite3-8b" } ) ,
386+ ) . toBeTruthy ( ) ;
366387 await act ( async ( ) =>
367- screen . getByRole ( "menuitem" , { name : "granite3-8b" } ) . click ( ) ,
388+ ( await screen . findByRole ( "menuitem" , { name : "granite3-8b" } ) ) . click ( ) ,
368389 ) ;
369390
370- const textArea = screen . getByLabelText ( "Send a message..." ) ;
391+ const textArea = await screen . findByLabelText ( "Send a message..." ) ;
371392 await act ( async ( ) => userEvent . type ( textArea , "Hello" ) ) ;
372- const sendButton = screen . getByLabelText ( "Send button" ) ;
393+ const sendButton = await screen . findByLabelText ( "Send button" ) ;
373394 await act ( async ( ) => fireEvent . click ( sendButton ) ) ;
374395 expect (
375- screen . getByText (
396+ await screen . findByText (
376397 "In Ansible, the precedence of variables is determined by the order..." ,
377398 ) ,
378399 ) . toBeInTheDocument ( ) ;
379- expect ( screen . getByText ( "Create variables" ) ) . toBeInTheDocument ( ) ;
400+ expect ( await screen . findByText ( "Create variables" ) ) . toBeInTheDocument ( ) ;
380401 } ) ;
381402} ) ;
0 commit comments