-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathViewComponentTest.test.ts
More file actions
230 lines (221 loc) · 8.78 KB
/
ViewComponentTest.test.ts
File metadata and controls
230 lines (221 loc) · 8.78 KB
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
/**
* Copyright (c) Microsoft Corporation.
* Licensed under the MIT License.
*
* @format
*/
import {dumpVisualTree} from '@react-native-windows/automation-commands';
import {goToComponentExample} from './RNTesterNavigation';
import {app} from '@react-native-windows/automation';
import {verifyNoErrorLogs} from './Helpers';
beforeAll(async () => {
// If window is partially offscreen, tests will fail to click on certain elements
await app.setWindowPosition(0, 0);
await app.setWindowSize(1000, 1250);
await goToComponentExample('View');
});
afterEach(async () => {
await verifyNoErrorLogs();
});
const searchBox = async (input: string) => {
const searchBox = await app.findElementByTestID('example_search');
await app.waitUntil(
async () => {
await searchBox.setValue(input);
return (await searchBox.getText()) === input;
},
{
interval: 1500,
timeout: 5000,
timeoutMsg: `Unable to enter correct search text into test searchbox.`,
},
);
};
describe('View Tests', () => {
test('Views can have shadows', async () => {
await searchBox('sha');
const component = await app.findElementByTestID('shadow');
await component.waitForDisplayed({timeout: 5000});
const dump = await dumpVisualTree('shadow');
expect(dump).toMatchSnapshot();
});
test('Views can have border styles', async () => {
await searchBox('sty');
const componentsTab = await app.findElementByTestID('border-style-button');
await componentsTab.waitForDisplayed({timeout: 5000});
const dump = await dumpVisualTree('border-style-button');
expect(dump).toMatchSnapshot();
});
test('Views can have offscreen alpha compositing', async () => {
await searchBox('off');
const componentsTab = await app.findElementByTestID(
'offscreen-alpha-compositing-button',
);
await componentsTab.waitForDisplayed({timeout: 5000});
const dump = await dumpVisualTree('offscreen-alpha-compositing-button');
expect(dump).toMatchSnapshot();
});
test('Views can have a z-index', async () => {
await searchBox('z');
const componentsTab = await app.findElementByTestID('z-index-button');
await componentsTab.waitForDisplayed({timeout: 5000});
const dump = await dumpVisualTree('z-index-button');
expect(dump).toMatchSnapshot();
});
test('Views can have display: none', async () => {
await searchBox('dis');
const componentsTab = await app.findElementByTestID('display-none-button');
await componentsTab.waitForDisplayed({timeout: 5000});
const dump = await dumpVisualTree('display-none-button');
expect(dump).toMatchSnapshot();
});
// NEW CODE
test('Views can have background color', async () => {
await searchBox('back');
const componentsTab = await app.findElementByTestID(
'view-test-background-color',
);
await componentsTab.waitForDisplayed({timeout: 5000});
const dump = await dumpVisualTree('view-test-background-color');
expect(dump).toMatchSnapshot();
});
test('Views can have borders', async () => {
await searchBox('bor');
const componentsTab = await app.findElementByTestID('view-test-border');
await componentsTab.waitForDisplayed({timeout: 5000});
const dump = await dumpVisualTree('view-test-border');
expect(dump).toMatchSnapshot();
});
test('Views can have customized pasdding and margins', async () => {
await searchBox('pad');
const componentsTab = await app.findElementByTestID(
'view-test-padding-margin',
);
await componentsTab.waitForDisplayed({timeout: 5000});
const dump = await dumpVisualTree('view-test-padding-margin');
expect(dump).toMatchSnapshot();
});
test('Views can have rounded borders', async () => {
await searchBox('bor');
const componentsTab = await app.findElementByTestID(
'view-test-rounded-borders',
);
await componentsTab.waitForDisplayed({timeout: 5000});
const dump = await dumpVisualTree('view-test-rounded-borders');
expect(dump).toMatchSnapshot();
});
test('Views can have overflow', async () => {
await searchBox('ove');
const componentsTab = await app.findElementByTestID('view-test-overflow');
await componentsTab.waitForDisplayed({timeout: 5000});
const dump = await dumpVisualTree('view-test-overflow');
expect(dump).toMatchSnapshot();
});
test('Views can have rounded borders', async () => {
await searchBox('bor');
const componentsTab = await app.findElementByTestID(
'view-test-rounded-borders',
);
await componentsTab.waitForDisplayed({timeout: 5000});
const dump = await dumpVisualTree('view-test-rounded-borders');
expect(dump).toMatchSnapshot();
});
test('Views can have customized opacity', async () => {
await searchBox('opa');
const componentsTab = await app.findElementByTestID('view-test-opacity');
await componentsTab.waitForDisplayed({timeout: 5000});
const dump = await dumpVisualTree('view-test-opacity');
expect(dump).toMatchSnapshot();
});
test('Views can have tooltips', async () => {
await searchBox('too');
const componentsTab = await app.findElementByTestID('tool-tip');
await componentsTab.waitForDisplayed({timeout: 5000});
const dump = await dumpVisualTree('tool-tip');
expect(dump).toMatchSnapshot();
});
test('Views can have backface visibility', async () => {
await searchBox('bac');
const componentsTab = await app.findElementByTestID(
'view-test-backface-visibility',
);
await componentsTab.waitForDisplayed({timeout: 5000});
const dump = await dumpVisualTree('view-test-backface-visibility');
expect(dump).toMatchSnapshot();
});
test('Views can have aria-labels', async () => {
await searchBox('ari');
const componentsTab = await app.findElementByTestID('view-test-aria-label');
await componentsTab.waitForDisplayed({timeout: 5000});
const dump = await dumpVisualTree('view-test-aria-label');
expect(dump).toMatchSnapshot();
});
test('Views can have flexgap', async () => {
await searchBox('fle');
const componentsTab = await app.findElementByTestID('view-test-flexgap');
await componentsTab.waitForDisplayed({timeout: 5000});
const dump = await dumpVisualTree('view-test-flexgap');
expect(dump).toMatchSnapshot();
});
test('Views can have insets', async () => {
await searchBox('ins');
const componentsTab = await app.findElementByTestID('view-test-insets');
await componentsTab.waitForDisplayed({timeout: 5000});
const dump = await dumpVisualTree('view-test-insets');
expect(dump).toMatchSnapshot();
});
test('Views can have customized accessibility', async () => {
await searchBox('acc');
const componentsTab = await app.findElementByTestID('accessibility');
await componentsTab.waitForDisplayed({timeout: 5000});
const dump = await dumpVisualTree('accessibility');
expect(dump).toMatchSnapshot();
});
test('Views can have a hitslop region', async () => {
await searchBox('hit');
const componentsTab = await app.findElementByTestID('hitslop');
await componentsTab.waitForDisplayed({timeout: 5000});
const dump = await dumpVisualTree('hitslop');
expect(dump).toMatchSnapshot();
});
test('Views can have logical border colors', async () => {
await searchBox('log');
const componentsTab = await app.findElementByTestID(
'view-test-logical-border-color',
);
await componentsTab.waitForDisplayed({timeout: 5000});
const dump = await dumpVisualTree('view-test-logical-border-color');
expect(dump).toMatchSnapshot();
});
test('Views can have a nativeid', async () => {
await searchBox('nat');
const componentsTab = await app.findElementByTestID('nativeid');
await componentsTab.waitForDisplayed({timeout: 5000});
const dump = await dumpVisualTree('nativeid');
expect(dump).toMatchSnapshot();
});
test('Views should update style upon fast refresh', async () => {
await searchBox('fas');
const componentsTab = await app.findElementByTestID('view-test-fast-refresh');
await componentsTab.waitForDisplayed({timeout: 5000});
// Take initial snapshot
const initialDump = await dumpVisualTree('view-test-fast-refresh');
expect(initialDump).toMatchSnapshot('initial-state');
// Click to change style (simulating fast refresh behavior)
await componentsTab.click();
// Wait a moment for the style change to apply
await app.waitUntil(
async () => {
const currentDump = await dumpVisualTree('view-test-fast-refresh');
return currentDump !== initialDump;
},
{
timeout: 3000,
timeoutMsg: 'View style did not update after interaction',
}
);
// Take snapshot after style change
const updatedDump = await dumpVisualTree('view-test-fast-refresh');
expect(updatedDump).toMatchSnapshot('updated-state');
});
});