@pixui-dev/pxw 0.1.16

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 (128) hide show
  1. package/bin/pxw.js +217 -0
  2. package/bin/wpbuild.js +10 -0
  3. package/config/default.conf +21 -0
  4. package/config/devops.js +358 -0
  5. package/config/h5es.js +10 -0
  6. package/config/index.html +181 -0
  7. package/config/pfbs.js +207 -0
  8. package/config/testhelp.js +0 -0
  9. package/config/util.js +140 -0
  10. package/config/webpack.js +291 -0
  11. package/lib/assets/border.png +0 -0
  12. package/lib/assets/check.html +62 -0
  13. package/lib/assets/pixui.png +0 -0
  14. package/lib/assets/preact.js +4354 -0
  15. package/lib/assets/preact.png +0 -0
  16. package/lib/check/main.less +63 -0
  17. package/lib/check/main.tsx +41 -0
  18. package/lib/check/tool.js +3 -0
  19. package/lib/check/util.tsx +110 -0
  20. package/lib/grpc-web/dist/ChunkParser.js +117 -0
  21. package/lib/grpc-web/dist/ChunkParser.js.map +1 -0
  22. package/lib/grpc-web/dist/Code.js +58 -0
  23. package/lib/grpc-web/dist/Code.js.map +1 -0
  24. package/lib/grpc-web/dist/client.js +299 -0
  25. package/lib/grpc-web/dist/client.js.map +1 -0
  26. package/lib/grpc-web/dist/debug.js +16 -0
  27. package/lib/grpc-web/dist/debug.js.map +1 -0
  28. package/lib/grpc-web/dist/detach.js +7 -0
  29. package/lib/grpc-web/dist/detach.js.map +1 -0
  30. package/lib/grpc-web/dist/index.js +29 -0
  31. package/lib/grpc-web/dist/index.js.map +1 -0
  32. package/lib/grpc-web/dist/invoke.js +32 -0
  33. package/lib/grpc-web/dist/invoke.js.map +1 -0
  34. package/lib/grpc-web/dist/message.js +3 -0
  35. package/lib/grpc-web/dist/message.js.map +1 -0
  36. package/lib/grpc-web/dist/metadata.js +5 -0
  37. package/lib/grpc-web/dist/metadata.js.map +1 -0
  38. package/lib/grpc-web/dist/service.js +3 -0
  39. package/lib/grpc-web/dist/service.js.map +1 -0
  40. package/lib/grpc-web/dist/transports/Transport.js +15 -0
  41. package/lib/grpc-web/dist/transports/Transport.js.map +1 -0
  42. package/lib/grpc-web/dist/transports/http/fetch.js +117 -0
  43. package/lib/grpc-web/dist/transports/http/fetch.js.map +1 -0
  44. package/lib/grpc-web/dist/transports/http/http.js +15 -0
  45. package/lib/grpc-web/dist/transports/http/http.js.map +1 -0
  46. package/lib/grpc-web/dist/transports/http/xhr.js +136 -0
  47. package/lib/grpc-web/dist/transports/http/xhr.js.map +1 -0
  48. package/lib/grpc-web/dist/transports/http/xhrUtil.js +36 -0
  49. package/lib/grpc-web/dist/transports/http/xhrUtil.js.map +1 -0
  50. package/lib/grpc-web/dist/transports/websocket/websocket.js +95 -0
  51. package/lib/grpc-web/dist/transports/websocket/websocket.js.map +1 -0
  52. package/lib/grpc-web/dist/typings/ChunkParser.d.ts +17 -0
  53. package/lib/grpc-web/dist/typings/Code.d.ts +20 -0
  54. package/lib/grpc-web/dist/typings/client.d.ts +25 -0
  55. package/lib/grpc-web/dist/typings/debug.d.ts +1 -0
  56. package/lib/grpc-web/dist/typings/detach.d.ts +1 -0
  57. package/lib/grpc-web/dist/typings/index.d.ts +45 -0
  58. package/lib/grpc-web/dist/typings/invoke.d.ts +20 -0
  59. package/lib/grpc-web/dist/typings/message.d.ts +8 -0
  60. package/lib/grpc-web/dist/typings/metadata.d.ts +2 -0
  61. package/lib/grpc-web/dist/typings/service.d.ts +16 -0
  62. package/lib/grpc-web/dist/typings/transports/Transport.d.ts +22 -0
  63. package/lib/grpc-web/dist/typings/transports/http/fetch.d.ts +6 -0
  64. package/lib/grpc-web/dist/typings/transports/http/http.d.ts +5 -0
  65. package/lib/grpc-web/dist/typings/transports/http/xhr.d.ts +27 -0
  66. package/lib/grpc-web/dist/typings/transports/http/xhrUtil.d.ts +3 -0
  67. package/lib/grpc-web/dist/typings/transports/websocket/websocket.d.ts +2 -0
  68. package/lib/grpc-web/dist/typings/unary.d.ts +23 -0
  69. package/lib/grpc-web/dist/typings/util.d.ts +2 -0
  70. package/lib/grpc-web/dist/unary.js +44 -0
  71. package/lib/grpc-web/dist/unary.js.map +1 -0
  72. package/lib/grpc-web/dist/util.js +11 -0
  73. package/lib/grpc-web/dist/util.js.map +1 -0
  74. package/lib/grpcTransport/PixHttp2Transport.ts +107 -0
  75. package/lib/grpcTransport/PixLuaTransport.ts +82 -0
  76. package/lib/h5es-types/v1.9.2/h5es.d.ts +1698 -0
  77. package/lib/h5es-types/v3.5.0/h5es.d.ts +1788 -0
  78. package/lib/pi_component/tinyList/tinyList.js +483 -0
  79. package/lib/pi_component/tinyList/tinyList.tsx +517 -0
  80. package/lib/pika-svelte/compiler.js +29829 -0
  81. package/lib/pika-svelte/easing/index.js +158 -0
  82. package/lib/pika-svelte/index.js +72 -0
  83. package/lib/pika-svelte/internal/index.js +1926 -0
  84. package/lib/pika-svelte/motion/index.js +210 -0
  85. package/lib/pika-svelte/package.json +145 -0
  86. package/lib/pika-svelte/register.js +57 -0
  87. package/lib/pika-svelte/rollup.config.js +126 -0
  88. package/lib/pika-svelte/store/index.js +123 -0
  89. package/lib/pika-svelte/transition/index.js +185 -0
  90. package/lib/preact-router.js +395 -0
  91. package/lib/preact.js +4355 -0
  92. package/lib/preact.tq.js +4385 -0
  93. package/lib/react-window/src/FixedSizeGrid.js +172 -0
  94. package/lib/react-window/src/FixedSizeList.js +91 -0
  95. package/lib/react-window/src/VariableSizeGrid.js +329 -0
  96. package/lib/react-window/src/VariableSizeList.js +231 -0
  97. package/lib/react-window/src/__tests__/FixedSizeGrid.js +942 -0
  98. package/lib/react-window/src/__tests__/FixedSizeList.js +749 -0
  99. package/lib/react-window/src/__tests__/VariableSizeGrid.js +598 -0
  100. package/lib/react-window/src/__tests__/VariableSizeList.js +345 -0
  101. package/lib/react-window/src/__tests__/__snapshots__/FixedSizeGrid.js.snap +912 -0
  102. package/lib/react-window/src/__tests__/__snapshots__/FixedSizeList.js.snap +568 -0
  103. package/lib/react-window/src/__tests__/__snapshots__/VariableSizeGrid.js.snap +542 -0
  104. package/lib/react-window/src/__tests__/__snapshots__/VariableSizeList.js.snap +331 -0
  105. package/lib/react-window/src/__tests__/areEqual.js +28 -0
  106. package/lib/react-window/src/__tests__/shouldComponentUpdate.js +32 -0
  107. package/lib/react-window/src/areEqual.js +13 -0
  108. package/lib/react-window/src/createGridComponent.js +657 -0
  109. package/lib/react-window/src/createListComponent.js +574 -0
  110. package/lib/react-window/src/domHelpers.js +69 -0
  111. package/lib/react-window/src/index.js +9 -0
  112. package/lib/react-window/src/shallowDiffers.js +17 -0
  113. package/lib/react-window/src/shouldComponentUpdate.js +11 -0
  114. package/lib/react-window/src/test.js.flow +382 -0
  115. package/lib/react-window/src/timer.js +36 -0
  116. package/lib/svelte-tab/Tab.svelte +31 -0
  117. package/lib/svelte-tab/TabList.svelte +10 -0
  118. package/lib/svelte-tab/TabPanel.svelte +13 -0
  119. package/lib/svelte-tab/Tabs.svelte +68 -0
  120. package/lib/svelte-tab/tabs.js +4 -0
  121. package/lib/types/css.d.ts +7476 -0
  122. package/lib/types/dom.ts +17 -0
  123. package/lib/types/ext.d.ts +81 -0
  124. package/lib/types/internal.d.ts +94 -0
  125. package/lib/types/jsx.d.ts +309 -0
  126. package/lib/types/preact.d.ts +340 -0
  127. package/package.json +111 -0
  128. package/tsconfig.json +30 -0
