Skip to content

Commit ace015d

Browse files
authored
feat(5591): schema composition cypress tests. (#5592)
1 parent 712a7d6 commit ace015d

File tree

4 files changed

+194
-1
lines changed

4 files changed

+194
-1
lines changed

cypress/e2e/shared/editor.test.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,33 @@ describe('Editor+LSP communication', () => {
8181

8282
runTest('time-machine--bottom')
8383
})
84+
85+
describe('in Script Editor', () => {
86+
before(() => {
87+
cy.flush()
88+
cy.signin()
89+
cy.get('@org').then(({id}: Organization) => {
90+
cy.visit(`/orgs/${id}/data-explorer`)
91+
cy.getByTestID('tree-nav').should('be.visible')
92+
cy.setFeatureFlags({
93+
newDataExplorer: true,
94+
}).then(() => {
95+
// cy.wait($time) is necessary to consistently ensure sufficient time for the feature flag override.
96+
// The flag reset happens via redux, (it's not a network request), so we can't cy.wait($intercepted_route).
97+
cy.wait(1200)
98+
cy.getByTestID('flux-query-builder-toggle').then($toggle => {
99+
cy.wrap($toggle).should('be.visible')
100+
// Switch to Flux Query Builder if not yet
101+
if (!$toggle.hasClass('active')) {
102+
// hasClass is a jQuery function
103+
$toggle.click()
104+
cy.getByTestID('flux-query-builder--menu').contains('New Script')
105+
}
106+
})
107+
})
108+
})
109+
})
110+
111+
runTest('flux-editor')
112+
})
84113
})

cypress/e2e/shared/fluxQueryBuilder.test.ts

Lines changed: 163 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
import {Organization} from '../../../src/types'
22

