@khanacademy/wonder-blocks-form 4.4.4 → 4.4.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/package.json +3 -3
- package/src/components/__tests__/checkbox-group.test.tsx +11 -11
- package/src/components/__tests__/labeled-text-field.test.tsx +73 -60
- package/src/components/__tests__/radio-group.test.tsx +13 -13
- package/src/components/__tests__/text-field.test.tsx +58 -46
- package/tsconfig-build.tsbuildinfo +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @khanacademy/wonder-blocks-form
|
|
2
2
|
|
|
3
|
+
## 4.4.6
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [c39bfd29]
|
|
8
|
+
- @khanacademy/wonder-blocks-layout@2.0.29
|
|
9
|
+
|
|
10
|
+
## 4.4.5
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- Updated dependencies [e6433bee]
|
|
15
|
+
- @khanacademy/wonder-blocks-clickable@4.1.2
|
|
16
|
+
|
|
3
17
|
## 4.4.4
|
|
4
18
|
|
|
5
19
|
### Patch Changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@khanacademy/wonder-blocks-form",
|
|
3
|
-
"version": "4.4.
|
|
3
|
+
"version": "4.4.6",
|
|
4
4
|
"design": "v1",
|
|
5
5
|
"description": "Form components for Wonder Blocks.",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -16,11 +16,11 @@
|
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
18
|
"@babel/runtime": "^7.18.6",
|
|
19
|
-
"@khanacademy/wonder-blocks-clickable": "^4.1.
|
|
19
|
+
"@khanacademy/wonder-blocks-clickable": "^4.1.2",
|
|
20
20
|
"@khanacademy/wonder-blocks-color": "^3.0.0",
|
|
21
21
|
"@khanacademy/wonder-blocks-core": "^6.3.1",
|
|
22
22
|
"@khanacademy/wonder-blocks-icon": "^4.0.1",
|
|
23
|
-
"@khanacademy/wonder-blocks-layout": "^2.0.
|
|
23
|
+
"@khanacademy/wonder-blocks-layout": "^2.0.29",
|
|
24
24
|
"@khanacademy/wonder-blocks-tokens": "^1.1.0",
|
|
25
25
|
"@khanacademy/wonder-blocks-typography": "^2.1.10"
|
|
26
26
|
},
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import {render, screen} from "@testing-library/react";
|
|
3
|
-
import userEvent from "@testing-library/user-event";
|
|
3
|
+
import {userEvent} from "@testing-library/user-event";
|
|
4
4
|
|
|
5
5
|
import CheckboxGroup from "../checkbox-group";
|
|
6
6
|
import Choice from "../choice";
|
|
@@ -31,7 +31,7 @@ describe("CheckboxGroup", () => {
|
|
|
31
31
|
);
|
|
32
32
|
};
|
|
33
33
|
|
|
34
|
-
it("has the correct items checked", () => {
|
|
34
|
+
it("has the correct items checked", async () => {
|
|
35
35
|
// Arrange, Act
|
|
36
36
|
render(<TestComponent />);
|
|
37
37
|
|
|
@@ -44,14 +44,14 @@ describe("CheckboxGroup", () => {
|
|
|
44
44
|
expect(checkboxes[2]).not.toBeChecked();
|
|
45
45
|
});
|
|
46
46
|
|
|
47
|
-
it("clicking a selected choice deselects it", () => {
|
|
47
|
+
it("clicking a selected choice deselects it", async () => {
|
|
48
48
|
// Arrange
|
|
49
49
|
render(<TestComponent />);
|
|
50
50
|
|
|
51
51
|
const checkboxes = screen.getAllByRole("checkbox");
|
|
52
52
|
|
|
53
53
|
// Act
|
|
54
|
-
userEvent.click(checkboxes[0]);
|
|
54
|
+
await userEvent.click(checkboxes[0]);
|
|
55
55
|
|
|
56
56
|
// Assert
|
|
57
57
|
expect(checkboxes[0]).not.toBeChecked();
|
|
@@ -59,7 +59,7 @@ describe("CheckboxGroup", () => {
|
|
|
59
59
|
expect(checkboxes[2]).not.toBeChecked();
|
|
60
60
|
});
|
|
61
61
|
|
|
62
|
-
it("should set aria-invalid on choices when there's an error message", () => {
|
|
62
|
+
it("should set aria-invalid on choices when there's an error message", async () => {
|
|
63
63
|
// Arrange, Act
|
|
64
64
|
render(<TestComponent errorMessage="there's an error" />);
|
|
65
65
|
|
|
@@ -71,7 +71,7 @@ describe("CheckboxGroup", () => {
|
|
|
71
71
|
expect(checkboxes[2]).toHaveAttribute("aria-invalid", "true");
|
|
72
72
|
});
|
|
73
73
|
|
|
74
|
-
it("checks that aria attributes have been added correctly", () => {
|
|
74
|
+
it("checks that aria attributes have been added correctly", async () => {
|
|
75
75
|
// Arrange, Act
|
|
76
76
|
render(<TestComponent />);
|
|
77
77
|
|
|
@@ -85,7 +85,7 @@ describe("CheckboxGroup", () => {
|
|
|
85
85
|
});
|
|
86
86
|
|
|
87
87
|
describe("flexible props", () => {
|
|
88
|
-
it("should render with a React.Node label", () => {
|
|
88
|
+
it("should render with a React.Node label", async () => {
|
|
89
89
|
// Arrange, Act
|
|
90
90
|
render(
|
|
91
91
|
<CheckboxGroup
|
|
@@ -105,10 +105,10 @@ describe("CheckboxGroup", () => {
|
|
|
105
105
|
);
|
|
106
106
|
|
|
107
107
|
// Assert
|
|
108
|
-
expect(screen.
|
|
108
|
+
expect(await screen.findByText("strong")).toBeInTheDocument();
|
|
109
109
|
});
|
|
110
110
|
|
|
111
|
-
it("should render with a React.Node description", () => {
|
|
111
|
+
it("should render with a React.Node description", async () => {
|
|
112
112
|
// Arrange, Act
|
|
113
113
|
render(
|
|
114
114
|
<CheckboxGroup
|
|
@@ -129,10 +129,10 @@ describe("CheckboxGroup", () => {
|
|
|
129
129
|
);
|
|
130
130
|
|
|
131
131
|
// Assert
|
|
132
|
-
expect(screen.
|
|
132
|
+
expect(await screen.findByText("strong")).toBeInTheDocument();
|
|
133
133
|
});
|
|
134
134
|
|
|
135
|
-
it("should filter out false-y children when rendering", () => {
|
|
135
|
+
it("should filter out false-y children when rendering", async () => {
|
|
136
136
|
// Arrange, Act
|
|
137
137
|
render(
|
|
138
138
|
<CheckboxGroup
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import {render, screen, fireEvent} from "@testing-library/react";
|
|
3
|
-
import userEvent from "@testing-library/user-event";
|
|
3
|
+
import {userEvent} from "@testing-library/user-event";
|
|
4
4
|
|
|
5
5
|
import {StyleSheet} from "aphrodite";
|
|
6
6
|
import {color} from "@khanacademy/wonder-blocks-tokens";
|
|
7
7
|
import LabeledTextField from "../labeled-text-field";
|
|
8
8
|
|
|
9
9
|
describe("LabeledTextField", () => {
|
|
10
|
-
it("labeledtextfield becomes focused", () => {
|
|
10
|
+
it("labeledtextfield becomes focused", async () => {
|
|
11
11
|
// Arrange
|
|
12
12
|
render(<LabeledTextField label="Label" value="" onChange={() => {}} />);
|
|
13
|
-
const field = screen.
|
|
13
|
+
const field = await screen.findByRole("textbox");
|
|
14
14
|
|
|
15
15
|
// Act
|
|
16
|
-
userEvent.tab();
|
|
16
|
+
await userEvent.tab();
|
|
17
17
|
|
|
18
18
|
// Assert
|
|
19
19
|
expect(field).toHaveFocus();
|
|
@@ -24,17 +24,17 @@ describe("LabeledTextField", () => {
|
|
|
24
24
|
render(<LabeledTextField label="Label" value="" onChange={() => {}} />);
|
|
25
25
|
|
|
26
26
|
// focus
|
|
27
|
-
userEvent.tab();
|
|
27
|
+
await userEvent.tab();
|
|
28
28
|
|
|
29
29
|
// Act
|
|
30
30
|
// blur
|
|
31
|
-
userEvent.tab();
|
|
31
|
+
await userEvent.tab();
|
|
32
32
|
|
|
33
33
|
// Assert
|
|
34
|
-
expect(screen.
|
|
34
|
+
expect(await screen.findByRole("textbox")).not.toHaveFocus();
|
|
35
35
|
});
|
|
36
36
|
|
|
37
|
-
it("id prop is passed to input", () => {
|
|
37
|
+
it("id prop is passed to input", async () => {
|
|
38
38
|
// Arrange
|
|
39
39
|
const id = "exampleid";
|
|
40
40
|
|
|
@@ -50,11 +50,11 @@ describe("LabeledTextField", () => {
|
|
|
50
50
|
);
|
|
51
51
|
|
|
52
52
|
// Assert
|
|
53
|
-
const input = screen.
|
|
53
|
+
const input = await screen.findByRole("textbox");
|
|
54
54
|
expect(input).toHaveAttribute("id", `${id}-field`);
|
|
55
55
|
});
|
|
56
56
|
|
|
57
|
-
it("auto-generated id is passed to input when id prop is not set", () => {
|
|
57
|
+
it("auto-generated id is passed to input when id prop is not set", async () => {
|
|
58
58
|
// Arrange
|
|
59
59
|
|
|
60
60
|
// Act
|
|
@@ -63,11 +63,11 @@ describe("LabeledTextField", () => {
|
|
|
63
63
|
// Assert
|
|
64
64
|
// Since the generated id is unique, we cannot know what it will be.
|
|
65
65
|
// We only test if the id attribute starts with "uid-" and ends with "-field".
|
|
66
|
-
const input = screen.
|
|
66
|
+
const input = await screen.findByRole("textbox");
|
|
67
67
|
expect(input.getAttribute("id")).toMatch(/uid-.*-field/);
|
|
68
68
|
});
|
|
69
69
|
|
|
70
|
-
it("type prop is passed to input", () => {
|
|
70
|
+
it("type prop is passed to input", async () => {
|
|
71
71
|
// Arrange
|
|
72
72
|
const type = "email";
|
|
73
73
|
|
|
@@ -82,11 +82,11 @@ describe("LabeledTextField", () => {
|
|
|
82
82
|
);
|
|
83
83
|
|
|
84
84
|
// Assert
|
|
85
|
-
const input = screen.
|
|
85
|
+
const input = await screen.findByRole("textbox");
|
|
86
86
|
expect(input).toHaveAttribute("type", type);
|
|
87
87
|
});
|
|
88
88
|
|
|
89
|
-
it("label prop is rendered", () => {
|
|
89
|
+
it("label prop is rendered", async () => {
|
|
90
90
|
// Arrange
|
|
91
91
|
const label = "Label";
|
|
92
92
|
|
|
@@ -94,10 +94,10 @@ describe("LabeledTextField", () => {
|
|
|
94
94
|
render(<LabeledTextField label={label} value="" onChange={() => {}} />);
|
|
95
95
|
|
|
96
96
|
// Assert
|
|
97
|
-
expect(screen.
|
|
97
|
+
expect(await screen.findByText(label)).toBeInTheDocument();
|
|
98
98
|
});
|
|
99
99
|
|
|
100
|
-
it("description prop is rendered", () => {
|
|
100
|
+
it("description prop is rendered", async () => {
|
|
101
101
|
// Arrange
|
|
102
102
|
const description = "Description";
|
|
103
103
|
|
|
@@ -112,10 +112,10 @@ describe("LabeledTextField", () => {
|
|
|
112
112
|
);
|
|
113
113
|
|
|
114
114
|
// Assert
|
|
115
|
-
expect(screen.
|
|
115
|
+
expect(await screen.findByText(description)).toBeInTheDocument();
|
|
116
116
|
});
|
|
117
117
|
|
|
118
|
-
it("value prop is set on mount", () => {
|
|
118
|
+
it("value prop is set on mount", async () => {
|
|
119
119
|
// Arrange
|
|
120
120
|
const value = "Value";
|
|
121
121
|
|
|
@@ -129,7 +129,7 @@ describe("LabeledTextField", () => {
|
|
|
129
129
|
);
|
|
130
130
|
|
|
131
131
|
// Assert
|
|
132
|
-
const input = screen.
|
|
132
|
+
const input = await screen.findByRole("textbox");
|
|
133
133
|
expect(input).toHaveAttribute("value", value);
|
|
134
134
|
});
|
|
135
135
|
|
|
@@ -152,11 +152,11 @@ describe("LabeledTextField", () => {
|
|
|
152
152
|
);
|
|
153
153
|
|
|
154
154
|
// Assert
|
|
155
|
-
const input = screen.
|
|
155
|
+
const input = await screen.findByRole("textbox");
|
|
156
156
|
expect(input).toHaveAttribute("value", newValue);
|
|
157
157
|
});
|
|
158
158
|
|
|
159
|
-
it("disabled prop disables the input", () => {
|
|
159
|
+
it("disabled prop disables the input", async () => {
|
|
160
160
|
// Arrange
|
|
161
161
|
|
|
162
162
|
// Act
|
|
@@ -170,11 +170,11 @@ describe("LabeledTextField", () => {
|
|
|
170
170
|
);
|
|
171
171
|
|
|
172
172
|
// Assert
|
|
173
|
-
const input = screen.
|
|
173
|
+
const input = await screen.findByRole("textbox");
|
|
174
174
|
expect(input).toBeDisabled();
|
|
175
175
|
});
|
|
176
176
|
|
|
177
|
-
it("ariaDescribedby prop sets aria-describedby", () => {
|
|
177
|
+
it("ariaDescribedby prop sets aria-describedby", async () => {
|
|
178
178
|
// Arrange
|
|
179
179
|
const ariaDescription = "aria description";
|
|
180
180
|
|
|
@@ -189,11 +189,11 @@ describe("LabeledTextField", () => {
|
|
|
189
189
|
);
|
|
190
190
|
|
|
191
191
|
// Assert
|
|
192
|
-
const input = screen.
|
|
192
|
+
const input = await screen.findByRole("textbox");
|
|
193
193
|
expect(input.getAttribute("aria-describedby")).toEqual(ariaDescription);
|
|
194
194
|
});
|
|
195
195
|
|
|
196
|
-
it("auto-generates a unique error when ariaDescribedby is not passed in", () => {
|
|
196
|
+
it("auto-generates a unique error when ariaDescribedby is not passed in", async () => {
|
|
197
197
|
// Arrange
|
|
198
198
|
|
|
199
199
|
// Act
|
|
@@ -211,13 +211,13 @@ describe("LabeledTextField", () => {
|
|
|
211
211
|
// we cannot know what it will be.
|
|
212
212
|
// We only test if the aria-describedby attribute starts with
|
|
213
213
|
// "uid-" and ends with "-error".
|
|
214
|
-
const input = screen.
|
|
214
|
+
const input = await screen.findByRole("textbox");
|
|
215
215
|
expect(input.getAttribute("aria-describedby")).toMatch(
|
|
216
216
|
/^uid-.*-error$/,
|
|
217
217
|
);
|
|
218
218
|
});
|
|
219
219
|
|
|
220
|
-
it("validate prop is called when input changes", () => {
|
|
220
|
+
it("validate prop is called when input changes", async () => {
|
|
221
221
|
// Arrange
|
|
222
222
|
const validate = jest.fn((value: string): any => {});
|
|
223
223
|
render(
|
|
@@ -231,7 +231,7 @@ describe("LabeledTextField", () => {
|
|
|
231
231
|
|
|
232
232
|
// Act
|
|
233
233
|
const newValue = "New Value";
|
|
234
|
-
const input = screen.
|
|
234
|
+
const input = await screen.findByRole("textbox");
|
|
235
235
|
// @see https://testing-library.com/docs/react-testing-library/faq
|
|
236
236
|
// How do I test input onChange handlers?
|
|
237
237
|
// eslint-disable-next-line testing-library/prefer-user-event
|
|
@@ -241,7 +241,7 @@ describe("LabeledTextField", () => {
|
|
|
241
241
|
expect(validate).toHaveBeenCalledWith(newValue);
|
|
242
242
|
});
|
|
243
243
|
|
|
244
|
-
it("onValidate prop is called on new validated input", () => {
|
|
244
|
+
it("onValidate prop is called on new validated input", async () => {
|
|
245
245
|
// Arrange
|
|
246
246
|
const handleValidate = jest.fn((errorMessage?: string | null) => {});
|
|
247
247
|
const errorMessage = "Password must be at least 8 characters long";
|
|
@@ -264,13 +264,16 @@ describe("LabeledTextField", () => {
|
|
|
264
264
|
|
|
265
265
|
// Act
|
|
266
266
|
// Select all text and replace it with the new value.
|
|
267
|
-
|
|
267
|
+
const textbox = await screen.findByRole("textbox");
|
|
268
|
+
await userEvent.click(textbox);
|
|
269
|
+
await userEvent.clear(textbox);
|
|
270
|
+
await userEvent.paste("Short");
|
|
268
271
|
|
|
269
272
|
// Assert
|
|
270
273
|
expect(handleValidate).toHaveBeenCalledWith(errorMessage);
|
|
271
274
|
});
|
|
272
275
|
|
|
273
|
-
it("onChange prop is called on input change", () => {
|
|
276
|
+
it("onChange prop is called on input change", async () => {
|
|
274
277
|
// Arrange
|
|
275
278
|
const handleChange = jest.fn((newValue: string) => {});
|
|
276
279
|
|
|
@@ -280,7 +283,7 @@ describe("LabeledTextField", () => {
|
|
|
280
283
|
|
|
281
284
|
// Act
|
|
282
285
|
const newValue = "new value";
|
|
283
|
-
const input = screen.
|
|
286
|
+
const input = await screen.findByRole("textbox");
|
|
284
287
|
// @see https://testing-library.com/docs/react-testing-library/faq
|
|
285
288
|
// How do I test input onChange handlers?
|
|
286
289
|
// eslint-disable-next-line testing-library/prefer-user-event
|
|
@@ -290,7 +293,7 @@ describe("LabeledTextField", () => {
|
|
|
290
293
|
expect(handleChange).toHaveBeenCalledWith(newValue);
|
|
291
294
|
});
|
|
292
295
|
|
|
293
|
-
it("onKeyDown prop is called on keyboard keypress", () => {
|
|
296
|
+
it("onKeyDown prop is called on keyboard keypress", async () => {
|
|
294
297
|
// Arrange
|
|
295
298
|
const handleKeyDown = jest.fn(
|
|
296
299
|
(event: React.KeyboardEvent<HTMLInputElement>) => {
|
|
@@ -308,13 +311,13 @@ describe("LabeledTextField", () => {
|
|
|
308
311
|
);
|
|
309
312
|
|
|
310
313
|
// Act
|
|
311
|
-
userEvent.type(screen.
|
|
314
|
+
await userEvent.type(await screen.findByRole("textbox"), "{enter}");
|
|
312
315
|
|
|
313
316
|
// Assert
|
|
314
317
|
expect(handleKeyDown).toHaveReturnedWith("Enter");
|
|
315
318
|
});
|
|
316
319
|
|
|
317
|
-
it("onFocus prop is called when field is focused", () => {
|
|
320
|
+
it("onFocus prop is called when field is focused", async () => {
|
|
318
321
|
// Arrange
|
|
319
322
|
const handleFocus = jest.fn(() => {});
|
|
320
323
|
render(
|
|
@@ -327,7 +330,7 @@ describe("LabeledTextField", () => {
|
|
|
327
330
|
);
|
|
328
331
|
|
|
329
332
|
// Act
|
|
330
|
-
const field = screen.
|
|
333
|
+
const field = await screen.findByRole("textbox");
|
|
331
334
|
field.focus();
|
|
332
335
|
|
|
333
336
|
// Assert
|
|
@@ -347,11 +350,11 @@ describe("LabeledTextField", () => {
|
|
|
347
350
|
);
|
|
348
351
|
|
|
349
352
|
// focus
|
|
350
|
-
userEvent.tab();
|
|
353
|
+
await userEvent.tab();
|
|
351
354
|
|
|
352
355
|
// Act
|
|
353
356
|
// blur
|
|
354
|
-
userEvent.tab();
|
|
357
|
+
await userEvent.tab();
|
|
355
358
|
|
|
356
359
|
// Assert
|
|
357
360
|
expect(handleBlur).toHaveBeenCalled();
|
|
@@ -372,7 +375,7 @@ describe("LabeledTextField", () => {
|
|
|
372
375
|
);
|
|
373
376
|
|
|
374
377
|
// Assert
|
|
375
|
-
const input = screen.
|
|
378
|
+
const input = await screen.findByPlaceholderText(placeholder);
|
|
376
379
|
expect(input).toBeInTheDocument();
|
|
377
380
|
});
|
|
378
381
|
|
|
@@ -389,7 +392,7 @@ describe("LabeledTextField", () => {
|
|
|
389
392
|
/>,
|
|
390
393
|
);
|
|
391
394
|
|
|
392
|
-
const textField = screen.
|
|
395
|
+
const textField = await screen.findByRole("textbox");
|
|
393
396
|
textField.focus();
|
|
394
397
|
|
|
395
398
|
// Assert
|
|
@@ -437,7 +440,7 @@ describe("LabeledTextField", () => {
|
|
|
437
440
|
);
|
|
438
441
|
|
|
439
442
|
// Assert
|
|
440
|
-
const input = screen.
|
|
443
|
+
const input = await screen.findByRole("textbox");
|
|
441
444
|
expect(input).toHaveAttribute("data-test-id", `${testId}-field`);
|
|
442
445
|
});
|
|
443
446
|
|
|
@@ -455,7 +458,7 @@ describe("LabeledTextField", () => {
|
|
|
455
458
|
);
|
|
456
459
|
|
|
457
460
|
// Assert
|
|
458
|
-
const input = screen.
|
|
461
|
+
const input = await screen.findByRole("textbox");
|
|
459
462
|
expect(input).toHaveAttribute("readOnly");
|
|
460
463
|
});
|
|
461
464
|
|
|
@@ -474,13 +477,13 @@ describe("LabeledTextField", () => {
|
|
|
474
477
|
);
|
|
475
478
|
|
|
476
479
|
// Assert
|
|
477
|
-
const input = screen.
|
|
480
|
+
const input = await screen.findByRole("textbox");
|
|
478
481
|
expect(input).toHaveAttribute("autoComplete", autoComplete);
|
|
479
482
|
});
|
|
480
483
|
});
|
|
481
484
|
|
|
482
485
|
describe("Required LabeledTextField", () => {
|
|
483
|
-
test("has * when `required` prop is true", () => {
|
|
486
|
+
test("has * when `required` prop is true", async () => {
|
|
484
487
|
// Arrange
|
|
485
488
|
|
|
486
489
|
// Act
|
|
@@ -494,10 +497,10 @@ describe("Required LabeledTextField", () => {
|
|
|
494
497
|
);
|
|
495
498
|
|
|
496
499
|
// Assert
|
|
497
|
-
expect(screen.
|
|
500
|
+
expect(await screen.findByText("*")).toBeInTheDocument();
|
|
498
501
|
});
|
|
499
502
|
|
|
500
|
-
test("does not have * when `required` prop is false", () => {
|
|
503
|
+
test("does not have * when `required` prop is false", async () => {
|
|
501
504
|
// Arrange
|
|
502
505
|
|
|
503
506
|
// Act
|
|
@@ -514,7 +517,7 @@ describe("Required LabeledTextField", () => {
|
|
|
514
517
|
expect(screen.queryByText("*")).not.toBeInTheDocument();
|
|
515
518
|
});
|
|
516
519
|
|
|
517
|
-
test("aria-required is true when `required` prop is true", () => {
|
|
520
|
+
test("aria-required is true when `required` prop is true", async () => {
|
|
518
521
|
// Arrange
|
|
519
522
|
|
|
520
523
|
// Act
|
|
@@ -528,13 +531,15 @@ describe("Required LabeledTextField", () => {
|
|
|
528
531
|
/>,
|
|
529
532
|
);
|
|
530
533
|
|
|
531
|
-
const textField = screen.
|
|
534
|
+
const textField = await screen.findByTestId(
|
|
535
|
+
"foo-labeled-text-field-field",
|
|
536
|
+
);
|
|
532
537
|
|
|
533
538
|
// Assert
|
|
534
539
|
expect(textField).toHaveAttribute("aria-required", "true");
|
|
535
540
|
});
|
|
536
541
|
|
|
537
|
-
test("aria-required is false when `required` prop is false", () => {
|
|
542
|
+
test("aria-required is false when `required` prop is false", async () => {
|
|
538
543
|
// Arrange
|
|
539
544
|
|
|
540
545
|
// Act
|
|
@@ -548,13 +553,15 @@ describe("Required LabeledTextField", () => {
|
|
|
548
553
|
/>,
|
|
549
554
|
);
|
|
550
555
|
|
|
551
|
-
const textField = screen.
|
|
556
|
+
const textField = await screen.findByTestId(
|
|
557
|
+
"foo-labeled-text-field-field",
|
|
558
|
+
);
|
|
552
559
|
|
|
553
560
|
// Assert
|
|
554
561
|
expect(textField).toHaveAttribute("aria-required", "false");
|
|
555
562
|
});
|
|
556
563
|
|
|
557
|
-
test("displays the default message when the `required` prop is `true`", () => {
|
|
564
|
+
test("displays the default message when the `required` prop is `true`", async () => {
|
|
558
565
|
// Arrange
|
|
559
566
|
const TextFieldWrapper = () => {
|
|
560
567
|
const [value, setValue] = React.useState("");
|
|
@@ -571,21 +578,23 @@ describe("Required LabeledTextField", () => {
|
|
|
571
578
|
|
|
572
579
|
render(<TextFieldWrapper />);
|
|
573
580
|
|
|
574
|
-
const textField = screen.
|
|
581
|
+
const textField = await screen.findByTestId(
|
|
582
|
+
"test-labeled-text-field-field",
|
|
583
|
+
);
|
|
575
584
|
textField.focus();
|
|
576
|
-
userEvent.
|
|
577
|
-
userEvent.clear(textField);
|
|
585
|
+
await userEvent.type(textField, "a");
|
|
586
|
+
await userEvent.clear(textField);
|
|
578
587
|
|
|
579
588
|
// Act
|
|
580
589
|
textField.blur();
|
|
581
590
|
|
|
582
591
|
// Assert
|
|
583
|
-
expect(screen.
|
|
592
|
+
expect(await screen.findByRole("alert")).toHaveTextContent(
|
|
584
593
|
"This field is required.",
|
|
585
594
|
);
|
|
586
595
|
});
|
|
587
596
|
|
|
588
|
-
test("displays the string passed into `required`", () => {
|
|
597
|
+
test("displays the string passed into `required`", async () => {
|
|
589
598
|
// Arrange
|
|
590
599
|
const errorMessage = "This is an example error message.";
|
|
591
600
|
|
|
@@ -604,15 +613,19 @@ describe("Required LabeledTextField", () => {
|
|
|
604
613
|
|
|
605
614
|
render(<TextFieldWrapper />);
|
|
606
615
|
|
|
607
|
-
const textField = screen.
|
|
616
|
+
const textField = await screen.findByTestId(
|
|
617
|
+
"test-labeled-text-field-field",
|
|
618
|
+
);
|
|
608
619
|
textField.focus();
|
|
609
|
-
userEvent.
|
|
610
|
-
userEvent.clear(textField);
|
|
620
|
+
await userEvent.type(textField, "a");
|
|
621
|
+
await userEvent.clear(textField);
|
|
611
622
|
|
|
612
623
|
// Act
|
|
613
624
|
textField.blur();
|
|
614
625
|
|
|
615
626
|
// Assert
|
|
616
|
-
expect(screen.
|
|
627
|
+
expect(await screen.findByRole("alert")).toHaveTextContent(
|
|
628
|
+
errorMessage,
|
|
629
|
+
);
|
|
617
630
|
});
|
|
618
631
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import {render, screen} from "@testing-library/react";
|
|
3
|
-
import userEvent from "@testing-library/user-event";
|
|
3
|
+
import {userEvent} from "@testing-library/user-event";
|
|
4
4
|
|
|
5
5
|
import RadioGroup from "../radio-group";
|
|
6
6
|
import Choice from "../choice";
|
|
@@ -35,7 +35,7 @@ describe("RadioGroup", () => {
|
|
|
35
35
|
};
|
|
36
36
|
|
|
37
37
|
describe("behavior", () => {
|
|
38
|
-
it("selects only one item at a time", () => {
|
|
38
|
+
it("selects only one item at a time", async () => {
|
|
39
39
|
// Arrange, Act
|
|
40
40
|
render(<TestComponent />);
|
|
41
41
|
|
|
@@ -48,14 +48,14 @@ describe("RadioGroup", () => {
|
|
|
48
48
|
expect(radios[2]).not.toBeChecked();
|
|
49
49
|
});
|
|
50
50
|
|
|
51
|
-
it("changes selection when selectedValue changes", () => {
|
|
51
|
+
it("changes selection when selectedValue changes", async () => {
|
|
52
52
|
// Arrange
|
|
53
53
|
render(<TestComponent />);
|
|
54
54
|
|
|
55
55
|
const radios = screen.getAllByRole("radio");
|
|
56
56
|
|
|
57
57
|
// Act
|
|
58
|
-
userEvent.click(radios[1]);
|
|
58
|
+
await userEvent.click(radios[1]);
|
|
59
59
|
|
|
60
60
|
// Assert
|
|
61
61
|
// a starts off checked
|
|
@@ -64,7 +64,7 @@ describe("RadioGroup", () => {
|
|
|
64
64
|
expect(radios[2]).not.toBeChecked();
|
|
65
65
|
});
|
|
66
66
|
|
|
67
|
-
it("should set aria-invalid on choices when there's an error message", () => {
|
|
67
|
+
it("should set aria-invalid on choices when there's an error message", async () => {
|
|
68
68
|
// Arrange, Act
|
|
69
69
|
render(<TestComponent errorMessage="there's an error" />);
|
|
70
70
|
|
|
@@ -76,7 +76,7 @@ describe("RadioGroup", () => {
|
|
|
76
76
|
expect(radios[2]).toHaveAttribute("aria-invalid", "true");
|
|
77
77
|
});
|
|
78
78
|
|
|
79
|
-
it("doesn't change when an already selected item is reselected", () => {
|
|
79
|
+
it("doesn't change when an already selected item is reselected", async () => {
|
|
80
80
|
// Arrange
|
|
81
81
|
const handleChange = jest.fn();
|
|
82
82
|
render(<TestComponent onChange={handleChange} />);
|
|
@@ -85,13 +85,13 @@ describe("RadioGroup", () => {
|
|
|
85
85
|
|
|
86
86
|
// Act
|
|
87
87
|
// a is already selected, onChange shouldn't be called
|
|
88
|
-
userEvent.click(radios[0]);
|
|
88
|
+
await userEvent.click(radios[0]);
|
|
89
89
|
|
|
90
90
|
// Assert
|
|
91
91
|
expect(handleChange).toHaveBeenCalledTimes(0);
|
|
92
92
|
});
|
|
93
93
|
|
|
94
|
-
it("checks that aria attributes have been added correctly", () => {
|
|
94
|
+
it("checks that aria attributes have been added correctly", async () => {
|
|
95
95
|
// Arrange, Act
|
|
96
96
|
render(<TestComponent />);
|
|
97
97
|
|
|
@@ -105,7 +105,7 @@ describe("RadioGroup", () => {
|
|
|
105
105
|
});
|
|
106
106
|
|
|
107
107
|
describe("flexible props", () => {
|
|
108
|
-
it("should render with a React.Node label", () => {
|
|
108
|
+
it("should render with a React.Node label", async () => {
|
|
109
109
|
// Arrange, Act
|
|
110
110
|
render(
|
|
111
111
|
<RadioGroup
|
|
@@ -125,10 +125,10 @@ describe("RadioGroup", () => {
|
|
|
125
125
|
);
|
|
126
126
|
|
|
127
127
|
// Assert
|
|
128
|
-
expect(screen.
|
|
128
|
+
expect(await screen.findByText("strong")).toBeInTheDocument();
|
|
129
129
|
});
|
|
130
130
|
|
|
131
|
-
it("should render with a React.Node description", () => {
|
|
131
|
+
it("should render with a React.Node description", async () => {
|
|
132
132
|
// Arrange, Act
|
|
133
133
|
render(
|
|
134
134
|
<RadioGroup
|
|
@@ -149,10 +149,10 @@ describe("RadioGroup", () => {
|
|
|
149
149
|
);
|
|
150
150
|
|
|
151
151
|
// Assert
|
|
152
|
-
expect(screen.
|
|
152
|
+
expect(await screen.findByText("strong")).toBeInTheDocument();
|
|
153
153
|
});
|
|
154
154
|
|
|
155
|
-
it("should filter out false-y children when rendering", () => {
|
|
155
|
+
it("should filter out false-y children when rendering", async () => {
|
|
156
156
|
// Arrange, Act
|
|
157
157
|
render(
|
|
158
158
|
<RadioGroup
|