@khanacademy/wonder-blocks-accordion 1.3.7 → 1.3.9

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 CHANGED
@@ -1,5 +1,25 @@
1
1
  # @khanacademy/wonder-blocks-accordion
2
2
 
3
+ ## 1.3.9
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [6999fd39]
8
+ - @khanacademy/wonder-blocks-tokens@2.1.0
9
+ - @khanacademy/wonder-blocks-clickable@4.2.9
10
+
11
+ ## 1.3.8
12
+
13
+ ### Patch Changes
14
+
15
+ - 02a1b298: Make sure we don't package tsconfig and tsbuildinfo files
16
+ - Updated dependencies [02a1b298]
17
+ - @khanacademy/wonder-blocks-clickable@4.2.8
18
+ - @khanacademy/wonder-blocks-core@7.0.1
19
+ - @khanacademy/wonder-blocks-icon@4.1.5
20
+ - @khanacademy/wonder-blocks-tokens@2.0.1
21
+ - @khanacademy/wonder-blocks-typography@2.1.16
22
+
3
23
  ## 1.3.7
4
24
 
5
25
  ### Patch Changes
@@ -45,8 +45,8 @@ export type TagType = "h1" | "h2" | "h3" | "h4" | "h5" | "h6";
45
45
  * </AccordionSection>
46
46
  * ```
47
47
  */
48
- declare const AccordionSection: React.ForwardRefExoticComponent<Readonly<import("../../../wonder-blocks-core/src/util/aria-types").AriaAttributes> & Readonly<{
49
- role?: import("../../../wonder-blocks-core/src/util/aria-types").AriaRole | undefined;
48
+ declare const AccordionSection: React.ForwardRefExoticComponent<Readonly<import("@khanacademy/wonder-blocks-core").AriaAttributes> & Readonly<{
49
+ role?: import("@khanacademy/wonder-blocks-core").AriaRole | undefined;
50
50
  }> & {
51
51
  /**
52
52
  * The unique identifier for the accordion section.
@@ -31,8 +31,8 @@ export type AccordionCornerKindType = "square" | "rounded" | "rounded-per-sectio
31
31
  * </Accordion>
32
32
  * ```
33
33
  */
