Skip to content

Commit

Permalink
[ftr] migrate AppsMenuService to FtrService class (#100588) (#100745)
Browse files Browse the repository at this point in the history
Co-authored-by: spalger <[email protected]>
Co-authored-by: Kibana Machine <[email protected]>

Co-authored-by: Spencer <[email protected]>
Co-authored-by: spalger <[email protected]>
  • Loading branch information
3 people authored May 26, 2021
1 parent ced8ee5 commit df8ba92
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 112 deletions.
219 changes: 109 additions & 110 deletions test/functional/services/apps_menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,133 +6,132 @@
* Side Public License, v 1.
*/

import { FtrProviderContext } from '../ftr_provider_context';
import { FtrService } from '../ftr_provider_context';

export function AppsMenuProvider({ getService, getPageObjects }: FtrProviderContext) {
const testSubjects = getService('testSubjects');
const log = getService('log');
const config = getService('config');
const defaultFindTimeout = config.get('timeouts.find');
const find = getService('find');
export class AppsMenuService extends FtrService {
private readonly testSubjects = this.ctx.getService('testSubjects');
private readonly log = this.ctx.getService('log');
private readonly config = this.ctx.getService('config');
private readonly find = this.ctx.getService('find');

return new (class AppsMenu {
private async waitUntilLoadingHasFinished() {
try {
await this.isGlobalLoadingIndicatorVisible();
} catch (exception) {
if (exception.name === 'ElementNotVisible') {
// selenium might just have been too slow to catch it
} else {
throw exception;
}
private readonly defaultFindTimeout = this.config.get('timeouts.find');

private async waitUntilLoadingHasFinished() {
try {
await this.isGlobalLoadingIndicatorVisible();
} catch (exception) {
if (exception.name === 'ElementNotVisible') {
// selenium might just have been too slow to catch it
} else {
throw exception;
}
await this.awaitGlobalLoadingIndicatorHidden();
}
await this.awaitGlobalLoadingIndicatorHidden();
}

private async isGlobalLoadingIndicatorVisible() {
log.debug('isGlobalLoadingIndicatorVisible');
return await testSubjects.exists('globalLoadingIndicator', { timeout: 1500 });
}
private async isGlobalLoadingIndicatorVisible() {
this.log.debug('isGlobalLoadingIndicatorVisible');
return await this.testSubjects.exists('globalLoadingIndicator', { timeout: 1500 });
}

private async awaitGlobalLoadingIndicatorHidden() {
await testSubjects.existOrFail('globalLoadingIndicator-hidden', {
allowHidden: true,
timeout: defaultFindTimeout * 10,
});
}
/**
* Close the collapsible nav
* TODO #64541 can replace with a data-test-subj
*/
public async closeCollapsibleNav() {
const CLOSE_BUTTON = '[data-test-subj=collapsibleNav] > button';
if (await find.existsByCssSelector(CLOSE_BUTTON)) {
// Close button is only visible when focused
const button = await find.byCssSelector(CLOSE_BUTTON);
await button.focus();
private async awaitGlobalLoadingIndicatorHidden() {
await this.testSubjects.existOrFail('globalLoadingIndicator-hidden', {
allowHidden: true,
timeout: this.defaultFindTimeout * 10,
});
}
/**
* Close the collapsible nav
* TODO #64541 can replace with a data-test-subj
*/
public async closeCollapsibleNav() {
const CLOSE_BUTTON = '[data-test-subj=collapsibleNav] > button';
if (await this.find.existsByCssSelector(CLOSE_BUTTON)) {
// Close button is only visible when focused
const button = await this.find.byCssSelector(CLOSE_BUTTON);
await button.focus();

await find.clickByCssSelector(CLOSE_BUTTON);
}
await this.find.clickByCssSelector(CLOSE_BUTTON);
}
}

public async openCollapsibleNav() {
if (!(await testSubjects.exists('collapsibleNav'))) {
await testSubjects.click('toggleNavButton');
}
public async openCollapsibleNav() {
if (!(await this.testSubjects.exists('collapsibleNav'))) {
await this.testSubjects.click('toggleNavButton');
}
}

/**
* Get the attributes from each of the links in the apps menu
*/
public async readLinks() {
// wait for the chrome to finish initializing
await this.waitUntilLoadingHasFinished();
await this.openCollapsibleNav();
const appMenu = await testSubjects.find('collapsibleNav');
const $ = await appMenu.parseDomContent();
const links = $.findTestSubjects('collapsibleNavAppLink')
.toArray()
.map((link) => {
return {
text: $(link).text(),
href: $(link).attr('href'),
disabled: $(link).attr('disabled') != null,
};
});
/**
* Get the attributes from each of the links in the apps menu
*/
public async readLinks() {
// wait for the chrome to finish initializing
await this.waitUntilLoadingHasFinished();
await this.openCollapsibleNav();
const appMenu = await this.testSubjects.find('collapsibleNav');
const $ = await appMenu.parseDomContent();
const links = $.findTestSubjects('collapsibleNavAppLink')
.toArray()
.map((link) => {
return {
text: $(link).text(),
href: $(link).attr('href'),
disabled: $(link).attr('disabled') != null,
};
});

await this.closeCollapsibleNav();
await this.closeCollapsibleNav();

return links;
}
return links;
}

/**
* Get the attributes from the link with the given name.
* @param name
*/
public async getLink(name: string) {
return (await this.readLinks()).find((nl) => nl.text === name);
}
/**
* Get the attributes from the link with the given name.
* @param name
*/
public async getLink(name: string) {
return (await this.readLinks()).find((nl) => nl.text === name);
}

/**
* Determine if an app link with the given name exists
* @param name
*/
public async linkExists(name: string) {
return (await this.readLinks()).some((nl) => nl.text === name);
}
/**
* Determine if an app link with the given name exists
* @param name
*/
public async linkExists(name: string) {
return (await this.readLinks()).some((nl) => nl.text === name);
}

/**
* Click the app link within the app menu that has the given name
* @param name
* @param options.closeCollapsibleNav
* @param options.category - optional field to ensure that a link is clicked in a particular category
* helpful when there may be a recent link with the same name as an app
*/
public async clickLink(
name: string,
{
closeCollapsibleNav = true,
category,
}: { closeCollapsibleNav?: boolean; category?: string } = {}
) {
try {
log.debug(`click "${name}" app link`);
await this.openCollapsibleNav();
let nav;
if (typeof category === 'string') {
nav = await testSubjects.find(`collapsibleNavGroup-${category}`);
} else {
nav = await testSubjects.find('collapsibleNav');
}
const link = await nav.findByPartialLinkText(name);
await link.click();
/**
* Click the app link within the app menu that has the given name
* @param name
* @param options.closeCollapsibleNav
* @param options.category - optional field to ensure that a link is clicked in a particular category
* helpful when there may be a recent link with the same name as an app
*/
public async clickLink(
name: string,
{
closeCollapsibleNav = true,
category,
}: { closeCollapsibleNav?: boolean; category?: string } = {}
) {
try {
this.log.debug(`click "${name}" app link`);
await this.openCollapsibleNav();
let nav;
if (typeof category === 'string') {
nav = await this.testSubjects.find(`collapsibleNavGroup-${category}`);
} else {
nav = await this.testSubjects.find('collapsibleNav');
}
const link = await nav.findByPartialLinkText(name);
await link.click();

if (closeCollapsibleNav) {
await this.closeCollapsibleNav();
}
} finally {
// Intentionally empty
if (closeCollapsibleNav) {
await this.closeCollapsibleNav();
}
} finally {
// Intentionally empty
}
})();
}
}
4 changes: 2 additions & 2 deletions test/functional/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import { services as commonServiceProviders } from '../../common/services';

import { AppsMenuProvider } from './apps_menu';
import { AppsMenuService } from './apps_menu';
import {
BrowserProvider,
FailureDebuggingProvider,
Expand Down Expand Up @@ -77,7 +77,7 @@ export const services = {
inspector: InspectorService,
fieldEditor: FieldEditorService,
vegaDebugInspector: VegaDebugInspectorViewService,
appsMenu: AppsMenuProvider,
appsMenu: AppsMenuService,
globalNav: GlobalNavService,
toasts: ToastsService,
savedQueryManagementComponent: SavedQueryManagementComponentProvider,
Expand Down

0 comments on commit df8ba92

Please sign in to comment.