This repository was archived by the owner on May 19, 2025. It is now read-only.
forked from replayio-public/react-hook-form
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasicSchemaValidation.spec.ts
More file actions
209 lines (192 loc) · 9 KB
/
basicSchemaValidation.spec.ts
File metadata and controls
209 lines (192 loc) · 9 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
import { expect, test } from '@playwright/test';
test.describe('basicSchemaValidation form validation', () => {
test('should validate the form with onSubmit mode', async ({ page }) => {
await page.goto('http://localhost:3000/basic-schema-validation/onSubmit');
await page.locator('button').click();
const firstNameInput = page.locator('input[name="firstName"]');
await firstNameInput.click(); // this ensures the input is focused
const isFocused = await page.evaluate(
(input) => document.activeElement === input,
await firstNameInput.elementHandle(),
);
expect(isFocused).toBe(true);
await expect(page.locator('input[name="firstName"] + p')).toContainText(
'firstName error',
);
await expect(page.locator('input[name="lastName"] + p')).toContainText(
'lastName error',
);
await expect(page.locator('select[name="selectNumber"] + p')).toContainText(
'selectNumber error',
);
await expect(
page.locator('input[name="minRequiredLength"] + p'),
).toContainText('minRequiredLength error');
await expect(page.locator('input[name="radio"] + p')).toContainText(
'radio error',
);
await page.locator('input[name="firstName"]').fill('bill');
await page.locator('input[name="lastName"]').fill('luo123456');
await page.locator('select[name="selectNumber"]').selectOption('1');
await page.locator('input[name="pattern"]').fill('luo');
await page.locator('input[name="min"]').fill('1');
await page.locator('input[name="max"]').fill('21');
await page.locator('input[name="minDate"]').fill('2019-07-30');
await page.locator('input[name="maxDate"]').fill('2019-08-02');
await page.locator('input[name="lastName"]').fill('luo');
await page.locator('input[name="minLength"]').fill('b');
await expect(page.locator('input[name="minLength"] + p')).toContainText(
'minLength error',
);
await expect(page.locator('input[name="pattern"] + p')).toContainText(
'pattern error',
);
await expect(page.locator('input[name="min"] + p')).toContainText(
'min error',
);
await expect(page.locator('input[name="max"] + p')).toContainText(
'max error',
);
await expect(page.locator('input[name="minDate"] + p')).toContainText(
'minDate error',
);
await expect(page.locator('input[name="maxDate"] + p')).toContainText(
'maxDate error',
);
await page.locator('input[name="pattern"]').fill('23');
await page.locator('input[name="minLength"]').fill('bi');
await page.locator('input[name="minRequiredLength"]').fill('bi');
await page.locator('input[name="radio"][value="1"]').check();
await page.locator('input[name="min"]').fill('11');
await page.locator('input[name="max"]').fill('19');
await page.locator('input[name="minDate"]').fill('2019-08-01');
await page.locator('input[name="maxDate"]').fill('2019-08-01');
await page.locator('input[name="checkbox"]').check();
await expect(page.locator('p')).toHaveCount(0);
// await expect(page.locator('#renderCount')).toContainText('24');
});
test('should validate the form with onBlur mode', async ({ page }) => {
await page.goto('http://localhost:3000/basic-schema-validation/onBlur');
await page.locator('input[name="firstName"]').click();
await page.locator('input[name="firstName"]').blur();
await expect(page.locator('input[name="firstName"] + p')).toContainText(
'firstName error',
);
await page.locator('input[name="firstName"]').fill('bill');
await page.locator('input[name="lastName"]').click();
await page.locator('input[name="lastName"]').blur();
await expect(page.locator('input[name="lastName"] + p')).toContainText(
'lastName error',
);
await page.locator('input[name="lastName"]').fill('luo123456');
await page.locator('input[name="lastName"]').blur();
await expect(page.locator('input[name="lastName"] + p')).toContainText(
'lastName error',
);
await page.locator('select[name="selectNumber"]').click();
await page.locator('select[name="selectNumber"]').blur();
await expect(page.locator('select[name="selectNumber"] + p')).toContainText(
'selectNumber error',
);
await page.locator('select[name="selectNumber"]').selectOption('1');
await page.locator('input[name="pattern"]').fill('luo');
await page.locator('input[name="min"]').fill('1');
await page.locator('input[name="max"]').fill('21');
await page.locator('input[name="minDate"]').fill('2019-07-30');
await page.locator('input[name="maxDate"]').fill('2019-08-02');
await page.locator('input[name="lastName"]').fill('luo');
await page.locator('input[name="minLength"]').fill('b');
await page.locator('input[name="minLength"]').blur();
await expect(page.locator('input[name="pattern"] + p')).toContainText(
'pattern error',
);
await expect(page.locator('input[name="minLength"] + p')).toContainText(
'minLength error',
);
await expect(page.locator('input[name="min"] + p')).toContainText(
'min error',
);
await expect(page.locator('input[name="max"] + p')).toContainText(
'max error',
);
await expect(page.locator('input[name="minDate"] + p')).toContainText(
'minDate error',
);
await expect(page.locator('input[name="maxDate"] + p')).toContainText(
'maxDate error',
);
await page.locator('input[name="pattern"]').fill('23');
await page.locator('input[name="minLength"]').fill('bi');
await page.locator('input[name="minRequiredLength"]').fill('bi');
await page.locator('input[name="radio"]').first().click();
await page.locator('input[name="lastName"]').blur();
// await expect(page.locator('input[name="radio"] + p')).toContainText(
// 'radio error',
// );
await page.locator('input[name="radio"][value="1"]').check();
await page.locator('input[name="min"]').fill('11');
await page.locator('input[name="max"]').fill('19');
await page.locator('input[name="minDate"]').fill('2019-08-01');
await page.locator('input[name="maxDate"]').fill('2019-08-01');
await page.locator('input[name="checkbox"]').click();
// await expect(page.locator('p')).toHaveCount(0);
// await expect(page.locator('#renderCount')).toContainText('22');
});
test('should validate the form with onChange mode', async ({ page }) => {
await page.goto('http://localhost:3000/basic-schema-validation/onChange');
await page.locator('input[name="firstName"]').fill('bill');
await page.locator('input[name="lastName"]').click();
await page.locator('input[name="lastName"]').fill('luo123456');
await page.locator('input[name="lastName"]').fill('');
await expect(page.locator('input[name="lastName"] + p')).toContainText(
'lastName error',
);
await page.locator('input[name="lastName"]').fill('luo123456');
await expect(page.locator('input[name="lastName"] + p')).toContainText(
'lastName error',
);
await page.locator('select[name="selectNumber"]').selectOption('1');
await page.locator('select[name="selectNumber"]').selectOption('');
await expect(page.locator('select[name="selectNumber"] + p')).toContainText(
'selectNumber error',
);
await page.locator('select[name="selectNumber"]').selectOption('1');
await page.locator('input[name="pattern"]').fill('luo');
await page.locator('input[name="min"]').fill('1');
await page.locator('input[name="max"]').fill('21');
await page.locator('input[name="minDate"]').fill('2019-07-30');
await page.locator('input[name="maxDate"]').fill('2019-08-02');
await page.locator('input[name="lastName"]').fill('luo');
await page.locator('input[name="minLength"]').fill('b');
await expect(page.locator('input[name="pattern"] + p')).toContainText(
'pattern error',
);
await expect(page.locator('input[name="minLength"] + p')).toContainText(
'minLength error',
);
await expect(page.locator('input[name="min"] + p')).toContainText(
'min error',
);
await expect(page.locator('input[name="max"] + p')).toContainText(
'max error',
);
await expect(page.locator('input[name="minDate"] + p')).toContainText(
'minDate error',
);
await expect(page.locator('input[name="maxDate"] + p')).toContainText(
'maxDate error',
);
await page.locator('input[name="pattern"]').fill('23');
await page.locator('input[name="minLength"]').fill('bi');
await page.locator('input[name="minRequiredLength"]').fill('bi');
await page.locator('input[name="radio"]').first().click();
await page.locator('input[name="radio"][value="1"]').check();
await page.locator('input[name="min"]').fill('11');
await page.locator('input[name="max"]').fill('19');
await page.locator('input[name="minDate"]').fill('2019-08-01');
await page.locator('input[name="maxDate"]').fill('2019-08-01');
await page.locator('input[name="checkbox"]').check();
await expect(page.locator('p')).toHaveCount(0);
// await expect(page.locator('#renderCount')).toContainText('26');
});
});