|
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 | 11 | const RENDER_COMPLETE_SELECTOR = '[data-render-complete="true"]'; |
12 | 12 | const RENDER_COMPLETE_PENDING_SELECTOR = '[data-render-complete="false"]'; |
13 | 13 | const DATA_LOADING_SELECTOR = '[data-loading]'; |
14 | 14 |
|
15 | | -export function RenderableProvider({ getService }: FtrProviderContext) { |
16 | | - const log = getService('log'); |
17 | | - const retry = getService('retry'); |
18 | | - const find = getService('find'); |
| 15 | +export class RenderableService extends FtrService { |
| 16 | + private readonly log = this.ctx.getService('log'); |
| 17 | + private readonly retry = this.ctx.getService('retry'); |
| 18 | + private readonly find = this.ctx.getService('find'); |
19 | 19 |
|
20 | | - class Renderable { |
21 | | - /** |
22 | | - * This method waits for a certain number of objects to finish rendering and loading, which is indicated |
23 | | - * by a couple tags. The RENDER_COMPLETE_SELECTOR indicates that it's done initially loading up. Some |
24 | | - * visualizations also add a DATA_LOADING_SELECTOR when the internal data is loading. This test will not |
25 | | - * return if any of those tags are found. |
26 | | - * @param count {Number} Number of RENDER_COMPLETE_SELECTORs to wait for. |
27 | | - */ |
28 | | - public async waitForRender(count: number = 1): Promise<void> { |
29 | | - log.debug(`Renderable.waitForRender for ${count} elements`); |
30 | | - await retry.try(async () => { |
31 | | - const completedElements = await find.allByCssSelector(RENDER_COMPLETE_SELECTOR); |
32 | | - if (completedElements.length < count) { |
33 | | - const pendingElements = await find.allByCssSelector(RENDER_COMPLETE_PENDING_SELECTOR); |
34 | | - const pendingElementNames = []; |
35 | | - for (const pendingElement of pendingElements) { |
36 | | - const title = await pendingElement.getAttribute('data-title'); |
37 | | - pendingElementNames.push(title); |
38 | | - } |
39 | | - throw new Error(`${ |
40 | | - completedElements.length |
41 | | - } elements completed rendering, still waiting on a total of ${count} |
42 | | - specifically:\n${pendingElementNames.join('\n')}`); |
| 20 | + /** |
| 21 | + * This method waits for a certain number of objects to finish rendering and loading, which is indicated |
| 22 | + * by a couple tags. The RENDER_COMPLETE_SELECTOR indicates that it's done initially loading up. Some |
| 23 | + * visualizations also add a DATA_LOADING_SELECTOR when the internal data is loading. This test will not |
| 24 | + * return if any of those tags are found. |
| 25 | + * @param count {Number} Number of RENDER_COMPLETE_SELECTORs to wait for. |
| 26 | + */ |
| 27 | + public async waitForRender(count: number = 1): Promise<void> { |
| 28 | + this.log.debug(`Renderable.waitForRender for ${count} elements`); |
| 29 | + await this.retry.try(async () => { |
| 30 | + const completedElements = await this.find.allByCssSelector(RENDER_COMPLETE_SELECTOR); |
| 31 | + if (completedElements.length < count) { |
| 32 | + const pendingElements = await this.find.allByCssSelector(RENDER_COMPLETE_PENDING_SELECTOR); |
| 33 | + const pendingElementNames = []; |
| 34 | + for (const pendingElement of pendingElements) { |
| 35 | + const title = await pendingElement.getAttribute('data-title'); |
| 36 | + pendingElementNames.push(title); |
43 | 37 | } |
| 38 | + throw new Error(`${ |
| 39 | + completedElements.length |
| 40 | + } elements completed rendering, still waiting on a total of ${count} |
| 41 | + specifically:\n${pendingElementNames.join('\n')}`); |
| 42 | + } |
44 | 43 |
|
45 | | - const stillLoadingElements = await find.allByCssSelector(DATA_LOADING_SELECTOR, 1000); |
46 | | - if (stillLoadingElements.length > 0) { |
47 | | - throw new Error(`${stillLoadingElements.length} elements still loading contents`); |
48 | | - } |
49 | | - }); |
50 | | - } |
| 44 | + const stillLoadingElements = await this.find.allByCssSelector(DATA_LOADING_SELECTOR, 1000); |
| 45 | + if (stillLoadingElements.length > 0) { |
| 46 | + throw new Error(`${stillLoadingElements.length} elements still loading contents`); |
| 47 | + } |
| 48 | + }); |
51 | 49 | } |
52 | | - |
53 | | - return new Renderable(); |
54 | 50 | } |
0 commit comments