@khanacademy/wonder-blocks-form 4.9.2 → 4.9.3

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.
Files changed (35) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/components/checkbox-core.d.ts +2 -2
  3. package/dist/components/checkbox.d.ts +2 -2
  4. package/dist/components/choice-internal.d.ts +2 -2
  5. package/dist/components/choice.d.ts +2 -2
  6. package/dist/components/radio-core.d.ts +2 -2
  7. package/dist/components/radio.d.ts +2 -2
  8. package/dist/components/text-area.d.ts +2 -2
  9. package/package.json +7 -7
  10. package/src/__tests__/__snapshots__/custom-snapshot.test.tsx.snap +0 -247
  11. package/src/__tests__/custom-snapshot.test.tsx +0 -48
  12. package/src/components/__tests__/checkbox-group.test.tsx +0 -162
  13. package/src/components/__tests__/checkbox.test.tsx +0 -138
  14. package/src/components/__tests__/field-heading.test.tsx +0 -225
  15. package/src/components/__tests__/labeled-text-field.test.tsx +0 -750
  16. package/src/components/__tests__/radio-group.test.tsx +0 -182
  17. package/src/components/__tests__/text-area.test.tsx +0 -1286
  18. package/src/components/__tests__/text-field.test.tsx +0 -562
  19. package/src/components/checkbox-core.tsx +0 -239
  20. package/src/components/checkbox-group.tsx +0 -174
  21. package/src/components/checkbox.tsx +0 -99
  22. package/src/components/choice-internal.tsx +0 -184
  23. package/src/components/choice.tsx +0 -157
  24. package/src/components/field-heading.tsx +0 -169
  25. package/src/components/group-styles.ts +0 -33
  26. package/src/components/labeled-text-field.tsx +0 -317
  27. package/src/components/radio-core.tsx +0 -171
  28. package/src/components/radio-group.tsx +0 -159
  29. package/src/components/radio.tsx +0 -82
  30. package/src/components/text-area.tsx +0 -430
  31. package/src/components/text-field.tsx +0 -399
  32. package/src/index.ts +0 -17
  33. package/src/util/types.ts +0 -85
  34. package/tsconfig-build.json +0 -19
  35. package/tsconfig-build.tsbuildinfo +0 -1
