-
Notifications
You must be signed in to change notification settings - Fork 50
Expand file tree
/
Copy pathvariables.cy.ts
More file actions
414 lines (310 loc) · 14.8 KB
/
variables.cy.ts
File metadata and controls
414 lines (310 loc) · 14.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
import {Organization} from '../../../src/types'
describe('Variables', () => {
beforeEach(() => {
cy.flush()
cy.signin()
cy.get('@org').then(({id}: Organization) => {
cy.createQueryVariable(id)
cy.visit(`orgs/${id}/settings/variables`)
cy.getByTestID('tree-nav')
})
// Double check that the new schemaComposition flag does not interfere.
cy.setFeatureFlags({
schemaComposition: true,
})
// cy.wait($time) is necessary to consistently ensure sufficient time for the feature flag override.
// The flag reset happens via redux, (it's not a network request), so we can't cy.wait($intercepted_route).
cy.wait(1200)
cy.location('pathname').should('match', /\/variables$/)
})
it('can CRUD a CSV, upload, map, and query variable and search for variables based on names', () => {
// Navigate away from and back to variables index using the nav bar
cy.clickNavBarItem('nav-item-dashboards')
cy.clickNavBarItem('nav-item-settings')
cy.getByTestID('templates--tab').click()
cy.getByTestID('variables--tab').click()
cy.getByTestID('resource-card variable').should('have.length', 1)
// ensure that the default variables are not accessible on the Variables Tab
cy.getByTestID('resource-card variable').should(
'not.contain',
'timeRangeStart'
)
cy.getByTestID('resource-card variable').should(
'not.contain',
'timeRangeStop'
)
cy.getByTestID('resource-card variable').should(
'not.contain',
'windowPeriod'
)
cy.getByTestID('add-resource-dropdown--button').click()
cy.getByTestID('add-resource-dropdown--new').click()
cy.getByTestID('variable-type-dropdown--button').click()
cy.getByTestID('variable-type-dropdown-constant').click()
// Create a CSV variable
const variableName = 'AnotherVariable'
cy.getByInputName('name').type(variableName)
cy.get('textarea').type('1,2,3,4,5,6')
cy.getByTestID('csv-value-select-dropdown').click().contains('6').click()
cy.get('form').contains('Create').click()
cy.getByTestID(`variable-card--name ${variableName}`).click()
cy.getByTestID('notification-success--dismiss').should('exist')
cy.getByTestID('notification-success--dismiss').click()
// Change it to a Query variable
cy.getByTestID('edit-variable--overlay').within(() => {
cy.getByTestID('variable-type-dropdown--button').click()
cy.getByTestID('variable-type-dropdown-query').click()
cy.getByTestID('flux-editor').monacoType(
'filter(fn: (r) => r._field == "cpu")'
)
cy.getByTestID('variable-update-submit--button')
.contains('Submit')
.click()
})
cy.getByTestID('notification-success--dismiss').should('exist')
cy.getByTestID('notification-success--dismiss').click()
cy.getByTestID(`variable-card--name ${variableName}`).click()
// Change it to a Map variable
cy.getByTestID('edit-variable--overlay').within(() => {
cy.getByTestID('variable-type-dropdown--button').click()
cy.getByTestID('variable-type-dropdown-map').click()
const lastMapItem = 'Mila Emile,"o61AhpOGr5aO3cYVArC0"'
cy.get('textarea').type(`Juanito MacNeil,"5TKl6l8i4idg15Fxxe4P"
Astrophel Chaudhary,"bDhZbuVj5RV94NcFXZPm"
Ochieng Benes,"YIhg6SoMKRUH8FMlHs3V"
${lastMapItem}`)
cy.getByTestID('map-variable-dropdown--button').click()
cy.contains(lastMapItem).click()
cy.getByTestID('variable-update-submit--button')
.contains('Submit')
.click()
})
cy.getByTestID('notification-success--dismiss').should('exist')
cy.getByTestID('notification-success--dismiss').click()
cy.getByTestID('resource-card variable').should('have.length', 2)
// Search variable by name
cy.getByTestID('search-widget').type(variableName)
cy.getByTestID('resource-card variable')
.should('have.length', 1)
.contains(variableName)
// Delete a variable
cy.getByTestID(`context-delete-variable ${variableName}--button`)
.first()
.click()
cy.getByTestID(`context-delete-variable ${variableName}--confirm-button`)
.first()
.click()
cy.getByTestID('notification-success--dismiss').should('exist')
cy.getByTestID('notification-success--dismiss').click()
cy.getByTestID('search-widget').clear()
cy.getByTestID('resource-card variable')
.should('have.length', 1)
.contains('LittleVariable')
// Rename the variable
cy.getByTestID('context-menu-variable').last().click({force: true})
cy.getByTestID('context-rename-variable').click({force: true})
cy.getByTestID('danger-confirmation--button').click()
cy.getByInputName('name').type('Renamed')
cy.getByTestID('rename-variable-submit').click()
cy.getByTestID('notification-success--dismiss').should('exist')
cy.getByTestID('notification-success--dismiss').click()
cy.getByTestID(`variable-card--name LittleVariableRenamed`).contains(
'Renamed'
)
// Create a Map variable from scratch
cy.getByTestID('add-resource-dropdown--button').click()
cy.getByTestID('add-resource-dropdown--new').click()
cy.getByTestID('variable-type-dropdown--button').click()
cy.getByTestID('variable-type-dropdown-map').click()
const mapVariableName = 'MapVariable'
cy.getByInputName('name').type(mapVariableName)
cy.get('textarea').type(`Astrophel Chaudhary,"bDhZbuVj5RV94NcFXZPm"
Ochieng Benes,"YIhg6SoMKRUH8FMlHs3V"`)
cy.getByTestID('map-variable-dropdown--button').click().last().click()
cy.get('form').contains('Create').click()
cy.getByTestID('notification-success--dismiss').should('exist')
cy.getByTestID('notification-success--dismiss').click()
cy.getByTestID(`variable-card--name ${mapVariableName}`).should('exist')
// Create a Query variable from scratch
cy.getByTestID('add-resource-dropdown--button').click()
cy.getByTestID('add-resource-dropdown--new').click()
cy.getByTestID('variable-type-dropdown--button').click()
cy.getByTestID('variable-type-dropdown-map').click()
const queryVariableName = 'QueryVariable'
cy.getByInputName('name').type(queryVariableName)
cy.getByTestID('variable-type-dropdown--button').click()
cy.getByTestID('variable-type-dropdown-query').click()
cy.getByTestID('flux-editor').monacoType(
'filter(fn: (r) => r._field == "cpu")'
)
cy.get('form').contains('Create').click()
cy.getByTestID('notification-success--dismiss').should('exist')
cy.getByTestID('notification-success--dismiss').click()
cy.getByTestID(`variable-card--name ${queryVariableName}`).contains(
queryVariableName
)
})
it('can prevent variable names with hyphens or spaces from being saved', () => {
// Prevent creation of a CSV variable with hyphens or spaces
cy.getByTestID('add-resource-dropdown--button').should('be.visible')
cy.getByTestID('add-resource-dropdown--button').click()
cy.getByTestID('add-resource-dropdown--new').should('be.visible')
cy.getByTestID('add-resource-dropdown--new').click()
cy.getByTestID('variable-type-dropdown--button').should('be.visible')
cy.getByTestID('variable-type-dropdown--button').click()
cy.getByTestID('variable-type-dropdown--button').should('be.visible')
cy.getByTestID('variable-type-dropdown-constant').click()
cy.get('textarea').type('1,2,3,4,5,6')
cy.getByTestID('csv-value-select-dropdown').click().contains('6').click()
cy.getByInputName('name').type('bad name')
cy.getByTestID('variable-form-save').should('be.disabled')
cy.getByInputName('name').clear().type('bad-name')
cy.getByTestID('variable-form-save').should('be.disabled')
// Prevent creation of a Query variable with hyphens or spaces
cy.getByTestID('variable-type-dropdown--button').click()
cy.getByTestID('variable-type-dropdown-query').click()
cy.getByTestID('flux-editor').monacoType(
'filter(fn: (r) => r._field == "cpu")'
)
cy.getByInputName('name').clear().type('bad name')
cy.getByTestID('variable-form-save').should('be.disabled')
cy.getByInputName('name').clear().type('bad-name')
cy.getByTestID('variable-form-save').should('be.disabled')
// Prevent creation of a Map variable with hyphens or spaces
cy.getByTestID('variable-type-dropdown--button').click()
cy.getByTestID('variable-type-dropdown-map').click()
const lastMapItem = 'Mila Emile,"o61AhpOGr5aO3cYVArC0"'
cy.get('textarea').type(`Juanito MacNeil,"5TKl6l8i4idg15Fxxe4P"
Astrophel Chaudhary,"bDhZbuVj5RV94NcFXZPm"
Ochieng Benes,"YIhg6SoMKRUH8FMlHs3V"
${lastMapItem}`)
cy.getByTestID('map-variable-dropdown--button').click()
cy.contains(lastMapItem).click()
cy.getByInputName('name').clear().type('bad name')
cy.getByTestID('variable-form-save').should('be.disabled')
cy.getByInputName('name').clear().type('bad-name')
cy.getByTestID('variable-form-save').should('be.disabled')
})
it('can create and delete a label and sort by variable name', () => {
cy.getByTestID('inline-labels--add').should('be.visible')
// Create a label for the existing variable
const labelName = 'label'
cy.getByTestID('inline-labels--add').clickAttached()
cy.getByTestID('inline-labels--popover--contents').type(labelName)
cy.getByTestID('inline-labels--create-new').click()
cy.getByTestID('create-label-form--submit')
.scrollIntoView()
.should('be.visible')
cy.getByTestID('create-label-form--submit').click()
cy.getByTestID('overlay--children').should('not.exist')
// Create a CSV variable
const variableName = 'SecondVariable'
cy.getByTestID('add-resource-dropdown--button').should('be.visible')
cy.getByTestID('add-resource-dropdown--button').click()
cy.getByTestID('add-resource-dropdown--new').should('be.visible')
cy.getByTestID('add-resource-dropdown--new').click()
cy.getByTestID('variable-type-dropdown--button').should('be.visible')
cy.getByTestID('variable-type-dropdown--button').click()
cy.getByTestID('variable-type-dropdown--button').should('be.visible')
cy.getByTestID('variable-type-dropdown-constant').click()
cy.getByInputName('name').type(variableName)
cy.get('textarea').type('1,2,3,4,5,6')
cy.getByTestID('csv-value-select-dropdown').click().contains('6').click()
cy.get('form').contains('Create').click()
// Delete the label
cy.getByTestID(`label--pill--delete ${labelName}`).click({force: true})
cy.getByTestID('resource-card variable').should('have.length', 2)
cy.getByTestID('search-widget').clear()
cy.getByTestID('inline-labels--empty').should('exist')
cy.getByTestID('resource-card variable').last().contains(variableName)
cy.getByTestID('resource-sorter--button').click()
cy.getByTestID('resource-sorter--name-desc').click()
cy.getByTestID('resource-card variable').first().contains(variableName)
})
it('can filter by variable or label name', () => {
const firstVariableName = 'LittleVariable'
cy.getByTestID('resource-card variable')
.should('have.length', 1)
.contains(firstVariableName)
// Create a Query variable from scratch
const secondVariableName = 'SecondVariable'
cy.getByTestID('add-resource-dropdown--button').click()
cy.getByTestID('add-resource-dropdown--new').click()
cy.getByTestID('variable-type-dropdown--button').click()
cy.getByTestID('variable-type-dropdown-query').click()
cy.getByTestID('flux-editor').monacoType(
'filter(fn: (r) => r._field == "cpu")'
)
cy.getByInputName('name').type(secondVariableName)
cy.get('form').contains('Create').click()
// Create a CSV variable
const thirdVariableName = 'ThirdVariable'
cy.getByTestID('add-resource-dropdown--button').click()
cy.getByTestID('add-resource-dropdown--new').click()
cy.getByTestID('variable-type-dropdown--button').click()
cy.getByTestID('variable-type-dropdown-constant').click()
cy.getByInputName('name').type(thirdVariableName)
cy.get('textarea').type('1,2,3,4,5,6')
cy.getByTestID('csv-value-select-dropdown').click().contains('6').click()
cy.get('form').contains('Create').click()
// Ensure we have three variables and three buttons to add labels
cy.getByTestID('resource-card variable').should('have.length', 3)
cy.get('button.inline-labels--add').should('have.length', 3)
// Create the labels
const firstLabelName = 'little'
cy.get('button.inline-labels--add').first().clickAttached()
cy.getByTestID('inline-labels--popover-field').type(firstLabelName)
cy.getByTestID('inline-labels--create-new').click()
cy.getByTestID('create-label-form--submit')
.scrollIntoView()
.should('be.visible')
cy.getByTestID('create-label-form--submit').click()
const secondLabelName = 'query'
cy.get('button.inline-labels--add').eq(1).clickAttached()
cy.getByTestID('inline-labels--popover-field').type(secondLabelName)
cy.getByTestID('inline-labels--create-new').click()
cy.getByTestID('create-label-form--submit')
.scrollIntoView()
.should('be.visible')
cy.getByTestID('create-label-form--submit').click()
const thirdLabelName = 'csv'
cy.get('button.inline-labels--add').last().clickAttached()
cy.getByTestID('inline-labels--popover-field').type(thirdLabelName)
cy.getByTestID('inline-labels--create-new').click()
cy.getByTestID('create-label-form--submit')
.scrollIntoView()
.should('be.visible')
cy.getByTestID('create-label-form--submit').click()
// Select ascending order and use filter on variable name
cy.getByTestID('resource-sorter--button').click()
cy.getByTestID('resource-sorter--name-asc').click()
cy.getByTestID('search-widget').type(firstVariableName)
cy.getByTestID('resource-card variable')
.should('have.length', 1)
.contains(firstVariableName)
cy.getByTestID('search-widget').clear().type(secondVariableName)
cy.getByTestID('resource-card variable')
.should('have.length', 1)
.contains(secondVariableName)
cy.getByTestID('search-widget').clear().type(thirdVariableName)
cy.getByTestID('resource-card variable')
.should('have.length', 1)
.contains(thirdVariableName)
// Select descending order and use filter on label name
cy.getByTestID('search-widget').clear()
cy.getByTestID('resource-sorter--button').click()
cy.getByTestID('resource-sorter--name-desc').click()
cy.getByTestID('search-widget').type(firstLabelName)
cy.getByTestID('resource-card variable')
.should('have.length', 1)
.contains(firstVariableName)
cy.getByTestID('search-widget').clear().type(secondLabelName)
cy.getByTestID('resource-card variable')
.should('have.length', 1)
.contains(secondVariableName)
cy.getByTestID('search-widget').clear().type(thirdLabelName)
cy.getByTestID('resource-card variable')
.should('have.length', 1)
.contains(thirdVariableName)
})
})