Skip to content

Commit b8a15eb

Browse files
committed
[ftr] migrate "listingTable" service to FtrService class
1 parent a0ddca8 commit b8a15eb

File tree

2 files changed

+170
-173
lines changed

2 files changed

+170
-173
lines changed

test/functional/services/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ import {
4343
ElasticChartProvider,
4444
VegaDebugInspectorViewProvider,
4545
} from './visualizations';
46-
import { ListingTableProvider } from './listing_table';
46+
import { ListingTableService } from './listing_table';
4747
import { SavedQueryManagementComponentProvider } from './saved_query_management_component';
4848
import { KibanaSupertestProvider } from './supertest';
4949
import { MenuToggleProvider } from './menu_toggle';
@@ -63,7 +63,7 @@ export const services = {
6363
dashboardVisualizations: DashboardVisualizationProvider,
6464
dashboardExpect: DashboardExpectProvider,
6565
failureDebugging: FailureDebuggingProvider,
66-
listingTable: ListingTableProvider,
66+
listingTable: ListingTableService,
6767
dashboardAddPanel: DashboardAddPanelProvider,
6868
dashboardReplacePanel: DashboardReplacePanelProvider,
6969
dashboardPanelActions: DashboardPanelActionsProvider,

test/functional/services/listing_table.ts

Lines changed: 168 additions & 171 deletions
Original file line numberDiff line numberDiff line change
@@ -7,202 +7,199 @@
77
*/
88

99
import expect from '@kbn/expect';
10-
import { FtrProviderContext } from '../ftr_provider_context';
10+
import { FtrService } from '../ftr_provider_context';
1111

12-
type AppName = 'visualize' | 'dashboard' | 'map';
12+
type AppName = keyof typeof PREFIX_MAP;
13+
const PREFIX_MAP = { visualize: 'vis', dashboard: 'dashboard', map: 'map' };
1314

14-
export function ListingTableProvider({ getService, getPageObjects }: FtrProviderContext) {
15-
const testSubjects = getService('testSubjects');
16-
const find = getService('find');
17-
const log = getService('log');
18-
const retry = getService('retry');
19-
const { common, header } = getPageObjects(['common', 'header']);
20-
const prefixMap = { visualize: 'vis', dashboard: 'dashboard', map: 'map' };
15+
export class ListingTableService extends FtrService {
16+
private readonly testSubjects = this.ctx.getService('testSubjects');
17+
private readonly find = this.ctx.getService('find');
18+
private readonly log = this.ctx.getService('log');
19+
private readonly retry = this.ctx.getService('retry');
20+
private readonly common = this.ctx.getPageObjects(['common']).common;
21+
private readonly header = this.ctx.getPageObjects(['header']).header;
2122

22-
class ListingTable {
23-
private async getSearchFilter() {
24-
return await testSubjects.find('tableListSearchBox');
25-
}
23+
private async getSearchFilter() {
24+
return await this.testSubjects.find('tableListSearchBox');
25+
}
2626

27-
/**
28-
* Returns search input value on landing page
29-
*/
30-
public async getSearchFilterValue() {
31-
const searchFilter = await this.getSearchFilter();
32-
return await searchFilter.getAttribute('value');
33-
}
27+
/**
28+
* Returns search input value on landing page
29+
*/
30+
public async getSearchFilterValue() {
31+
const searchFilter = await this.getSearchFilter();
32+
return await searchFilter.getAttribute('value');
33+
}
3434

35-
/**
36-
* Clears search input on landing page
37-
*/
38-
public async clearSearchFilter() {
39-
const searchFilter = await this.getSearchFilter();
40-
await searchFilter.clearValue();
41-
await searchFilter.click();
42-
}
35+
/**
36+
* Clears search input on landing page
37+
*/
38+
public async clearSearchFilter() {
39+
const searchFilter = await this.getSearchFilter();
40+
await searchFilter.clearValue();
41+
await searchFilter.click();
42+
}
4343

44-
private async getAllItemsNamesOnCurrentPage(): Promise<string[]> {
45-
const visualizationNames = [];
46-
const links = await find.allByCssSelector('.euiTableRow .euiLink');
47-
for (let i = 0; i < links.length; i++) {
48-
visualizationNames.push(await links[i].getVisibleText());
49-
}
50-
log.debug(`Found ${visualizationNames.length} visualizations on current page`);
51-
return visualizationNames;
44+
private async getAllItemsNamesOnCurrentPage(): Promise<string[]> {
45+
const visualizationNames = [];
46+
const links = await this.find.allByCssSelector('.euiTableRow .euiLink');
47+
for (let i = 0; i < links.length; i++) {
48+
visualizationNames.push(await links[i].getVisibleText());
5249
}
50+
this.log.debug(`Found ${visualizationNames.length} visualizations on current page`);
51+
return visualizationNames;
52+
}
5353

54-
public async waitUntilTableIsLoaded() {
55-
return retry.try(async () => {
56-
const isLoaded = await find.existsByDisplayedByCssSelector(
57-
'[data-test-subj="itemsInMemTable"]:not(.euiBasicTable-loading)'
58-
);
59-
60-
if (isLoaded) {
61-
return true;
62-
} else {
63-
throw new Error('Waiting');
64-
}
65-
});
66-
}
54+
public async waitUntilTableIsLoaded() {
55+
return this.retry.try(async () => {
56+
const isLoaded = await this.find.existsByDisplayedByCssSelector(
57+
'[data-test-subj="itemsInMemTable"]:not(.euiBasicTable-loading)'
58+
);
6759

68-
/**
69-
* Navigates through all pages on Landing page and returns array of items names
70-
*/
71-
public async getAllItemsNames(): Promise<string[]> {
72-
log.debug('ListingTable.getAllItemsNames');
73-
let morePages = true;
74-
let visualizationNames: string[] = [];
75-
while (morePages) {
76-
visualizationNames = visualizationNames.concat(await this.getAllItemsNamesOnCurrentPage());
77-
morePages = !(
78-
(await testSubjects.getAttribute('pagination-button-next', 'disabled')) === 'true'
79-
);
80-
if (morePages) {
81-
await testSubjects.click('pagerNextButton');
82-
await header.waitUntilLoadingHasFinished();
83-
}
60+
if (isLoaded) {
61+
return true;
62+
} else {
63+
throw new Error('Waiting');
8464
}
85-
return visualizationNames;
86-
}
65+
});
66+
}
8767

88-
/**
89-
* Returns items count on landing page
90-
*/
91-
public async expectItemsCount(appName: AppName, count: number) {
92-
await retry.try(async () => {
93-
const elements = await find.allByCssSelector(
94-
`[data-test-subj^="${prefixMap[appName]}ListingTitleLink"]`
95-
);
96-
expect(elements.length).to.equal(count);
97-
});
68+
/**
69+
* Navigates through all pages on Landing page and returns array of items names
70+
*/
71+
public async getAllItemsNames(): Promise<string[]> {
72+
this.log.debug('ListingTable.getAllItemsNames');
73+
let morePages = true;
74+
let visualizationNames: string[] = [];
75+
while (morePages) {
76+
visualizationNames = visualizationNames.concat(await this.getAllItemsNamesOnCurrentPage());
77+
morePages = !(
78+
(await this.testSubjects.getAttribute('pagination-button-next', 'disabled')) === 'true'
79+
);
80+
if (morePages) {
81+
await this.testSubjects.click('pagerNextButton');
82+
await this.header.waitUntilLoadingHasFinished();
83+
}
9884
}
85+
return visualizationNames;
86+
}
9987

100-
/**
101-
* Types name into search field on Landing page and waits till search completed
102-
* @param name item name
103-
*/
104-
public async searchForItemWithName(name: string, { escape = true }: { escape?: boolean } = {}) {
105-
log.debug(`searchForItemWithName: ${name}`);
106-
107-
await retry.try(async () => {
108-
const searchFilter = await this.getSearchFilter();
109-
await searchFilter.clearValue();
110-
await searchFilter.click();
111-
112-
if (escape) {
113-
name = name
114-
// Note: this replacement of - to space is to preserve original logic but I'm not sure why or if it's needed.
115-
.replace('-', ' ')
116-
// Remove `[*]` from search as it is not supported by EUI Query's syntax.
117-
.replace(/ *\[[^)]*\] */g, '');
118-
}
119-
120-
await searchFilter.type(name);
121-
await common.pressEnterKey();
122-
});
88+
/**
89+
* Returns items count on landing page
90+
*/
91+
public async expectItemsCount(appName: AppName, count: number) {
92+
await this.retry.try(async () => {
93+
const elements = await this.find.allByCssSelector(
94+
`[data-test-subj^="${PREFIX_MAP[appName]}ListingTitleLink"]`
95+
);
96+
expect(elements.length).to.equal(count);
97+
});
98+
}
12399

124-
await header.waitUntilLoadingHasFinished();
125-
}
100+
/**
101+
* Types name into search field on Landing page and waits till search completed
102+
* @param name item name
103+
*/
104+
public async searchForItemWithName(name: string, { escape = true }: { escape?: boolean } = {}) {
105+
this.log.debug(`searchForItemWithName: ${name}`);
126106

127-
/**
128-
* Searches for item on Landing page and retruns items count that match `ListingTitleLink-${name}` pattern
129-
*/
130-
public async searchAndExpectItemsCount(appName: AppName, name: string, count: number) {
131-
await this.searchForItemWithName(name);
132-
await retry.try(async () => {
133-
const links = await testSubjects.findAll(
134-
`${prefixMap[appName]}ListingTitleLink-${name.replace(/ /g, '-')}`
135-
);
136-
expect(links.length).to.equal(count);
137-
});
138-
}
107+
await this.retry.try(async () => {
108+
const searchFilter = await this.getSearchFilter();
109+
await searchFilter.clearValue();
110+
await searchFilter.click();
139111

140-
public async clickDeleteSelected() {
141-
await testSubjects.click('deleteSelectedItems');
142-
}
112+
if (escape) {
113+
name = name
114+
// Note: this replacement of - to space is to preserve original logic but I'm not sure why or if it's needed.
115+
.replace('-', ' ')
116+
// Remove `[*]` from search as it is not supported by EUI Query's syntax.
117+
.replace(/ *\[[^)]*\] */g, '');
118+
}
143119

144-
public async clickItemCheckbox(id: string) {
145-
await testSubjects.click(`checkboxSelectRow-${id}`);
146-
}
120+
await searchFilter.type(name);
121+
await this.common.pressEnterKey();
122+
});
147123

148-
/**
149-
* Searches for item by name, selects checbox and deletes it
150-
* @param name item name
151-
* @param id row id
152-
*/
153-
public async deleteItem(name: string, id: string) {
154-
await this.searchForItemWithName(name);
155-
await this.clickItemCheckbox(id);
156-
await this.clickDeleteSelected();
157-
await common.clickConfirmOnModal();
158-
}
124+
await this.header.waitUntilLoadingHasFinished();
125+
}
159126

160-
/**
161-
* Clicks item on Landing page by link name if it is present
162-
*/
163-
public async clickItemLink(appName: AppName, name: string) {
164-
await testSubjects.click(
165-
`${prefixMap[appName]}ListingTitleLink-${name.split(' ').join('-')}`
127+
/**
128+
* Searches for item on Landing page and retruns items count that match `ListingTitleLink-${name}` pattern
129+
*/
130+
public async searchAndExpectItemsCount(appName: AppName, name: string, count: number) {
131+
await this.searchForItemWithName(name);
132+
await this.retry.try(async () => {
133+
const links = await this.testSubjects.findAll(
134+
`${PREFIX_MAP[appName]}ListingTitleLink-${name.replace(/ /g, '-')}`
166135
);
167-
}
136+
expect(links.length).to.equal(count);
137+
});
138+
}
168139

169-
/**
170-
* Checks 'SelectAll' checkbox on
171-
*/
172-
public async checkListingSelectAllCheckbox() {
173-
const element = await testSubjects.find('checkboxSelectAll');
174-
const isSelected = await element.isSelected();
175-
if (!isSelected) {
176-
log.debug(`checking checkbox "checkboxSelectAll"`);
177-
await testSubjects.click('checkboxSelectAll');
178-
}
179-
}
140+
public async clickDeleteSelected() {
141+
await this.testSubjects.click('deleteSelectedItems');
142+
}
180143

181-
/**
182-
* Clicks NewItem button on Landing page
183-
* @param promptBtnTestSubj testSubj locator for Prompt button
184-
*/
185-
public async clickNewButton(promptBtnTestSubj: string): Promise<void> {
186-
await retry.tryForTime(20000, async () => {
187-
// newItemButton button is only visible when there are items in the listing table is displayed.
188-
const isnNewItemButtonPresent = await testSubjects.exists('newItemButton', {
189-
timeout: 10000,
190-
});
191-
if (isnNewItemButtonPresent) {
192-
await testSubjects.click('newItemButton');
193-
} else {
194-
// no items exist, click createPromptButton to create new dashboard/visualization
195-
await testSubjects.click(promptBtnTestSubj);
196-
}
197-
});
144+
public async clickItemCheckbox(id: string) {
145+
await this.testSubjects.click(`checkboxSelectRow-${id}`);
146+
}
147+
148+
/**
149+
* Searches for item by name, selects checbox and deletes it
150+
* @param name item name
151+
* @param id row id
152+
*/
153+
public async deleteItem(name: string, id: string) {
154+
await this.searchForItemWithName(name);
155+
await this.clickItemCheckbox(id);
156+
await this.clickDeleteSelected();
157+
await this.common.clickConfirmOnModal();
158+
}
159+
160+
/**
161+
* Clicks item on Landing page by link name if it is present
162+
*/
163+
public async clickItemLink(appName: AppName, name: string) {
164+
await this.testSubjects.click(
165+
`${PREFIX_MAP[appName]}ListingTitleLink-${name.split(' ').join('-')}`
166+
);
167+
}
168+
169+
/**
170+
* Checks 'SelectAll' checkbox on
171+
*/
172+
public async checkListingSelectAllCheckbox() {
173+
const element = await this.testSubjects.find('checkboxSelectAll');
174+
const isSelected = await element.isSelected();
175+
if (!isSelected) {
176+
this.log.debug(`checking checkbox "checkboxSelectAll"`);
177+
await this.testSubjects.click('checkboxSelectAll');
198178
}
179+
}
199180

200-
public async onListingPage(appName: AppName) {
201-
return await testSubjects.exists(`${appName}LandingPage`, {
202-
timeout: 5000,
181+
/**
182+
* Clicks NewItem button on Landing page
183+
* @param promptBtnTestSubj testSubj locator for Prompt button
184+
*/
185+
public async clickNewButton(promptBtnTestSubj: string): Promise<void> {
186+
await this.retry.tryForTime(20000, async () => {
187+
// newItemButton button is only visible when there are items in the listing table is displayed.
188+
const isnNewItemButtonPresent = await this.testSubjects.exists('newItemButton', {
189+
timeout: 10000,
203190
});
204-
}
191+
if (isnNewItemButtonPresent) {
192+
await this.testSubjects.click('newItemButton');
193+
} else {
194+
// no items exist, click createPromptButton to create new dashboard/visualization
195+
await this.testSubjects.click(promptBtnTestSubj);
196+
}
197+
});
205198
}
206199

207-
return new ListingTable();
200+
public async onListingPage(appName: AppName) {
201+
return await this.testSubjects.exists(`${appName}LandingPage`, {
202+
timeout: 5000,
203+
});
204+
}
208205
}

0 commit comments

Comments
 (0)