4
4
screen ,
5
5
userEvent ,
6
6
waitFor ,
7
+ within ,
7
8
} from '@mongodb-js/testing-library-compass' ;
8
9
import { AssistantChat } from './assistant-chat' ;
9
10
import { expect } from 'chai' ;
@@ -30,6 +31,12 @@ describe('AssistantChat', function () {
30
31
type : 'text' ,
31
32
text : 'Hello! How can I help you with MongoDB today?' ,
32
33
} ,
34
+ {
35
+ type : 'source-url' ,
36
+ title : 'MongoDB' ,
37
+ url : 'https://en.wikipedia.org/wiki/MongoDB' ,
38
+ sourceId : '1' ,
39
+ } ,
33
40
] ,
34
41
} ,
35
42
] ;
@@ -471,16 +478,14 @@ describe('AssistantChat', function () {
471
478
) ;
472
479
473
480
// First click thumbs down to potentially open feedback form
474
- const thumbsDownButton = assistantMessage . querySelector (
475
- '[aria-label="Thumbs Down Icon"] '
476
- ) as HTMLElement ;
481
+ const thumbsDownButton = within ( assistantMessage ) . getByLabelText (
482
+ 'Dislike this message '
483
+ ) ;
477
484
478
485
userEvent . click ( thumbsDownButton ) ;
479
486
480
487
// Look for feedback text area (the exact implementation depends on LeafyGreen)
481
- const feedbackTextArea = screen . getByTestId (
482
- 'lg-chat-message_actions-feedback_textarea'
483
- ) ;
488
+ const feedbackTextArea = within ( assistantMessage ) . getByRole ( 'textbox' ) ;
484
489
485
490
userEvent . type ( feedbackTextArea , 'This response was not helpful' ) ;
486
491
@@ -527,4 +532,33 @@ describe('AssistantChat', function () {
527
532
expect ( screen . queryByLabelText ( 'Thumbs Down Icon' ) ) . to . not . exist ;
528
533
} ) ;
529
534
} ) ;
535
+
536
+ describe ( 'related sources' , function ( ) {
537
+ it ( 'displays related resources links for assistant messages that include them' , async function ( ) {
538
+ renderWithChat ( mockMessages ) ;
539
+ userEvent . click ( screen . getByLabelText ( 'Expand Related Resources' ) ) ;
540
+
541
+ // TODO(COMPASS-9860) can't find the links in test-electron on RHEL and Ubuntu.
542
+ if ( ( process as any ) . type === 'renderer' ) {
543
+ return this . skip ( ) ;
544
+ }
545
+
546
+ await waitFor ( ( ) => {
547
+ expect ( screen . getByRole ( 'link' , { name : 'MongoDB' } ) ) . to . have . attribute (
548
+ 'href' ,
549
+ 'https://en.wikipedia.org/wiki/MongoDB'
550
+ ) ;
551
+ } ) ;
552
+ } ) ;
553
+
554
+ it ( 'does not display related resources section when there are no source-url parts' , function ( ) {
555
+ const messages = mockMessages . map ( ( message ) => ( {
556
+ ...message ,
557
+ parts : message . parts . filter ( ( part ) => part . type !== 'source-url' ) ,
558
+ } ) ) ;
559
+ renderWithChat ( messages ) ;
560
+
561
+ expect ( screen . queryByLabelText ( 'Expand Related Resources' ) ) . to . not . exist ;
562
+ } ) ;
563
+ } ) ;
530
564
} ) ;
0 commit comments