Skip to content

Commit 4d1cddc

Browse files
committed
chore: add entry points
1 parent a656e36 commit 4d1cddc

File tree

2 files changed

+180
-0
lines changed

2 files changed

+180
-0
lines changed

packages/compass-e2e-tests/helpers/selectors.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -897,6 +897,9 @@ export const AggregationSavedPipelineCardDeleteButton = (
897897
export const AggregationExplainButton =
898898
'[data-testid="pipeline-toolbar-explain-aggregation-button"]';
899899
export const AggregationExplainModal = '[data-testid="explain-plan-modal"]';
900+
export const ExplainPlanInterpretButton =
901+
'[data-testid="interpret-for-me-button"]';
902+
export const ExplainPlanCloseButton = '[data-testid="explain-close-button"]';
900903
export const AggregationExplainModalCloseButton = `${AggregationExplainModal} [aria-label*="Close"]`;
901904

902905
// Create view from pipeline modal

packages/compass-e2e-tests/tests/assistant.test.ts

Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
screenshotIfFailed,
1010
skipForWeb,
1111
TEST_COMPASS_WEB,
12+
DEFAULT_CONNECTION_NAME_1,
1213
} from '../helpers/compass';
1314
import type { Compass } from '../helpers/compass';
1415
import * as Selectors from '../helpers/selectors';
@@ -395,4 +396,180 @@ describe('MongoDB Assistant', function () {
395396
);
396397
});
397398
});
399+
400+
describe('entry points', function () {
401+
const dbName = 'test';
402+
const collectionName = 'entryPoints';
403+
before(async function () {
404+
await browser.setupDefaultConnections();
405+
await browser.connectToDefaults();
406+
await browser.selectConnectionMenuItem(
407+
DEFAULT_CONNECTION_NAME_1,
408+
Selectors.CreateDatabaseButton,
409+
false
410+
);
411+
await browser.addDatabase(dbName, collectionName);
412+
});
413+
414+
describe('explain plan entry point', function () {
415+
let useExplainPlanEntryPoint: () => Promise<void>;
416+
417+
before(async function () {
418+
await browser.navigateToCollectionTab(
419+
DEFAULT_CONNECTION_NAME_1,
420+
dbName,
421+
collectionName,
422+
'Aggregations'
423+
);
424+
await setAIOptIn(browser, true);
425+
await setAIFeatures(browser, true);
426+
427+
mockAssistantServer.setResponse({
428+
status: 200,
429+
body: 'You should create an index.',
430+
});
431+
});
432+
433+
beforeEach(function () {
434+
useExplainPlanEntryPoint = async () => {
435+
// Open explain plan modal by clicking the explain button
436+
const explainButton = browser.$(Selectors.AggregationExplainButton);
437+
await explainButton.waitForDisplayed();
438+
await explainButton.click();
439+
440+
// Wait for the explain plan modal to open and finish loading
441+
const explainModal = browser.$(Selectors.AggregationExplainModal);
442+
await explainModal.waitForDisplayed();
443+
444+
// Wait for the explain plan to be ready (loader should disappear)
445+
const explainLoader = browser.$(Selectors.ExplainLoader);
446+
await explainLoader.waitForDisplayed({
447+
reverse: true,
448+
timeout: 10000,
449+
});
450+
451+
// Click the "Interpret for me" button
452+
const interpretButton = browser.$(
453+
Selectors.ExplainPlanInterpretButton
454+
);
455+
await interpretButton.waitForDisplayed();
456+
await interpretButton.click();
457+
458+
// The modal should close
459+
await explainModal.waitForDisplayed({ reverse: true });
460+
461+
// The assistant drawer should open
462+
const assistantDrawer = browser.$(Selectors.SideDrawer);
463+
await assistantDrawer.waitForDisplayed();
464+
};
465+
});
466+
467+
it('opens assistant with explain plan prompt when clicking "Interpret for me"', async function () {
468+
await useExplainPlanEntryPoint();
469+
470+
const confirmButton = browser.$('button*=Confirm');
471+
await confirmButton.waitForDisplayed();
472+
await confirmButton.click();
473+
474+
await browser.pause(100);
475+
476+
const messages = await getDisplayedMessages();
477+
expect(messages).deep.equal([
478+
{ text: 'Interpret this explain plan output for me.', role: 'user' },
479+
{ text: 'You should create an index.', role: 'assistant' },
480+
]);
481+
482+
expect(mockAssistantServer.getRequests()).to.have.lengthOf(1);
483+
});
484+
485+
it('does not send request when user cancels confirmation', async function () {
486+
// Navigate to collection Aggregations tab
487+
await browser.navigateToCollectionTab(
488+
DEFAULT_CONNECTION_NAME_1,
489+
dbName,
490+
collectionName,
491+
'Aggregations'
492+
);
493+
494+
await useExplainPlanEntryPoint();
495+
496+
const chatMessages = browser.$(Selectors.AssistantChatMessages);
497+
await chatMessages.waitForDisplayed();
498+
expect(await chatMessages.getText()).to.include(
499+
'Please confirm your request'
500+
);
501+
502+
// Click Cancel button
503+
const cancelButton = browser.$('button*=Cancel');
504+
await cancelButton.waitForDisplayed();
505+
await cancelButton.click();
506+
507+
// Wait a bit to ensure no request is sent
508+
await browser.pause(300);
509+
510+
const finalMessages = await getDisplayedMessages();
511+
expect(finalMessages.length).to.equal(0);
512+
513+
expect(await chatMessages.getText()).to.include(
514+
'Please confirm your request'
515+
);
516+
expect(await chatMessages.getText()).to.include('Request cancelled');
517+
518+
// Verify no assistant request was made
519+
expect(mockAssistantServer.getRequests()).to.be.empty;
520+
});
521+
});
522+
523+
describe('error message view entry point', function () {
524+
let useErrorViewEntryPoint: () => Promise<void>;
525+
before(async function () {
526+
await setAIOptIn(browser, true);
527+
528+
mockAssistantServer.setResponse({
529+
status: 200,
530+
body: 'You should review the connection string.',
531+
});
532+
useErrorViewEntryPoint = async () => {
533+
const connectionToastErrorDebugButton = browser.$(
534+
Selectors.ConnectionToastErrorDebugButton
535+
);
536+
await connectionToastErrorDebugButton.waitForDisplayed();
537+
await connectionToastErrorDebugButton.click();
538+
};
539+
});
540+
541+
it('opens assistant with error message view prompt when clicking "Debug for me"', async function () {
542+
void (await browser.connectWithConnectionString(
543+
'mongodb-invalid://localhost:27017'
544+
));
545+
await useErrorViewEntryPoint();
546+
547+
const messages = await getDisplayedMessages();
548+
expect(messages).deep.equal([
549+
{
550+
text: 'Diagnose why my Compass connection is failing and help me debug it.',
551+
role: 'user',
552+
},
553+
{
554+
text: 'You should review the connection string.',
555+
role: 'assistant',
556+
},
557+
]);
558+
559+
expect(mockAssistantServer.getRequests()).to.have.lengthOf(1);
560+
});
561+
562+
it('should display opt-in modal when clicking "Debug for me" without opt-in ', async function () {
563+
await setAIOptIn(browser, false);
564+
void (await browser.connectWithConnectionString(
565+
'mongodb-invalid://localhost:27017'
566+
));
567+
await useErrorViewEntryPoint();
568+
569+
const optInModal = browser.$(Selectors.AIOptInModal);
570+
await optInModal.waitForDisplayed();
571+
expect(await optInModal.isDisplayed()).to.be.true;
572+
});
573+
});
574+
});
398575
});

0 commit comments

Comments
 (0)