Skip to content

Commit

Permalink
Extract common functionality to service
Browse files Browse the repository at this point in the history
  • Loading branch information
Maja Grubic committed Feb 28, 2023
1 parent 4d70c00 commit aaf7209
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 18 deletions.
20 changes: 2 additions & 18 deletions test/functional/services/dashboard/add_panel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
* 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';
import { WebElementWrapper } from '../lib/web_element_wrapper';

export class DashboardAddPanelService extends FtrService {
private readonly log = this.ctx.getService('log');
Expand Down Expand Up @@ -151,27 +149,13 @@ export class DashboardAddPanelService extends FtrService {
await this.flyout.ensureClosed('dashboardAddPanel');
}

async getRowAtIndex(rows: WebElementWrapper[], rowIndex: number) {
const cell = await rows[rowIndex].findByTestSubject('savedObjectFinderTitle');
const button = await cell.findByTagName('button');
const name = await button.getVisibleText();
return { button, name };
}

async addEveryVisualization(filter: string) {
this.log.debug('DashboardAddPanel.addEveryVisualization');
await this.ensureAddPanelIsShowing();
if (filter) {
await this.savedObjectsFinder.filterEmbeddableNames(filter.replace('-', ' '));
}
await this.savedObjectsFinder.toggleFilter('Visualization');
const itemList = await this.testSubjects.find('savedObjectsFinderTable');
await this.retry.try(async () => {
const embeddableListBody = await itemList.findByTagName('tbody');
const embeddableRows = await embeddableListBody.findAllByCssSelector('tr');
const { name } = await this.getRowAtIndex(embeddableRows, 0);
expect(name.includes('search')).to.be(false);
});
await this.savedObjectsFinder.waitForFilter('Visualization', 'search');
let morePages = true;
const vizList: string[][] = [];
while (morePages) {
Expand All @@ -189,7 +173,7 @@ export class DashboardAddPanelService extends FtrService {
if (filter) {
await this.savedObjectsFinder.filterEmbeddableNames(filter.replace('-', ' '));
}
await this.savedObjectsFinder.toggleFilter('Saved search');
await this.savedObjectsFinder.waitForFilter('Saved search', 'visualization');
let morePages = true;
while (morePages) {
searchList.push(await this.addEveryEmbeddableOnCurrentPage());
Expand Down
21 changes: 21 additions & 0 deletions test/functional/services/saved_objects_finder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@
* Side Public License, v 1.
*/

import expect from '@kbn/expect';
import { FtrService } from '../ftr_provider_context';
import { WebElementWrapper } from './lib/web_element_wrapper';

export class SavedObjectsFinderService 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');

public async toggleFilterPopover() {
this.log.debug('SavedObjectsFinder.toggleFilter');
Expand All @@ -37,13 +40,31 @@ export class SavedObjectsFinderService extends FtrService {
}
}

public async waitForFilter(type: string, expectCondition: string) {
await this.toggleFilter(type);
const itemList = await this.testSubjects.find('savedObjectsFinderTable');
await this.retry.try(async () => {
const embeddableListBody = await itemList.findByTagName('tbody');
const embeddableRows = await embeddableListBody.findAllByCssSelector('tr');
const { name } = await this.getRowAtIndex(embeddableRows, 0);
expect(name.includes(expectCondition)).to.be(false);
});
}

public async filterEmbeddableNames(name: string) {
// The search input field may be disabled while the table is loading so wait for it
await this.waitForListLoading();
await this.testSubjects.setValue('savedObjectFinderSearchInput', name);
await this.waitForListLoading();
}

private async getRowAtIndex(rows: WebElementWrapper[], rowIndex: number) {
const cell = await rows[rowIndex].findByTestSubject('savedObjectFinderTitle');
const button = await cell.findByTagName('button');
const name = await button.getVisibleText();
return { button, name };
}

private async waitForListLoading() {
await this.testSubjects.waitForDeleted('savedObjectFinderLoadingIndicator');
}
Expand Down

0 comments on commit aaf7209

Please sign in to comment.