@@ -11,6 +11,7 @@ import type { Compass } from '../../helpers/compass';
1111import * as Selectors from '../../helpers/selectors' ;
1212import { createNumbersCollection } from '../../helpers/insert-data' ;
1313import { isTestingAtlasCloudSandbox } from '../../helpers/test-runner-context' ;
14+ import { switchPipelineMode } from '../../helpers/commands/switch-pipeline-mode' ;
1415
1516describe ( '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 ) ;
0 commit comments