Skip to content

Commit efd7562

Browse files
committed
chore: fixups
1 parent 5f57459 commit efd7562

File tree

1 file changed

+89
-85
lines changed

1 file changed

+89
-85
lines changed

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

Lines changed: 89 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@ describe('MongoDB Assistant', function () {
3838
const collectionName = 'entryPoints';
3939

4040
before(async function () {
41-
skipForWeb(this, 'ai assistant not yet available in compass-web');
42-
4341
process.env.COMPASS_E2E_SKIP_ATLAS_SIGNIN = 'true';
4442

4543
// Start a mock Atlas service for feature flag checks
@@ -55,7 +53,6 @@ describe('MongoDB Assistant', function () {
5553

5654
telemetry = await startTelemetryServer();
5755
compass = await init(this.test?.fullTitle());
58-
browser = compass.browser;
5956

6057
sendMessage = async (
6158
text: string,
@@ -75,34 +72,41 @@ describe('MongoDB Assistant', function () {
7572
await submitButton.click();
7673
};
7774

75+
const setup = async () => {
76+
browser = compass.browser;
77+
await browser.setupDefaultConnections();
78+
await browser.connectToDefaults();
79+
await browser.selectConnectionMenuItem(
80+
DEFAULT_CONNECTION_NAME_1,
81+
Selectors.CreateDatabaseButton,
82+
false
83+
);
84+
await browser.addDatabase(dbName, collectionName);
85+
86+
await browser.navigateToCollectionTab(
87+
DEFAULT_CONNECTION_NAME_1,
88+
dbName,
89+
collectionName,
90+
'Aggregations'
91+
);
92+
};
93+
7894
setAIOptIn = async (newValue: boolean) => {
7995
if (
8096
(await browser.getFeature('optInGenAIFeatures')) === true &&
8197
newValue === false
8298
) {
99+
await cleanup(compass);
83100
// 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 });
101+
compass = await init(this.test?.fullTitle(), { firstRun: true });
102+
await setup();
85103
return;
86104
}
87105

88106
await browser.setFeature('optInGenAIFeatures', newValue);
89107
};
90108

91-
await browser.setupDefaultConnections();
92-
await browser.connectToDefaults();
93-
await browser.selectConnectionMenuItem(
94-
DEFAULT_CONNECTION_NAME_1,
95-
Selectors.CreateDatabaseButton,
96-
false
97-
);
98-
await browser.addDatabase(dbName, collectionName);
99-
100-
await browser.navigateToCollectionTab(
101-
DEFAULT_CONNECTION_NAME_1,
102-
dbName,
103-
collectionName,
104-
'Aggregations'
105-
);
109+
await setup();
106110
});
107111

108112
after(async function () {
@@ -164,72 +168,6 @@ describe('MongoDB Assistant', function () {
164168
});
165169
});
166170

167-
describe('before opt-in', function () {
168-
before(async function () {
169-
await setAIOptIn(false);
170-
});
171-
172-
it('does not send the message if the user declines the opt-in', async function () {
173-
await openAssistantDrawer(browser);
174-
175-
await sendMessage(testMessage);
176-
177-
const declineLink = browser.$(Selectors.AIOptInModalDeclineLink);
178-
await declineLink.waitForDisplayed();
179-
await declineLink.click();
180-
181-
const optInModal = browser.$(Selectors.AIOptInModal);
182-
await optInModal.waitForDisplayed({ reverse: true });
183-
184-
const chatInput = browser.$(Selectors.AssistantChatInputTextArea);
185-
expect(await chatInput.getValue()).not.to.equal(testMessage);
186-
187-
expect(await getDisplayedMessages(browser)).to.deep.equal([]);
188-
189-
expect(mockAssistantServer.getRequests()).to.be.empty;
190-
});
191-
192-
describe('entry points', function () {
193-
it('should display opt-in modal for connection error entry point', async function () {
194-
await browser.connectWithConnectionString(
195-
'mongodb-invalid://localhost:27017',
196-
{ connectionStatus: 'failure' }
197-
);
198-
await browser.clickVisible(
199-
browser.$(Selectors.ConnectionToastErrorDebugButton)
200-
);
201-
202-
const optInModal = browser.$(Selectors.AIOptInModal);
203-
await optInModal.waitForDisplayed();
204-
expect(await optInModal.isDisplayed()).to.be.true;
205-
206-
const declineLink = browser.$(Selectors.AIOptInModalDeclineLink);
207-
await declineLink.waitForDisplayed();
208-
await declineLink.click();
209-
210-
await optInModal.waitForDisplayed({ reverse: true });
211-
212-
expect(await getDisplayedMessages(browser)).to.deep.equal([]);
213-
});
214-
215-
it('should display opt-in modal for explain plan entry point', async function () {
216-
await useExplainPlanEntryPoint(browser);
217-
218-
const optInModal = browser.$(Selectors.AIOptInModal);
219-
await optInModal.waitForDisplayed();
220-
expect(await optInModal.isDisplayed()).to.be.true;
221-
222-
const declineLink = browser.$(Selectors.AIOptInModalDeclineLink);
223-
await declineLink.waitForDisplayed();
224-
await declineLink.click();
225-
226-
await optInModal.waitForDisplayed({ reverse: true });
227-
228-
expect(await getDisplayedMessages(browser)).to.deep.equal([]);
229-
});
230-
});
231-
});
232-
233171
describe('opting in', function () {
234172
before(async function () {
235173
await setAIOptIn(false);
@@ -465,6 +403,72 @@ describe('MongoDB Assistant', function () {
465403
});
466404
});
467405
});
406+
407+
describe('before opt-in', function () {
408+
before(async function () {
409+
await setAIOptIn(false);
410+
});
411+
412+
it('does not send the message if the user declines the opt-in', async function () {
413+
await openAssistantDrawer(browser);
414+
415+
await sendMessage(testMessage);
416+
417+
const declineLink = browser.$(Selectors.AIOptInModalDeclineLink);
418+
await declineLink.waitForDisplayed();
419+
await declineLink.click();
420+
421+
const optInModal = browser.$(Selectors.AIOptInModal);
422+
await optInModal.waitForDisplayed({ reverse: true });
423+
424+
const chatInput = browser.$(Selectors.AssistantChatInputTextArea);
425+
expect(await chatInput.getValue()).not.to.equal(testMessage);
426+
427+
expect(await getDisplayedMessages(browser)).to.deep.equal([]);
428+
429+
expect(mockAssistantServer.getRequests()).to.be.empty;
430+
});
431+
432+
describe('entry points', function () {
433+
it('should display opt-in modal for connection error entry point', async function () {
434+
await browser.connectWithConnectionString(
435+
'mongodb-invalid://localhost:27017',
436+
{ connectionStatus: 'failure' }
437+
);
438+
await browser.clickVisible(
439+
browser.$(Selectors.ConnectionToastErrorDebugButton)
440+
);
441+
442+
const optInModal = browser.$(Selectors.AIOptInModal);
443+
await optInModal.waitForDisplayed();
444+
expect(await optInModal.isDisplayed()).to.be.true;
445+
446+
const declineLink = browser.$(Selectors.AIOptInModalDeclineLink);
447+
await declineLink.waitForDisplayed();
448+
await declineLink.click();
449+
450+
await optInModal.waitForDisplayed({ reverse: true });
451+
452+
expect(await getDisplayedMessages(browser)).to.deep.equal([]);
453+
});
454+
455+
it('should display opt-in modal for explain plan entry point', async function () {
456+
await useExplainPlanEntryPoint(browser);
457+
458+
const optInModal = browser.$(Selectors.AIOptInModal);
459+
await optInModal.waitForDisplayed();
460+
expect(await optInModal.isDisplayed()).to.be.true;
461+
462+
const declineLink = browser.$(Selectors.AIOptInModalDeclineLink);
463+
await declineLink.waitForDisplayed();
464+
await declineLink.click();
465+
466+
await optInModal.waitForDisplayed({ reverse: true });
467+
468+
expect(await getDisplayedMessages(browser)).to.deep.equal([]);
469+
});
470+
});
471+
});
468472
});
469473

470474
async function setAIFeatures(browser: CompassBrowser, newValue: boolean) {

0 commit comments

Comments
 (0)