34
- declare const Accordion: React.ForwardRefExoticComponent<Readonly<import("../../../wonder-blocks-core/src/util/aria-types").AriaAttributes> & Readonly<{
35
- role?: import("../../../wonder-blocks-core/src/util/aria-types").AriaRole | undefined;
34
+ declare const Accordion: React.ForwardRefExoticComponent<Readonly<import("@khanacademy/wonder-blocks-core").AriaAttributes> & Readonly<{
35
+ role?: import("@khanacademy/wonder-blocks-core").AriaRole | undefined;
36
36
  }> & {
37
37
  /**
38
38
  * The unique identifier for the accordion.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@khanacademy/wonder-blocks-accordion",
3
- "version": "1.3.7",
3
+ "version": "1.3.9",
4
4
  "design": "v1",
5
5
  "description": "Accordion components for Wonder Blocks.",
6
6
  "main": "dist/index.js",
@@ -16,11 +16,11 @@
16
16
  "access": "public"
17
17
  },
18
18
  "dependencies": {
19
- "@khanacademy/wonder-blocks-clickable": "^4.2.7",
20
- "@khanacademy/wonder-blocks-core": "^7.0.0",
21
- "@khanacademy/wonder-blocks-icon": "^4.1.4",
22
- "@khanacademy/wonder-blocks-tokens": "^2.0.0",
23
- "@khanacademy/wonder-blocks-typography": "^2.1.15"
19
+ "@khanacademy/wonder-blocks-clickable": "^4.2.9",
20
+ "@khanacademy/wonder-blocks-core": "^7.0.1",
21
+ "@khanacademy/wonder-blocks-icon": "^4.1.5",
22
+ "@khanacademy/wonder-blocks-tokens": "^2.1.0",
23
+ "@khanacademy/wonder-blocks-typography": "^2.1.16"
24
24
  },
25
25
  "peerDependencies": {
26
26
  "@phosphor-icons/core": "^2.0.2",
@@ -1,211 +0,0 @@
1
- import * as React from "react";
2
- import {render, screen} from "@testing-library/react";
3
-
4
- import AccordionSectionHeader from "../accordion-section-header";
5
-
6
- describe("AccordionSectionHeader", () => {
7
- test("renders with string header, h2 by default", () => {
8
- // Arrange
9
- render(
10
- <AccordionSectionHeader
11
- id="accordion-section-header"
12
- header="Title"
13
- caretPosition="end"
14
- cornerKind="square"
15
- expanded={false}
16
- animated={false}
17
- onClick={() => {}}
18
- sectionContentUniqueId="section-content-unique-id"
19
- isFirstSection={false}
20
- isLastSection={false}
21
- />,
22
- );
23
-
24
- // Act
25
- const header = screen.getByRole("heading", {level: 2, name: "Title"});
26
-
27
- // Assert
28
- expect(header).toBeVisible();
29
- });
30
-
31
- test("renders with the specified tag", () => {
32
- // Arrange
33
- render(
34
- <AccordionSectionHeader
35
- id="accordion-section-header"
36
- header="Title"
37
- caretPosition="end"
38
- cornerKind="square"
39
- expanded={false}
40
- animated={false}
41
- onClick={() => {}}
42
- sectionContentUniqueId="section-content-unique-id"
43
- isFirstSection={false}
44
- isLastSection={false}
45
- tag="h3"
46
- />,
47
- );
48
-
49
- // Act
50
- const header = screen.getByRole("heading", {level: 3, name: "Title"});
51
-
52
- // Assert
53
- expect(header).toBeVisible();
54
- });
55
-
56
- test("renders with react element header", () => {
57
- // Arrange
58
-
59
- // Act
60
- render(
61
- <AccordionSectionHeader
62
- id="accordion-section-header"
63
- header={<div>Section content</div>}
64
- caretPosition="end"
65
- cornerKind="square"
66
- expanded={false}
67
- animated={false}
68
- onClick={() => {}}
69
- sectionContentUniqueId="section-content-unique-id"
70
- isFirstSection={false}
71
- isLastSection={false}
72
- />,
73
- );
74
-
75
- // Assert
76
- expect(screen.getByText("Section content")).toBeVisible();
77
- });
78
-
79
- test("clicking on the header calls onClick", () => {
80
- // Arrange
81
- const onClickSpy = jest.fn();
82
-
83
- // Act
84
- render(
85
- <AccordionSectionHeader
86
- id="accordion-section-header"
87
- header="Title"
88
- caretPosition="end"
89
- cornerKind="square"
90
- expanded={false}
91
- animated={false}
92
- onClick={onClickSpy}
93
- sectionContentUniqueId="section-content-unique-id"
94
- isFirstSection={false}
95
- isLastSection={false}
96
- />,
97
- );
98
- screen.getByText("Title").click();
99
-
100
- // Assert
101
- expect(onClickSpy).toHaveBeenCalledTimes(1);
102
- });
103
-
104
- test("includes transition styles when animated is true", () => {
105
- // Arrange
106
- render(
107
- <AccordionSectionHeader
108
- id="accordion-section-header"
109
- header="Title"
110
- caretPosition="end"
111
- cornerKind="square"
112
- expanded={false}
113
- animated={true}
114
- onClick={() => {}}
115
- sectionContentUniqueId="section-content-unique-id"
116
- isFirstSection={false}
117
- isLastSection={false}
118
- />,
119
- );
120
-
121
- // Act
122
- const header = screen.getByRole("button");
123
-
124
- // Assert
125
- expect(header).toHaveStyle({
126
- transition: "border-radius 300ms",
127
- });
128
- });
129
-
130
- test("does not include transition styles when animated is false", () => {
131
- // Arrange
132
- render(
133
- <AccordionSectionHeader
134
- id="accordion-section-header"
135
- header="Title"
136
- caretPosition="end"
137
- cornerKind="square"
138
- expanded={false}
139
- animated={false}
140
- onClick={() => {}}
141
- sectionContentUniqueId="section-content-unique-id"
142
- isFirstSection={false}
143
- isLastSection={false}
144
- />,
145
- );
146
-
147
- // Act
148
- const header = screen.getByRole("button");
149
-
150
- // Assert
151
- expect(header).not.toHaveStyle({
152
- transition: "border-radius 300ms",
153
- });
154
- });
155
-
156
- test("shows icon when collapsible is true", () => {
157
- // Arrange
158
- render(
159
- <AccordionSectionHeader
160
- id="accordion-section-header"
161
- header="Title"
162
- caretPosition="end"
163
- cornerKind="square"
164
- expanded={false}
165
- animated={false}
166
- collapsible={true}
167
- onClick={() => {}}
168
- sectionContentUniqueId="section-content-unique-id"
169
- isFirstSection={false}
170
- isLastSection={false}
171
- testId="accordion-section-header"
172
- />,
173
- );
174
-
175
- // Act
176
- const icon = screen.queryByTestId(
177
- "accordion-section-header-caret-icon",
178
- );
179
-
180
- // Assert
181
- expect(icon).toBeInTheDocument();
182
- });
183
-
184
- test("does not show icon when collapsible is false", () => {
185
- // Arrange
186
- render(
187
- <AccordionSectionHeader
188
- id="accordion-section-header"
189
- header="Title"
190
- caretPosition="end"
191
- cornerKind="square"
192
- expanded={false}
193
- animated={false}
194
- collapsible={false}
195
- onClick={() => {}}
196
- sectionContentUniqueId="section-content-unique-id"
197
- isFirstSection={false}
198
- isLastSection={false}
199
- testId="accordion-section-header"
200
- />,
201
- );
202
-
203
- // Act
204
- const icon = screen.queryByTestId(
205
- "accordion-section-header-caret-icon",
206
- );
207
-
208
- // Assert
209
- expect(icon).not.toBeInTheDocument();
210
- });
211
- });
@@ -1,361 +0,0 @@
1
- import * as React from "react";
2
- import {render, screen} from "@testing-library/react";
3
-
4
- import {RenderStateRoot} from "@khanacademy/wonder-blocks-core";
5
-
6
- import AccordionSection from "../accordion-section";
7
-
8
- describe("AccordionSection", () => {
9
- test("renders without open panel when expanded is false", () => {
10
- // Arrange
11
-
12
- // Act
13
- render(
14
- <AccordionSection header="Title">Section content</AccordionSection>,
15
- {wrapper: RenderStateRoot},
16
- );
17
-
18
- // Assert
19
- expect(screen.getByText("Title")).toBeVisible();
20
- expect(screen.queryByText("Section content")).not.toBeVisible();
21
- });
22
-
23
- test("renders with open panel when expanded is true", () => {
24
- // Arrange
25
-
26
- // Act
27
- render(
28
- <AccordionSection header="Title" expanded={true}>
29
- Section content
30
- </AccordionSection>,
31
- {wrapper: RenderStateRoot},
32
- );
33
-
34
- // Assert
35
- expect(screen.getByText("Title")).toBeVisible();
36
- expect(screen.queryByText("Section content")).toBeVisible();
37
- });
38
-
39
- test("renders children when child is a react element", () => {
40
- // Arrange
41
-
42
- // Act
43
- render(
44
- <AccordionSection header="Title" expanded={true}>
45
- <div>Section content</div>
46
- </AccordionSection>,
47
- {wrapper: RenderStateRoot},
48
- );
49
-
50
- // Assert
51
- expect(screen.getByText("Title")).toBeVisible();
52
- expect(screen.queryByText("Section content")).toBeVisible();
53
- });
54
-
55
- test("calls onToggle when clicked (controlled)", () => {
56
- // Arrange
57
- const onToggleSpy = jest.fn();
58
-
59
- render(
60
- <AccordionSection
61
- header="Title"
62
- expanded={false}
63
- onToggle={onToggleSpy}
64
- >
65
- Section content
66
- </AccordionSection>,
67
- {wrapper: RenderStateRoot},
68
- );
69
-
70
- const button = screen.getByRole("button", {name: "Title"});
71
-
72
- // Act
73
- button.click();
74
-
75
- // Assert
76
- expect(onToggleSpy).toHaveBeenCalledTimes(1);
77
- });
78
-
79
- test("calls onToggle when clicked (uncontrolled: no expanded, includes onToggle)", () => {
80
- // Arrange
81
- const onToggleSpy = jest.fn();
82
-
83
- render(
84
- <AccordionSection header="Title" onToggle={onToggleSpy}>
85
- Section content
86
- </AccordionSection>,
87
- {wrapper: RenderStateRoot},
88
- );
89
-
90
- const button = screen.getByRole("button", {name: "Title"});
91
-
92
- // Act
93
- button.click();
94
-
95
- // Assert
96
- expect(onToggleSpy).toHaveBeenCalledTimes(1);
97
- });
98
-
99
- test("shows/hides panel when clicked (uncontrolled: includes expanded, no onToggle)", () => {
100
- // Arrange
101
- render(
102
- <AccordionSection header="Title" expanded={true}>
103
- Section content
104
- </AccordionSection>,
105
- {wrapper: RenderStateRoot},
106
- );
107
-
108
- // Act
109
- // Make sure the section is open at first
110
- expect(screen.getByText("Section content")).toBeVisible();
111
-
112
- const button = screen.getByRole("button", {name: "Title"});
113
- button.click();
114
-
115
- // Assert
116
- // Make sure the section has closed after clicking
117
- expect(screen.queryByText("Section content")).not.toBeVisible();
118
- // Repeat clicking to confirm behavior
119
- button.click();
120
- expect(screen.getByText("Section content")).toBeVisible();
121
- });
122
-
123
- test("shows/hides panel when clicked (uncontrolled: no expanded, no onToggle)", () => {
124
- // Arrange
125
- render(
126
- <AccordionSection header="Title">Section content</AccordionSection>,
127
- {wrapper: RenderStateRoot},
128
- );
129
-
130
- // Act
131
- // Make sure the section is closed at first
132
- expect(screen.queryByText("Section content")).not.toBeVisible();
133
-
134
- const button = screen.getByRole("button", {name: "Title"});
135
- button.click();
136
-
137
- // Assert
138
- // Make sure the section has opened after clicking
139
- expect(screen.getByText("Section content")).toBeVisible();
140
- // Repeat clicking to confirm behavior
141
- button.click();
142
- expect(screen.queryByText("Section content")).not.toBeVisible();
143
- });
144
-
145
- test("is h2 by default", () => {
146
- // Arrange
147
- render(
148
- <AccordionSection header="Title">Section content</AccordionSection>,
149
- {wrapper: RenderStateRoot},
150
- );
151
-
152
- // Act
153
- const header = screen.getByRole("heading", {level: 2});
154
-
155
- // Assert
156
- expect(header).toBeVisible();
157
- });
158
-
159
- test("uses provided tag", () => {
160
- // Arrange
161
- render(
162
- <AccordionSection header="Title" tag="h3">
163
- Section content
164
- </AccordionSection>,
165
- {wrapper: RenderStateRoot},
166
- );
167
-
168
- // Act
169
- const header = screen.getByRole("heading", {level: 3});
170
-
171
- // Assert
172
- expect(header).toBeVisible();
173
- });
174
-
175
- test("uses the header's testId as button's data-testid", () => {
176
- // Arrange
177
- render(
178
- <AccordionSection header="Title" testId="accordion-section">
179
- Section content
180
- </AccordionSection>,
181
- {wrapper: RenderStateRoot},
182
- );
183
-
184
- // Act
185
- const button = screen.getByRole("button", {name: "Title"});
186
-
187
- // Assert
188
- expect(button).toHaveAttribute(
189
- "data-testid",
190
- "accordion-section-header",
191
- );
192
- });
193
-
194
- test("wrapper style when cornerKind is square", () => {
195
- // Arrange
196
- render(
197
- <AccordionSection
198
- header="Title"
199
- cornerKind="square"
200
- testId="accordion-section-test-id"
201
- >
202
- Section content
203
- </AccordionSection>,
204
- {wrapper: RenderStateRoot},
205
- );
206
-
207
- // Act
208
- const wrapper = screen.getByTestId("accordion-section-test-id");
209
-
210
- // Assert
211
- expect(wrapper).toHaveStyle({"border-radius": 0});
212
- });
213
-
214
- test("wrapper style when cornerKind is rounded", () => {
215
- // Arrange
216
- render(
217
- <AccordionSection
218
- header="Title"
219
- cornerKind="rounded"
220
- testId="accordion-section-test-id"
221
- >
222
- Section content
223
- </AccordionSection>,
224
- {wrapper: RenderStateRoot},
225
- );
226
-
227
- // Act
228
- const wrapper = screen.getByTestId("accordion-section-test-id");
229
-
230
- // Assert
231
- expect(wrapper).toHaveStyle({
232
- borderStartStartRadius: "12px",
233
- borderStartEndRadius: "12px",
234
- borderEndStartRadius: "12px",
235
- borderEndEndRadius: "12px",
236
- });
237
- });
238
-
239
- test("wrapper style when cornerKind is rounded-per-section", () => {
240
- // Arrange
241
- render(
242
- <AccordionSection
243
- header="Title"
244
- cornerKind="rounded-per-section"
245
- testId="accordion-section-test-id"
246
- >
247
- Section content
248
- </AccordionSection>,
249
- {wrapper: RenderStateRoot},
250
- );
251
-
252
- // Act
253
- const wrapper = screen.getByTestId("accordion-section-test-id");
254
-
255
- // Assert
256
- expect(wrapper).toHaveStyle({
257
- "border-radius": "12px",
258
- });
259
- });
260
-
261
- test("aria-disabled is false by default", () => {
262
- // Arrange
263
- render(
264
- <AccordionSection header="Title">Section content</AccordionSection>,
265
- {wrapper: RenderStateRoot},
266
- );
267
-
268
- // Act
269
- const button = screen.getByRole("button", {name: "Title"});
270
-
271
- // Assert
272
- expect(button).toHaveAttribute("aria-disabled", "false");
273
- });
274
-
275
- test("sets aria-disabled to true when collapsible prop is false", () => {
276
- // Arrange
277
- render(
278
- <AccordionSection header="Title" collapsible={false}>
279
- Section content
280
- </AccordionSection>,
281
- {wrapper: RenderStateRoot},
282
- );
283
-
284
- // Act
285
- const button = screen.getByRole("button", {name: "Title"});
286
-
287
- // Assert
288
- expect(button).toHaveAttribute("aria-disabled", "true");
289
- });
290
-
291
- test("does not allow clicking when collapsible prop is false", () => {
292
- // Arrange
293
- render(
294
- <AccordionSection header="Title" collapsible={false}>
295
- Section content
296
- </AccordionSection>,
297
- {wrapper: RenderStateRoot},
298
- );
299
-
300
- // Act
301
- const button = screen.getByRole("button", {name: "Title"});
302
- button.click();
303
-
304
- // Assert
305
- // Confirm the content is still visible even though the
306
- // header button was clicked.
307
- expect(screen.queryByText("Section content")).toBeVisible();
308
- });
309
-
310
- test("includes transition when animated is true", () => {
311
- // Arrange
312
- render(
313
- <AccordionSection
314
- header="Title"
315
- animated={true}
316
- testId="accordion-section"
317
- >
318
- Section content
319
- </AccordionSection>,
320
- {wrapper: RenderStateRoot},
321
- );
322
-
323
- // Act
324
- const wrapper = screen.getByTestId("accordion-section");
325
- const header = screen.getByTestId("accordion-section-header");
326
-
327
- // Assert
328
- expect(wrapper).toHaveStyle({
329
- transition: "grid-template-rows 300ms",
330
- });
331
- expect(header).toHaveStyle({
332
- transition: "border-radius 300ms",
333
- });
334
- });
335
-
336
- test("does not include transition when animated is false", () => {
337
- // Arrange
338
- render(
339
- <AccordionSection
340
- header="Title"
341
- animated={false}
342
- testId="accordion-section"
343
- >
344
- Section content
345
- </AccordionSection>,
346
- {wrapper: RenderStateRoot},
347
- );
348
-
349
- // Act
350
- const wrapper = screen.getByTestId("accordion-section");
351
- const header = screen.getByTestId("accordion-section-header");
352
-
353
- // Assert
354
- expect(wrapper).not.toHaveStyle({
355
- transition: "grid-template-rows 300ms",
356
- });
357
- expect(header).not.toHaveStyle({
358
- transition: "border-radius 300ms",
359
- });
360
- });
361
- });