@@ -1,138 +0,0 @@
1
- import * as React from "react";
2
- import {render, screen} from "@testing-library/react";
3
-
4
- import Checkbox from "../checkbox";
5
-
6
- describe("Checkbox", () => {
7
- test("uses the ID prop when it is specified", () => {
8
- // Arrange, Act
9
- render(
10
- <Checkbox
11
- id="specified-checkbox-id"
12
- label="Receive assignment reminders for Algebra"
13
- description="You will receive a reminder 24 hours before each deadline"
14
- checked={false}
15
- onChange={() => {}}
16
- />,
17
- );
18
-
19
- const checkbox = screen.getByRole("checkbox");
20
-
21
- // Assert
22
- expect(checkbox).toHaveAttribute("id", "specified-checkbox-id");
23
- });
24
-
25
- test("provides a unique ID when the ID prop is not specified", () => {
26
- // Arrange, Act
27
- render(
28
- <Checkbox
29
- label="Receive assignment reminders for Algebra"
30
- description="You will receive a reminder 24 hours before each deadline"
31
- checked={false}
32
- onChange={() => {}}
33
- />,
34
- );
35
-
36
- const checkbox = screen.getByRole("checkbox");
37
-
38
- // Assert
39
- expect(checkbox).toHaveAttribute("id", "uid-choice-1-main");
40
- });
41
-
42
- test("clicking the checkbox triggers `onChange`", () => {
43
- // Arrange
44
- const onChangeSpy = jest.fn();
45
- render(
46
- <Checkbox
47
- label="Receive assignment reminders for Algebra"
48
- description="You will receive a reminder 24 hours before each deadline"
49
- checked={false}
50
- onChange={onChangeSpy}
51
- />,
52
- );
53
-
54
- // Act
55
- const checkbox = screen.getByRole("checkbox");
56
- checkbox.click();
57
-
58
- // Assert
59
- expect(onChangeSpy).toHaveBeenCalled();
60
- });
61
-
62
- test("clicks the label triggers `onChange`", () => {
63
- // Arrange
64
- const onChangeSpy = jest.fn();
65
- render(
66
- <Checkbox
67
- label="Receive assignment reminders for Algebra"
68
- description="You will receive a reminder 24 hours before each deadline"
69
- checked={false}
70
- onChange={onChangeSpy}
71
- />,
72
- );
73
-
74
- // Act
75
- const checkboxLabel = screen.getByText(
76
- "Receive assignment reminders for Algebra",
77
- );
78
- checkboxLabel.click();
79
-
80
- // Assert
81
- expect(onChangeSpy).toHaveBeenCalled();
82
- });
83
-
84
- test.each`
85
- indeterminateValue | checkedValue
86
- ${true} | ${null}
87
- ${false} | ${true}
88
- ${false} | ${false}
89
- `(
90
- "sets the indeterminate property to $indeterminateValue when checked is $checkedValue (with ref)",
91
- ({indeterminateValue, checkedValue}) => {
92
- // Arrange
93
- const ref = React.createRef<HTMLInputElement>();
94
-
95
- // Act
96
- render(
97
- <Checkbox
98
- label="Some label"
99
- description="Some description"
100
- checked={checkedValue}
101
- onChange={() => {}}
102
- ref={ref}
103
- />,
104
- );
105
-
106
- // Assert
107
- expect(ref?.current?.indeterminate).toBe(indeterminateValue);
108
- },
109
- );
110
-
111
- test.each`
112
- indeterminateValue | checkedValue
113
- ${true} | ${null}
114
- ${false} | ${true}
115
- ${false} | ${false}
116
- `(
117
- "sets the indeterminate property to $indeterminateValue when checked is $checkedValue (innerRef)",
118
- ({indeterminateValue, checkedValue}) => {
119
- // Arrange
120
- render(
121
- <Checkbox
122
- label="Some label"
123
- description="Some description"
124
- checked={checkedValue}
125
- onChange={() => {}}
126
- />,
127
- );
128
-
129
- // Act
130
- const inputElement = screen.getByRole(
131
- "checkbox",
132
- ) as HTMLInputElement;
133
-
134
- // Assert
135
- expect(inputElement.indeterminate).toBe(indeterminateValue);
136
- },
137
- );
138
- });
@@ -1,225 +0,0 @@
1
- import * as React from "react";
2
- import {render, screen} from "@testing-library/react";
3
- import {StyleSheet} from "aphrodite";
4
-
5
- import {I18nInlineMarkup} from "@khanacademy/wonder-blocks-i18n";
6
- import {Body} from "@khanacademy/wonder-blocks-typography";
7
-
8
- import FieldHeading from "../field-heading";
9
- import TextField from "../text-field";
10
-
11
- describe("FieldHeading", () => {
12
- it("fieldheading renders the label text", () => {
13
- // Arrange
14
- const label = "Label";
15
-
16
- // Act
17
- render(
18
- <FieldHeading
19
- field={<TextField id="tf-1" value="" onChange={() => {}} />}
20
- label={label}
21
- />,
22
- );
23
-
24
- // Assert
25
- expect(screen.getByText(label)).toBeInTheDocument();
26
- });
27
-
28
- it("fieldheading renders the description text", () => {
29
- // Arrange
30
- const description = "Description";
31
-
32
- // Act
33
- render(
34
- <FieldHeading
35
- field={<TextField id="tf-1" value="" onChange={() => {}} />}
36
- label="Label"
37
- description={description}
38
- />,
39
- );
40
-
41
- // Assert
42
- expect(screen.getByText(description)).toBeInTheDocument();
43
- });
44
-
45
- it("fieldheading renders the error text", () => {
46
- // Arrange
47
- const error = "Error";
48
-
49
- // Act
50
- render(
51
- <FieldHeading
52
- field={<TextField id="tf-1" value="" onChange={() => {}} />}
53
- label="Label"
54
- error={error}
55
- />,
56
- );
57
-
58
- // Assert
59
- expect(screen.getByRole("alert")).toBeInTheDocument();
60
- });
61
-
62
- it("fieldheading adds testId to label", () => {
63
- // Arrange
64
- const testId = "testid";
65
-
66
- // Act
67
- render(
68
- <FieldHeading
69
- field={<TextField id="tf-1" value="" onChange={() => {}} />}
70
- label="Label"
71
- testId={testId}
72
- />,
73
- );
74
-
75
- // Assert
76
- const label = screen.getByTestId(`${testId}-label`);
77
- expect(label).toBeInTheDocument();
78
- });
79
-
80
- it("fieldheading adds testId to description", () => {
81
- // Arrange
82
- const testId = "testid";
83
-
84
- // Act
85
- render(
86
- <FieldHeading
87
- field={<TextField id="tf-1" value="" onChange={() => {}} />}
88
- label="Label"
89
- description="Description"
90
- testId={testId}
91
- />,
92
- );
93
-
94
- // Assert
95
- const description = screen.getByTestId(`${testId}-description`);
96
- expect(description).toBeInTheDocument();
97
- });
98
-
99
- it("fieldheading adds testId to error", () => {
100
- // Arrange
101
- const testId = "testid";
102
-
103
- // Act
104
- render(
105
- <FieldHeading
106
- field={<TextField id="tf-1" value="" onChange={() => {}} />}
107
- label="Label"
108
- error="Error"
109
- testId={testId}
110
- />,
111
- );
112
-
113
- // Assert
114
- const error = screen.getByTestId(`${testId}-error`);
115
- expect(error).toBeInTheDocument();
116
- });
117
-
118
- it("fieldheading adds the correctly formatted id to label's htmlFor", () => {
119
- // Arrange
120
- const id = "exampleid";
121
- const testId = "testid";
122
-
123
- // Act
124
- render(
125
- <FieldHeading
126
- field={<TextField id="tf-1" value="" onChange={() => {}} />}
127
- label="Label"
128
- id={id}
129
- testId={testId}
130
- />,
131
- );
132
-
133
- // Assert
134
- const label = screen.getByTestId(`${testId}-label`);
135
- expect(label).toHaveAttribute("for", `${id}-field`);
136
- });
137
-
138
- it("fieldheading adds the correctly formatted id to error's id", () => {
139
- // Arrange
140
- const id = "exampleid";
141
- const testId = "testid";
142
-
143
- // Act
144
- render(
145
- <FieldHeading
146
- field={<TextField id="tf-1" value="" onChange={() => {}} />}
147
- label="Label"
148
- error="Error"
149
- id={id}
150
- testId={testId}
151
- />,
152
- );
153
-
154
- // Assert
155
- const error = screen.getByRole("alert");
156
- expect(error).toHaveAttribute("id", `${id}-error`);
157
- });
158
-
159
- it("stype prop applies to the fieldheading container", () => {
160
- // Arrange
161
- const styles = StyleSheet.create({
162
- style1: {
163
- flexGrow: 1,
164
- background: "blue",
165
- },
166
- });
167
-
168
- // Act
169
- const {container} = render(
170
- <FieldHeading
171
- field={<TextField id="tf-1" value="" onChange={() => {}} />}
172
- label="Label"
173
- error="Error"
174
- style={styles.style1}
175
- />,
176
- );
177
-
178
- // Assert
179
- const fieldHeading = container.childNodes[0];
180
- expect(fieldHeading).toHaveStyle("background: blue");
181
- });
182
-
183
- it("should render a LabelMedium when the 'label' prop is a I18nInlineMarkup", () => {
184
- // Arrange
185
-
186
- // Act
187
- render(
188
- <FieldHeading
189
- field={<TextField id="tf-1" value="" onChange={() => {}} />}
190
- label={
191
- <I18nInlineMarkup b={(s: string) => <b>{s}</b>}>
192
- {"<b>Test</b> Hello, world!"}
193
- </I18nInlineMarkup>
194
- }
195
- />,
196
- );
197
-
198
- // Assert
199
- const label = screen.getByText("Hello, world!");
200
- // LabelMedium has a font-size of 16px
201
- expect(label).toHaveStyle("font-size: 16px");
202
- });
203
-
204
- it("should render a LabelSmall when the 'description' prop is a I18nInlineMarkup", () => {
205
- // Arrange
206
-
207
- // Act
208
- render(
209
- <FieldHeading
210
- field={<TextField id="tf-1" value="" onChange={() => {}} />}
211
- label={<Body>Hello, world</Body>}
212
- description={
213
- <I18nInlineMarkup b={(s: string) => <b>{s}</b>}>
214
- {"<b>Test</b> description"}
215
- </I18nInlineMarkup>
216
- }
217
- />,
218
- );
219
-
220
- // Assert
221
- const description = screen.getByText("description");
222
- // LabelSmall has a font-size of 16px
223
- expect(description).toHaveStyle("font-size: 14px");
224
- });
225
- });