|
1 | 1 | import {Organization} from '../../../src/types' |
2 | 2 |
|
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', () => { |
4 | 15 | beforeEach(() => { |
5 | 16 | cy.flush().then(() => { |
6 | 17 | cy.signin().then(() => { |
@@ -174,4 +185,155 @@ describe('FluxQueryBuilder', () => { |
174 | 185 | // numbers of API calls that are time consuming and unnecessary |
175 | 186 | }) |
176 | 187 | }) |
| 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 | + }) |
177 | 339 | }) |
0 commit comments