Skip to content

Commit f3c846c

Browse files
Spencerspalgerkibanamachine
authored
[ftr] migrate AppsMenuService to FtrService class (#100588)
Co-authored-by: spalger <spalger@users.noreply.github.com> Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
1 parent b6d5952 commit f3c846c

File tree

2 files changed

+111
-112
lines changed

2 files changed

+111
-112
lines changed

test/functional/services/apps_menu.ts

Lines changed: 109 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -6,133 +6,132 @@
66
* Side Public License, v 1.
77
*/
88

9-
import { FtrProviderContext } from '../ftr_provider_context';
9+
import { FtrService } from '../ftr_provider_context';
1010

11-
export function AppsMenuProvider({ getService, getPageObjects }: FtrProviderContext) {
12-
const testSubjects = getService('testSubjects');
13-
const log = getService('log');
14-
const config = getService('config');
15-
const defaultFindTimeout = config.get('timeouts.find');
16-
const find = getService('find');
11+
export class AppsMenuService extends FtrService {
12+
private readonly testSubjects = this.ctx.getService('testSubjects');
13+
private readonly log = this.ctx.getService('log');
14+
private readonly config = this.ctx.getService('config');
15+
private readonly find = this.ctx.getService('find');
1716

18-
return new (class AppsMenu {
19-
private async waitUntilLoadingHasFinished() {
20-
try {
21-
await this.isGlobalLoadingIndicatorVisible();
22-
} catch (exception) {
23-
if (exception.name === 'ElementNotVisible') {
24-
// selenium might just have been too slow to catch it
25-
} else {
26-
throw exception;
27-
}
17+
private readonly defaultFindTimeout = this.config.get('timeouts.find');
18+
19+
private async waitUntilLoadingHasFinished() {
20+
try {
21+
await this.isGlobalLoadingIndicatorVisible();
22+
} catch (exception) {
23+
if (exception.name === 'ElementNotVisible') {
24+
// selenium might just have been too slow to catch it
25+
} else {
26+
throw exception;
2827
}
29-
await this.awaitGlobalLoadingIndicatorHidden();
3028
}
29+
await this.awaitGlobalLoadingIndicatorHidden();
30+
}
3131

32-
private async isGlobalLoadingIndicatorVisible() {
33-
log.debug('isGlobalLoadingIndicatorVisible');
34-
return await testSubjects.exists('globalLoadingIndicator', { timeout: 1500 });
35-
}
32+
private async isGlobalLoadingIndicatorVisible() {
33+
this.log.debug('isGlobalLoadingIndicatorVisible');
34+
return await this.testSubjects.exists('globalLoadingIndicator', { timeout: 1500 });
35+
}
3636

37-
private async awaitGlobalLoadingIndicatorHidden() {
38-
await testSubjects.existOrFail('globalLoadingIndicator-hidden', {
39-
allowHidden: true,
40-
timeout: defaultFindTimeout * 10,
41-
});
42-
}
43-
/**
44-
* Close the collapsible nav
45-
* TODO #64541 can replace with a data-test-subj
46-
*/
47-
public async closeCollapsibleNav() {
48-
const CLOSE_BUTTON = '[data-test-subj=collapsibleNav] > button';
49-
if (await find.existsByCssSelector(CLOSE_BUTTON)) {
50-
// Close button is only visible when focused
51-
const button = await find.byCssSelector(CLOSE_BUTTON);
52-
await button.focus();
37+
private async awaitGlobalLoadingIndicatorHidden() {
38+
await this.testSubjects.existOrFail('globalLoadingIndicator-hidden', {
39+
allowHidden: true,
40+
timeout: this.defaultFindTimeout * 10,
41+
});
42+
}
43+
/**
44+
* Close the collapsible nav
45+
* TODO #64541 can replace with a data-test-subj
46+
*/
47+
public async closeCollapsibleNav() {
48+
const CLOSE_BUTTON = '[data-test-subj=collapsibleNav] > button';
49+
if (await this.find.existsByCssSelector(CLOSE_BUTTON)) {
50+
// Close button is only visible when focused
51+
const button = await this.find.byCssSelector(CLOSE_BUTTON);
52+
await button.focus();
5353

54-
await find.clickByCssSelector(CLOSE_BUTTON);
55-
}
54+
await this.find.clickByCssSelector(CLOSE_BUTTON);
5655
}
56+
}
5757

58-
public async openCollapsibleNav() {
59-
if (!(await testSubjects.exists('collapsibleNav'))) {
60-
await testSubjects.click('toggleNavButton');
61-
}
58+
public async openCollapsibleNav() {
59+
if (!(await this.testSubjects.exists('collapsibleNav'))) {
60+
await this.testSubjects.click('toggleNavButton');
6261
}
62+
}
6363

64-
/**
65-
* Get the attributes from each of the links in the apps menu
66-
*/
67-
public async readLinks() {
68-
// wait for the chrome to finish initializing
69-
await this.waitUntilLoadingHasFinished();
70-
await this.openCollapsibleNav();
71-
const appMenu = await testSubjects.find('collapsibleNav');
72-
const $ = await appMenu.parseDomContent();
73-
const links = $.findTestSubjects('collapsibleNavAppLink')
74-
.toArray()
75-
.map((link) => {
76-
return {
77-
text: $(link).text(),
78-
href: $(link).attr('href'),
79-
disabled: $(link).attr('disabled') != null,
80-
};
81-
});
64+
/**
65+
* Get the attributes from each of the links in the apps menu
66+
*/
67+
public async readLinks() {
68+
// wait for the chrome to finish initializing
69+
await this.waitUntilLoadingHasFinished();
70+
await this.openCollapsibleNav();
71+
const appMenu = await this.testSubjects.find('collapsibleNav');
72+
const $ = await appMenu.parseDomContent();
73+
const links = $.findTestSubjects('collapsibleNavAppLink')
74+
.toArray()
75+
.map((link) => {
76+
return {
77+
text: $(link).text(),
78+
href: $(link).attr('href'),
79+
disabled: $(link).attr('disabled') != null,
80+
};
81+
});
8282

83-
await this.closeCollapsibleNav();
83+
await this.closeCollapsibleNav();
8484

85-
return links;
86-
}
85+
return links;
86+
}
8787

88-
/**
89-
* Get the attributes from the link with the given name.
90-
* @param name
91-
*/
92-
public async getLink(name: string) {
93-
return (await this.readLinks()).find((nl) => nl.text === name);
94-
}
88+
/**
89+
* Get the attributes from the link with the given name.
90+
* @param name
91+
*/
92+
public async getLink(name: string) {
93+
return (await this.readLinks()).find((nl) => nl.text === name);
94+
}
9595

96-
/**
97-
* Determine if an app link with the given name exists
98-
* @param name
99-
*/
100-
public async linkExists(name: string) {
101-
return (await this.readLinks()).some((nl) => nl.text === name);
102-
}
96+
/**
97+
* Determine if an app link with the given name exists
98+
* @param name
99+
*/
100+
public async linkExists(name: string) {
101+
return (await this.readLinks()).some((nl) => nl.text === name);
102+
}
103103

104-
/**
105-
* Click the app link within the app menu that has the given name
106-
* @param name
107-
* @param options.closeCollapsibleNav
108-
* @param options.category - optional field to ensure that a link is clicked in a particular category
109-
* helpful when there may be a recent link with the same name as an app
110-
*/
111-
public async clickLink(
112-
name: string,
113-
{
114-
closeCollapsibleNav = true,
115-
category,
116-
}: { closeCollapsibleNav?: boolean; category?: string } = {}
117-
) {
118-
try {
119-
log.debug(`click "${name}" app link`);
120-
await this.openCollapsibleNav();
121-
let nav;
122-
if (typeof category === 'string') {
123-
nav = await testSubjects.find(`collapsibleNavGroup-${category}`);
124-
} else {
125-
nav = await testSubjects.find('collapsibleNav');
126-
}
127-
const link = await nav.findByPartialLinkText(name);
128-
await link.click();
104+
/**
105+
* Click the app link within the app menu that has the given name
106+
* @param name
107+
* @param options.closeCollapsibleNav
108+
* @param options.category - optional field to ensure that a link is clicked in a particular category
109+
* helpful when there may be a recent link with the same name as an app
110+
*/
111+
public async clickLink(
112+
name: string,
113+
{
114+
closeCollapsibleNav = true,
115+
category,
116+
}: { closeCollapsibleNav?: boolean; category?: string } = {}
117+
) {
118+
try {
119+
this.log.debug(`click "${name}" app link`);
120+
await this.openCollapsibleNav();
121+
let nav;
122+
if (typeof category === 'string') {
123+
nav = await this.testSubjects.find(`collapsibleNavGroup-${category}`);
124+
} else {
125+
nav = await this.testSubjects.find('collapsibleNav');
126+
}
127+
const link = await nav.findByPartialLinkText(name);
128+
await link.click();
129129

130-
if (closeCollapsibleNav) {
131-
await this.closeCollapsibleNav();
132-
}
133-
} finally {
134-
// Intentionally empty
130+
if (closeCollapsibleNav) {
131+
await this.closeCollapsibleNav();
135132
}
133+
} finally {
134+
// Intentionally empty
136135
}
137-
})();
136+
}
138137
}

test/functional/services/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

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

11-
import { AppsMenuProvider } from './apps_menu';
11+
import { AppsMenuService } from './apps_menu';
1212
import {
1313
BrowserProvider,
1414
FailureDebuggingProvider,
@@ -77,7 +77,7 @@ export const services = {
7777
inspector: InspectorService,
7878
fieldEditor: FieldEditorService,
7979
vegaDebugInspector: VegaDebugInspectorViewService,
80-
appsMenu: AppsMenuProvider,
80+
appsMenu: AppsMenuService,
8181
globalNav: GlobalNavService,
8282
toasts: ToastsService,
8383
savedQueryManagementComponent: SavedQueryManagementComponentProvider,

0 commit comments

Comments
 (0)