/
listing_table.ts
329 lines (290 loc) · 10.3 KB
/
listing_table.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
/*
* 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 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
import expect from '@kbn/expect';
import { FtrService } from '../ftr_provider_context';
type AppName = keyof typeof PREFIX_MAP;
const PREFIX_MAP = {
visualize: 'vis',
dashboard: 'dashboard',
map: 'map',
eventAnnotation: 'eventAnnotation',
};
export class ListingTableService extends FtrService {
private readonly testSubjects = this.ctx.getService('testSubjects');
private readonly find = this.ctx.getService('find');
private readonly log = this.ctx.getService('log');
private readonly retry = this.ctx.getService('retry');
private readonly common = this.ctx.getPageObject('common');
private readonly tagPopoverToggle = this.ctx.getService('menuToggle').create({
name: 'Tag Popover',
menuTestSubject: 'tagSelectableList',
toggleButtonTestSubject: 'tagFilterPopoverButton',
});
private async getSearchFilter() {
return await this.testSubjects.find('tableListSearchBox');
}
/**
* Returns search input value on landing page
*/
public async getSearchFilterValue() {
const searchFilter = await this.getSearchFilter();
return await searchFilter.getAttribute('value');
}
/**
* Set search input value on landing page
*/
public async setSearchFilterValue(value: string) {
const searchFilter = await this.getSearchFilter();
searchFilter.type(value);
}
/**
* Clears search input on landing page
*/
public async clearSearchFilter() {
this.testSubjects.click('clearSearchButton');
}
private async getAllItemsNamesOnCurrentPage(): Promise<string[]> {
const visualizationNames = [];
const links = await this.find.allByCssSelector('.euiTableRow .euiLink');
for (let i = 0; i < links.length; i++) {
visualizationNames.push(await links[i].getVisibleText());
}
this.log.debug(`Found ${visualizationNames.length} visualizations on current page`);
return visualizationNames;
}
private async getAllSelectableItemsNamesOnCurrentPage(): Promise<string[]> {
const visualizationNames = [];
// TODO - use .euiTableRow-isSelectable when it's working again (https://github.com/elastic/eui/issues/7515)
const rows = await this.find.allByCssSelector('.euiTableRow');
for (let i = 0; i < rows.length; i++) {
const checkbox = await rows[i].findByCssSelector('.euiCheckbox__input');
if (await checkbox.isEnabled()) {
const link = await rows[i].findByCssSelector('.euiLink');
visualizationNames.push(await link.getVisibleText());
}
}
this.log.debug(`Found ${visualizationNames.length} selectable visualizations on current page`);
return visualizationNames;
}
public async waitUntilTableIsLoaded() {
return this.retry.try(async () => {
const isLoaded = await this.find.existsByDisplayedByCssSelector(
'[data-test-subj="itemsInMemTable"]:not(.euiBasicTable-loading)'
);
if (isLoaded) {
return true;
} else {
throw new Error('Waiting');
}
});
}
/**
* Navigates through all pages on Landing page and returns array of items names that are selectable
* Added for visualize_integration saved object tagging tests
*/
public async getAllSelectableItemsNames(): Promise<string[]> {
this.log.debug('ListingTable.getAllItemsNames');
let morePages = true;
let visualizationNames: string[] = [];
while (morePages) {
visualizationNames = visualizationNames.concat(
await this.getAllSelectableItemsNamesOnCurrentPage()
);
morePages = !(
(await this.testSubjects.getAttribute('pagination-button-next', 'disabled')) === 'true'
);
if (morePages) {
await this.testSubjects.click('pagerNextButton');
await this.waitUntilTableIsLoaded();
}
}
return visualizationNames;
}
/**
* Select tags in the searchbar's tag filter.
*/
public async selectFilterTags(...tagNames: string[]): Promise<void> {
await this.openTagPopover();
// select the tags
for (const tagName of tagNames) {
await this.testSubjects.click(`tag-searchbar-option-${tagName.replace(' ', '_')}`);
}
await this.closeTagPopover();
await this.waitUntilTableIsLoaded();
}
public async openTagPopover(): Promise<void> {
this.log.debug('ListingTable.openTagPopover');
await this.tagPopoverToggle.open();
}
public async closeTagPopover(): Promise<void> {
this.log.debug('ListingTable.closeTagPopover');
await this.tagPopoverToggle.close();
}
/**
* Navigates through all pages on Landing page and returns array of items names
*/
public async getAllItemsNames(): Promise<string[]> {
this.log.debug('ListingTable.getAllItemsNames');
let morePages = true;
let visualizationNames: string[] = [];
while (morePages) {
visualizationNames = visualizationNames.concat(await this.getAllItemsNamesOnCurrentPage());
morePages = !(
(await this.testSubjects.getAttribute('pagination-button-next', 'disabled')) === 'true'
);
if (morePages) {
await this.testSubjects.click('pagerNextButton');
await this.waitUntilTableIsLoaded();
}
}
return visualizationNames;
}
/**
* Open the inspect flyout
*/
public async inspectVisualization(index: number = 0) {
const inspectButtons = await this.testSubjects.findAll('inspect-action');
await inspectButtons[index].click();
}
public async inspectorFieldsReadonly() {
const disabledValues = await Promise.all([
this.testSubjects.getAttribute('nameInput', 'readonly'),
this.testSubjects.getAttribute('descriptionInput', 'readonly'),
]);
return disabledValues.every((value) => value === 'true');
}
public async closeInspector() {
await this.testSubjects.click('closeFlyoutButton');
}
/**
* Edit Visualization title and description in the flyout
*/
public async editVisualizationDetails(
{ title, description }: { title?: string; description?: string } = {},
shouldSave: boolean = true
) {
if (title) {
await this.testSubjects.setValue('nameInput', title);
}
if (description) {
await this.testSubjects.setValue('descriptionInput', description);
}
if (shouldSave) {
await this.retry.try(async () => {
await this.testSubjects.click('saveButton');
await this.testSubjects.missingOrFail('flyoutTitle');
});
}
}
/**
* Returns items count on landing page
*/
public async expectItemsCount(appName: AppName, count: number, findTimeout?: number) {
await this.retry.try(async () => {
const elements = await this.find.allByCssSelector(
`[data-test-subj^="${PREFIX_MAP[appName]}ListingTitleLink"]`,
findTimeout ?? 10000
);
expect(elements.length).to.equal(count);
});
}
/**
* Types name into search field on Landing page and waits till search completed
* @param name item name
*/
public async searchForItemWithName(name: string, { escape = true }: { escape?: boolean } = {}) {
this.log.debug(`searchForItemWithName: ${name}`);
await this.retry.try(async () => {
const searchFilter = await this.getSearchFilter();
await searchFilter.clearValue();
await searchFilter.click();
if (escape) {
name = name
// Note: this replacement of - to space is to preserve original logic but I'm not sure why or if it's needed.
.replace('-', ' ')
// Remove `[*]` from search as it is not supported by EUI Query's syntax.
.replace(/ *\[[^)]*\] */g, '');
}
await searchFilter.type(name);
await this.common.pressEnterKey();
});
await this.waitUntilTableIsLoaded();
}
/**
* Searches for item on Landing page and retruns items count that match `ListingTitleLink-${name}` pattern
*/
public async searchAndExpectItemsCount(appName: AppName, name: string, count: number) {
await this.searchForItemWithName(name);
await this.retry.try(async () => {
const links = await this.testSubjects.findAll(
`${PREFIX_MAP[appName]}ListingTitleLink-${name.replace(/ /g, '-')}`
);
expect(links.length).to.equal(count);
});
}
public async clickDeleteSelected() {
await this.testSubjects.click('deleteSelectedItems');
}
public async selectFirstItemInList() {
await this.find.clickByCssSelector('.euiTableCellContent .euiCheckbox__input');
}
public async clickItemCheckbox(id: string) {
await this.testSubjects.click(`checkboxSelectRow-${id}`);
}
/**
* Searches for item by name, selects checbox and deletes it
* @param name item name
* @param id row id
*/
public async deleteItem(name: string, id?: string) {
await this.searchForItemWithName(name);
if (id) {
await this.clickItemCheckbox(id);
} else {
await this.selectFirstItemInList();
}
await this.clickDeleteSelected();
await this.common.clickConfirmOnModal();
}
/**
* Clicks item on Landing page by link name if it is present
*/
public async clickItemLink(appName: AppName, name: string) {
await this.testSubjects.click(
`${PREFIX_MAP[appName]}ListingTitleLink-${name.split(' ').join('-')}`
);
}
/**
* Checks 'SelectAll' checkbox on
*/
public async checkListingSelectAllCheckbox() {
const element = await this.testSubjects.find('checkboxSelectAll');
const isSelected = await element.isSelected();
if (!isSelected) {
this.log.debug(`checking checkbox "checkboxSelectAll"`);
await this.testSubjects.click('checkboxSelectAll');
}
}
/**
* Clicks NewItem button on Landing page
*/
public async clickNewButton(): Promise<void> {
await this.testSubjects.click('newItemButton');
}
public async isShowingEmptyPromptCreateNewButton(): Promise<void> {
await this.testSubjects.existOrFail('newItemButton');
}
public async onListingPage(appName: AppName) {
return await this.testSubjects.exists(`${appName}LandingPage`, {
timeout: 5000,
});
}
public async selectTab(which: number) {
await this.find.clickByCssSelector(`.euiTab:nth-child(${which})`);
}
}