@khanacademy/wonder-blocks-dropdown 2.6.7 → 2.6.8
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 +6 -0
- package/dist/es/index.js +202 -79
- package/dist/index.js +310 -174
- package/package.json +1 -1
- package/src/__tests__/__snapshots__/generated-snapshot.test.js.snap +1 -1
- package/src/__tests__/generated-snapshot.test.js +1 -1
- package/src/components/__tests__/action-menu.test.js +126 -166
- package/src/components/__tests__/dropdown-core-virtualized.test.js +20 -35
- package/src/components/__tests__/dropdown-core.test.js +724 -652
- package/src/components/__tests__/dropdown-popper.test.js +51 -0
- package/src/components/__tests__/multi-select.test.js +717 -518
- package/src/components/__tests__/single-select.test.js +52 -41
- package/src/components/action-item.js +2 -0
- package/src/components/dropdown-core.js +159 -90
- package/src/components/dropdown-popper.js +105 -0
- package/src/components/single-select.md +1 -1
- package/src/components/single-select.stories.js +49 -1
|
@@ -1,39 +1,20 @@
|
|
|
1
1
|
//@flow
|
|
2
2
|
import * as React from "react";
|
|
3
|
-
import {
|
|
4
|
-
import {mount} from "enzyme";
|
|
5
|
-
import "jest-enzyme";
|
|
3
|
+
import {render, screen} from "@testing-library/react";
|
|
6
4
|
|
|
7
5
|
import OptionItem from "../option-item.js";
|
|
8
6
|
import SeparatorItem from "../separator-item.js";
|
|
9
7
|
import DropdownCoreVirtualized from "../dropdown-core-virtualized.js";
|
|
10
8
|
import SearchTextInput from "../search-text-input.js";
|
|
11
9
|
|
|
12
|
-
import {unmountAll} from "../../../../../utils/testing/enzyme-shim.js";
|
|
13
|
-
|
|
14
10
|
describe("DropdownCoreVirtualized", () => {
|
|
15
11
|
beforeEach(() => {
|
|
16
12
|
jest.useFakeTimers();
|
|
17
|
-
|
|
18
|
-
// Jest doesn't fake out the animation frame API, so we're going to do
|
|
19
|
-
// it here and map it to timeouts, that way we can use the fake timer
|
|
20
|
-
// API to test our animation frame things.
|
|
21
|
-
jest.spyOn(global, "requestAnimationFrame").mockImplementation((fn) =>
|
|
22
|
-
setTimeout(fn, 0),
|
|
23
|
-
);
|
|
24
|
-
jest.spyOn(global, "cancelAnimationFrame").mockImplementation((id) =>
|
|
25
|
-
clearTimeout(id),
|
|
26
|
-
);
|
|
27
13
|
});
|
|
28
14
|
|
|
29
15
|
afterEach(() => {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
// we set with a setTimeout but are clearing with clearAnimationFrame
|
|
33
|
-
// because we restored the clearAnimationFrame mock (and we won't
|
|
34
|
-
// have cleared the timeout we actually set!)
|
|
35
|
-
unmountAll();
|
|
36
|
-
jest.restoreAllMocks();
|
|
16
|
+
jest.runOnlyPendingTimers();
|
|
17
|
+
jest.useRealTimers();
|
|
37
18
|
});
|
|
38
19
|
|
|
39
20
|
it("should sort the items on first load", () => {
|
|
@@ -64,20 +45,16 @@ describe("DropdownCoreVirtualized", () => {
|
|
|
64
45
|
},
|
|
65
46
|
];
|
|
66
47
|
|
|
67
|
-
|
|
48
|
+
// Act
|
|
49
|
+
const {container} = render(
|
|
68
50
|
<DropdownCoreVirtualized
|
|
69
51
|
data={[...initialItems, ...optionItems]}
|
|
70
52
|
/>,
|
|
71
53
|
);
|
|
72
54
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
const firstLabel = wrapper.find(OptionItem).first().text();
|
|
77
|
-
|
|
78
|
-
// Assert
|
|
79
|
-
// make sure we are rendering the longest item first
|
|
80
|
-
expect(firstLabel).toEqual("ccc");
|
|
55
|
+
// Assert make sure we are rendering from the longest item to the
|
|
56
|
+
// shortest item.
|
|
57
|
+
expect(container).toHaveTextContent(/ccc.*bb.*a/i);
|
|
81
58
|
});
|
|
82
59
|
|
|
83
60
|
it("should render a virtualized list", () => {
|
|
@@ -87,7 +64,7 @@ describe("DropdownCoreVirtualized", () => {
|
|
|
87
64
|
<OptionItem
|
|
88
65
|
key={i}
|
|
89
66
|
value={(i + 1).toString()}
|
|
90
|
-
label={`School ${i + 1}
|
|
67
|
+
label={`School ${i + 1}`}
|
|
91
68
|
/>
|
|
92
69
|
),
|
|
93
70
|
focusable: true,
|
|
@@ -114,15 +91,23 @@ describe("DropdownCoreVirtualized", () => {
|
|
|
114
91
|
},
|
|
115
92
|
];
|
|
116
93
|
|
|
117
|
-
const
|
|
94
|
+
const {rerender} = render(
|
|
118
95
|
<DropdownCoreVirtualized data={initialItems} width={300} />,
|
|
119
96
|
);
|
|
120
97
|
|
|
121
98
|
// Act
|
|
122
99
|
// append items to update container height
|
|
123
|
-
|
|
100
|
+
rerender(
|
|
101
|
+
<DropdownCoreVirtualized
|
|
102
|
+
data={[...initialItems, ...optionItems]}
|
|
103
|
+
width={300}
|
|
104
|
+
/>,
|
|
105
|
+
);
|
|
106
|
+
|
|
107
|
+
const option = screen.getAllByRole("option")[0];
|
|
124
108
|
|
|
125
109
|
// Assert
|
|
126
|
-
|
|
110
|
+
// `left` is only injected by the virtualized list
|
|
111
|
+
expect(option).toHaveStyle("left: 0px");
|
|
127
112
|
});
|
|
128
113
|
});
|