-
Notifications
You must be signed in to change notification settings - Fork 170
/
Copy pathperformance-marks.test.ts
135 lines (116 loc) · 4.66 KB
/
performance-marks.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import { BasePageObject } from '@cloudscape-design/browser-test-tools/page-objects';
import useBrowser from '@cloudscape-design/browser-test-tools/use-browser';
function setupTest(
pageName: string,
testFn: (parameters: {
page: BasePageObject;
getMarks: () => Promise<PerformanceMark[]>;
getElementPerformanceMarkText: (id: string) => Promise<string>;
}) => Promise<void>
) {
return useBrowser(async browser => {
const page = new BasePageObject(browser);
await browser.url(`#/light/button/${pageName}`);
const getMarks = async () => {
await new Promise(r => setTimeout(r, 200));
const marks = await browser.execute(() => performance.getEntriesByType('mark') as PerformanceMark[]);
return marks.filter(m => m.detail?.source === 'awsui');
};
const getElementPerformanceMarkText = (id: string) => page.getText(`[data-analytics-performance-mark="${id}"]`);
await testFn({ page, getMarks, getElementPerformanceMarkText });
});
}
describe('Button', () => {
test(
'Emits a mark only for primary visible buttons which are loaded',
setupTest('performance-marks', async ({ getMarks, getElementPerformanceMarkText }) => {
const marks = await getMarks();
expect(marks).toHaveLength(1);
expect(marks[0].name).toBe('primaryButtonRendered');
expect(marks[0].detail).toMatchObject({
source: 'awsui',
instanceIdentifier: expect.any(String),
loading: false,
disabled: false,
inViewport: true,
text: 'Primary button',
});
await expect(getElementPerformanceMarkText(marks[0].detail.instanceIdentifier)).resolves.toBe('Primary button');
})
);
test(
'Emits a mark when properties change',
setupTest('performance-marks', async ({ page, getMarks, getElementPerformanceMarkText }) => {
await page.click('#loading');
const marks = await getMarks();
expect(marks).toHaveLength(2);
expect(marks[0].name).toBe('primaryButtonRendered');
expect(marks[0].detail).toMatchObject({
source: 'awsui',
instanceIdentifier: marks[0].detail.instanceIdentifier,
loading: false,
disabled: false,
inViewport: true,
text: 'Primary button',
});
await expect(getElementPerformanceMarkText(marks[0].detail.instanceIdentifier)).resolves.toBe('Primary button');
expect(marks[1].name).toBe('primaryButtonUpdated');
expect(marks[1].detail).toMatchObject({
source: 'awsui',
instanceIdentifier: marks[1].detail.instanceIdentifier,
loading: false,
disabled: false,
inViewport: true,
text: 'Primary button with loading and disabled props',
});
await expect(getElementPerformanceMarkText(marks[1].detail.instanceIdentifier)).resolves.toBe(
'Primary button with loading and disabled props'
);
})
);
test(
'Does not emit a mark when inside a modal',
setupTest('performance-marks-in-modal', async ({ getMarks, getElementPerformanceMarkText }) => {
const marks = await getMarks();
expect(marks).toHaveLength(1);
expect(marks[0].detail).toMatchObject({
text: 'Button OUTSIDE modal',
});
await expect(getElementPerformanceMarkText(marks[0].detail.instanceIdentifier)).resolves.toBe(
'Button OUTSIDE modal'
);
})
);
test(
'Emits a mark when evaluateComponentVisibility event for loaded button components',
setupTest('performance-marks', async ({ page, getMarks, getElementPerformanceMarkText }) => {
let marks = await getMarks();
expect(marks).toHaveLength(1);
await page.click('#evaluateComponentVisibility');
marks = await getMarks();
expect(marks).toHaveLength(2);
expect(marks[0].name).toBe('primaryButtonRendered');
expect(marks[0].detail).toMatchObject({
source: 'awsui',
instanceIdentifier: marks[0].detail.instanceIdentifier,
loading: false,
disabled: false,
inViewport: true,
text: 'Primary button',
});
await expect(getElementPerformanceMarkText(marks[0].detail.instanceIdentifier)).resolves.toBe('Primary button');
expect(marks[1].name).toBe('primaryButtonUpdated');
expect(marks[1].detail).toMatchObject({
source: 'awsui',
instanceIdentifier: marks[1].detail.instanceIdentifier,
loading: false,
disabled: false,
inViewport: true,
text: 'Primary button',
});
await expect(getElementPerformanceMarkText(marks[1].detail.instanceIdentifier)).resolves.toBe('Primary button');
})
);
});