|
7 | 7 | */ |
8 | 8 |
|
9 | 9 | import expect from '@kbn/expect'; |
10 | | -import { FtrProviderContext } from '../ftr_provider_context'; |
| 10 | +import { FtrService } from '../ftr_provider_context'; |
11 | 11 |
|
12 | | -type AppName = 'visualize' | 'dashboard' | 'map'; |
| 12 | +type AppName = keyof typeof PREFIX_MAP; |
| 13 | +const PREFIX_MAP = { visualize: 'vis', dashboard: 'dashboard', map: 'map' }; |
13 | 14 |
|
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; |
21 | 22 |
|
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 | + } |
26 | 26 |
|
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 | + } |
34 | 34 |
|
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 | + } |
43 | 43 |
|
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()); |
52 | 49 | } |
| 50 | + this.log.debug(`Found ${visualizationNames.length} visualizations on current page`); |
| 51 | + return visualizationNames; |
| 52 | + } |
53 | 53 |
|
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 | + ); |
67 | 59 |
|
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'); |
84 | 64 | } |
85 | | - return visualizationNames; |
86 | | - } |
| 65 | + }); |
| 66 | + } |
87 | 67 |
|
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 | + } |
98 | 84 | } |
| 85 | + return visualizationNames; |
| 86 | + } |
99 | 87 |
|
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 | + } |
123 | 99 |
|
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}`); |
126 | 106 |
|
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(); |
139 | 111 |
|
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 | + } |
143 | 119 |
|
144 | | - public async clickItemCheckbox(id: string) { |
145 | | - await testSubjects.click(`checkboxSelectRow-${id}`); |
146 | | - } |
| 120 | + await searchFilter.type(name); |
| 121 | + await this.common.pressEnterKey(); |
| 122 | + }); |
147 | 123 |
|
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 | + } |
159 | 126 |
|
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, '-')}` |
166 | 135 | ); |
167 | | - } |
| 136 | + expect(links.length).to.equal(count); |
| 137 | + }); |
| 138 | + } |
168 | 139 |
|
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 | + } |
180 | 143 |
|
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'); |
198 | 178 | } |
| 179 | + } |
199 | 180 |
|
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, |
203 | 190 | }); |
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 | + }); |
205 | 198 | } |
206 | 199 |
|
207 | | - return new ListingTable(); |
| 200 | + public async onListingPage(appName: AppName) { |
| 201 | + return await this.testSubjects.exists(`${appName}LandingPage`, { |
| 202 | + timeout: 5000, |
| 203 | + }); |
| 204 | + } |
208 | 205 | } |
0 commit comments