|
1 | 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
2 | 2 | // SPDX-License-Identifier: Apache-2.0 |
| 3 | + |
3 | 4 | import { BasePageObject } from '@cloudscape-design/browser-test-tools/page-objects'; |
4 | 5 | import useBrowser from '@cloudscape-design/browser-test-tools/use-browser'; |
5 | 6 |
|
6 | | -function setupTest( |
7 | | - pageName: string, |
8 | | - testFn: (parameters: { |
9 | | - page: BasePageObject; |
10 | | - getMarks: () => Promise<PerformanceMark[]>; |
11 | | - getElementPerformanceMarkText: (id: string) => Promise<string>; |
12 | | - }) => Promise<void> |
13 | | -) { |
14 | | - return useBrowser(async browser => { |
15 | | - const page = new BasePageObject(browser); |
16 | | - await browser.url(`#/light/button-dropdown/${pageName}`); |
17 | | - const getMarks = async () => { |
18 | | - await new Promise(r => setTimeout(r, 200)); |
19 | | - const marks = await browser.execute(() => performance.getEntriesByType('mark') as PerformanceMark[]); |
20 | | - return marks.filter(m => m.detail?.source === 'awsui'); |
21 | | - }; |
22 | | - const getElementPerformanceMarkText = (id: string) => page.getText(`[data-analytics-performance-mark="${id}"]`); |
23 | | - |
24 | | - await testFn({ page, getMarks, getElementPerformanceMarkText }); |
25 | | - }); |
| 7 | +function getMarkSelector(mark: PerformanceMark) { |
| 8 | + return `[data-analytics-performance-mark="${mark.detail.instanceIdentifier}"]`; |
26 | 9 | } |
27 | 10 |
|
28 | | -describe('ButtonDropdown', () => { |
29 | | - test( |
30 | | - 'Emits a single mark', |
31 | | - setupTest('main-action', async ({ getMarks, getElementPerformanceMarkText }) => { |
32 | | - const marks = await getMarks(); |
| 11 | +test( |
| 12 | + 'ButtonDropdown emits a single mark', |
| 13 | + useBrowser(async browser => { |
| 14 | + const page = new BasePageObject(browser); |
| 15 | + await browser.url('#/light/button-dropdown/main-action'); |
| 16 | + await new Promise(r => setTimeout(r, 200)); |
| 17 | + |
| 18 | + await page.waitForAssertion(async () => { |
| 19 | + const allMarks = await browser.execute(() => performance.getEntriesByType('mark') as PerformanceMark[]); |
| 20 | + const awsuiMarks = allMarks.filter(m => m.detail?.source === 'awsui'); |
33 | 21 |
|
34 | | - expect(marks).toHaveLength(1); |
35 | | - expect(marks[0].name).toBe('primaryButtonRendered'); |
36 | | - expect(marks[0].detail).toMatchObject({ |
| 22 | + expect(awsuiMarks).toHaveLength(1); |
| 23 | + expect(awsuiMarks[0].name).toBe('primaryButtonRendered'); |
| 24 | + expect(awsuiMarks[0].detail).toMatchObject({ |
37 | 25 | source: 'awsui', |
38 | 26 | instanceIdentifier: expect.any(String), |
39 | 27 | loading: false, |
40 | 28 | disabled: false, |
41 | 29 | inViewport: true, |
42 | 30 | text: 'Launch instance', |
43 | 31 | }); |
44 | | - |
45 | | - await expect(getElementPerformanceMarkText(marks[0].detail.instanceIdentifier)).resolves.toBe('Launch instance'); |
46 | | - }) |
47 | | - ); |
48 | | -}); |
| 32 | + await expect(page.getText(getMarkSelector(awsuiMarks[0]))).resolves.toBe('Launch instance'); |
| 33 | + }); |
| 34 | + }) |
| 35 | +); |
0 commit comments