@@ -30,6 +30,7 @@ describe('MongoDB Assistant', function () {
30
30
response ?: MockAssistantResponse ;
31
31
}
32
32
) => Promise < void > ;
33
+ let setAIOptIn : ( newValue : boolean ) => Promise < void > ;
33
34
34
35
const testMessage = 'What is MongoDB?' ;
35
36
const testResponse = 'MongoDB is a database.' ;
@@ -74,6 +75,19 @@ describe('MongoDB Assistant', function () {
74
75
await submitButton . click ( ) ;
75
76
} ;
76
77
78
+ setAIOptIn = async ( newValue : boolean ) => {
79
+ if (
80
+ ( await browser . getFeature ( 'optInGenAIFeatures' ) ) === true &&
81
+ newValue === false
82
+ ) {
83
+ // Reseting the opt-in to false can be tricky so it's best to start over in this case.
84
+ compass = await init ( this . test ?. fullTitle ( ) , { firstRun : false } ) ;
85
+ return ;
86
+ }
87
+
88
+ await browser . setFeature ( 'optInGenAIFeatures' , newValue ) ;
89
+ } ;
90
+
77
91
await browser . setupDefaultConnections ( ) ;
78
92
await browser . connectToDefaults ( ) ;
79
93
await browser . selectConnectionMenuItem (
@@ -151,8 +165,8 @@ describe('MongoDB Assistant', function () {
151
165
} ) ;
152
166
153
167
describe ( 'before opt-in' , function ( ) {
154
- beforeEach ( async function ( ) {
155
- await setAIOptIn ( browser , false ) ;
168
+ before ( async function ( ) {
169
+ await setAIOptIn ( false ) ;
156
170
} ) ;
157
171
158
172
it ( 'does not send the message if the user declines the opt-in' , async function ( ) {
@@ -176,16 +190,14 @@ describe('MongoDB Assistant', function () {
176
190
} ) ;
177
191
178
192
describe ( 'entry points' , function ( ) {
179
- beforeEach ( async function ( ) {
180
- await setAIOptIn ( browser , false ) ;
181
- } ) ;
182
-
183
193
it ( 'should display opt-in modal for connection error entry point' , async function ( ) {
184
194
await browser . connectWithConnectionString (
185
195
'mongodb-invalid://localhost:27017' ,
186
196
{ connectionStatus : 'failure' }
187
197
) ;
188
- await useErrorViewEntryPoint ( browser ) ;
198
+ await browser . clickVisible (
199
+ browser . $ ( Selectors . ConnectionToastErrorDebugButton )
200
+ ) ;
189
201
190
202
const optInModal = browser . $ ( Selectors . AIOptInModal ) ;
191
203
await optInModal . waitForDisplayed ( ) ;
@@ -216,38 +228,40 @@ describe('MongoDB Assistant', function () {
216
228
expect ( await getDisplayedMessages ( browser ) ) . to . deep . equal ( [ ] ) ;
217
229
} ) ;
218
230
} ) ;
231
+ } ) ;
219
232
220
- describe ( 'opting in' , function ( ) {
221
- it ( 'sends the message if the user opts in' , async function ( ) {
222
- await openAssistantDrawer ( browser ) ;
233
+ describe ( 'opting in' , function ( ) {
234
+ before ( async function ( ) {
235
+ await setAIOptIn ( false ) ;
236
+ await openAssistantDrawer ( browser ) ;
237
+ } ) ;
223
238
224
- await sendMessage ( testMessage ) ;
239
+ it ( 'sends the message if the user opts in' , async function ( ) {
240
+ await sendMessage ( testMessage ) ;
225
241
226
- const optInModal = browser . $ ( Selectors . AIOptInModal ) ;
227
- await optInModal . waitForDisplayed ( ) ;
228
- expect ( await optInModal . isDisplayed ( ) ) . to . be . true ;
242
+ const optInModal = browser . $ ( Selectors . AIOptInModal ) ;
243
+ await optInModal . waitForDisplayed ( ) ;
244
+ expect ( await optInModal . isDisplayed ( ) ) . to . be . true ;
229
245
230
- const acceptButton = browser . $ ( Selectors . AIOptInModalAcceptButton ) ;
231
- await acceptButton . waitForClickable ( ) ;
232
- await acceptButton . click ( ) ;
246
+ const acceptButton = browser . $ ( Selectors . AIOptInModalAcceptButton ) ;
247
+ await acceptButton . waitForClickable ( ) ;
248
+ await acceptButton . click ( ) ;
233
249
234
- await optInModal . waitForDisplayed ( { reverse : true } ) ;
250
+ await optInModal . waitForDisplayed ( { reverse : true } ) ;
235
251
236
- const chatInput = browser . $ ( Selectors . AssistantChatInputTextArea ) ;
237
- expect ( await chatInput . getValue ( ) ) . to . equal ( '' ) ;
252
+ const chatInput = browser . $ ( Selectors . AssistantChatInputTextArea ) ;
253
+ expect ( await chatInput . getValue ( ) ) . to . equal ( '' ) ;
238
254
239
- expect ( await getDisplayedMessages ( browser ) ) . to . deep . equal ( [
240
- { text : testMessage , role : 'user' } ,
241
- { text : testResponse , role : 'assistant' } ,
242
- ] ) ;
243
- } ) ;
255
+ expect ( await getDisplayedMessages ( browser ) ) . to . deep . equal ( [
256
+ { text : testMessage , role : 'user' } ,
257
+ { text : testResponse , role : 'assistant' } ,
258
+ ] ) ;
244
259
} ) ;
245
260
} ) ;
246
261
247
262
describe ( 'after opt-in' , function ( ) {
248
- beforeEach ( async function ( ) {
249
- await setAIOptIn ( browser , true ) ;
250
-
263
+ before ( async function ( ) {
264
+ await setAIOptIn ( true ) ;
251
265
await openAssistantDrawer ( browser ) ;
252
266
} ) ;
253
267
@@ -275,7 +289,12 @@ describe('MongoDB Assistant', function () {
275
289
} ) ;
276
290
277
291
it ( 'displays multiple messages correctly' , async function ( ) {
278
- await sendMessage ( testMessage ) ;
292
+ await sendMessage ( testMessage , {
293
+ response : {
294
+ status : 200 ,
295
+ body : testResponse ,
296
+ } ,
297
+ } ) ;
279
298
280
299
await sendMessage ( 'This is a different message' , {
281
300
response : {
@@ -331,17 +350,13 @@ describe('MongoDB Assistant', function () {
331
350
const thumbsDownButton = assistantMessage . $ (
332
351
'[aria-label="Dislike this message"]'
333
352
) ;
334
- await thumbsDownButton . waitForDisplayed ( ) ;
335
- await thumbsDownButton . click ( ) ;
353
+ await browser . clickVisible ( thumbsDownButton ) ;
336
354
337
355
const feedbackTextarea = assistantMessage . $ ( 'textarea' ) ;
338
356
await feedbackTextarea . waitForDisplayed ( ) ;
339
-
340
357
await feedbackTextarea . setValue ( 'This is a test feedback' ) ;
341
358
342
- const submitButton = browser . $ ( 'button*=Submit' ) ;
343
- await submitButton . waitForClickable ( ) ;
344
- await submitButton . click ( ) ;
359
+ await browser . clickVisible ( browser . $ ( 'button*=Submit' ) ) ;
345
360
346
361
await feedbackTextarea . waitForDisplayed ( { reverse : true } ) ;
347
362
@@ -356,7 +371,7 @@ describe('MongoDB Assistant', function () {
356
371
describe ( 'entry points' , function ( ) {
357
372
describe ( 'explain plan entry point' , function ( ) {
358
373
before ( async function ( ) {
359
- await setAIOptIn ( browser , true ) ;
374
+ await setAIOptIn ( true ) ;
360
375
await setAIFeatures ( browser , true ) ;
361
376
362
377
mockAssistantServer . setResponse ( {
@@ -417,9 +432,7 @@ describe('MongoDB Assistant', function () {
417
432
} ) ;
418
433
419
434
describe ( 'error message entry point' , function ( ) {
420
- before ( async function ( ) {
421
- await setAIOptIn ( browser , true ) ;
422
-
435
+ before ( function ( ) {
423
436
mockAssistantServer . setResponse ( {
424
437
status : 200 ,
425
438
body : 'You should review the connection string.' ,
@@ -431,7 +444,9 @@ describe('MongoDB Assistant', function () {
431
444
'mongodb-invalid://localhost:27017' ,
432
445
{ connectionStatus : 'failure' }
433
446
) ;
434
- await useErrorViewEntryPoint ( browser ) ;
447
+ await browser . clickVisible (
448
+ browser . $ ( Selectors . ConnectionToastErrorDebugButton )
449
+ ) ;
435
450
436
451
const messages = await getDisplayedMessages ( browser ) ;
437
452
expect ( messages ) . deep . equal ( [
@@ -455,11 +470,9 @@ describe('MongoDB Assistant', function () {
455
470
async function setAIFeatures ( browser : CompassBrowser , newValue : boolean ) {
456
471
await browser . openSettingsModal ( 'ai' ) ;
457
472
458
- // Wait for AI settings content to be visible
459
- const aiSettingsContent = browser . $ (
460
- Selectors . ArtificialIntelligenceSettingsContent
461
- ) ;
462
- await aiSettingsContent . waitForDisplayed ( ) ;
473
+ await browser
474
+ . $ ( Selectors . ArtificialIntelligenceSettingsContent )
475
+ . waitForDisplayed ( ) ;
463
476
464
477
const currentValue =
465
478
( await browser
@@ -481,19 +494,8 @@ async function setAIFeatures(browser: CompassBrowser, newValue: boolean) {
481
494
} ) ;
482
495
}
483
496
484
- async function setAIOptIn ( browser : CompassBrowser , enabled : boolean ) {
485
- // Reset the opt-in preference by using the execute command
486
- await browser . setFeature ( 'optInGenAIFeatures' , enabled ) ;
487
-
488
- // Wait for the IPC to be processed
489
- await browser . pause ( 500 ) ;
490
- }
491
-
492
497
async function openAssistantDrawer ( browser : CompassBrowser ) {
493
- const drawerButton = browser . $ ( Selectors . AssistantDrawerButton ) ;
494
- await drawerButton . waitForDisplayed ( ) ;
495
- await drawerButton . waitForClickable ( ) ;
496
- await drawerButton . click ( ) ;
498
+ await browser . clickVisible ( Selectors . AssistantDrawerButton ) ;
497
499
}
498
500
499
501
async function clearChat ( browser : CompassBrowser ) {
@@ -509,11 +511,8 @@ async function clearChat(browser: CompassBrowser) {
509
511
}
510
512
511
513
async function getDisplayedMessages ( browser : CompassBrowser ) {
512
- // Wait for the messages container to be visible
513
- const chatMessages = browser . $ ( Selectors . AssistantChatMessages ) ;
514
- await chatMessages . waitForDisplayed ( ) ;
514
+ await browser . $ ( Selectors . AssistantChatMessages ) . waitForDisplayed ( ) ;
515
515
516
- // Get all individual message elements
517
516
const messageElements = await browser
518
517
. $$ ( Selectors . AssistantChatMessage )
519
518
. getElements ( ) ;
@@ -540,42 +539,13 @@ async function getDisplayedMessages(browser: CompassBrowser) {
540
539
}
541
540
542
541
async function useExplainPlanEntryPoint ( browser : CompassBrowser ) {
543
- // Open explain plan modal by clicking the explain button
544
- const explainButton = browser . $ ( Selectors . AggregationExplainButton ) ;
545
- await explainButton . waitForDisplayed ( ) ;
546
- await explainButton . click ( ) ;
547
-
548
- // Wait for the explain plan modal to open and finish loading
549
- const explainModal = browser . $ ( Selectors . AggregationExplainModal ) ;
550
- await explainModal . waitForDisplayed ( ) ;
551
-
552
- // Wait for the explain plan to be ready (loader should disappear)
553
- const explainLoader = browser . $ ( Selectors . ExplainLoader ) ;
554
- await explainLoader . waitForDisplayed ( {
555
- reverse : true ,
556
- timeout : 10000 ,
557
- } ) ;
558
-
559
- // Click the "Interpret for me" button
560
- const interpretButton = browser . $ ( Selectors . ExplainPlanInterpretButton ) ;
561
- await interpretButton . waitForDisplayed ( ) ;
562
- await interpretButton . click ( ) ;
542
+ await browser . clickVisible ( Selectors . AggregationExplainButton ) ;
563
543
564
- // The modal should close
565
- await explainModal . waitForDisplayed ( { reverse : true } ) ;
544
+ await browser . clickVisible ( Selectors . ExplainPlanInterpretButton ) ;
566
545
567
- // The assistant drawer should open
568
- const assistantDrawer = browser . $ ( Selectors . SideDrawer ) ;
569
- await assistantDrawer . waitForDisplayed ( ) ;
570
- }
571
-
572
- async function useErrorViewEntryPoint ( browser : CompassBrowser ) {
573
- const connectionToastErrorDebugButton = browser . $ (
574
- Selectors . ConnectionToastErrorDebugButton
575
- ) ;
576
- await connectionToastErrorDebugButton . waitForDisplayed ( ) ;
577
- await connectionToastErrorDebugButton . click ( ) ;
578
- await connectionToastErrorDebugButton . waitForDisplayed ( {
546
+ await browser . $ ( Selectors . AggregationExplainModal ) . waitForDisplayed ( {
579
547
reverse : true ,
580
548
} ) ;
549
+
550
+ await browser . $ ( Selectors . AssistantChatMessages ) . waitForDisplayed ( ) ;
581
551
}
0 commit comments