@@ -11,6 +11,17 @@ jest.mock('../../api/api', () => ({
11
11
historyDelete : jest . fn ( )
12
12
} ) )
13
13
14
+ // Mocking TooltipHost from @fluentui /react
15
+ jest . mock ( '@fluentui/react' , ( ) => {
16
+ const actual = jest . requireActual ( '@fluentui/react' ) ;
17
+ return {
18
+ ...actual ,
19
+ TooltipHost : ( { children } : { children : React . ReactNode } ) => (
20
+ < div data-testid = "tooltip-mock" > { children } </ div >
21
+ ) ,
22
+ } ;
23
+ } ) ;
24
+
14
25
const conversation : Conversation = {
15
26
id : '1' ,
16
27
title : 'Test Chat' ,
@@ -47,7 +58,7 @@ describe('ChatHistoryListItemCell', () => {
47
58
} )
48
59
49
60
test ( 'renders the chat history item' , ( ) => {
50
- render ( < ChatHistoryListItemCell { ...componentProps } /> ) ;
61
+ render ( < ChatHistoryListItemCell { ...componentProps } /> ) ;
51
62
const titleElement = screen . getByText ( / T e s t C h a t / i)
52
63
expect ( titleElement ) . toBeInTheDocument ( )
53
64
} )
@@ -71,10 +82,10 @@ render(<ChatHistoryListItemCell {...componentProps} />);
71
82
// Check if the truncated title is in the document
72
83
const truncatedTitle = screen . getByText ( / A v e r y l o n g t i t l e t h a t s h o u l .../ i)
73
84
expect ( truncatedTitle ) . toBeInTheDocument ( )
74
- } )
85
+ } )
75
86
76
87
test ( 'calls onSelect when clicked' , ( ) => {
77
- render ( < ChatHistoryListItemCell { ...componentProps } /> ) ;
88
+ render ( < ChatHistoryListItemCell { ...componentProps } /> ) ;
78
89
const item = screen . getByLabelText ( 'chat history item' )
79
90
fireEvent . click ( item )
80
91
expect ( mockOnSelect ) . toHaveBeenCalledWith ( conversation )
@@ -93,7 +104,7 @@ render(<ChatHistoryListItemCell {...componentProps} />);
93
104
// Expect that no content related to the title is rendered
94
105
const titleElement = screen . queryByText ( / T e s t C h a t / i) ;
95
106
expect ( titleElement ) . not . toBeInTheDocument ( ) ;
96
- } )
107
+ } )
97
108
98
109
test ( 'displays delete and edit buttons on hover' , async ( ) => {
99
110
const mockAppStateUpdated = {
@@ -132,7 +143,7 @@ render(<ChatHistoryListItemCell {...componentProps} />);
132
143
} )
133
144
134
145
test ( 'shows confirmation dialog and deletes item' , async ( ) => {
135
- ; ( historyDelete as jest . Mock ) . mockResolvedValueOnce ( {
146
+ ; ( historyDelete as jest . Mock ) . mockResolvedValueOnce ( {
136
147
ok : true ,
137
148
json : async ( ) => ( { } )
138
149
} )
@@ -156,7 +167,7 @@ render(<ChatHistoryListItemCell {...componentProps} />);
156
167
} )
157
168
158
169
test ( 'when delete API fails or return false' , async ( ) => {
159
- ; ( historyDelete as jest . Mock ) . mockResolvedValueOnce ( {
170
+ ; ( historyDelete as jest . Mock ) . mockResolvedValueOnce ( {
160
171
ok : false ,
161
172
json : async ( ) => ( { } )
162
173
} )
@@ -204,10 +215,10 @@ render(<ChatHistoryListItemCell {...componentProps} />);
204
215
const appStateWithRequestInitiated = {
205
216
...componentProps ,
206
217
isGenerating : true ,
207
- selectedConvId :'1'
218
+ selectedConvId : '1'
208
219
}
209
220
210
- render ( < ChatHistoryListItemCell { ...appStateWithRequestInitiated } onSelect = { mockOnSelect } /> ) ;
221
+ render ( < ChatHistoryListItemCell { ...appStateWithRequestInitiated } onSelect = { mockOnSelect } /> ) ;
211
222
const item = screen . getByLabelText ( 'chat history item' )
212
223
fireEvent . mouseEnter ( item )
213
224
const deleteButton = screen . getByTitle ( / D e l e t e / i)
@@ -218,10 +229,10 @@ render(<ChatHistoryListItemCell {...componentProps} />);
218
229
} )
219
230
220
231
test ( 'does not disable buttons when request is not initiated' , ( ) => {
221
- render ( < ChatHistoryListItemCell { ...componentProps } /> ) ;
222
- const item = screen . getByLabelText ( 'chat history item' )
223
- fireEvent . mouseEnter ( item )
224
- const deleteButton = screen . getByTitle ( / D e l e t e / i)
232
+ render ( < ChatHistoryListItemCell { ...componentProps } /> ) ;
233
+ const item = screen . getByLabelText ( 'chat history item' )
234
+ fireEvent . mouseEnter ( item )
235
+ const deleteButton = screen . getByTitle ( / D e l e t e / i)
225
236
const editButton = screen . getByTitle ( / E d i t / i)
226
237
227
238
expect ( deleteButton ) . not . toBeDisabled ( )
@@ -245,12 +256,12 @@ render(<ChatHistoryListItemCell {...componentProps} />);
245
256
} )
246
257
247
258
test ( 'handles input onChange and onKeyDown ENTER events correctly' , async ( ) => {
248
- ; ( historyRename as jest . Mock ) . mockResolvedValueOnce ( {
259
+ ; ( historyRename as jest . Mock ) . mockResolvedValueOnce ( {
249
260
ok : true ,
250
261
json : async ( ) => ( { } )
251
262
} )
252
263
253
- render ( < ChatHistoryListItemCell { ...componentProps } /> ) ;
264
+ render ( < ChatHistoryListItemCell { ...componentProps } /> ) ;
254
265
// Simulate hover to reveal Edit button
255
266
const item = screen . getByLabelText ( 'chat history item' )
256
267
fireEvent . mouseEnter ( item )
@@ -316,7 +327,7 @@ render(<ChatHistoryListItemCell {...componentProps} />);
316
327
test ( 'Should hide the rename from when cancel it.' , async ( ) => {
317
328
userEvent . setup ( )
318
329
319
- render ( < ChatHistoryListItemCell { ...componentProps } /> )
330
+ render ( < ChatHistoryListItemCell { ...componentProps } /> )
320
331
const item = screen . getByLabelText ( 'chat history item' )
321
332
fireEvent . mouseEnter ( item )
322
333
// Wait for the Edit button to appear and click it
@@ -336,10 +347,10 @@ render(<ChatHistoryListItemCell {...componentProps} />);
336
347
337
348
test . skip ( 'handles rename save API failed' , async ( ) => {
338
349
userEvent . setup ( )
339
- ; ( historyRename as jest . Mock ) . mockRejectedValue ( {
340
- ok : false ,
341
- json : async ( ) => ( { } )
342
- } )
350
+ ; ( historyRename as jest . Mock ) . mockRejectedValue ( {
351
+ ok : false ,
352
+ json : async ( ) => ( { } )
353
+ } )
343
354
344
355
render ( < ChatHistoryListItemCell { ...componentProps } /> ) ;
345
356
// Simulate hover to reveal Edit button
@@ -380,12 +391,12 @@ render(<ChatHistoryListItemCell {...componentProps} />);
380
391
date : new Date ( ) . toISOString ( )
381
392
}
382
393
383
- ; ( historyRename as jest . Mock ) . mockResolvedValueOnce ( {
384
- ok : false ,
385
- json : async ( ) => ( { message : 'Title already exists' } )
386
- } )
394
+ ; ( historyRename as jest . Mock ) . mockResolvedValueOnce ( {
395
+ ok : false ,
396
+ json : async ( ) => ( { message : 'Title already exists' } )
397
+ } )
387
398
388
- render ( < ChatHistoryListItemCell { ...componentProps } /> ) ;
399
+ render ( < ChatHistoryListItemCell { ...componentProps } /> ) ;
389
400
const item = screen . getByLabelText ( 'chat history item' )
390
401
fireEvent . mouseEnter ( item )
391
402
@@ -406,7 +417,7 @@ render(<ChatHistoryListItemCell {...componentProps} />);
406
417
407
418
408
419
test ( 'triggers edit functionality when Enter key is pressed' , async ( ) => {
409
- ; ( historyRename as jest . Mock ) . mockResolvedValueOnce ( {
420
+ ; ( historyRename as jest . Mock ) . mockResolvedValueOnce ( {
410
421
ok : true ,
411
422
json : async ( ) => ( { message : 'Title changed' } )
412
423
} )
@@ -438,12 +449,12 @@ render(<ChatHistoryListItemCell {...componentProps} />);
438
449
} )
439
450
440
451
test ( 'successfully saves edited title' , async ( ) => {
441
- ; ( historyRename as jest . Mock ) . mockResolvedValueOnce ( {
452
+ ; ( historyRename as jest . Mock ) . mockResolvedValueOnce ( {
442
453
ok : true ,
443
454
json : async ( ) => ( { } )
444
455
} )
445
456
446
- render ( < ChatHistoryListItemCell { ...componentProps } /> ) ;
457
+ render ( < ChatHistoryListItemCell { ...componentProps } /> ) ;
447
458
const item = screen . getByLabelText ( 'chat history item' )
448
459
fireEvent . mouseEnter ( item )
449
460
@@ -500,7 +511,7 @@ render(<ChatHistoryListItemCell {...componentProps} />);
500
511
///////
501
512
502
513
test ( 'opens delete confirmation dialog when Enter key is pressed on the Delete button' , async ( ) => {
503
- render ( < ChatHistoryListItemCell { ...componentProps } /> ) ;
514
+ render ( < ChatHistoryListItemCell { ...componentProps } /> ) ;
504
515
const item = screen . getByLabelText ( 'chat history item' )
505
516
fireEvent . mouseEnter ( item )
506
517
@@ -511,7 +522,7 @@ render(<ChatHistoryListItemCell {...componentProps} />);
511
522
} )
512
523
513
524
test ( 'opens delete confirmation dialog when Space key is pressed on the Delete button' , async ( ) => {
514
- render ( < ChatHistoryListItemCell { ...componentProps } /> ) ;
525
+ render ( < ChatHistoryListItemCell { ...componentProps } /> ) ;
515
526
const item = screen . getByLabelText ( 'chat history item' )
516
527
fireEvent . mouseEnter ( item )
517
528
@@ -522,7 +533,7 @@ render(<ChatHistoryListItemCell {...componentProps} />);
522
533
} )
523
534
524
535
test ( 'opens edit input when Space key is pressed on the Edit button' , async ( ) => {
525
- render ( < ChatHistoryListItemCell { ...componentProps } /> ) ;
536
+ render ( < ChatHistoryListItemCell { ...componentProps } /> ) ;
526
537
const item = screen . getByLabelText ( 'chat history item' )
527
538
fireEvent . mouseEnter ( item )
528
539
@@ -534,7 +545,7 @@ render(<ChatHistoryListItemCell {...componentProps} />);
534
545
} )
535
546
536
547
test ( 'opens edit input when Enter key is pressed on the Edit button' , async ( ) => {
537
- render ( < ChatHistoryListItemCell { ...componentProps } /> ) ;
548
+ render ( < ChatHistoryListItemCell { ...componentProps } /> ) ;
538
549
const item = screen . getByLabelText ( 'chat history item' )
539
550
fireEvent . mouseEnter ( item )
540
551
@@ -547,11 +558,11 @@ render(<ChatHistoryListItemCell {...componentProps} />);
547
558
548
559
test ( 'handles rename save when the updated text is equal to initial text' , async ( ) => {
549
560
userEvent . setup ( )
550
- ; ( historyRename as jest . Mock ) . mockRejectedValue ( {
551
- ok : false ,
552
- json : async ( ) => ( { message : 'Title not changed' } )
553
- } )
554
- render ( < ChatHistoryListItemCell { ...componentProps } /> )
561
+ ; ( historyRename as jest . Mock ) . mockRejectedValue ( {
562
+ ok : false ,
563
+ json : async ( ) => ( { message : 'Title not changed' } )
564
+ } )
565
+ render ( < ChatHistoryListItemCell { ...componentProps } /> )
555
566
556
567
// Simulate hover to reveal Edit button
557
568
const item = screen . getByLabelText ( 'chat history item' )
@@ -573,26 +584,26 @@ render(<ChatHistoryListItemCell {...componentProps} />);
573
584
//fireEvent.change(inputItem, { target: { value: 'Test Chat' } });
574
585
} )
575
586
expect ( historyRename ) . not . toHaveBeenCalled ( )
576
- } )
577
- test ( 'Should hide the rename from on Enter or space .' , async ( ) => {
578
- userEvent . setup ( )
579
-
580
- render ( < ChatHistoryListItemCell { ...componentProps } /> )
581
- const item = screen . getByLabelText ( 'chat history item' )
582
- fireEvent . mouseEnter ( item )
583
- // Wait for the Edit button to appear and click it
584
- await waitFor ( ( ) => {
585
- const editButton = screen . getByTitle ( / E d i t / i)
586
- fireEvent . click ( editButton )
587
587
} )
588
+ test ( 'Should hide the rename from on Enter or space .' , async ( ) => {
589
+ userEvent . setup ( )
588
590
589
- const editButton = screen . getByRole ( 'button' , { name : 'cancel edit title' } )
590
- fireEvent . keyDown ( editButton , { key : 'Enter' , code : 'Enter' , charCode : 13 } )
591
+ render ( < ChatHistoryListItemCell { ...componentProps } /> )
592
+ const item = screen . getByLabelText ( 'chat history item' )
593
+ fireEvent . mouseEnter ( item )
594
+ // Wait for the Edit button to appear and click it
595
+ await waitFor ( ( ) => {
596
+ const editButton = screen . getByTitle ( / E d i t / i)
597
+ fireEvent . click ( editButton )
598
+ } )
591
599
592
- // Wait for the error to be hidden after 5 seconds
593
- await waitFor ( ( ) => {
594
- const input = screen . queryByLabelText ( 'confirm new title' )
595
- expect ( input ) . not . toBeInTheDocument ( )
600
+ const editButton = screen . getByRole ( 'button' , { name : 'cancel edit title' } )
601
+ fireEvent . keyDown ( editButton , { key : 'Enter' , code : 'Enter' , charCode : 13 } )
602
+
603
+ // Wait for the error to be hidden after 5 seconds
604
+ await waitFor ( ( ) => {
605
+ const input = screen . queryByLabelText ( 'confirm new title' )
606
+ expect ( input ) . not . toBeInTheDocument ( )
607
+ } )
596
608
} )
597
609
} )
598
- } )
0 commit comments