@@ -0,0 +1,345 @@
1
+ import React, { createRef, PureComponent } from 'react';
2
+ import { render } from 'react-dom';
3
+ import { Simulate } from 'react-dom/test-utils';
4
+ import ReactTestRenderer from 'react-test-renderer';
5
+ import { VariableSizeList } from '..';
6
+
7
+ const simulateScroll = (instance, scrollOffset, direction = 'vertical') => {
8
+ if (direction === 'horizontal') {
9
+ instance._outerRef.scrollLeft = scrollOffset;
10
+ }
11
+ else {
12
+ instance._outerRef.scrollTop = scrollOffset;
13
+ }
14
+ Simulate.scroll(instance._outerRef);
15
+ };
16
+
17
+ const findScrollContainer = (rendered) => rendered.root.children[0].children[0];
18
+
19
+ describe('VariableSizeList', () => {
20
+ let itemRenderer, itemSize, defaultProps, onItemsRendered;
21
+
22
+ // Use PureComponent to test memoization.
23
+ // Pass through to itemRenderer mock for easier test assertions.
24
+ class PureItemRenderer extends PureComponent {
25
+ render() {
26
+ return itemRenderer(this.props);
27
+ }
28
+ }
29
+
30
+ beforeEach(() => {
31
+ jest.useFakeTimers();
32
+
33
+ // JSdom does not do actual layout and so doesn't return meaningful values here.
34
+ // For the purposes of our tests though, we can mock out semi-meaningful values.
35
+ // This mock is required for e.g. "onScroll" tests to work properly.
36
+ Object.defineProperties(HTMLElement.prototype, {
37
+ clientWidth: {
38
+ configurable: true,
39
+ get: function () {
40
+ return parseInt(this.style.width, 10) || 0;
41
+ },
42
+ },
43
+ clientHeight: {
44
+ configurable: true,
45
+ get: function () {
46
+ return parseInt(this.style.height, 10) || 0;
47
+ },
48
+ },
49
+ scrollHeight: {
50
+ configurable: true,
51
+ get: () => Number.MAX_SAFE_INTEGER,
52
+ },
53
+ scrollWidth: {
54
+ configurable: true,
55
+ get: () => Number.MAX_SAFE_INTEGER,
56
+ },
57
+ });
58
+
59
+ itemRenderer = jest.fn(({ style, ...rest }) => <div style={style}>{JSON.stringify(rest, null, 2)}</div>);
60
+ itemSize = jest.fn((index) => 25 + index);
61
+ onItemsRendered = jest.fn();
62
+ defaultProps = {
63
+ children: PureItemRenderer,
64
+ estimatedItemSize: 25,
65
+ height: 100,
66
+ itemCount: 20,
67
+ itemSize,
68
+ onItemsRendered,
69
+ width: 50,
70
+ };
71
+ });
72
+
73
+ // Much of the shared List functionality is already tested by FixedSizeList tests.
74
+ // This test covers functionality that is unique to VariableSizeList.
75
+
76
+ it('should render an empty list', () => {
77
+ ReactTestRenderer.create(<VariableSizeList {...defaultProps} itemCount={0} />);
78
+ expect(itemSize).not.toHaveBeenCalled();
79
+ expect(itemRenderer).not.toHaveBeenCalled();
80
+ expect(onItemsRendered).not.toHaveBeenCalled();
81
+ });
82
+
83
+ it('changing itemSize does not impact the rendered items', () => {
84
+ const rendered = ReactTestRenderer.create(<VariableSizeList {...defaultProps} />);
85
+ itemRenderer.mockClear();
86
+ rendered.update(<VariableSizeList {...defaultProps} itemSize={(index) => 50} onItemsRendered={onItemsRendered} />);
87
+ expect(itemRenderer).not.toHaveBeenCalled();
88
+ });
89
+
90
+ describe('estimatedItemSize', () => {
91
+ it('should estimate an initial scrollable size based on this value', () => {
92
+ const itemSize = jest.fn(() => 25);
93
+ const rendered = ReactTestRenderer.create(<VariableSizeList {...defaultProps} estimatedItemSize={50} height={100} itemCount={100} itemSize={itemSize} overscanCount={0} />);
94
+ // We'll render 5 rows initially, each at 25px tall (125px total).
95
+ // The remaining 95 rows will be estimated at 50px tall (4,750px total).
96
+ // This means an initial height estimate of 4,875px.
97
+ expect(itemSize).toHaveBeenCalledTimes(5);
98
+ const scrollContainer = findScrollContainer(rendered);
99
+ expect(scrollContainer.props.style.height).toEqual(4875);
100
+ });
101
+
102
+ it('should udpate the scrollable size as more items are measured', () => {
103
+ const itemSize = jest.fn(() => 25);
104
+ const rendered = ReactTestRenderer.create(<VariableSizeList {...defaultProps} estimatedItemSize={50} itemCount={100} itemSize={itemSize} overscanCount={0} />);
105
+ rendered.getInstance().scrollToItem(18);
106
+ // Including the additional 1 (minimum) overscan row,
107
+ // We've now measured 20 rows, each at 25px tall (500px total).
108
+ // The remaining 80 rows will be estimated at 50px tall (4,500px total).
109
+ // This means an updated height estimate of 4,500px.
110
+ expect(itemSize).toHaveBeenCalledTimes(20);
111
+ const scrollContainer = findScrollContainer(rendered);
112
+ expect(scrollContainer.props.style.height).toEqual(4500);
113
+ });
114
+ });
115
+
116
+ describe('scrollToItem method', () => {
117
+ it('should not set invalid offsets when the list contains few items', () => {
118
+ const onScroll = jest.fn();
119
+ const rendered = ReactTestRenderer.create(<VariableSizeList {...defaultProps} itemCount={3} onScroll={onScroll} />);
120
+ expect(onItemsRendered).toMatchSnapshot();
121
+ onItemsRendered.mockClear();
122
+ rendered.getInstance().scrollToItem(0);
123
+ expect(onItemsRendered).not.toHaveBeenCalled();
124
+ });
125
+
126
+ it('should scroll to the correct item for align = "auto"', () => {
127
+ const onItemsRendered = jest.fn();
128
+ const rendered = ReactTestRenderer.create(<VariableSizeList {...defaultProps} onItemsRendered={onItemsRendered} />);
129
+ // Scroll down enough to show item 10 at the bottom.
130
+ rendered.getInstance().scrollToItem(10, 'auto');
131
+ // No need to scroll again; item 9 is already visible.
132
+ // Overscan indices will change though, since direction changes.
133
+ rendered.getInstance().scrollToItem(9, 'auto');
134
+ // Scroll up enough to show item 2 at the top.
135
+ rendered.getInstance().scrollToItem(2, 'auto');
136
+ expect(onItemsRendered.mock.calls).toMatchSnapshot();
137
+ });
138
+
139
+ it('scroll with align = "auto" should work with partially-visible items', () => {
140
+ const rendered = ReactTestRenderer.create(
141
+ // Create list where items don't fit exactly into container.
142
+ // The container has space for 3 1/3 items.
143
+ <VariableSizeList {...defaultProps} itemCount={100} itemSize={() => 30} />,
144
+ );
145
+ // Scroll down enough to show item 10 at the bottom.
146
+ // Should show 4 items: 3 full and one partial at the beginning
147
+ rendered.getInstance().scrollToItem(10, 'auto');
148
+ // No need to scroll again; item 9 is already visible.
149
+ // Because there's no scrolling, it won't call onItemsRendered.
150
+ rendered.getInstance().scrollToItem(9, 'auto');
151
+ // Scroll to near the end. #96 will be shown as partial.
152
+ rendered.getInstance().scrollToItem(99, 'auto');
153
+ // Scroll back to show #96 fully. This will cause #99 to be shown as a
154
+ // partial. Because #96 was already shown previously as a partial, all
155
+ // props of the onItemsRendered will be the same. This means that even
156
+ // though a scroll happened in the DOM, onItemsRendered won't be called.
157
+ rendered.getInstance().scrollToItem(96, 'auto');
158
+ // Scroll forward again. Because item #99 was already shown partially,
159
+ // all props of the onItemsRendered will be the same.
160
+ rendered.getInstance().scrollToItem(99, 'auto');
161
+ // Scroll to the second item. A partial fifth item should
162
+ // be shown after it.
163
+ rendered.getInstance().scrollToItem(1, 'auto');
164
+ // Scroll to the first item. Now the fourth item should be a partial.
165
+ rendered.getInstance().scrollToItem(0, 'auto');
166
+ expect(onItemsRendered.mock.calls).toMatchSnapshot();
167
+ });
168
+
169
+ it('should scroll to the correct item for align = "start"', () => {
170
+ const onItemsRendered = jest.fn();
171
+ const rendered = ReactTestRenderer.create(<VariableSizeList {...defaultProps} onItemsRendered={onItemsRendered} />);
172
+ // Scroll down enough to show item 10 at the top.
173
+ rendered.getInstance().scrollToItem(10, 'start');
174
+ // Scroll back up so that item 9 is at the top.
175
+ // Overscroll direction wil change too.
176
+ rendered.getInstance().scrollToItem(9, 'start');
177
+ // Item 19 can't align at the top because there aren't enough items.
178
+ // Scroll down as far as possible though.
179
+ // Overscroll direction wil change again.
180
+ rendered.getInstance().scrollToItem(19, 'start');
181
+ expect(onItemsRendered.mock.calls).toMatchSnapshot();
182
+ });
183
+
184
+ it('should scroll to the correct item for align = "end"', () => {
185
+ const onItemsRendered = jest.fn();
186
+ const rendered = ReactTestRenderer.create(<VariableSizeList {...defaultProps} onItemsRendered={onItemsRendered} />);
187
+ // Scroll down enough to show item 10 at the bottom.
188
+ rendered.getInstance().scrollToItem(10, 'end');
189
+ // Scroll back up so that item 9 is at the bottom.
190
+ // Overscroll direction wil change too.
191
+ rendered.getInstance().scrollToItem(9, 'end');
192
+ // Item 1 can't align at the bottom because it's too close to the beginning.
193
+ // Scroll up as far as possible though.
194
+ // Overscroll direction wil change again.
195
+ rendered.getInstance().scrollToItem(1, 'end');
196
+ expect(onItemsRendered.mock.calls).toMatchSnapshot();
197
+ });
198
+
199
+ it('should scroll to the correct item for align = "center"', () => {
200
+ const onItemsRendered = jest.fn();
201
+ const rendered = ReactTestRenderer.create(<VariableSizeList {...defaultProps} onItemsRendered={onItemsRendered} />);
202
+ // Scroll down enough to show item 10 in the middle.
203
+ rendered.getInstance().scrollToItem(10, 'center');
204
+ // Scroll back up so that item 9 is in the middle.
205
+ // Overscroll direction wil change too.
206
+ rendered.getInstance().scrollToItem(9, 'center');
207
+ // Item 1 can't align in the middle because it's too close to the beginning.
208
+ // Scroll up as far as possible though.
209
+ // Overscroll direction wil change again.
210
+ rendered.getInstance().scrollToItem(1, 'center');
211
+ expect(onItemsRendered.mock.calls).toMatchSnapshot();
212
+ // Item 19 can't align in the middle because it's too close to the end.
213
+ // Scroll down as far as possible though.
214
+ // Overscroll direction wil change again.
215
+ rendered.getInstance().scrollToItem(19, 'center');
216
+ expect(onItemsRendered.mock.calls).toMatchSnapshot();
217
+ });
218
+
219
+ it('should scroll to the correct item for align = "smart"', () => {
220
+ const onItemsRendered = jest.fn();
221
+ const rendered = ReactTestRenderer.create(<VariableSizeList {...defaultProps} onItemsRendered={onItemsRendered} />);
222
+ // Scroll down enough to show item 10 in the middle.
223
+ rendered.getInstance().scrollToItem(10, 'smart');
224
+ // Scrolldn't scroll at all because it's close enough.
225
+ rendered.getInstance().scrollToItem(9, 'smart');
226
+ // Should scroll but not center because it's close enough.
227
+ rendered.getInstance().scrollToItem(6, 'smart');
228
+ // Item 1 can't align in the middle because it's too close to the beginning.
229
+ // Scroll up as far as possible though.
230
+ rendered.getInstance().scrollToItem(1, 'smart');
231
+ expect(onItemsRendered.mock.calls).toMatchSnapshot();
232
+ });
233
+ });
234
+
235
+ describe('onScroll', () => {
236
+ it('scrolling should report partial items correctly in onItemsRendered', () => {
237
+ // Use ReactDOM renderer so the container ref works correctly.
238
+ const instance = render(<VariableSizeList {...defaultProps} initialScrollOffset={20} itemCount={100} itemSize={() => 25} />, document.createElement('div'));
239
+ // Scroll 2 items fwd, but thanks to the initialScrollOffset, we should
240
+ // still be showing partials on both ends.
241
+ simulateScroll(instance, 70);
242
+ // Scroll a little fwd to cause partials to be hidden
243
+ simulateScroll(instance, 75);
244
+ // Scroll backwards to show partials again
245
+ simulateScroll(instance, 70);
246
+ // Scroll near the end so that the last item is shown
247
+ // as a partial.
248
+ simulateScroll(instance, 96 * 25 - 5);
249
+ // Scroll to the end. No partials.
250
+ simulateScroll(instance, 96 * 25);
251
+ // Verify that backwards scrolling near the end works OK.
252
+ simulateScroll(instance, 96 * 25 - 5);
253
+ expect(onItemsRendered.mock.calls).toMatchSnapshot();
254
+ });
255
+ });
256
+
257
+ describe('resetAfterIndex method', () => {
258
+ it('should recalculate the estimated total size', () => {
259
+ const itemSize = jest.fn(() => 75);
260
+ const rendered = ReactTestRenderer.create(<VariableSizeList {...defaultProps} itemSize={(index) => 25} />);
261
+ rendered.getInstance().scrollToItem(19);
262
+ // We've measured every item initially.
263
+ const scrollContainer = findScrollContainer(rendered);
264
+ expect(scrollContainer.props.style.height).toEqual(500);
265
+ // Supplying a new itemSize alone should not impact anything.
266
+ rendered.update(<VariableSizeList {...defaultProps} itemSize={itemSize} />);
267
+ expect(scrollContainer.props.style.height).toEqual(500);
268
+ // Reset styles after index 15,
269
+ // And verify that the new estimated total takes this into account.
270
+ rendered.getInstance().resetAfterIndex(15);
271
+ rendered.getInstance().scrollToItem(19);
272
+ expect(itemSize).toHaveBeenCalledTimes(5);
273
+ expect(scrollContainer.props.style.height).toEqual(750);
274
+ });
275
+
276
+ it('should delay the recalculation of the estimated total size if shouldForceUpdate is false', () => {
277
+ const rendered = ReactTestRenderer.create(<VariableSizeList {...defaultProps} estimatedItemSize={30} overscanCount={1} itemSize={(index) => 25} />);
278
+ const scrollContainer = findScrollContainer(rendered);
279
+ // The estimated total size should be (100 + 25 * 1 + 30 * 15)px = 575px.
280
+ expect(scrollContainer.props.style.height).toEqual(575);
281
+ // Supplying a new itemSize alone should not impact anything.
282
+ // Although the list get re-rendered by passing inline functions,
283
+ // but it still use the cached metrics to calculate the estimated size.
284
+ rendered.update(<VariableSizeList {...defaultProps} estimatedItemSize={30} overscanCount={1} itemSize={(index) => 20} />);
285
+ expect(scrollContainer.props.style.height).toEqual(575);
286
+ // Reset calculation cache but don't re-render the list,
287
+ // the estimated total size should stay the same.
288
+ rendered.getInstance().resetAfterIndex(0, false);
289
+ expect(scrollContainer.props.style.height).toEqual(575);
290
+ // Pass inline function to make the list re-render.
291
+ rendered.update(<VariableSizeList {...defaultProps} estimatedItemSize={30} overscanCount={1} itemSize={(index) => 20} />);
292
+ // The estimated total height should be (100 + 20 * 1 + 30 * 14)px = 540px.
293
+ expect(scrollContainer.props.style.height).toEqual(540);
294
+ });
295
+
296
+ it('should re-render items after the specified index with updated styles', () => {
297
+ const itemSize = jest.fn(() => 75);
298
+ const rendered = ReactTestRenderer.create(<VariableSizeList {...defaultProps} itemCount={5} itemSize={(index) => 25} />);
299
+ // We've rendered 5 rows initially.
300
+ expect(itemRenderer).toHaveBeenCalledTimes(5);
301
+ expect(itemRenderer.mock.calls[3][0].style.height).toBe(25);
302
+ // Supplying a new itemSize alone should not impact anything.
303
+ rendered.update(<VariableSizeList {...defaultProps} itemCount={5} itemSize={itemSize} />);
304
+ // Reset styles for rows 4 and 5.
305
+ // And verify that the affected rows are re-rendered with new styles.
306
+ itemRenderer.mockClear();
307
+ rendered.getInstance().resetAfterIndex(3);
308
+ expect(itemRenderer).toHaveBeenCalledTimes(5);
309
+ expect(itemRenderer.mock.calls[3][0].style.height).toBe(75);
310
+ });
311
+ });
312
+
313
+ describe('props validation', () => {
314
+ beforeEach(() => spyOn(console, 'error'));
315
+
316
+ it('should fail if non-function itemSize is provided', () => {
317
+ expect(() => ReactTestRenderer.create(<VariableSizeList {...defaultProps} itemSize={123} />)).toThrow(
318
+ 'An invalid "itemSize" prop has been specified. ' + 'Value should be a function. "number" was specified.',
319
+ );
320
+ });
321
+ });
322
+
323
+ // https://github.com/bvaughn/react-window/pull/138
324
+ it('should descrease scroll size when itemCount decreases', () => {
325
+ const innerRef = createRef();
326
+ const listRef = createRef();
327
+
328
+ class Wrapper extends PureComponent {
329
+ state = { itemCount: 100 };
330
+ render() {
331
+ return <VariableSizeList {...defaultProps} itemCount={this.state.itemCount} innerRef={innerRef} ref={listRef} />;
332
+ }
333
+ }
334
+
335
+ // Use ReactDOM renderer so "scroll" events work correctly.
336
+ const instance = render(<Wrapper />, document.createElement('div'));
337
+
338
+ // Simulate scrolling past several rows.
339
+ simulateScroll(listRef.current, 3000);
340
+
341
+ // Decrease itemCount a lot and verify the scroll height is descreased as well.
342
+ instance.setState({ itemCount: 3 });
343
+ expect(innerRef.current.style.height).toEqual('78px');
344
+ });
345
+ });