-
Notifications
You must be signed in to change notification settings - Fork 8.3k
/
Copy pathlens_page.ts
1362 lines (1222 loc) · 47.6 KB
/
lens_page.ts
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
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import expect from '@kbn/expect';
import { setTimeout as setTimeoutAsync } from 'timers/promises';
import { FtrProviderContext } from '../ftr_provider_context';
import { logWrapper } from './log_wrapper';
export function LensPageProvider({ getService, getPageObjects }: FtrProviderContext) {
const log = getService('log');
const testSubjects = getService('testSubjects');
const retry = getService('retry');
const elasticChart = getService('elasticChart');
const find = getService('find');
const comboBox = getService('comboBox');
const browser = getService('browser');
const dashboardAddPanel = getService('dashboardAddPanel');
const PageObjects = getPageObjects([
'common',
'header',
'timePicker',
'common',
'visualize',
'dashboard',
'timeToVisualize',
]);
return logWrapper('lensPage', log, {
/**
* Clicks the index pattern filters toggle.
*/
async toggleIndexPatternFiltersPopover() {
await testSubjects.click('lnsIndexPatternFiltersToggle');
},
async findAllFields() {
const fields = await testSubjects.findAll('lnsFieldListPanelField');
return await Promise.all(fields.map((field) => field.getVisibleText()));
},
async isLensPageOrFail() {
return await testSubjects.existOrFail('lnsApp', { timeout: 1000 });
},
/**
* Move the date filter to the specified time range, defaults to
* a range that has data in our dataset.
*/
async goToTimeRange(fromTime?: string, toTime?: string) {
await PageObjects.timePicker.ensureHiddenNoDataPopover();
fromTime = fromTime || PageObjects.timePicker.defaultStartTime;
toTime = toTime || PageObjects.timePicker.defaultEndTime;
await PageObjects.timePicker.setAbsoluteRange(fromTime, toTime);
},
/**
* Wait for the specified element to have text that passes the specified test.
*
* @param selector - the element selector
* @param test - the test function to run on the element's text
*/
async assertExpectedText(selector: string, test: (value?: string) => boolean) {
let actualText: string | undefined;
await retry.waitForWithTimeout('assertExpectedText', 1000, async () => {
actualText = await find.byCssSelector(selector).then((el) => el.getVisibleText());
return test(actualText);
});
if (!test(actualText)) {
throw new Error(`"${actualText}" did not match expectation.`);
}
},
/**
* Asserts that the specified element has the expected inner text.
*
* @param selector - the element selector
* @param expectedText - the expected text
*/
assertExactText(selector: string, expectedText: string) {
return this.assertExpectedText(selector, (value) => value === expectedText);
},
/**
* Clicks a visualize list item's title (in the visualize app).
*
* @param title - the title of the list item to be clicked
*/
clickVisualizeListItemTitle(title: string) {
return retry.try(async () => {
await testSubjects.click(`visListingTitleLink-${title}`);
await this.isLensPageOrFail();
});
},
/**
* Changes the specified dimension to the specified operation and (optinally) field.
*
* @param opts.dimension - the selector of the dimension being changed
* @param opts.operation - the desired operation ID for the dimension
* @param opts.field - the desired field for the dimension
* @param layerIndex - the index of the layer
*/
async configureDimension(
opts: {
dimension: string;
operation: string;
field?: string;
isPreviousIncompatible?: boolean;
keepOpen?: boolean;
palette?: string;
formula?: string;
},
layerIndex = 0
) {
await retry.try(async () => {
await testSubjects.click(`lns-layerPanel-${layerIndex} > ${opts.dimension}`);
await testSubjects.exists(`lns-indexPatternDimension-${opts.operation}`);
});
if (opts.operation === 'formula') {
await this.switchToFormula();
} else {
const operationSelector = opts.isPreviousIncompatible
? `lns-indexPatternDimension-${opts.operation} incompatible`
: `lns-indexPatternDimension-${opts.operation}`;
async function getAriaPressed() {
const operationSelectorContainer = await testSubjects.find(operationSelector);
await testSubjects.click(operationSelector);
const ariaPressed = await operationSelectorContainer.getAttribute('aria-pressed');
return ariaPressed;
}
// adding retry here as it seems that there is a flakiness of the operation click
// it seems that the aria-pressed attribute is updated to true when the button is clicked
await retry.waitFor('aria pressed to be true', async () => {
const ariaPressedStatus = await getAriaPressed();
return ariaPressedStatus === 'true';
});
}
if (opts.field) {
const target = await testSubjects.find('indexPattern-dimension-field');
await comboBox.openOptionsList(target);
await comboBox.setElement(target, opts.field);
}
if (opts.formula) {
// Formula takes time to open
await PageObjects.common.sleep(500);
await this.typeFormula(opts.formula);
}
if (opts.palette) {
await this.setPalette(opts.palette);
}
if (!opts.keepOpen) {
await this.closeDimensionEditor();
}
},
/**
* Changes the specified dimension to the specified operation and (optinally) field.
*
* @param opts.dimension - the selector of the dimension being changed
* @param opts.operation - the desired operation ID for the dimension
* @param opts.field - the desired field for the dimension
* @param layerIndex - the index of the layer
*/
async configureReference(opts: {
operation?: string;
field?: string;
isPreviousIncompatible?: boolean;
}) {
if (opts.operation) {
const target = await testSubjects.find('indexPattern-subFunction-selection-row');
await comboBox.openOptionsList(target);
await comboBox.setElement(target, opts.operation);
}
if (opts.field) {
const target = await testSubjects.find('indexPattern-reference-field-selection-row');
await comboBox.openOptionsList(target);
await comboBox.setElement(target, opts.field);
}
},
/**
* Drags field to workspace
*
* @param field - the desired field for the dimension
* */
async dragFieldToWorkspace(field: string) {
const from = `lnsFieldListPanelField-${field}`;
await find.existsByCssSelector(from);
await browser.html5DragAndDrop(
testSubjects.getCssSelector(from),
testSubjects.getCssSelector('lnsWorkspace')
);
await this.waitForLensDragDropToFinish();
await this.waitForVisualization();
},
/**
* Drags field to geo field workspace
*
* @param field - the desired geo_point or geo_shape field
* */
async dragFieldToGeoFieldWorkspace(field: string) {
const from = `lnsFieldListPanelField-${field}`;
await find.existsByCssSelector(from);
await browser.html5DragAndDrop(
testSubjects.getCssSelector(from),
testSubjects.getCssSelector('lnsGeoFieldWorkspace')
);
await this.waitForLensDragDropToFinish();
await PageObjects.header.waitUntilLoadingHasFinished();
},
/**
* Drags field to workspace
*
* @param field - the desired field for the dimension
* */
async clickField(field: string) {
await testSubjects.click(`lnsFieldListPanelField-${field}`);
},
async editField() {
await retry.try(async () => {
await testSubjects.click('lnsFieldListPanelEdit');
await testSubjects.missingOrFail('lnsFieldListPanelEdit');
});
},
async removeField() {
await retry.try(async () => {
await testSubjects.click('lnsFieldListPanelRemove');
await testSubjects.missingOrFail('lnsFieldListPanelRemove');
});
},
async searchField(name: string) {
await testSubjects.setValue('lnsIndexPatternFieldSearch', name, {
clearWithKeyboard: true,
typeCharByChar: true,
});
},
async waitForField(field: string) {
await testSubjects.existOrFail(`lnsFieldListPanelField-${field}`);
},
async waitForMissingDataViewWarning() {
await retry.try(async () => {
await testSubjects.existOrFail(`missing-refs-failure`);
});
},
async waitForMissingDataViewWarningDisappear() {
await retry.try(async () => {
await testSubjects.missingOrFail(`missing-refs-failure`);
});
},
async waitForEmptyWorkspace() {
await retry.try(async () => {
await testSubjects.existOrFail(`empty-workspace`);
});
},
async waitForWorkspaceWithVisualization() {
await retry.try(async () => {
await testSubjects.existOrFail(`lnsVisualizationContainer`);
});
},
async waitForFieldMissing(field: string) {
await retry.try(async () => {
await testSubjects.missingOrFail(`lnsFieldListPanelField-${field}`);
});
},
async pressMetaKey(metaKey: 'shift' | 'alt' | 'ctrl') {
const metaToAction = {
shift: 'duplicate',
alt: 'swap',
ctrl: 'combine',
};
const waitTime = 1000;
log.debug(`Wait ${waitTime}ms for the extra dop options to show up`);
await setTimeoutAsync(waitTime);
const browserKey =
metaKey === 'shift'
? browser.keys.SHIFT
: metaKey === 'alt'
? browser.keys.ALT
: browser.keys.COMMAND;
log.debug(`Press ${metaKey} with keyboard`);
await retry.try(async () => {
await browser.pressKeys(browserKey);
await find.existsByCssSelector(
`.lnsDragDrop__extraDrop > [data-test-subj="lnsDragDrop-${metaToAction[metaKey]}"].lnsDragDrop-isActiveDropTarget`
);
});
},
/**
* Copies field to chosen destination that is defined by distance of `steps`
* (right arrow presses) from it
*
* @param fieldName - the desired field for the dimension
* @param steps - number of steps user has to press right
* @param reverse - defines the direction of going through drops
* */
async dragFieldWithKeyboard(
fieldName: string,
steps = 1,
reverse = false,
metaKey?: 'shift' | 'alt' | 'ctrl'
) {
const field = await find.byCssSelector(
`[data-test-subj="lnsDragDrop_draggable-${fieldName}"] [data-test-subj="lnsDragDrop-keyboardHandler"]`
);
await field.focus();
await retry.try(async () => {
await browser.pressKeys(browser.keys.ENTER);
await testSubjects.exists('.lnsDragDrop-isDropTarget'); // checks if we're in dnd mode and there's any drop target active
});
for (let i = 0; i < steps; i++) {
await browser.pressKeys(reverse ? browser.keys.LEFT : browser.keys.RIGHT);
}
if (metaKey) {
this.pressMetaKey(metaKey);
}
await browser.pressKeys(browser.keys.ENTER);
await this.waitForLensDragDropToFinish();
await PageObjects.header.waitUntilLoadingHasFinished();
},
/**
* Selects draggable element and moves it by number of `steps`
*
* @param group - the group of the element
* @param index - the index of the element in the group
* @param steps - number of steps of presses right or left
* @param reverse - defines the direction of going through drops
* */
async dimensionKeyboardDragDrop(
group: string,
index = 0,
steps = 1,
reverse = false,
metaKey?: 'shift' | 'alt' | 'ctrl'
) {
const elements = await find.allByCssSelector(
`[data-test-subj="${group}"] [data-test-subj="lnsDragDrop-keyboardHandler"]`
);
const el = elements[index];
await el.focus();
await browser.pressKeys(browser.keys.ENTER);
for (let i = 0; i < steps; i++) {
await browser.pressKeys(reverse ? browser.keys.LEFT : browser.keys.RIGHT);
}
if (metaKey) {
this.pressMetaKey(metaKey);
}
await browser.pressKeys(browser.keys.ENTER);
await this.waitForLensDragDropToFinish();
await PageObjects.header.waitUntilLoadingHasFinished();
},
/**
* Selects draggable element and reorders it by number of `steps`
*
* @param group - the group of the element
* @param index - the index of the element in the group
* @param steps - number of steps of presses right or left
* @param reverse - defines the direction of going through drops
* */
async dimensionKeyboardReorder(group: string, index = 0, steps = 1, reverse = false) {
const elements = await find.allByCssSelector(
`[data-test-subj="${group}"] [data-test-subj="lnsDragDrop-keyboardHandler"]`
);
const el = elements[index];
await el.focus();
await browser.pressKeys(browser.keys.ENTER);
for (let i = 0; i < steps; i++) {
await browser.pressKeys(reverse ? browser.keys.ARROW_UP : browser.keys.ARROW_DOWN);
}
await browser.pressKeys(browser.keys.ENTER);
await this.waitForLensDragDropToFinish();
await PageObjects.header.waitUntilLoadingHasFinished();
},
async waitForLensDragDropToFinish() {
await retry.try(async () => {
const exists = await find.existsByCssSelector('.lnsDragDrop-isActiveGroup');
if (exists) {
throw new Error('UI still in drag/drop mode');
}
});
},
/**
* Drags field to dimension trigger
*
* @param field - the desired field for the dimension
* @param dimension - the selector of the dimension being changed
* */
async dragFieldToDimensionTrigger(field: string, dimension: string) {
const from = `lnsFieldListPanelField-${field}`;
await find.existsByCssSelector(from);
await browser.html5DragAndDrop(
testSubjects.getCssSelector(from),
testSubjects.getCssSelector(dimension)
);
await this.waitForLensDragDropToFinish();
await PageObjects.header.waitUntilLoadingHasFinished();
},
/**
* Drags from a dimension to another dimension trigger
*
* @param from - the selector of the dimension being moved
* @param to - the selector of the dimension being dropped to
* */
async dragDimensionToDimension(from: string, to: string) {
await find.existsByCssSelector(from);
await browser.html5DragAndDrop(
testSubjects.getCssSelector(from),
testSubjects.getCssSelector(to)
);
await this.waitForLensDragDropToFinish();
await PageObjects.header.waitUntilLoadingHasFinished();
},
/**
* Reorder elements within the group
*
* @param startIndex - the index of dragging element starting from 1
* @param endIndex - the index of drop starting from 1
* */
async reorderDimensions(dimension: string, startIndex: number, endIndex: number) {
const dragging = `[data-test-subj='${dimension}']:nth-of-type(${startIndex}) .lnsDragDrop`;
const dropping = `[data-test-subj='${dimension}']:nth-of-type(${endIndex}) [data-test-subj='lnsDragDrop-reorderableDropLayer'`;
await find.existsByCssSelector(dragging);
await browser.html5DragAndDrop(dragging, dropping);
await this.waitForLensDragDropToFinish();
await PageObjects.header.waitUntilLoadingHasFinished();
},
async assertPalette(palette: string) {
await retry.try(async () => {
await testSubjects.click('lns-palettePicker');
const currentPalette = await (
await find.byCssSelector('[role=option][aria-selected=true]')
).getAttribute('id');
expect(currentPalette).to.equal(palette);
});
},
async toggleToolbarPopover(buttonTestSub: string) {
await testSubjects.click(buttonTestSub);
},
/**
* Open the specified dimension.
*
* @param dimension - the selector of the dimension panel to open
* @param layerIndex - the index of the layer
*/
async openDimensionEditor(dimension: string, layerIndex = 0) {
await retry.try(async () => {
await testSubjects.click(`lns-layerPanel-${layerIndex} > ${dimension}`);
});
},
async isDimensionEditorOpen() {
return await testSubjects.exists('lns-indexPattern-dimensionContainerBack');
},
// closes the dimension editor flyout
async closeDimensionEditor() {
await retry.try(async () => {
await testSubjects.click('lns-indexPattern-dimensionContainerBack');
await testSubjects.missingOrFail('lns-indexPattern-dimensionContainerBack');
});
},
async enableTimeShift() {
await testSubjects.click('indexPattern-advanced-popover');
await retry.try(async () => {
await testSubjects.click('indexPattern-time-shift-enable');
});
},
async setTimeShift(shift: string) {
await comboBox.setCustom('indexPattern-dimension-time-shift', shift);
},
async enableFilter() {
await testSubjects.click('indexPattern-advanced-popover');
await retry.try(async () => {
await testSubjects.click('indexPattern-filter-by-enable');
});
},
async setFilterBy(queryString: string) {
this.typeFilter(queryString);
await retry.try(async () => {
await testSubjects.click('indexPattern-filters-existingFilterTrigger');
});
},
async typeFilter(queryString: string) {
const queryInput = await testSubjects.find('indexPattern-filters-queryStringInput');
await queryInput.type(queryString);
},
async hasFixAction() {
return await testSubjects.exists('errorFixAction');
},
async useFixAction() {
await testSubjects.click('errorFixAction');
await this.waitForVisualization();
},
async isTopLevelAggregation() {
return await testSubjects.isEuiSwitchChecked('indexPattern-nesting-switch');
},
/**
* Removes the dimension matching a specific test subject
*/
async removeDimension(dimensionTestSubj: string) {
await testSubjects.click(`${dimensionTestSubj} > indexPattern-dimension-remove`);
},
/**
* adds new filter to filters agg
*/
async addFilterToAgg(queryString: string) {
await testSubjects.click('lns-newBucket-add');
this.typeFilter(queryString);
// Problem here is that after typing in the queryInput a dropdown will fetch the server
// with suggestions and show up. Depending on the cursor position and some other factors
// pressing Enter at this point may lead to auto-complete the queryInput with random stuff from the
// dropdown which was not intended originally.
// To close the Filter popover we need to move to the label input and then press Enter:
// solution is to press Tab 2 twice (first Tab will close the dropdown) instead of Enter to avoid
// race condition with the dropdown
await PageObjects.common.pressTabKey();
await PageObjects.common.pressTabKey();
// Now it is safe to press Enter as we're in the label input
await PageObjects.common.pressEnterKey();
await PageObjects.common.sleep(1000); // give time for debounced components to rerender
},
/**
* Add new term to Top values/terms agg
* @param opts field to add
*/
async addTermToAgg(field: string) {
const lastIndex = (
await find.allByCssSelector('[data-test-subj^="indexPattern-dimension-field"]')
).length;
await retry.try(async () => {
await testSubjects.click('indexPattern-terms-add-field');
// count the number of defined terms
const target = await testSubjects.find(`indexPattern-dimension-field-${lastIndex}`, 1000);
await comboBox.openOptionsList(target);
await comboBox.setElement(target, field);
});
},
async checkTermsAreNotAvailableToAgg(fields: string[]) {
const lastIndex = (
await find.allByCssSelector('[data-test-subj^="indexPattern-dimension-field"]')
).length;
await testSubjects.click('indexPattern-terms-add-field');
// count the number of defined terms
const target = await testSubjects.find(`indexPattern-dimension-field-${lastIndex}`);
// await comboBox.openOptionsList(target);
for (const field of fields) {
await comboBox.setCustom(`indexPattern-dimension-field-${lastIndex}`, field);
await comboBox.openOptionsList(target);
await testSubjects.missingOrFail(`lns-fieldOption-${field}`);
}
},
/**
* Save the current Lens visualization.
*/
async save(
title: string,
saveAsNew?: boolean,
redirectToOrigin?: boolean,
saveToLibrary?: boolean,
addToDashboard?: 'new' | 'existing' | null,
dashboardId?: string
) {
await PageObjects.header.waitUntilLoadingHasFinished();
await testSubjects.click('lnsApp_saveButton');
await PageObjects.timeToVisualize.setSaveModalValues(title, {
saveAsNew,
redirectToOrigin,
addToDashboard: addToDashboard ? addToDashboard : null,
dashboardId,
saveToLibrary,
});
await testSubjects.click('confirmSaveSavedObjectButton');
await retry.waitForWithTimeout('Save modal to disappear', 1000, () =>
testSubjects
.missingOrFail('confirmSaveSavedObjectButton')
.then(() => true)
.catch(() => false)
);
},
async saveAndReturn() {
await testSubjects.click('lnsApp_saveAndReturnButton');
},
async expectSaveAndReturnButtonDisabled() {
const button = await testSubjects.find('lnsApp_saveAndReturnButton', 10000);
const disabledAttr = await button.getAttribute('disabled');
expect(disabledAttr).to.be('true');
},
async editDimensionLabel(label: string) {
await testSubjects.setValue('indexPattern-label-edit', label, { clearWithKeyboard: true });
},
async editDimensionFormat(format: string) {
const formatInput = await testSubjects.find('indexPattern-dimension-format');
await comboBox.openOptionsList(formatInput);
await comboBox.setElement(formatInput, format);
},
async editDimensionColor(color: string) {
const colorPickerInput = await testSubjects.find('~indexPattern-dimension-colorPicker');
await colorPickerInput.type(color);
await PageObjects.common.sleep(1000); // give time for debounced components to rerender
},
hasVisualOptionsButton() {
return testSubjects.exists('lnsVisualOptionsButton');
},
async openVisualOptions() {
await retry.try(async () => {
await testSubjects.click('lnsVisualOptionsButton');
await testSubjects.exists('lnsVisualOptionsButton');
});
},
async retrySetValue(
input: string,
value: string,
options = {
clearWithKeyboard: true,
typeCharByChar: true,
} as Record<string, boolean>
) {
await retry.try(async () => {
await testSubjects.setValue(input, value, options);
expect(await (await testSubjects.find(input)).getAttribute('value')).to.eql(value);
});
},
async useCurvedLines() {
await testSubjects.click('lnsCurveStyleToggle');
},
async editMissingValues(option: string) {
await testSubjects.click('lnsMissingValuesSelect');
const optionSelector = await find.byCssSelector(`#${option}`);
await optionSelector.click();
},
getTitle() {
return testSubjects.getAttribute('lns_ChartTitle', 'innerText');
},
async getFiltersAggLabels() {
const labels = [];
const filters = await testSubjects.findAll('indexPattern-filters-existingFilterContainer');
for (let i = 0; i < filters.length; i++) {
labels.push(await filters[i].getVisibleText());
}
log.debug(`Found ${labels.length} filters on current page`);
return labels;
},
/**
* Uses the Lens visualization switcher to switch visualizations.
*
* @param subVisualizationId - the ID of the sub-visualization to switch to, such as
* lnsDatatable or bar_stacked
*/
async switchToVisualization(subVisualizationId: string, searchTerm?: string) {
await this.openChartSwitchPopover();
await this.searchOnChartSwitch(subVisualizationId, searchTerm);
await testSubjects.click(`lnsChartSwitchPopover_${subVisualizationId}`);
await PageObjects.header.waitUntilLoadingHasFinished();
},
async openChartSwitchPopover() {
if (await testSubjects.exists('lnsChartSwitchList')) {
return;
}
await retry.try(async () => {
await testSubjects.click('lnsChartSwitchPopover');
await testSubjects.existOrFail('lnsChartSwitchList');
});
},
async changeAxisSide(newSide: string) {
await testSubjects.click(`lnsXY_axisSide_groups_${newSide}`);
},
/** Counts the visible warnings in the config panel */
async getErrorCount() {
const moreButton = await testSubjects.exists('configuration-failure-more-errors');
if (moreButton) {
await retry.try(async () => {
await testSubjects.click('configuration-failure-more-errors');
await testSubjects.missingOrFail('configuration-failure-more-errors');
});
}
const errors = await testSubjects.findAll('configuration-failure-error');
const expressionErrors = await testSubjects.findAll('expression-failure');
return (errors?.length ?? 0) + (expressionErrors?.length ?? 0);
},
async searchOnChartSwitch(subVisualizationId: string, searchTerm?: string) {
// Because the new chart switcher is now a virtualized list, the process needs some help
// So either pass a search string or pick the last 3 letters from the id (3 because pie
// is the smallest chart name) and use them to search
const queryTerm = searchTerm ?? subVisualizationId.substring(subVisualizationId.length - 3);
return await testSubjects.setValue('lnsChartSwitchSearch', queryTerm, {
clearWithKeyboard: true,
});
},
/**
* Checks a specific subvisualization in the chart switcher for a "data loss" indicator
*
* @param subVisualizationId - the ID of the sub-visualization to switch to, such as
* lnsDatatable or bar_stacked
*/
async hasChartSwitchWarning(subVisualizationId: string, searchTerm?: string) {
await this.openChartSwitchPopover();
await this.searchOnChartSwitch(subVisualizationId, searchTerm);
const element = await testSubjects.find(`lnsChartSwitchPopover_${subVisualizationId}`);
return await testSubjects.descendantExists(
`lnsChartSwitchPopoverAlert_${subVisualizationId}`,
element
);
},
/**
* Uses the Lens layer switcher to switch seriesType for xy charts.
*
* @param subVisualizationId - the ID of the sub-visualization to switch to, such as
* line,
*/
async switchLayerSeriesType(seriesType: string) {
await retry.try(async () => {
await testSubjects.click('lns_layer_settings');
await testSubjects.exists(`lnsXY_seriesType-${seriesType}`);
});
return await testSubjects.click(`lnsXY_seriesType-${seriesType}`);
},
/**
* Returns the number of layers visible in the chart configuration
*/
async getLayerCount() {
const elements = await testSubjects.findAll('lnsLayerRemove');
return elements.length;
},
/**
* Adds a new layer to the chart, fails if the chart does not support new layers
*/
async createLayer(layerType: string = 'data') {
await testSubjects.click('lnsLayerAddButton');
const layerCount = (await find.allByCssSelector(`[data-test-subj^="lns-layerPanel-"]`))
.length;
await retry.waitFor('check for layer type support', async () => {
const fasterChecks = await Promise.all([
(await find.allByCssSelector(`[data-test-subj^="lns-layerPanel-"]`)).length > layerCount,
testSubjects.exists(`lnsLayerAddButton-${layerType}`),
]);
return fasterChecks.filter(Boolean).length > 0;
});
if (await testSubjects.exists(`lnsLayerAddButton-${layerType}`)) {
await testSubjects.click(`lnsLayerAddButton-${layerType}`);
}
},
/**
* Changes the index pattern in the data panel
*/
async switchDataPanelIndexPattern(name: string) {
await testSubjects.click('indexPattern-switch-link');
await find.clickByCssSelector(`[title="${name}"]`);
await PageObjects.header.waitUntilLoadingHasFinished();
},
/**
* Changes the index pattern for the first layer
*/
async switchFirstLayerIndexPattern(name: string) {
await testSubjects.click('lns_layerIndexPatternLabel');
await find.clickByCssSelector(`.lnsChangeIndexPatternPopover [title="${name}"]`);
await PageObjects.header.waitUntilLoadingHasFinished();
},
/**
* Returns the current index pattern of the data panel
*/
async getDataPanelIndexPattern() {
return await (await testSubjects.find('indexPattern-switch-link')).getAttribute('title');
},
/**
* Returns the current index pattern of the first layer
*/
async getFirstLayerIndexPattern() {
return await (await testSubjects.find('lns_layerIndexPatternLabel')).getAttribute('title');
},
async linkedToOriginatingApp() {
await PageObjects.header.waitUntilLoadingHasFinished();
await testSubjects.existOrFail('lnsApp_saveAndReturnButton');
},
async notLinkedToOriginatingApp() {
await PageObjects.header.waitUntilLoadingHasFinished();
await testSubjects.missingOrFail('lnsApp_saveAndReturnButton');
},
/**
* Gets label of dimension trigger in dimension panel
*
* @param dimension - the selector of the dimension
* @param index - the index of the dimension trigger in group
*/
async getDimensionTriggerText(dimension: string, index = 0) {
const dimensionTexts = await this.getDimensionTriggersTexts(dimension);
return dimensionTexts[index];
},
/**
* Gets label of all dimension triggers in dimension group
*
* @param dimension - the selector of the dimension
*/
async getDimensionTriggersTexts(dimension: string) {
return retry.try(async () => {
const dimensionElements = await testSubjects.findAll(`${dimension} > lns-dimensionTrigger`);
const dimensionTexts = await Promise.all(
await dimensionElements.map(async (el) => await el.getVisibleText())
);
return dimensionTexts;
});
},
async isShowingNoResults() {
return (
(await (await testSubjects.find('lnsWorkspace')).getVisibleText()) === 'No results found'
);
},
async getCurrentChartDebugState() {
return await elasticChart.getChartDebugData('lnsWorkspace');
},
/**
* Gets text of the specified datatable header cell
*
* @param index - index of th element in datatable
*/
async getDatatableHeaderText(index = 0) {
const el = await this.getDatatableHeader(index);
return el.getVisibleText();
},
/**
* Gets text of the specified datatable cell
*
* @param rowIndex - index of row of the cell
* @param colIndex - index of column of the cell
*/
async getDatatableCellText(rowIndex = 0, colIndex = 0) {
const el = await this.getDatatableCell(rowIndex, colIndex);
return el.getVisibleText();
},
async getDatatableCellStyle(rowIndex = 0, colIndex = 0) {
const el = await this.getDatatableCell(rowIndex, colIndex);
const styleString = await el.getAttribute('style');
return styleString.split(';').reduce<Record<string, string>>((memo, cssLine) => {
const [prop, value] = cssLine.split(':');
if (prop && value) {
memo[prop.trim()] = value.trim();
}
return memo;
}, {});
},
async getCountOfDatatableColumns() {
const table = await find.byCssSelector('.euiDataGrid');
const $ = await table.parseDomContent();
return (await $('.euiDataGridHeaderCell__content')).length;
},
async getDatatableHeader(index = 0) {
log.debug(`All headers ${await testSubjects.getVisibleText('dataGridHeader')}`);
return find.byCssSelector(
`[data-test-subj="lnsDataTable"] [data-test-subj="dataGridHeader"] [role=columnheader]:nth-child(${
index + 1
})`
);
},
async getDatatableCell(rowIndex = 0, colIndex = 0) {
return await find.byCssSelector(
`[data-test-subj="lnsDataTable"] [data-test-subj="dataGridRowCell"][data-gridcell-column-index="${colIndex}"][data-gridcell-row-index="${rowIndex}"]`
);
},
async isDatatableHeaderSorted(index = 0) {
return find.existsByCssSelector(
`[data-test-subj="lnsDataTable"] [data-test-subj="dataGridHeader"] [role=columnheader]:nth-child(${
index + 1
}) [data-test-subj^="dataGridHeaderCellSortingIcon"]`
);
},
async changeTableSortingBy(colIndex = 0, direction: 'none' | 'ascending' | 'descending') {
const el = await this.getDatatableHeader(colIndex);
await el.click();
let buttonEl;
if (direction !== 'none') {
buttonEl = await find.byCssSelector(
`[data-test-subj^="dataGridHeaderCellActionGroup"] [title="Sort ${direction}"]`
);
} else {
buttonEl = await find.byCssSelector(
`[data-test-subj^="dataGridHeaderCellActionGroup"] li[class$="selected"] [title^="Sort"]`
);
}
return buttonEl.click();
},
async setTableSummaryRowFunction(
summaryFunction: 'none' | 'sum' | 'avg' | 'count' | 'min' | 'max'
) {
await testSubjects.click('lnsDatatable_summaryrow_function');
await testSubjects.click('lns-datatable-summary-' + summaryFunction);
},
async setTableSummaryRowLabel(newLabel: string) {
await testSubjects.setValue('lnsDatatable_summaryrow_label', newLabel, {
clearWithKeyboard: true,
typeCharByChar: true,
});
},
async setTableDynamicColoring(coloringType: 'none' | 'cell' | 'text') {
await testSubjects.click('lnsDatatable_dynamicColoring_groups_' + coloringType);
},
async openPalettePanel(chartType: string) {
await retry.try(async () => {
await testSubjects.click(`${chartType}_dynamicColoring_trigger`);
// wait for the UI to settle
await PageObjects.common.sleep(100);
await testSubjects.existOrFail('lns-indexPattern-PalettePanelContainer', { timeout: 2500 });
});
},
async closePalettePanel() {
await testSubjects.click('lns-indexPattern-PalettePanelContainerBack');
},
// different picker from the next one
async changePaletteTo(paletteName: string) {
await testSubjects.click(`lnsPalettePanel_dynamicColoring_palette_picker`);
await testSubjects.click(`${paletteName}-palette`);
},
async setPalette(paletteName: string) {