@khanacademy/wonder-blocks-form 4.9.2 → 4.9.4
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 +21 -0
- package/dist/components/checkbox-core.d.ts +2 -2
- package/dist/components/checkbox.d.ts +2 -2
- package/dist/components/choice-internal.d.ts +2 -2
- package/dist/components/choice.d.ts +2 -2
- package/dist/components/labeled-text-field.d.ts +9 -1
- package/dist/components/radio-core.d.ts +2 -2
- package/dist/components/radio.d.ts +2 -2
- package/dist/components/text-area.d.ts +2 -2
- package/dist/components/text-field.d.ts +10 -5
- package/dist/es/index.js +93 -48
- package/dist/index.js +93 -48
- package/package.json +7 -7
- package/src/__tests__/__snapshots__/custom-snapshot.test.tsx.snap +0 -247
- package/src/__tests__/custom-snapshot.test.tsx +0 -48
- package/src/components/__tests__/checkbox-group.test.tsx +0 -162
- package/src/components/__tests__/checkbox.test.tsx +0 -138
- package/src/components/__tests__/field-heading.test.tsx +0 -225
- package/src/components/__tests__/labeled-text-field.test.tsx +0 -750
- package/src/components/__tests__/radio-group.test.tsx +0 -182
- package/src/components/__tests__/text-area.test.tsx +0 -1286
- package/src/components/__tests__/text-field.test.tsx +0 -562
- package/src/components/checkbox-core.tsx +0 -239
- package/src/components/checkbox-group.tsx +0 -174
- package/src/components/checkbox.tsx +0 -99
- package/src/components/choice-internal.tsx +0 -184
- package/src/components/choice.tsx +0 -157
- package/src/components/field-heading.tsx +0 -169
- package/src/components/group-styles.ts +0 -33
- package/src/components/labeled-text-field.tsx +0 -317
- package/src/components/radio-core.tsx +0 -171
- package/src/components/radio-group.tsx +0 -159
- package/src/components/radio.tsx +0 -82
- package/src/components/text-area.tsx +0 -430
- package/src/components/text-field.tsx +0 -399
- package/src/index.ts +0 -17
- package/src/util/types.ts +0 -85
- package/tsconfig-build.json +0 -19
- package/tsconfig-build.tsbuildinfo +0 -1
|
@@ -1,182 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
import {render, screen} from "@testing-library/react";
|
|
3
|
-
import {userEvent} from "@testing-library/user-event";
|
|
4
|
-
|
|
5
|
-
import RadioGroup from "../radio-group";
|
|
6
|
-
import Choice from "../choice";
|
|
7
|
-
|
|
8
|
-
describe("RadioGroup", () => {
|
|
9
|
-
const TestComponent = ({
|
|
10
|
-
errorMessage,
|
|
11
|
-
onChange,
|
|
12
|
-
}: {
|
|
13
|
-
errorMessage?: string;
|
|
14
|
-
onChange?: () => unknown;
|
|
15
|
-
}) => {
|
|
16
|
-
const [selectedValue, setSelectedValue] = React.useState("a");
|
|
17
|
-
const handleChange = (selectedValue: any) => {
|
|
18
|
-
setSelectedValue(selectedValue);
|
|
19
|
-
onChange?.();
|
|
20
|
-
};
|
|
21
|
-
return (
|
|
22
|
-
<RadioGroup
|
|
23
|
-
label="Test"
|
|
24
|
-
description="test description"
|
|
25
|
-
groupName="test"
|
|
26
|
-
onChange={handleChange}
|
|
27
|
-
selectedValue={selectedValue}
|
|
28
|
-
errorMessage={errorMessage}
|
|
29
|
-
>
|
|
30
|
-
<Choice label="a" value="a" aria-labelledby="test-a" />
|
|
31
|
-
<Choice label="b" value="b" aria-labelledby="test-b" />
|
|
32
|
-
<Choice label="c" value="c" aria-labelledby="test-c" />
|
|
33
|
-
</RadioGroup>
|
|
34
|
-
);
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
describe("behavior", () => {
|
|
38
|
-
it("selects only one item at a time", async () => {
|
|
39
|
-
// Arrange, Act
|
|
40
|
-
render(<TestComponent />);
|
|
41
|
-
|
|
42
|
-
const radios = screen.getAllByRole("radio");
|
|
43
|
-
|
|
44
|
-
// Assert
|
|
45
|
-
// a starts off checked
|
|
46
|
-
expect(radios[0]).toBeChecked();
|
|
47
|
-
expect(radios[1]).not.toBeChecked();
|
|
48
|
-
expect(radios[2]).not.toBeChecked();
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
it("changes selection when selectedValue changes", async () => {
|
|
52
|
-
// Arrange
|
|
53
|
-
render(<TestComponent />);
|
|
54
|
-
|
|
55
|
-
const radios = screen.getAllByRole("radio");
|
|
56
|
-
|
|
57
|
-
// Act
|
|
58
|
-
await userEvent.click(radios[1]);
|
|
59
|
-
|
|
60
|
-
// Assert
|
|
61
|
-
// a starts off checked
|
|
62
|
-
expect(radios[0]).not.toBeChecked();
|
|
63
|
-
expect(radios[1]).toBeChecked();
|
|
64
|
-
expect(radios[2]).not.toBeChecked();
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
it("should set aria-invalid on choices when there's an error message", async () => {
|
|
68
|
-
// Arrange, Act
|
|
69
|
-
render(<TestComponent errorMessage="there's an error" />);
|
|
70
|
-
|
|
71
|
-
const radios = screen.getAllByRole("radio");
|
|
72
|
-
|
|
73
|
-
// Assert
|
|
74
|
-
expect(radios[0]).toHaveAttribute("aria-invalid", "true");
|
|
75
|
-
expect(radios[1]).toHaveAttribute("aria-invalid", "true");
|
|
76
|
-
expect(radios[2]).toHaveAttribute("aria-invalid", "true");
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
it("doesn't change when an already selected item is reselected", async () => {
|
|
80
|
-
// Arrange
|
|
81
|
-
const handleChange = jest.fn();
|
|
82
|
-
render(<TestComponent onChange={handleChange} />);
|
|
83
|
-
|
|
84
|
-
const radios = screen.getAllByRole("radio");
|
|
85
|
-
|
|
86
|
-
// Act
|
|
87
|
-
// a is already selected, onChange shouldn't be called
|
|
88
|
-
await userEvent.click(radios[0]);
|
|
89
|
-
|
|
90
|
-
// Assert
|
|
91
|
-
expect(handleChange).toHaveBeenCalledTimes(0);
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
it("checks that aria attributes have been added correctly", async () => {
|
|
95
|
-
// Arrange, Act
|
|
96
|
-
render(<TestComponent />);
|
|
97
|
-
|
|
98
|
-
const radios = screen.getAllByRole("radio");
|
|
99
|
-
|
|
100
|
-
// Assert
|
|
101
|
-
expect(radios[0]).toHaveAttribute("aria-labelledby", "test-a");
|
|
102
|
-
expect(radios[1]).toHaveAttribute("aria-labelledby", "test-b");
|
|
103
|
-
expect(radios[2]).toHaveAttribute("aria-labelledby", "test-c");
|
|
104
|
-
});
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
describe("flexible props", () => {
|
|
108
|
-
it("should render with a React.Node label", async () => {
|
|
109
|
-
// Arrange, Act
|
|
110
|
-
render(
|
|
111
|
-
<RadioGroup
|
|
112
|
-
label={
|
|
113
|
-
<span>
|
|
114
|
-
label with <strong>strong</strong> text
|
|
115
|
-
</span>
|
|
116
|
-
}
|
|
117
|
-
groupName="test"
|
|
118
|
-
onChange={() => {}}
|
|
119
|
-
selectedValue={"a"}
|
|
120
|
-
>
|
|
121
|
-
<Choice label="a" value="a" aria-labelledby="test-a" />
|
|
122
|
-
<Choice label="b" value="b" aria-labelledby="test-b" />
|
|
123
|
-
<Choice label="c" value="c" aria-labelledby="test-c" />
|
|
124
|
-
</RadioGroup>,
|
|
125
|
-
);
|
|
126
|
-
|
|
127
|
-
// Assert
|
|
128
|
-
expect(await screen.findByText("strong")).toBeInTheDocument();
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
it("should render with a React.Node description", async () => {
|
|
132
|
-
// Arrange, Act
|
|
133
|
-
render(
|
|
134
|
-
<RadioGroup
|
|
135
|
-
label="label"
|
|
136
|
-
description={
|
|
137
|
-
<span>
|
|
138
|
-
description with <strong>strong</strong> text
|
|
139
|
-
</span>
|
|
140
|
-
}
|
|
141
|
-
groupName="test"
|
|
142
|
-
onChange={() => {}}
|
|
143
|
-
selectedValue={"a"}
|
|
144
|
-
>
|
|
145
|
-
<Choice label="a" value="a" aria-labelledby="test-a" />
|
|
146
|
-
<Choice label="b" value="b" aria-labelledby="test-b" />
|
|
147
|
-
<Choice label="c" value="c" aria-labelledby="test-c" />
|
|
148
|
-
</RadioGroup>,
|
|
149
|
-
);
|
|
150
|
-
|
|
151
|
-
// Assert
|
|
152
|
-
expect(await screen.findByText("strong")).toBeInTheDocument();
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
it("should filter out false-y children when rendering", async () => {
|
|
156
|
-
// Arrange, Act
|
|
157
|
-
render(
|
|
158
|
-
<RadioGroup
|
|
159
|
-
label="label"
|
|
160
|
-
description="description"
|
|
161
|
-
groupName="test"
|
|
162
|
-
onChange={() => {}}
|
|
163
|
-
selectedValue={"a"}
|
|
164
|
-
>
|
|
165
|
-
<Choice label="a" value="a" aria-labelledby="test-a" />
|
|
166
|
-
{/* eslint-disable-next-line no-constant-condition */}
|
|
167
|
-
{false ? (
|
|
168
|
-
<Choice label="b" value="b" aria-labelledby="test-b" />
|
|
169
|
-
) : null}
|
|
170
|
-
<Choice label="c" value="c" aria-labelledby="test-c" />
|
|
171
|
-
{undefined}
|
|
172
|
-
{null}
|
|
173
|
-
</RadioGroup>,
|
|
174
|
-
);
|
|
175
|
-
|
|
176
|
-
// Assert
|
|
177
|
-
const radios = screen.getAllByRole("radio");
|
|
178
|
-
|
|
179
|
-
expect(radios).toHaveLength(2);
|
|
180
|
-
});
|
|
181
|
-
});
|
|
182
|
-
});
|