-
Notifications
You must be signed in to change notification settings - Fork 85
/
collection.spec.ts
94 lines (73 loc) · 2.24 KB
/
collection.spec.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
import { type Page, test, expect } from '@playwright/test';
import { getPlayground } from '../helpers';
async function runTest(
page: Page,
options: {
noClientValidate?: boolean;
} = {},
) {
const playground = getPlayground(page);
await playground.submit.click();
await expect(playground.error).toHaveText(['Required', 'Required']);
await playground.container.getByLabel('Y').click();
await playground.submit.click();
await expect(playground.error).toHaveText(['', 'Required']);
if (!options.noClientValidate) {
const invalidOption = playground.container.getByLabel('D');
await invalidOption.click();
await expect(playground.error).toHaveText(['', 'Invalid']);
// Uncheck it to remove the error
await invalidOption.click();
}
await playground.container.getByLabel('C').click();
await playground.submit.click();
await expect(playground.error).toHaveText(['', '']);
await expect.poll(playground.result).toStrictEqual({
status: 'success',
initialValue: {
singleChoice: 'y',
multipleChoice: 'c',
},
fields: ['singleChoice', 'multipleChoice'],
});
await playground.container.getByLabel('A').click();
await playground.submit.click();
await expect(playground.error).toHaveText(['', '']);
await expect.poll(playground.result).toStrictEqual({
status: 'success',
initialValue: {
singleChoice: 'y',
multipleChoice: ['a', 'c'],
},
fields: ['singleChoice', 'multipleChoice'],
});
}
test.describe('With JS', () => {
test('Client Validation', async ({ page }) => {
await page.goto('/collection');
await runTest(page);
});
test('Server Validation', async ({ page }) => {
await page.goto('/collection?noClientValidate=yes');
await runTest(page, {
noClientValidate: true,
});
});
test('Form reset', async ({ page }) => {
await page.goto('/collection');
const playground = getPlayground(page);
await playground.submit.click();
await expect(playground.error).toHaveText(['Required', 'Required']);
await playground.reset.click();
await expect(playground.error).toHaveText(['', '']);
});
});
test.describe('No JS', () => {
test.use({ javaScriptEnabled: false });
test('Validation', async ({ page }) => {
await page.goto('/collection');
await runTest(page, {
noClientValidate: true,
});
});
});