Skip to content

Commit d0ba6c7

Browse files
committed
fixup: add aggregation test, use sandbox preference update provider
1 parent f68573f commit d0ba6c7

File tree

13 files changed

+301
-174
lines changed

13 files changed

+301
-174
lines changed

packages/compass-e2e-tests/helpers/commands/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ export * from './unhide-index';
6262
export * from './hide-visible-modal';
6363
export * from './hide-visible-toasts';
6464
export * from './sidebar-collection';
65+
export * from './switch-pipeline-mode';
6566
export * from './read-first-document-content';
6667
export * from './read-stage-operators';
6768
export * from './click-confirmation-action';

packages/compass-e2e-tests/helpers/commands/set-feature.ts

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,32 @@ import type {
33
AllPreferences,
44
UserPreferences,
55
} from 'compass-preferences-model';
6+
import { isTestingWeb } from '../test-runner-context';
67

78
export async function setFeature<K extends keyof UserPreferences>(
89
browser: CompassBrowser,
910
name: K,
1011
value: UserPreferences[K]
1112
): Promise<void> {
13+
if (isTestingWeb()) {
14+
// When running in Compass web we cannot use the IPC to update the
15+
// preferences so we use a global function.
16+
await browser.execute(
17+
async (_name, _value) => {
18+
const attributes: Partial<AllPreferences> = {
19+
[_name]: _value === null ? undefined : _value,
20+
};
21+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
22+
await (globalThis as any).__compassWebE2ETestSavePreferences(
23+
attributes
24+
);
25+
},
26+
name,
27+
value
28+
);
29+
return;
30+
}
31+
1232
await browser.execute(
1333
async (_name, _value) => {
1434
// eslint-disable-next-line @typescript-eslint/no-var-requires
@@ -20,23 +40,3 @@ export async function setFeature<K extends keyof UserPreferences>(
2040
value
2141
);
2242
}
23-
24-
// When running in Compass web we cannot use the IPC to update the
25-
// preferences so we use a global function.
26-
export async function setFeatureCompassWeb<K extends keyof UserPreferences>(
27-
browser: CompassBrowser,
28-
name: K,
29-
value: UserPreferences[K]
30-
): Promise<void> {
31-
await browser.execute(
32-
async (_name, _value) => {
33-
const attributes: Partial<AllPreferences> = {
34-
[_name]: _value === null ? undefined : _value,
35-
};
36-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
37-
await (globalThis as any).__compassWebE2ETestSavePreferences(attributes);
38-
},
39-
name,
40-
value
41-
);
42-
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import type { CompassBrowser } from '../compass-browser';
2+
import * as Selectors from '../selectors';
3+
4+
export async function switchPipelineMode(
5+
browser: CompassBrowser,
6+
mode: 'as-text' | 'builder-ui'
7+
): Promise<void> {
8+
await browser.clickVisible(Selectors.aggregationPipelineModeToggle(mode));
9+
await browser.waitForAnimations(Selectors.AggregationBuilderWorkspace);
10+
}

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1239,12 +1239,11 @@ export const queryBarExportToLanguageButton = (tabName: string): string => {
12391239
const tabSelector = collectionContent(tabName);
12401240
return `${tabSelector} [data-testid="query-bar-open-export-to-language-button"]`;
12411241
};
1242-
export const QueryBarAIEntryButton =
1243-
'[data-testid="open-ai-query-entry-button"]';
1244-
export const QueryBarAITextInput = '[data-testid="ai-user-text-input"]';
1245-
export const QueryBarAIGenerateQueryButton =
1246-
'[data-testid="ai-generate-button"]';
1247-
export const QueryBarAIErrorMessageBanner = '[data-testid="ai-error-msg"]';
1242+
export const GenAIEntryButton = '[data-testid="open-ai-query-entry-button"]';
1243+
export const GenAITextInput = '[data-testid="ai-user-text-input"]';
1244+
export const GenAIGenerateQueryButton = '[data-testid="ai-generate-button"]';
1245+
export const GenAIErrorMessageBanner = '[data-testid="ai-error-msg"]';
1246+
export const GenAIOpenButton = '[data-testid="open-gen-ai-button"]';
12481247

12491248
// Workspace tabs
12501249
export const WorkspaceTabsContainer =

packages/compass-e2e-tests/tests/atlas-cloud/collection-ai-query.test.ts

Lines changed: 94 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import type { Compass } from '../../helpers/compass';
1111
import * as Selectors from '../../helpers/selectors';
1212
import { createNumbersCollection } from '../../helpers/insert-data';
1313
import { isTestingAtlasCloudSandbox } from '../../helpers/test-runner-context';
14+
import { switchPipelineMode } from '../../helpers/commands/switch-pipeline-mode';
1415

1516
describe('Collection ai query', function () {
1617
let compass: Compass;
@@ -42,53 +43,106 @@ describe('Collection ai query', function () {
4243
'Documents'
4344
);
4445

45-
await browser.setFeatureCompassWeb(
46-
'enableGenAIFeaturesAtlasProject',
47-
true
48-
);
49-
await browser.setFeatureCompassWeb(
46+
await browser.setFeature('enableGenAIFeaturesAtlasProject', true);
47+
await browser.setFeature(
5048
'enableGenAISampleDocumentPassingOnAtlasProject',
5149
true
5250
);
53-
await browser.setFeatureCompassWeb('enableGenAIFeaturesAtlasOrg', true);
54-
await browser.setFeatureCompassWeb(
55-
'optInDataExplorerGenAIFeatures',
56-
true
57-
);
51+
await browser.setFeature('enableGenAIFeaturesAtlasOrg', true);
52+
await browser.setFeature('optInDataExplorerGenAIFeatures', true);
5853
});
5954

60-
it('should update the query bar with a generated query', async function () {
61-
// Click the ai entry button.
62-
await browser.clickVisible(Selectors.QueryBarAIEntryButton);
55+
describe('on the documents tab', function () {
56+
beforeEach(async function () {
57+
await browser.navigateToCollectionTab(
58+
DEFAULT_CONNECTION_NAME_1,
59+
'test',
60+
'numbers',
61+
'Documents'
62+
);
63+
});
64+
65+
it('should update the query bar with a generated query', async function () {
66+
// Click the ai entry button.
67+
await browser.clickVisible(Selectors.GenAIEntryButton);
68+
69+
// Enter the ai prompt.
70+
await browser.clickVisible(Selectors.GenAITextInput);
71+
72+
const testUserInput = 'find all documents where i is greater than 50';
73+
await browser.setValueVisible(Selectors.GenAITextInput, testUserInput);
74+
75+
// Click generate.
76+
await browser.clickVisible(Selectors.GenAIGenerateQueryButton);
77+
78+
// Wait for the ipc events to succeed.
79+
await browser.waitUntil(async function () {
80+
// Make sure the query bar was updated.
81+
const queryBarFilterContent = await browser.getCodemirrorEditorText(
82+
Selectors.queryBarOptionInputFilter('Documents')
83+
);
84+
return (
85+
queryBarFilterContent.includes('$gt') &&
86+
queryBarFilterContent.includes('50')
87+
);
88+
});
89+
90+
// Run it and check that the correct documents are shown.
91+
await browser.runFind('Documents', true);
92+
const modifiedResult = await browser.getFirstListDocument();
93+
expect(modifiedResult.i).to.be.equal('51');
94+
});
95+
});
6396

64-
// Enter the ai prompt.
65-
await browser.clickVisible(Selectors.QueryBarAITextInput);
97+
describe('on the aggregations tab', function () {
98+
beforeEach(async function () {
99+
await browser.navigateToCollectionTab(
100+
DEFAULT_CONNECTION_NAME_1,
101+
'test',
102+
'numbers',
103+
'Aggregations'
104+
);
66105

67-
const testUserInput = 'find all documents where i is greater than 50';
68-
await browser.setValueVisible(
69-
Selectors.QueryBarAITextInput,
70-
testUserInput
71-
);
106+
await switchPipelineMode(browser, 'as-text');
107+
});
72108

73-
// Click generate.
74-
await browser.clickVisible(Selectors.QueryBarAIGenerateQueryButton);
109+
it('should update the aggregation editor with a generated aggregation', async function () {
110+
// Click the ai entry button.
111+
await browser.clickVisible(Selectors.GenAIOpenButton);
75112

76-
// Wait for the ipc events to succeed.
77-
await browser.waitUntil(async function () {
78-
// Make sure the query bar was updated.
79-
const queryBarFilterContent = await browser.getCodemirrorEditorText(
80-
Selectors.queryBarOptionInputFilter('Documents')
113+
// Enter the ai prompt.
114+
await browser.clickVisible(Selectors.GenAITextInput);
115+
116+
const testUserInput = 'find all documents where i is 99';
117+
await browser.setValueVisible(Selectors.GenAITextInput, testUserInput);
118+
119+
// Click generate.
120+
await browser.clickVisible(Selectors.GenAIGenerateQueryButton);
121+
122+
// Wait for the ipc events to succeed.
123+
await browser.waitUntil(async function () {
124+
const textContent = browser.$(Selectors.AggregationAsTextEditor);
125+
expect(await textContent.getText()).to.contain('$match');
126+
});
127+
128+
// Run it and check that the correct documents are shown.
129+
await browser.clickVisible(Selectors.RunPipelineButton);
130+
const resultsWorkspace = browser.$(
131+
Selectors.AggregationResultsWorkspace
81132
);
82-
return (
83-
queryBarFilterContent.includes('$gt') &&
84-
queryBarFilterContent.includes('50')
133+
await resultsWorkspace.waitForDisplayed();
134+
135+
await browser.clickVisible(
136+
Selectors.AggregationResultsJSONListSwitchButton
137+
);
138+
const documents = await browser.getCodemirrorEditorTextAll(
139+
Selectors.DocumentJSONEntry
85140
);
86-
});
87141

88-
// Run it and check that the correct documents are shown.
89-
await browser.runFind('Documents', true);
90-
const modifiedResult = await browser.getFirstListDocument();
91-
expect(modifiedResult.i).to.be.equal('51');
142+
expect(documents).to.have.lengthOf(1);
143+
expect(documents[0]).to.have.property('_id');
144+
expect(documents[0]).to.have.property('i', 99);
145+
});
92146
});
93147
});
94148

@@ -107,19 +161,13 @@ describe('Collection ai query', function () {
107161
'Documents'
108162
);
109163

110-
await browser.setFeatureCompassWeb(
111-
'enableGenAIFeaturesAtlasProject',
112-
true
113-
);
114-
await browser.setFeatureCompassWeb(
164+
await browser.setFeature('enableGenAIFeaturesAtlasProject', true);
165+
await browser.setFeature(
115166
'enableGenAISampleDocumentPassingOnAtlasProject',
116167
true
117168
);
118-
await browser.setFeatureCompassWeb('enableGenAIFeaturesAtlasOrg', true);
119-
await browser.setFeatureCompassWeb(
120-
'optInDataExplorerGenAIFeatures',
121-
false
122-
);
169+
await browser.setFeature('enableGenAIFeaturesAtlasOrg', false);
170+
await browser.setFeature('optInDataExplorerGenAIFeatures', true);
123171
});
124172

125173
it('should not show the gen ai intro button', async function () {
@@ -128,7 +176,7 @@ describe('Collection ai query', function () {
128176
.$(Selectors.queryBarOptionInputFilter('Documents'))
129177
.waitForDisplayed();
130178

131-
const aiIntroButton = browser.$(Selectors.QueryBarAIEntryButton);
179+
const aiIntroButton = browser.$(Selectors.GenAIEntryButton);
132180
const isSidebarCreateCollectionButtonExisting =
133181
await aiIntroButton.isExisting();
134182
expect(isSidebarCreateCollectionButtonExisting).to.be.equal(false);

packages/compass-e2e-tests/tests/atlas-login.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ describe('Atlas Login', function () {
295295
// control over it
296296
await browser.clickVisible('span=Not now');
297297

298-
const aiInput = browser.$(Selectors.QueryBarAITextInput);
298+
const aiInput = browser.$(Selectors.GenAITextInput);
299299
expect(await aiInput.isExisting()).to.eq(false);
300300
expect(await generateQueryButton.isDisplayed()).to.eq(true);
301301
});
@@ -328,7 +328,7 @@ describe('Atlas Login', function () {
328328
// control over it
329329
await browser.clickVisible('span=Not now');
330330

331-
const aiInput = browser.$(Selectors.QueryBarAITextInput);
331+
const aiInput = browser.$(Selectors.GenAITextInput);
332332
expect(await aiInput.isExisting()).to.eq(false);
333333
expect(await generateQueryButton.isDisplayed()).to.eq(true);
334334
});

packages/compass-e2e-tests/tests/collection-aggregations-tab.test.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
import { saveAggregationPipeline } from '../helpers/commands/save-aggregation-pipeline';
2020
import { Key } from 'webdriverio';
2121
import type { ChainablePromiseElement } from 'webdriverio';
22+
import { switchPipelineMode } from '../helpers/commands/switch-pipeline-mode';
2223

2324
const { expect } = chai;
2425

@@ -83,14 +84,6 @@ async function waitForTab(browser: CompassBrowser, namespace: string) {
8384
);
8485
}
8586

86-
async function switchPipelineMode(
87-
browser: CompassBrowser,
88-
mode: 'as-text' | 'builder-ui'
89-
) {
90-
await browser.clickVisible(Selectors.aggregationPipelineModeToggle(mode));
91-
await browser.waitForAnimations(Selectors.AggregationBuilderWorkspace);
92-
}
93-
9487
async function deleteStage(
9588
browser: CompassBrowser,
9689
index: number

packages/compass-e2e-tests/tests/collection-ai-query.test.ts

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -99,19 +99,16 @@ describe('Collection ai query', function () {
9999

100100
it('makes request to the server and updates the query bar with the response', async function () {
101101
// Click the ai entry button.
102-
await browser.clickVisible(Selectors.QueryBarAIEntryButton);
102+
await browser.clickVisible(Selectors.GenAIEntryButton);
103103

104104
// Enter the ai prompt.
105-
await browser.clickVisible(Selectors.QueryBarAITextInput);
105+
await browser.clickVisible(Selectors.GenAITextInput);
106106

107107
const testUserInput = 'find all documents where i is greater than 50';
108-
await browser.setValueVisible(
109-
Selectors.QueryBarAITextInput,
110-
testUserInput
111-
);
108+
await browser.setValueVisible(Selectors.GenAITextInput, testUserInput);
112109

113110
// Click generate.
114-
await browser.clickVisible(Selectors.QueryBarAIGenerateQueryButton);
111+
await browser.clickVisible(Selectors.GenAIGenerateQueryButton);
115112

116113
// Wait for the ipc events to succeed.
117114
await browser.waitUntil(async function () {
@@ -161,22 +158,19 @@ describe('Collection ai query', function () {
161158

162159
it('the error is shown to the user', async function () {
163160
// Click the ai entry button.
164-
await browser.clickVisible(Selectors.QueryBarAIEntryButton);
161+
await browser.clickVisible(Selectors.GenAIEntryButton);
165162

166163
// Enter the ai prompt.
167-
await browser.clickVisible(Selectors.QueryBarAITextInput);
164+
await browser.clickVisible(Selectors.GenAITextInput);
168165

169166
const testUserInput = 'find all documents where i is greater than 50';
170-
await browser.setValueVisible(
171-
Selectors.QueryBarAITextInput,
172-
testUserInput
173-
);
167+
await browser.setValueVisible(Selectors.GenAITextInput, testUserInput);
174168

175169
// Click generate.
176-
await browser.clickVisible(Selectors.QueryBarAIGenerateQueryButton);
170+
await browser.clickVisible(Selectors.GenAIGenerateQueryButton);
177171

178172
// Check that the error is shown.
179-
const errorBanner = browser.$(Selectors.QueryBarAIErrorMessageBanner);
173+
const errorBanner = browser.$(Selectors.GenAIErrorMessageBanner);
180174
await errorBanner.waitForDisplayed();
181175
expect(await errorBanner.getText()).to.equal(
182176
'Sorry, we were unable to generate the query, please try again. If the error persists, try changing your prompt.'

packages/compass-generative-ai/src/components/ai-experience-entry.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ const aiEntryLightModeStyles = css(
8686
);
8787

8888
function AIExperienceEntry({
89-
'data-testid': dataTestId,
89+
'data-testid': dataTestId = 'open-gen-ai-button',
9090
type,
9191
onClick,
9292
}: {

0 commit comments

Comments
 (0)