|
6 | 6 | * Side Public License, v 1. |
7 | 7 | */ |
8 | 8 |
|
9 | | -import { FtrProviderContext } from '../ftr_provider_context'; |
| 9 | +import { FtrService } from '../ftr_provider_context'; |
10 | 10 |
|
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'); |
17 | 16 |
|
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; |
28 | 27 | } |
29 | | - await this.awaitGlobalLoadingIndicatorHidden(); |
30 | 28 | } |
| 29 | + await this.awaitGlobalLoadingIndicatorHidden(); |
| 30 | + } |
31 | 31 |
|
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 | + } |
36 | 36 |
|
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(); |
53 | 53 |
|
54 | | - await find.clickByCssSelector(CLOSE_BUTTON); |
55 | | - } |
| 54 | + await this.find.clickByCssSelector(CLOSE_BUTTON); |
56 | 55 | } |
| 56 | + } |
57 | 57 |
|
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'); |
62 | 61 | } |
| 62 | + } |
63 | 63 |
|
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 | + }); |
82 | 82 |
|
83 | | - await this.closeCollapsibleNav(); |
| 83 | + await this.closeCollapsibleNav(); |
84 | 84 |
|
85 | | - return links; |
86 | | - } |
| 85 | + return links; |
| 86 | + } |
87 | 87 |
|
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 | + } |
95 | 95 |
|
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 | + } |
103 | 103 |
|
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(); |
129 | 129 |
|
130 | | - if (closeCollapsibleNav) { |
131 | | - await this.closeCollapsibleNav(); |
132 | | - } |
133 | | - } finally { |
134 | | - // Intentionally empty |
| 130 | + if (closeCollapsibleNav) { |
| 131 | + await this.closeCollapsibleNav(); |
135 | 132 | } |
| 133 | + } finally { |
| 134 | + // Intentionally empty |
136 | 135 | } |
137 | | - })(); |
| 136 | + } |
138 | 137 | } |
0 commit comments