@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.
@@ -1,39 +1,20 @@
1
1
  //@flow
2
2
  import * as React from "react";
3
- import {VariableSizeList as List} from "react-window";
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
- // We have to explicitly unmount before clearing mocks, otherwise jest
31
- // timers will throw because we'll try to clear an animation frame that
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
- const wrapper = mount(
48
+ // Act
49
+ const {container} = render(
68
50
  <DropdownCoreVirtualized
69
51
  data={[...initialItems, ...optionItems]}
70
52
  />,
71
53
  );
72
54
 
73
- jest.runAllTimers();
74
-
75
- // Act
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} in Wizarding World`}
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 wrapper = mount(
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
- wrapper.setProps({data: [...initialItems, ...optionItems]});
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
- expect(wrapper.find(List)).toExist();
110
+ // `left` is only injected by the virtualized list
111
+ expect(option).toHaveStyle("left: 0px");
127
112
  });
128
113
  });