3-
describe('FluxQueryBuilder', () => {
3+
const DEFAULT_SCHEMA = {
4+
bucket: null,
5+
measurement: null,
6+
fields: [],
7+
tagValues: [],
8+
composition: {
9+
synced: true,
10+
diverged: false,
11+
},
12+
}
13+
14+
describe('Script Builder', () => {
415
beforeEach(() => {
516
cy.flush().then(() => {
617
cy.signin().then(() => {
@@ -174,4 +185,155 @@ describe('FluxQueryBuilder', () => {
174185
// numbers of API calls that are time consuming and unnecessary
175186
})
176187
})
188+
189+
describe('Schema Composition', () => {
190+
beforeEach(() => {
191+
window.sessionStorage.setItem(
192+
'dataExplorer.schema',
193+
JSON.parse(JSON.stringify(DEFAULT_SCHEMA))
194+
)
195+
window.sessionStorage.setItem('dataExplorer.query', '')
196+
197+
cy.setFeatureFlags({
198+
schemaComposition: true,
199+
saveAsScript: true,
200+
}).then(() => {
201+
// cy.wait($time) is necessary to consistently ensure sufficient time for the feature flag override.
202+
// The flag reset happens via redux, (it's not a network request), so we can't cy.wait($intercepted_route).
203+
cy.wait(1200).then(() => {
204+
cy.reload()
205+
cy.getByTestID('flux-sync--toggle')
206+
})
207+
})
208+
})
209+
210+
const bucketName = 'defbuck'
211+
const measurement = 'ndbc'
212+
213+
const selectSchema = () => {
214+
cy.log('select bucket')
215+
cy.getByTestID('bucket-selector--dropdown-button').click()
216+
cy.getByTestID('bucket-selector--search-bar').type(bucketName)
217+
cy.getByTestID(`bucket-selector--dropdown--${bucketName}`).click()
218+
cy.getByTestID('bucket-selector--dropdown-button').should(
219+
'contain',
220+
bucketName
221+
)
222+
223+
cy.log('select measurement')
224+
cy.getByTestID('measurement-selector--dropdown-button')
225+
.should('be.visible')
226+
.should('contain', 'Select measurement')
227+
.click()
228+
cy.getByTestID('measurement-selector--dropdown--menu').type(measurement)
229+
cy.getByTestID(`searchable-dropdown--item ${measurement}`)
230+
.should('be.visible')
231+
.click()
232+
cy.getByTestID('measurement-selector--dropdown-button').should(
233+
'contain',
234+
measurement
235+
)
236+
}
237+
238+
const confirmSchemaComposition = () => {
239+
cy.getByTestID('flux-editor', {timeout: 30000})
240+
// we set a manual delay on page load, for composition initialization
241+
// https://github.com/influxdata/ui/blob/e76f934c6af60e24c6356f4e4ce9b067e5a9d0d5/src/languageSupport/languages/flux/lsp/connection.ts#L435-L440
242+
.contains(`from(bucket: "${bucketName}")`, {timeout: 30000})
243+
cy.getByTestID('flux-editor').contains(
244+
`|> filter(fn: (r) => r._measurement == "${measurement}")`
245+
)
246+
cy.getByTestID('flux-editor').contains(
247+
`|> yield(name: "_editor_composition")`
248+
)
249+
}
250+
251+
describe('default sync and resetting behavior:', () => {
252+
it('sync defaults to on. Can be toggled on/off. And can diverge (be disabled).', () => {
253+
cy.log('starts as synced')
254+
cy.getByTestID('flux-sync--toggle').should('have.class', 'active')
255+
256+
cy.log('sync toggles on and off')
257+
cy.getByTestID('flux-sync--toggle')
258+
.should('have.class', 'active')
259+
.click()
260+
.should('not.have.class', 'active')
261+
.click()
262+
.should('have.class', 'active')
263+
264+
cy.log('can diverge from sync')
265+
selectSchema()
266+
confirmSchemaComposition()
267+
cy.getByTestID('flux-editor').monacoType(
268+
'{upArrow}{upArrow} // make diverge'
269+
)
270+
271+
cy.log('toggle is now disabled')
272+
cy.getByTestID('flux-sync--toggle').should('have.class', 'disabled')
273+
})
274+
275+
it('should clear the editor text, and schema browser, with a new script', () => {
276+
cy.getByTestID('flux-editor', {timeout: 30000})
277+
278+
cy.log('modify schema browser')
279+
selectSchema()
280+
281+
cy.log('editor text contains the composition')
282+
cy.getByTestID('flux-editor').contains(
283+
`|> yield(name: "_editor_composition")`
284+
)
285+
286+
cy.log('click new script, and choose to delete current script')
287+
cy.getByTestID('flux-query-builder--new-script').click({force: true})
288+
cy.getByTestID('overlay--container')
289+
.should('be.visible')
290+
.within(() => {
291+
cy.getByTestID('flux-query-builder--no-save').click()
292+
})
293+
294+
cy.log('editor text is now empty')
295+
cy.getByTestID('flux-editor').within(() => {
296+
cy.get('textarea.inputarea').should('have.value', '')
297+
})
298+
299+
cy.log('schema browser has been cleared')
300+
cy.getByTestID('bucket-selector--dropdown-button').contains(
301+
'Select bucket'
302+
)
303+
})
304+
305+
it('should not be able to modify the composition when unsynced, yet still modify the saved schema -- which updates the composition when re-synced', () => {
306+
cy.log('start with empty editor text')
307+
cy.getByTestID('flux-editor', {timeout: 30000}).within(() => {
308+
cy.get('textarea.inputarea').should('have.value', '')
309+
})
310+
311+
cy.log('turn off sync')
312+
cy.getByTestID('flux-sync--toggle')
313+
.should('have.class', 'active')
314+
.click()
315+
cy.getByTestID('flux-sync--toggle').should('not.have.class', 'active')
316+
317+
cy.log('modify schema browser')
318+
selectSchema()
319+
320+
cy.log('editor text is still empty')
321+
cy.getByTestID('flux-editor').within(() => {
322+
cy.get('textarea.inputarea').should('have.value', '')
323+
})
324+
325+
cy.log('turn on sync')
326+
cy.getByTestID('flux-sync--toggle')
327+
.should('not.have.class', 'active')
328+
.click()
329+
cy.getByTestID('flux-sync--toggle').should('have.class', 'active')
330+
331+
cy.log('editor text contains the composition')
332+
// we set a manual delay for composition initialization
333+
// https://github.com/influxdata/ui/blob/e76f934c6af60e24c6356f4e4ce9b067e5a9d0d5/src/languageSupport/languages/flux/lsp/connection.ts#L435-L440
334+
cy.wait(3000)
335+
confirmSchemaComposition()
336+
})
337+
})
338+
})
177339
})

src/dataExplorer/components/FluxQueryBuilder.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ const FluxQueryBuilder: FC = () => {
134134
? ComponentStatus.Disabled
135135
: ComponentStatus.Default
136136
}
137+
testID="flux-query-builder--new-script"
137138
/>
138139
{isFlagEnabled('saveAsScript') && (
139140
<Button

src/dataExplorer/components/SaveAsScript.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ const SaveAsScript: FC<Props> = ({onClose, type}) => {
187187
color={ComponentColor.Default}
188188
onClick={clear}
189189
text="No, Delete"
190+
testID="flux-query-builder--no-save"
190191
/>
191192
)}
192193
{CLOUD && (

0 commit comments

Comments
 (0)