@depup/react-virtualized 9.22.6-depup.0

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 (254) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +34 -0
  3. package/changes.json +22 -0
  4. package/dist/commonjs/ArrowKeyStepper/ArrowKeyStepper.example.js +184 -0
  5. package/dist/commonjs/ArrowKeyStepper/ArrowKeyStepper.jest.js +338 -0
  6. package/dist/commonjs/ArrowKeyStepper/ArrowKeyStepper.js +204 -0
  7. package/dist/commonjs/ArrowKeyStepper/index.js +19 -0
  8. package/dist/commonjs/ArrowKeyStepper/types.js +5 -0
  9. package/dist/commonjs/AutoSizer/AutoSizer.example.js +104 -0
  10. package/dist/commonjs/AutoSizer/AutoSizer.jest.js +341 -0
  11. package/dist/commonjs/AutoSizer/AutoSizer.js +199 -0
  12. package/dist/commonjs/AutoSizer/AutoSizer.ssr.js +25 -0
  13. package/dist/commonjs/AutoSizer/index.js +19 -0
  14. package/dist/commonjs/CellMeasurer/CellMeasurer.DynamicHeightGrid.example.js +100 -0
  15. package/dist/commonjs/CellMeasurer/CellMeasurer.DynamicHeightList.example.js +99 -0
  16. package/dist/commonjs/CellMeasurer/CellMeasurer.DynamicHeightTableColumn.example.js +107 -0
  17. package/dist/commonjs/CellMeasurer/CellMeasurer.DynamicWidthGrid.example.js +102 -0
  18. package/dist/commonjs/CellMeasurer/CellMeasurer.DynamicWidthMultiGrid.example.js +107 -0
  19. package/dist/commonjs/CellMeasurer/CellMeasurer.example.js +129 -0
  20. package/dist/commonjs/CellMeasurer/CellMeasurer.jest.js +345 -0
  21. package/dist/commonjs/CellMeasurer/CellMeasurer.js +195 -0
  22. package/dist/commonjs/CellMeasurer/CellMeasurerCache.jest.js +298 -0
  23. package/dist/commonjs/CellMeasurer/CellMeasurerCache.js +202 -0
  24. package/dist/commonjs/CellMeasurer/index.js +22 -0
  25. package/dist/commonjs/CellMeasurer/types.js +14 -0
  26. package/dist/commonjs/Collection/Collection.example.js +231 -0
  27. package/dist/commonjs/Collection/Collection.jest.js +829 -0
  28. package/dist/commonjs/Collection/Collection.js +266 -0
  29. package/dist/commonjs/Collection/CollectionView.js +553 -0
  30. package/dist/commonjs/Collection/Section.jest.js +63 -0
  31. package/dist/commonjs/Collection/Section.js +57 -0
  32. package/dist/commonjs/Collection/SectionManager.jest.js +121 -0
  33. package/dist/commonjs/Collection/SectionManager.js +134 -0
  34. package/dist/commonjs/Collection/TestData.js +77 -0
  35. package/dist/commonjs/Collection/index.js +15 -0
  36. package/dist/commonjs/Collection/types.js +22 -0
  37. package/dist/commonjs/Collection/utils/calculateSizeAndPositionData.jest.js +34 -0
  38. package/dist/commonjs/Collection/utils/calculateSizeAndPositionData.js +38 -0
  39. package/dist/commonjs/ColumnSizer/ColumnSizer.example.js +159 -0
  40. package/dist/commonjs/ColumnSizer/ColumnSizer.jest.js +129 -0
  41. package/dist/commonjs/ColumnSizer/ColumnSizer.js +103 -0
  42. package/dist/commonjs/ColumnSizer/index.js +15 -0
  43. package/dist/commonjs/Grid/Grid.example.js +330 -0
  44. package/dist/commonjs/Grid/Grid.jest.js +2561 -0
  45. package/dist/commonjs/Grid/Grid.js +1432 -0
  46. package/dist/commonjs/Grid/Grid.ssr.js +62 -0
  47. package/dist/commonjs/Grid/accessibilityOverscanIndicesGetter.jest.js +92 -0
  48. package/dist/commonjs/Grid/accessibilityOverscanIndicesGetter.js +40 -0
  49. package/dist/commonjs/Grid/defaultCellRangeRenderer.js +139 -0
  50. package/dist/commonjs/Grid/defaultOverscanIndicesGetter.jest.js +92 -0
  51. package/dist/commonjs/Grid/defaultOverscanIndicesGetter.js +36 -0
  52. package/dist/commonjs/Grid/index.js +40 -0
  53. package/dist/commonjs/Grid/types.js +8 -0
  54. package/dist/commonjs/Grid/utils/CellSizeAndPositionManager.jest.js +375 -0
  55. package/dist/commonjs/Grid/utils/CellSizeAndPositionManager.js +296 -0
  56. package/dist/commonjs/Grid/utils/ScalingCellSizeAndPositionManager.jest.js +201 -0
  57. package/dist/commonjs/Grid/utils/ScalingCellSizeAndPositionManager.js +204 -0
  58. package/dist/commonjs/Grid/utils/calculateSizeAndPositionDataAndUpdateScrollOffset.jest.js +84 -0
  59. package/dist/commonjs/Grid/utils/calculateSizeAndPositionDataAndUpdateScrollOffset.js +59 -0
  60. package/dist/commonjs/Grid/utils/maxElementSize.js +22 -0
  61. package/dist/commonjs/Grid/utils/updateScrollIndexHelper.jest.js +180 -0
  62. package/dist/commonjs/Grid/utils/updateScrollIndexHelper.js +85 -0
  63. package/dist/commonjs/InfiniteLoader/InfiniteLoader.example.js +179 -0
  64. package/dist/commonjs/InfiniteLoader/InfiniteLoader.jest.js +571 -0
  65. package/dist/commonjs/InfiniteLoader/InfiniteLoader.js +274 -0
  66. package/dist/commonjs/InfiniteLoader/index.js +15 -0
  67. package/dist/commonjs/List/List.example.js +236 -0
  68. package/dist/commonjs/List/List.jest.js +517 -0
  69. package/dist/commonjs/List/List.js +318 -0
  70. package/dist/commonjs/List/index.js +19 -0
  71. package/dist/commonjs/List/types.js +6 -0
  72. package/dist/commonjs/Masonry/Masonry.example.js +287 -0
  73. package/dist/commonjs/Masonry/Masonry.jest.js +450 -0
  74. package/dist/commonjs/Masonry/Masonry.js +431 -0
  75. package/dist/commonjs/Masonry/PositionCache.js +88 -0
  76. package/dist/commonjs/Masonry/createCellPositioner.js +59 -0
  77. package/dist/commonjs/Masonry/index.js +22 -0
  78. package/dist/commonjs/MultiGrid/CellMeasurerCacheDecorator.js +106 -0
  79. package/dist/commonjs/MultiGrid/MultiGrid.example.js +131 -0
  80. package/dist/commonjs/MultiGrid/MultiGrid.jest.js +584 -0
  81. package/dist/commonjs/MultiGrid/MultiGrid.js +743 -0
  82. package/dist/commonjs/MultiGrid/index.js +15 -0
  83. package/dist/commonjs/ScrollSync/ScrollSync.example.js +257 -0
  84. package/dist/commonjs/ScrollSync/ScrollSync.jest.js +66 -0
  85. package/dist/commonjs/ScrollSync/ScrollSync.js +88 -0
  86. package/dist/commonjs/ScrollSync/index.js +15 -0
  87. package/dist/commonjs/Table/Column.jest.js +90 -0
  88. package/dist/commonjs/Table/Column.js +93 -0
  89. package/dist/commonjs/Table/SortDirection.js +19 -0
  90. package/dist/commonjs/Table/SortIndicator.js +40 -0
  91. package/dist/commonjs/Table/Table.example.js +325 -0
  92. package/dist/commonjs/Table/Table.jest.js +1257 -0
  93. package/dist/commonjs/Table/Table.js +742 -0
  94. package/dist/commonjs/Table/createMultiSort.jest.js +165 -0
  95. package/dist/commonjs/Table/createMultiSort.js +99 -0
  96. package/dist/commonjs/Table/defaultCellDataGetter.js +21 -0
  97. package/dist/commonjs/Table/defaultCellRenderer.js +19 -0
  98. package/dist/commonjs/Table/defaultHeaderRenderer.js +35 -0
  99. package/dist/commonjs/Table/defaultHeaderRowRenderer.js +21 -0
  100. package/dist/commonjs/Table/defaultRowRenderer.js +87 -0
  101. package/dist/commonjs/Table/index.js +78 -0
  102. package/dist/commonjs/Table/types.js +39 -0
  103. package/dist/commonjs/WindowScroller/WindowScroller.e2e.js +298 -0
  104. package/dist/commonjs/WindowScroller/WindowScroller.example.js +167 -0
  105. package/dist/commonjs/WindowScroller/WindowScroller.header-resize.e2e.js +359 -0
  106. package/dist/commonjs/WindowScroller/WindowScroller.jest.js +536 -0
  107. package/dist/commonjs/WindowScroller/WindowScroller.js +268 -0
  108. package/dist/commonjs/WindowScroller/WindowScroller.ssr.js +25 -0
  109. package/dist/commonjs/WindowScroller/index.js +23 -0
  110. package/dist/commonjs/WindowScroller/utils/dimensions.js +89 -0
  111. package/dist/commonjs/WindowScroller/utils/onScroll.js +70 -0
  112. package/dist/commonjs/index.js +180 -0
  113. package/dist/commonjs/jest-setup.js +7 -0
  114. package/dist/commonjs/utils/TestHelper.js +36 -0
  115. package/dist/commonjs/utils/animationFrame.js +29 -0
  116. package/dist/commonjs/utils/createCallbackMemoizer.jest.js +219 -0
  117. package/dist/commonjs/utils/createCallbackMemoizer.js +31 -0
  118. package/dist/commonjs/utils/getUpdatedOffsetForIndex.jest.js +68 -0
  119. package/dist/commonjs/utils/getUpdatedOffsetForIndex.js +38 -0
  120. package/dist/commonjs/utils/initCellMetadata.js +37 -0
  121. package/dist/commonjs/utils/requestAnimationTimeout.js +38 -0
  122. package/dist/commonjs/vendor/binarySearchBounds.js +200 -0
  123. package/dist/commonjs/vendor/detectElementResize.js +192 -0
  124. package/dist/commonjs/vendor/intervalTree.js +361 -0
  125. package/dist/es/ArrowKeyStepper/ArrowKeyStepper.example.js +176 -0
  126. package/dist/es/ArrowKeyStepper/ArrowKeyStepper.jest.js +332 -0
  127. package/dist/es/ArrowKeyStepper/ArrowKeyStepper.js +197 -0
  128. package/dist/es/ArrowKeyStepper/index.js +3 -0
  129. package/dist/es/ArrowKeyStepper/types.js +4 -0
  130. package/dist/es/AutoSizer/AutoSizer.example.js +96 -0
  131. package/dist/es/AutoSizer/AutoSizer.jest.js +335 -0
  132. package/dist/es/AutoSizer/AutoSizer.js +190 -0
  133. package/dist/es/AutoSizer/AutoSizer.js.flow +200 -0
  134. package/dist/es/AutoSizer/AutoSizer.ssr.js +19 -0
  135. package/dist/es/AutoSizer/index.js +2 -0
  136. package/dist/es/AutoSizer/index.js.flow +4 -0
  137. package/dist/es/CellMeasurer/CellMeasurer.DynamicHeightGrid.example.js +91 -0
  138. package/dist/es/CellMeasurer/CellMeasurer.DynamicHeightList.example.js +90 -0
  139. package/dist/es/CellMeasurer/CellMeasurer.DynamicHeightTableColumn.example.js +98 -0
  140. package/dist/es/CellMeasurer/CellMeasurer.DynamicWidthGrid.example.js +93 -0
  141. package/dist/es/CellMeasurer/CellMeasurer.DynamicWidthMultiGrid.example.js +98 -0
  142. package/dist/es/CellMeasurer/CellMeasurer.example.js +120 -0
  143. package/dist/es/CellMeasurer/CellMeasurer.jest.js +340 -0
  144. package/dist/es/CellMeasurer/CellMeasurer.js +187 -0
  145. package/dist/es/CellMeasurer/CellMeasurerCache.jest.js +293 -0
  146. package/dist/es/CellMeasurer/CellMeasurerCache.js +196 -0
  147. package/dist/es/CellMeasurer/index.js +4 -0
  148. package/dist/es/CellMeasurer/types.js +13 -0
  149. package/dist/es/Collection/Collection.example.js +223 -0
  150. package/dist/es/Collection/Collection.jest.js +824 -0
  151. package/dist/es/Collection/Collection.js +257 -0
  152. package/dist/es/Collection/CollectionView.js +544 -0
  153. package/dist/es/Collection/Section.jest.js +60 -0
  154. package/dist/es/Collection/Section.js +51 -0
  155. package/dist/es/Collection/SectionManager.jest.js +118 -0
  156. package/dist/es/Collection/SectionManager.js +128 -0
  157. package/dist/es/Collection/TestData.js +71 -0
  158. package/dist/es/Collection/index.js +3 -0
  159. package/dist/es/Collection/types.js +21 -0
  160. package/dist/es/Collection/utils/calculateSizeAndPositionData.jest.js +31 -0
  161. package/dist/es/Collection/utils/calculateSizeAndPositionData.js +31 -0
  162. package/dist/es/ColumnSizer/ColumnSizer.example.js +150 -0
  163. package/dist/es/ColumnSizer/ColumnSizer.jest.js +123 -0
  164. package/dist/es/ColumnSizer/ColumnSizer.js +95 -0
  165. package/dist/es/ColumnSizer/index.js +3 -0
  166. package/dist/es/Grid/Grid.example.js +321 -0
  167. package/dist/es/Grid/Grid.jest.js +2555 -0
  168. package/dist/es/Grid/Grid.js +1425 -0
  169. package/dist/es/Grid/Grid.ssr.js +57 -0
  170. package/dist/es/Grid/accessibilityOverscanIndicesGetter.jest.js +87 -0
  171. package/dist/es/Grid/accessibilityOverscanIndicesGetter.js +33 -0
  172. package/dist/es/Grid/defaultCellRangeRenderer.js +134 -0
  173. package/dist/es/Grid/defaultOverscanIndicesGetter.jest.js +87 -0
  174. package/dist/es/Grid/defaultOverscanIndicesGetter.js +29 -0
  175. package/dist/es/Grid/index.js +15 -0
  176. package/dist/es/Grid/types.js +96 -0
  177. package/dist/es/Grid/utils/CellSizeAndPositionManager.jest.js +372 -0
  178. package/dist/es/Grid/utils/CellSizeAndPositionManager.js +290 -0
  179. package/dist/es/Grid/utils/ScalingCellSizeAndPositionManager.jest.js +198 -0
  180. package/dist/es/Grid/utils/ScalingCellSizeAndPositionManager.js +198 -0
  181. package/dist/es/Grid/utils/calculateSizeAndPositionDataAndUpdateScrollOffset.jest.js +81 -0
  182. package/dist/es/Grid/utils/calculateSizeAndPositionDataAndUpdateScrollOffset.js +53 -0
  183. package/dist/es/Grid/utils/maxElementSize.js +16 -0
  184. package/dist/es/Grid/utils/updateScrollIndexHelper.jest.js +174 -0
  185. package/dist/es/Grid/utils/updateScrollIndexHelper.js +79 -0
  186. package/dist/es/InfiniteLoader/InfiniteLoader.example.js +170 -0
  187. package/dist/es/InfiniteLoader/InfiniteLoader.jest.js +565 -0
  188. package/dist/es/InfiniteLoader/InfiniteLoader.js +263 -0
  189. package/dist/es/InfiniteLoader/index.js +3 -0
  190. package/dist/es/List/List.example.js +227 -0
  191. package/dist/es/List/List.jest.js +511 -0
  192. package/dist/es/List/List.js +312 -0
  193. package/dist/es/List/index.js +3 -0
  194. package/dist/es/List/types.js +21 -0
  195. package/dist/es/Masonry/Masonry.example.js +278 -0
  196. package/dist/es/Masonry/Masonry.jest.js +444 -0
  197. package/dist/es/Masonry/Masonry.js +421 -0
  198. package/dist/es/Masonry/PositionCache.js +82 -0
  199. package/dist/es/Masonry/createCellPositioner.js +53 -0
  200. package/dist/es/Masonry/index.js +4 -0
  201. package/dist/es/MultiGrid/CellMeasurerCacheDecorator.js +100 -0
  202. package/dist/es/MultiGrid/MultiGrid.example.js +122 -0
  203. package/dist/es/MultiGrid/MultiGrid.jest.js +579 -0
  204. package/dist/es/MultiGrid/MultiGrid.js +733 -0
  205. package/dist/es/MultiGrid/index.js +3 -0
  206. package/dist/es/ScrollSync/ScrollSync.example.js +248 -0
  207. package/dist/es/ScrollSync/ScrollSync.jest.js +60 -0
  208. package/dist/es/ScrollSync/ScrollSync.js +80 -0
  209. package/dist/es/ScrollSync/index.js +3 -0
  210. package/dist/es/Table/Column.jest.js +84 -0
  211. package/dist/es/Table/Column.js +85 -0
  212. package/dist/es/Table/SortDirection.js +13 -0
  213. package/dist/es/Table/SortIndicator.js +31 -0
  214. package/dist/es/Table/Table.example.js +316 -0
  215. package/dist/es/Table/Table.jest.js +1251 -0
  216. package/dist/es/Table/Table.js +735 -0
  217. package/dist/es/Table/createMultiSort.jest.js +162 -0
  218. package/dist/es/Table/createMultiSort.js +93 -0
  219. package/dist/es/Table/defaultCellDataGetter.js +15 -0
  220. package/dist/es/Table/defaultCellRenderer.js +13 -0
  221. package/dist/es/Table/defaultHeaderRenderer.js +25 -0
  222. package/dist/es/Table/defaultHeaderRowRenderer.js +12 -0
  223. package/dist/es/Table/defaultRowRenderer.js +77 -0
  224. package/dist/es/Table/index.js +12 -0
  225. package/dist/es/Table/types.js +38 -0
  226. package/dist/es/WindowScroller/WindowScroller.e2e.js +295 -0
  227. package/dist/es/WindowScroller/WindowScroller.example.js +158 -0
  228. package/dist/es/WindowScroller/WindowScroller.header-resize.e2e.js +356 -0
  229. package/dist/es/WindowScroller/WindowScroller.jest.js +530 -0
  230. package/dist/es/WindowScroller/WindowScroller.js +259 -0
  231. package/dist/es/WindowScroller/WindowScroller.js.flow +277 -0
  232. package/dist/es/WindowScroller/WindowScroller.ssr.js +19 -0
  233. package/dist/es/WindowScroller/index.js +3 -0
  234. package/dist/es/WindowScroller/index.js.flow +6 -0
  235. package/dist/es/WindowScroller/utils/dimensions.js +81 -0
  236. package/dist/es/WindowScroller/utils/dimensions.js.flow +91 -0
  237. package/dist/es/WindowScroller/utils/onScroll.js +64 -0
  238. package/dist/es/WindowScroller/utils/onScroll.js.flow +94 -0
  239. package/dist/es/index.js +13 -0
  240. package/dist/es/jest-setup.js +5 -0
  241. package/dist/es/utils/TestHelper.js +30 -0
  242. package/dist/es/utils/animationFrame.js +23 -0
  243. package/dist/es/utils/createCallbackMemoizer.jest.js +216 -0
  244. package/dist/es/utils/createCallbackMemoizer.js +25 -0
  245. package/dist/es/utils/getUpdatedOffsetForIndex.jest.js +65 -0
  246. package/dist/es/utils/getUpdatedOffsetForIndex.js +32 -0
  247. package/dist/es/utils/initCellMetadata.js +31 -0
  248. package/dist/es/utils/requestAnimationTimeout.js +32 -0
  249. package/dist/es/vendor/binarySearchBounds.js +194 -0
  250. package/dist/es/vendor/detectElementResize.js +186 -0
  251. package/dist/es/vendor/intervalTree.js +354 -0
  252. package/dist/umd/react-virtualized.js +4638 -0
  253. package/package.json +188 -0
  254. package/styles.css +80 -0
@@ -0,0 +1,2555 @@
1
+ import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
2
+ import _createClass from "@babel/runtime/helpers/createClass";
3
+ import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
4
+ import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
5
+ import _inherits from "@babel/runtime/helpers/inherits";
6
+ import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
7
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
8
+ import _extends from "@babel/runtime/helpers/extends";
9
+ function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
10
+ function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
11
+ import _regeneratorRuntime from "@babel/runtime/regenerator";
12
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
13
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
14
+ import * as React from 'react';
15
+ import { findDOMNode } from 'react-dom';
16
+ import { Simulate } from 'react-dom/test-utils';
17
+ import TestRenderer from 'react-test-renderer';
18
+ import { render } from '../TestUtils';
19
+ import Grid, { DEFAULT_SCROLLING_RESET_TIME_INTERVAL } from './Grid';
20
+ import defaultCellRangeRenderer from './defaultCellRangeRenderer';
21
+ import { CellMeasurer, CellMeasurerCache } from '../CellMeasurer';
22
+ import { SCROLL_DIRECTION_BACKWARD, SCROLL_DIRECTION_FORWARD } from './defaultOverscanIndicesGetter';
23
+ import { getMaxElementSize } from './utils/maxElementSize.js';
24
+ var DEFAULT_COLUMN_WIDTH = 50;
25
+ var DEFAULT_HEIGHT = 100;
26
+ var DEFAULT_ROW_HEIGHT = 20;
27
+ var DEFAULT_WIDTH = 200;
28
+ var NUM_ROWS = 100;
29
+ var NUM_COLUMNS = 50;
30
+ function getScrollbarSize0() {
31
+ return 0;
32
+ }
33
+ function getScrollbarSize20() {
34
+ return 20;
35
+ }
36
+ describe('Grid', function () {
37
+ function defaultCellRenderer(_ref) {
38
+ var columnIndex = _ref.columnIndex,
39
+ key = _ref.key,
40
+ rowIndex = _ref.rowIndex,
41
+ style = _ref.style;
42
+ return /*#__PURE__*/React.createElement("div", {
43
+ className: "gridItem",
44
+ key: key,
45
+ style: style
46
+ }, "row:".concat(rowIndex, ", column:").concat(columnIndex));
47
+ }
48
+ function simulateScroll(_ref2) {
49
+ var grid = _ref2.grid,
50
+ _ref2$scrollLeft = _ref2.scrollLeft,
51
+ scrollLeft = _ref2$scrollLeft === void 0 ? 0 : _ref2$scrollLeft,
52
+ _ref2$scrollTop = _ref2.scrollTop,
53
+ scrollTop = _ref2$scrollTop === void 0 ? 0 : _ref2$scrollTop;
54
+ var target = {
55
+ scrollLeft: scrollLeft,
56
+ scrollTop: scrollTop
57
+ };
58
+ grid._scrollingContainer = target; // HACK to work around _onScroll target check
59
+ Simulate.scroll(findDOMNode(grid), {
60
+ target: target
61
+ });
62
+ }
63
+ function getMarkup() {
64
+ var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
65
+ return /*#__PURE__*/React.createElement(Grid, _extends({
66
+ cellRenderer: defaultCellRenderer,
67
+ columnCount: NUM_COLUMNS,
68
+ columnWidth: DEFAULT_COLUMN_WIDTH,
69
+ getScrollbarSize: getScrollbarSize0,
70
+ height: DEFAULT_HEIGHT,
71
+ overscanColumnCount: 0,
72
+ overscanRowCount: 0,
73
+ autoHeight: false,
74
+ rowHeight: DEFAULT_ROW_HEIGHT,
75
+ rowCount: NUM_ROWS,
76
+ width: DEFAULT_WIDTH
77
+ }, props));
78
+ }
79
+ describe('number of rendered children', function () {
80
+ it('should render enough children to fill the available area', function () {
81
+ var rendered = findDOMNode(render(getMarkup()));
82
+ expect(rendered.querySelectorAll('.gridItem').length).toEqual(20); // 5 rows x 4 columns
83
+ });
84
+ it('should not render more rows than available if the area is not filled', function () {
85
+ var rendered = findDOMNode(render(getMarkup({
86
+ rowCount: 2
87
+ })));
88
+ expect(rendered.querySelectorAll('.gridItem').length).toEqual(8); // 2 rows x 4 columns
89
+ });
90
+ it('should not render more columns than available if the area is not filled', function () {
91
+ var rendered = findDOMNode(render(getMarkup({
92
+ columnCount: 2
93
+ })));
94
+ expect(rendered.querySelectorAll('.gridItem').length).toEqual(10); // 5 rows x 2 columns
95
+ });
96
+
97
+ // Small performance tweak added in 5.5.6
98
+ it('should not render/parent cells that are null or false', function () {
99
+ function cellRenderer(_ref3) {
100
+ var columnIndex = _ref3.columnIndex,
101
+ key = _ref3.key,
102
+ rowIndex = _ref3.rowIndex,
103
+ style = _ref3.style;
104
+ if (columnIndex === 0) {
105
+ return null;
106
+ } else if (rowIndex === 0) {
107
+ return false;
108
+ } else {
109
+ return /*#__PURE__*/React.createElement("div", {
110
+ className: "cell",
111
+ key: key,
112
+ style: style
113
+ }, "row:".concat(rowIndex, ", column:").concat(columnIndex));
114
+ }
115
+ }
116
+ var rendered = findDOMNode(render(getMarkup({
117
+ columnCount: 3,
118
+ overscanColumnCount: 0,
119
+ overscanRowCount: 0,
120
+ rowCount: 3,
121
+ cellRenderer: cellRenderer
122
+ })));
123
+ expect(rendered.querySelectorAll('.cell').length).toEqual(4); // [1,1], [1,2], [2,1], and [2,2]
124
+ expect(rendered.textContent).not.toContain('column:0');
125
+ expect(rendered.textContent).not.toContain('row:0');
126
+ });
127
+ it('should scroll to the last existing point when rows are removed', function () {
128
+ var grid = render(getMarkup({
129
+ rowCount: 15
130
+ }));
131
+ simulateScroll({
132
+ grid: grid,
133
+ scrollTop: 200
134
+ });
135
+ var updatedGrid = render(getMarkup({
136
+ rowCount: 10
137
+ }));
138
+ expect(updatedGrid.state.scrollTop).toEqual(100);
139
+ });
140
+ it('should scroll to the last existing point when columns are removed', function () {
141
+ var grid = render(getMarkup({
142
+ columnCount: 12
143
+ }));
144
+ simulateScroll({
145
+ grid: grid,
146
+ scrollLeft: 400
147
+ });
148
+ var updatedGrid = render(getMarkup({
149
+ columnCount: 8
150
+ }));
151
+ expect(updatedGrid.state.scrollLeft).toEqual(200);
152
+ });
153
+ it('should not scroll unseen rows are removed', function () {
154
+ render(getMarkup({
155
+ rowCount: 15
156
+ }));
157
+ var updatedGrid = render(getMarkup({
158
+ rowCount: 10
159
+ }));
160
+ expect(updatedGrid.state.scrollTop).toEqual(0);
161
+ });
162
+ it('should not scroll when unseen columns are removed', function () {
163
+ render(getMarkup({
164
+ columnCount: 12
165
+ }));
166
+ var updatedGrid = render(getMarkup({
167
+ columnCount: 8
168
+ }));
169
+ expect(updatedGrid.state.scrollLeft).toEqual(0);
170
+ });
171
+ });
172
+ describe('shows and hides scrollbars based on rendered content', function () {
173
+ it('should set overflowX:hidden if columns fit within the available width and y-axis has no scrollbar', function () {
174
+ var rendered = findDOMNode(render(getMarkup({
175
+ columnCount: 4,
176
+ getScrollbarSize: getScrollbarSize20,
177
+ rowCount: 5
178
+ })));
179
+ expect(rendered.style.overflowX).toEqual('hidden');
180
+ });
181
+ it('should set overflowX:hidden if columns and y-axis scrollbar fit within the available width', function () {
182
+ var rendered = findDOMNode(render(getMarkup({
183
+ columnCount: 4,
184
+ getScrollbarSize: getScrollbarSize20,
185
+ width: 200 + getScrollbarSize20()
186
+ })));
187
+ expect(rendered.style.overflowX).toEqual('hidden');
188
+ });
189
+ it('should leave overflowX:auto if columns require more than the available width', function () {
190
+ var rendered = findDOMNode(render(getMarkup({
191
+ columnCount: 4,
192
+ getScrollbarSize: getScrollbarSize20,
193
+ width: 200 - 1,
194
+ rowCount: 5
195
+ })));
196
+ expect(rendered.style.overflowX).not.toEqual('hidden');
197
+ });
198
+ it('should leave overflowX:auto if columns and y-axis scrollbar require more than the available width', function () {
199
+ var rendered = findDOMNode(render(getMarkup({
200
+ columnCount: 4,
201
+ getScrollbarSize: getScrollbarSize20,
202
+ width: 200 + getScrollbarSize20() - 1
203
+ })));
204
+ expect(rendered.style.overflowX).not.toEqual('hidden');
205
+ });
206
+ it('should set overflowY:hidden if rows fit within the available width and xaxis has no scrollbar', function () {
207
+ var rendered = findDOMNode(render(getMarkup({
208
+ getScrollbarSize: getScrollbarSize20,
209
+ rowCount: 5,
210
+ columnCount: 4
211
+ })));
212
+ expect(rendered.style.overflowY).toEqual('hidden');
213
+ });
214
+ it('should set overflowY:hidden if rows and x-axis scrollbar fit within the available width', function () {
215
+ var rendered = findDOMNode(render(getMarkup({
216
+ getScrollbarSize: getScrollbarSize20,
217
+ rowCount: 5,
218
+ height: 100 + getScrollbarSize20()
219
+ })));
220
+ expect(rendered.style.overflowY).toEqual('hidden');
221
+ });
222
+ it('should leave overflowY:auto if rows require more than the available width', function () {
223
+ var rendered = findDOMNode(render(getMarkup({
224
+ getScrollbarSize: getScrollbarSize20,
225
+ rowCount: 5,
226
+ height: 100 - 1,
227
+ columnCount: 4
228
+ })));
229
+ expect(rendered.style.overflowY).not.toEqual('hidden');
230
+ });
231
+ it('should leave overflowY:auto if rows and x-axis scrollbar require more than the available width', function () {
232
+ var rendered = findDOMNode(render(getMarkup({
233
+ getScrollbarSize: getScrollbarSize20,
234
+ rowCount: 5,
235
+ height: 100 + getScrollbarSize20() - 1
236
+ })));
237
+ expect(rendered.style.overflowY).not.toEqual('hidden');
238
+ });
239
+ it('should accept styles that overwrite calculated ones', function () {
240
+ var rendered = findDOMNode(render(getMarkup({
241
+ columnCount: 1,
242
+ getScrollbarSize: getScrollbarSize20,
243
+ height: 1,
244
+ rowCount: 1,
245
+ style: {
246
+ overflowY: 'visible',
247
+ overflowX: 'visible'
248
+ },
249
+ width: 1
250
+ })));
251
+ expect(rendered.style.overflowY).toEqual('visible');
252
+ expect(rendered.style.overflowX).toEqual('visible');
253
+ });
254
+ });
255
+
256
+ /** Tests scrolling via initial props */
257
+ describe(':scrollToColumn and :scrollToRow', function () {
258
+ it('should scroll to the left', function () {
259
+ var grid = render(getMarkup({
260
+ scrollToColumn: 0
261
+ }));
262
+ expect(grid.state.scrollLeft).toEqual(0);
263
+ });
264
+ it('should scroll over to the middle', function () {
265
+ var grid = render(getMarkup({
266
+ scrollToColumn: 24
267
+ }));
268
+ // 50 columns * 50 item width = 2,500 total item width
269
+ // 4 columns can be visible at a time and :scrollLeft is initially 0,
270
+ // So the minimum amount of scrolling leaves the 25th item at the right (just scrolled into view).
271
+ expect(grid.state.scrollLeft).toEqual(1050);
272
+ });
273
+ it('should scroll to the far right', function () {
274
+ var grid = render(getMarkup({
275
+ scrollToColumn: 49
276
+ }));
277
+ // 50 columns * 50 item width = 2,500 total item width
278
+ // Target offset for the last item then is 2,500 - 200
279
+ expect(grid.state.scrollLeft).toEqual(2300);
280
+ });
281
+ it('should scroll to the top', function () {
282
+ var grid = render(getMarkup({
283
+ scrollToRow: 0
284
+ }));
285
+ expect(grid.state.scrollTop).toEqual(0);
286
+ });
287
+ it('should scroll down to the middle', function () {
288
+ var grid = render(getMarkup({
289
+ scrollToRow: 49
290
+ }));
291
+ // 100 rows * 20 item height = 2,000 total item height
292
+ // 5 rows can be visible at a time and :scrollTop is initially 0,
293
+ // So the minimum amount of scrolling leaves the 50th item at the bottom (just scrolled into view).
294
+ expect(grid.state.scrollTop).toEqual(900);
295
+ });
296
+ it('should scroll to the bottom', function () {
297
+ var grid = render(getMarkup({
298
+ scrollToRow: 99
299
+ }));
300
+ // 100 rows * 20 item height = 2,000 total item height
301
+ // Target offset for the last item then is 2,000 - 100
302
+ expect(grid.state.scrollTop).toEqual(1900);
303
+ });
304
+ it('should scroll to a row and column just added', function () {
305
+ var grid = render(getMarkup());
306
+ expect(grid.state.scrollLeft).toEqual(0);
307
+ expect(grid.state.scrollTop).toEqual(0);
308
+ grid = render(getMarkup({
309
+ columnCount: NUM_COLUMNS + 1,
310
+ rowCount: NUM_ROWS + 1,
311
+ scrollToColumn: NUM_COLUMNS,
312
+ scrollToRow: NUM_ROWS
313
+ }));
314
+ expect(grid.state.scrollLeft).toEqual(2350);
315
+ expect(grid.state.scrollTop).toEqual(1920);
316
+ });
317
+ it('should scroll back to a newly-added cell without a change in prop', function () {
318
+ var grid = render(getMarkup({
319
+ columnCount: NUM_COLUMNS,
320
+ rowCount: NUM_ROWS,
321
+ scrollToColumn: NUM_COLUMNS,
322
+ scrollToRow: NUM_ROWS
323
+ }));
324
+ grid = render(getMarkup({
325
+ columnCount: NUM_COLUMNS + 1,
326
+ rowCount: NUM_ROWS + 1,
327
+ scrollToColumn: NUM_COLUMNS,
328
+ scrollToRow: NUM_ROWS
329
+ }));
330
+ expect(grid.state.scrollLeft).toEqual(2350);
331
+ expect(grid.state.scrollTop).toEqual(1920);
332
+ });
333
+ it('should scroll to the correct position for :scrollToAlignment "start"', function () {
334
+ var grid = render(getMarkup({
335
+ scrollToAlignment: 'start',
336
+ scrollToColumn: 24,
337
+ scrollToRow: 49
338
+ }));
339
+ // 50 columns * 50 item width = 2,500 total item width
340
+ // 100 rows * 20 item height = 2,000 total item height
341
+ // 4 columns and 5 rows can be visible at a time.
342
+ // The minimum amount of scrolling leaves the specified cell in the bottom/right corner (just scrolled into view).
343
+ // Since alignment is set to "start" we should scroll past this point until the cell is aligned top/left.
344
+ expect(grid.state.scrollLeft).toEqual(1200);
345
+ expect(grid.state.scrollTop).toEqual(980);
346
+ });
347
+ it('should scroll to the correct position for :scrollToAlignment "end"', function () {
348
+ render(getMarkup({
349
+ scrollToColumn: 99,
350
+ scrollToRow: 99
351
+ }));
352
+ var grid = render(getMarkup({
353
+ scrollToAlignment: 'end',
354
+ scrollToColumn: 24,
355
+ scrollToRow: 49
356
+ }));
357
+ // 50 columns * 50 item width = 2,500 total item width
358
+ // 100 rows * 20 item height = 2,000 total item height
359
+ // We first scroll past the specified cell and then back.
360
+ // The minimum amount of scrolling then should leave the specified cell in the top/left corner (just scrolled into view).
361
+ // Since alignment is set to "end" we should scroll past this point until the cell is aligned bottom/right.
362
+ expect(grid.state.scrollLeft).toEqual(1050);
363
+ expect(grid.state.scrollTop).toEqual(900);
364
+ });
365
+ it('should scroll to the correct position for :scrollToAlignment "center"', function () {
366
+ render(getMarkup({
367
+ scrollToColumn: 99,
368
+ scrollToRow: 99
369
+ }));
370
+ var grid = render(getMarkup({
371
+ scrollToAlignment: 'center',
372
+ scrollToColumn: 24,
373
+ scrollToRow: 49
374
+ }));
375
+ // 50 columns * 50 item width = 2,500 total item width
376
+ // Viewport width is 200
377
+ // Column 24 starts at 1,200, center point at 1,225, so...
378
+ expect(grid.state.scrollLeft).toEqual(1125);
379
+ // 100 rows * 20 item height = 2,000 total item height
380
+ // Viewport height is 100
381
+ // Row 49 starts at 980, center point at 990, so...
382
+ expect(grid.state.scrollTop).toEqual(940);
383
+ });
384
+
385
+ // Tests issue #691
386
+ it('should set the correct :scrollLeft after height increases from 0', function () {
387
+ render.unmount();
388
+ expect(findDOMNode(render(getMarkup({
389
+ height: 0,
390
+ scrollToColumn: 24
391
+ }))).scrollLeft || 0).toEqual(0);
392
+ expect(findDOMNode(render(getMarkup({
393
+ height: 100,
394
+ scrollToColumn: 24
395
+ }))).scrollLeft).toEqual(1050);
396
+ });
397
+
398
+ // Tests issue #691
399
+ it('should set the correct :scrollTop after width increases from 0', function () {
400
+ render.unmount();
401
+ expect(findDOMNode(render(getMarkup({
402
+ scrollToRow: 49,
403
+ width: 0
404
+ }))).scrollTop || 0).toEqual(0);
405
+ expect(findDOMNode(render(getMarkup({
406
+ scrollToRow: 49,
407
+ width: 100
408
+ }))).scrollTop).toEqual(900);
409
+ });
410
+
411
+ // Tests issue #218
412
+ it('should set the correct :scrollTop after row and column counts increase from 0', function () {
413
+ var expectedScrollTop = 100 * DEFAULT_ROW_HEIGHT - DEFAULT_HEIGHT + DEFAULT_ROW_HEIGHT;
414
+ render(getMarkup({
415
+ columnCount: 0,
416
+ rowCount: 150,
417
+ scrollToRow: 100
418
+ }));
419
+ expect(findDOMNode(render(getMarkup({
420
+ columnCount: 150,
421
+ rowCount: 150,
422
+ scrollToRow: 100
423
+ }))).scrollTop).toEqual(expectedScrollTop);
424
+ });
425
+ it('should support scrollToCell() public method', function () {
426
+ var grid = render(getMarkup());
427
+ expect(grid.state.scrollLeft).toEqual(0);
428
+ expect(grid.state.scrollTop).toEqual(0);
429
+ grid.scrollToCell({
430
+ columnIndex: 24,
431
+ rowIndex: 49
432
+ });
433
+ // 50 columns * 50 item width = 2,500 total item width
434
+ // 4 columns can be visible at a time and :scrollLeft is initially 0,
435
+ // So the minimum amount of scrolling leaves the 25th item at the right (just scrolled into view).
436
+ expect(grid.state.scrollLeft).toEqual(1050);
437
+ // 100 rows * 20 item height = 2,000 total item height
438
+ // 5 rows can be visible at a time and :scrollTop is initially 0,
439
+ // So the minimum amount of scrolling leaves the 50th item at the bottom (just scrolled into view).
440
+ expect(grid.state.scrollTop).toEqual(900);
441
+
442
+ // Change column without affecting row
443
+ grid.scrollToCell({
444
+ columnIndex: 49
445
+ });
446
+ expect(grid.state.scrollLeft).toEqual(2300);
447
+ expect(grid.state.scrollTop).toEqual(900);
448
+
449
+ // Change row without affecting column
450
+ grid.scrollToCell({
451
+ rowIndex: 99
452
+ });
453
+ expect(grid.state.scrollLeft).toEqual(2300);
454
+ expect(grid.state.scrollTop).toEqual(1900);
455
+ });
456
+ it('should support scrollToPosition() public method', function () {
457
+ var grid = render(getMarkup());
458
+ expect(grid.state.scrollLeft).toEqual(0);
459
+ expect(grid.state.scrollTop).toEqual(0);
460
+ grid.scrollToPosition({
461
+ scrollLeft: 50,
462
+ scrollTop: 100
463
+ });
464
+ expect(grid.state.scrollLeft).toEqual(50);
465
+ expect(grid.state.scrollTop).toEqual(100);
466
+
467
+ // Change column without affecting row
468
+ grid.scrollToPosition({
469
+ scrollLeft: 25
470
+ });
471
+ expect(grid.state.scrollLeft).toEqual(25);
472
+ expect(grid.state.scrollTop).toEqual(100);
473
+
474
+ // Change row without affecting column
475
+ grid.scrollToPosition({
476
+ scrollTop: 50
477
+ });
478
+ expect(grid.state.scrollLeft).toEqual(25);
479
+ expect(grid.state.scrollTop).toEqual(50);
480
+ });
481
+ it('should support handleScrollEvent() public method', function () {
482
+ var grid = render(getMarkup());
483
+ expect(grid.state.scrollLeft).toEqual(0);
484
+ expect(grid.state.scrollTop).toEqual(0);
485
+ grid.handleScrollEvent({
486
+ scrollLeft: 50,
487
+ scrollTop: 100
488
+ });
489
+ expect(grid.state.isScrolling).toEqual(true);
490
+ expect(grid.state.scrollLeft).toEqual(50);
491
+ expect(grid.state.scrollTop).toEqual(100);
492
+ });
493
+ it('should support getOffsetForCell() public method', function () {
494
+ var grid = render(getMarkup());
495
+ var _grid$getOffsetForCel = grid.getOffsetForCell({
496
+ columnIndex: 24,
497
+ rowIndex: 49
498
+ }),
499
+ scrollLeft = _grid$getOffsetForCel.scrollLeft,
500
+ scrollTop = _grid$getOffsetForCel.scrollTop;
501
+ // 50 columns * 50 item width = 2,500 total item width
502
+ // 4 columns can be visible at a time and :scrollLeft is initially 0,
503
+ // So the minimum amount of scrolling leaves the 25th item at the right (just scrolled into view).
504
+ expect(scrollLeft).toEqual(1050);
505
+ // 100 rows * 20 item height = 2,000 total item height
506
+ // 5 rows can be visible at a time and :scrollTop is initially 0,
507
+ // So the minimum amount of scrolling leaves the 50th item at the bottom (just scrolled into view).
508
+ expect(scrollTop).toEqual(900);
509
+ });
510
+ it('should support getTotalRowsHeight() public method', function () {
511
+ var grid = render(getMarkup());
512
+ grid.recomputeGridSize();
513
+ var totalHeight = grid.getTotalRowsHeight();
514
+ // 100 rows * 20 item height = 2,000 total item height
515
+ expect(totalHeight).toEqual(2000);
516
+ });
517
+ it('should support getTotalColumnsWidth() public method', function () {
518
+ var grid = render(getMarkup());
519
+ grid.recomputeGridSize();
520
+ var totalWidth = grid.getTotalColumnsWidth();
521
+ // 50 columns * 50 item width = 2,500 total item width
522
+ expect(totalWidth).toEqual(2500);
523
+ });
524
+
525
+ // See issue #565
526
+ it('should update scroll position to account for changed cell sizes within a function prop wrapper', function () {
527
+ var _rowHeight = 20;
528
+ var props = {
529
+ height: 100,
530
+ rowCount: 100,
531
+ rowHeight: function rowHeight(_ref4) {
532
+ var index = _ref4.index;
533
+ return index === 99 ? _rowHeight : 20;
534
+ },
535
+ scrollToRow: 99
536
+ };
537
+ var grid = render(getMarkup(props));
538
+ var node = findDOMNode(grid);
539
+ expect(node.scrollTop).toBe(1900);
540
+ _rowHeight = 40;
541
+ grid.recomputeGridSize({
542
+ rowIndex: 99
543
+ });
544
+ expect(node.scrollTop).toBe(1920);
545
+ });
546
+ it('should not restore scrollLeft when scrolling left and recomputeGridSize with columnIndex smaller than scrollToColumn', function () {
547
+ var props = {
548
+ columnWidth: 50,
549
+ columnCount: 100,
550
+ height: 100,
551
+ rowCount: 100,
552
+ rowHeight: 20,
553
+ scrollToColumn: 50,
554
+ scrollToRow: 50,
555
+ width: 100
556
+ };
557
+ var grid = render(getMarkup(props));
558
+ expect(grid.state.scrollLeft).toEqual(2450);
559
+ simulateScroll({
560
+ grid: grid,
561
+ scrollLeft: 2250
562
+ });
563
+ expect(grid.state.scrollLeft).toEqual(2250);
564
+ expect(grid.state.scrollDirectionHorizontal).toEqual(SCROLL_DIRECTION_BACKWARD);
565
+ grid.recomputeGridSize({
566
+ columnIndex: 30
567
+ });
568
+ expect(grid.state.scrollLeft).toEqual(2250);
569
+ });
570
+ it('should not restore scrollTop when scrolling up and recomputeGridSize with rowIndex smaller than scrollToRow', function () {
571
+ var props = {
572
+ columnWidth: 50,
573
+ columnCount: 100,
574
+ height: 100,
575
+ rowCount: 100,
576
+ rowHeight: 20,
577
+ scrollToColumn: 50,
578
+ scrollToRow: 50,
579
+ width: 100
580
+ };
581
+ var grid = render(getMarkup(props));
582
+ expect(grid.state.scrollTop).toEqual(920);
583
+ simulateScroll({
584
+ grid: grid,
585
+ scrollTop: 720
586
+ });
587
+ expect(grid.state.scrollTop).toEqual(720);
588
+ expect(grid.state.scrollDirectionVertical).toEqual(SCROLL_DIRECTION_BACKWARD);
589
+ grid.recomputeGridSize({
590
+ rowIndex: 20
591
+ });
592
+ expect(grid.state.scrollTop).toEqual(720);
593
+ });
594
+ it('should restore scroll offset for column when row count increases from 0 (and vice versa)', function () {
595
+ var props = {
596
+ columnWidth: 50,
597
+ columnCount: 100,
598
+ height: 100,
599
+ rowCount: 100,
600
+ rowHeight: 20,
601
+ scrollToColumn: 50,
602
+ scrollToRow: 50,
603
+ width: 100
604
+ };
605
+ var grid = render(getMarkup(props));
606
+ expect(grid.state.scrollLeft).toEqual(2450);
607
+ expect(grid.state.scrollTop).toEqual(920);
608
+ render(getMarkup(_objectSpread(_objectSpread({}, props), {}, {
609
+ columnCount: 0
610
+ })));
611
+ expect(grid.state.scrollLeft).toEqual(0);
612
+ expect(grid.state.scrollTop).toEqual(0);
613
+ render(getMarkup(props));
614
+ expect(grid.state.scrollLeft).toEqual(2450);
615
+ expect(grid.state.scrollTop).toEqual(920);
616
+ render(getMarkup(_objectSpread(_objectSpread({}, props), {}, {
617
+ rowCount: 0
618
+ })));
619
+ expect(grid.state.scrollLeft).toEqual(0);
620
+ expect(grid.state.scrollTop).toEqual(0);
621
+ render(getMarkup(props));
622
+ expect(grid.state.scrollLeft).toEqual(2450);
623
+ expect(grid.state.scrollTop).toEqual(920);
624
+ });
625
+ it('should take scrollbar size into account when aligning cells', function () {
626
+ var grid = render(getMarkup({
627
+ columnWidth: 50,
628
+ columnCount: 100,
629
+ getScrollbarSize: getScrollbarSize20,
630
+ height: 100,
631
+ rowCount: 100,
632
+ rowHeight: 20,
633
+ scrollToColumn: 50,
634
+ scrollToRow: 50,
635
+ width: 100
636
+ }));
637
+ expect(grid.state.scrollLeft).toEqual(2450 + getScrollbarSize20());
638
+ expect(grid.state.scrollTop).toEqual(920 + getScrollbarSize20());
639
+ });
640
+ });
641
+ describe('property updates', function () {
642
+ it('should update :scrollToColumn position when :columnWidth changes', function () {
643
+ var grid = findDOMNode(render(getMarkup({
644
+ scrollToColumn: 25
645
+ })));
646
+ expect(grid.textContent).toContain('column:25');
647
+ // Making columns taller pushes name off/beyond the scrolled area
648
+ grid = findDOMNode(render(getMarkup({
649
+ scrollToColumn: 25,
650
+ columnWidth: 20
651
+ })));
652
+ expect(grid.textContent).toContain('column:25');
653
+ });
654
+ it('should update :scrollToRow position when :rowHeight changes', function () {
655
+ var grid = findDOMNode(render(getMarkup({
656
+ scrollToRow: 50
657
+ })));
658
+ expect(grid.textContent).toContain('row:50');
659
+ // Making rows taller pushes name off/beyond the scrolled area
660
+ grid = findDOMNode(render(getMarkup({
661
+ scrollToRow: 50,
662
+ rowHeight: 20
663
+ })));
664
+ expect(grid.textContent).toContain('row:50');
665
+ });
666
+ it('should update :scrollToColumn position when :width changes', function () {
667
+ var grid = findDOMNode(render(getMarkup({
668
+ scrollToColumn: 25
669
+ })));
670
+ expect(grid.textContent).toContain('column:25');
671
+ // Making the grid narrower leaves only room for 1 item
672
+ grid = findDOMNode(render(getMarkup({
673
+ scrollToColumn: 25,
674
+ width: 50
675
+ })));
676
+ expect(grid.textContent).toContain('column:25');
677
+ });
678
+ it('should update :scrollToRow position when :height changes', function () {
679
+ var grid = findDOMNode(render(getMarkup({
680
+ scrollToRow: 50
681
+ })));
682
+ expect(grid.textContent).toContain('row:50');
683
+ // Making the grid shorter leaves only room for 1 item
684
+ grid = findDOMNode(render(getMarkup({
685
+ scrollToRow: 50,
686
+ height: 20
687
+ })));
688
+ expect(grid.textContent).toContain('row:50');
689
+ });
690
+ it('should update :scrollToColumn position when :scrollToColumn changes', function () {
691
+ var grid = findDOMNode(render(getMarkup()));
692
+ expect(grid.textContent).not.toContain('column:25');
693
+ grid = findDOMNode(render(getMarkup({
694
+ scrollToColumn: 25
695
+ })));
696
+ expect(grid.textContent).toContain('column:25');
697
+ });
698
+ it('should update :scrollToRow position when :scrollToRow changes', function () {
699
+ var grid = findDOMNode(render(getMarkup()));
700
+ expect(grid.textContent).not.toContain('row:50');
701
+ grid = findDOMNode(render(getMarkup({
702
+ scrollToRow: 50
703
+ })));
704
+ expect(grid.textContent).toContain('row:50');
705
+ });
706
+ it('should update scroll position if size shrinks smaller than the current scroll', function () {
707
+ var grid = findDOMNode(render(getMarkup({
708
+ scrollToColumn: 250
709
+ })));
710
+ grid = findDOMNode(render(getMarkup()));
711
+ grid = findDOMNode(render(getMarkup({
712
+ scrollToColumn: 250,
713
+ columnCount: 10
714
+ })));
715
+ expect(grid.textContent).toContain('column:9');
716
+ });
717
+ it('should update scroll position if size shrinks smaller than the current scroll', function () {
718
+ var grid = findDOMNode(render(getMarkup({
719
+ scrollToRow: 500
720
+ })));
721
+ grid = findDOMNode(render(getMarkup()));
722
+ grid = findDOMNode(render(getMarkup({
723
+ scrollToRow: 500,
724
+ rowCount: 10
725
+ })));
726
+ expect(grid.textContent).toContain('row:9');
727
+ });
728
+ });
729
+ describe('noContentRenderer', function () {
730
+ it('should call :noContentRenderer if :columnCount is 0', function () {
731
+ var list = findDOMNode(render(getMarkup({
732
+ noContentRenderer: function noContentRenderer() {
733
+ return /*#__PURE__*/React.createElement("div", null, "No data");
734
+ },
735
+ columnCount: 0
736
+ })));
737
+ expect(list.textContent).toEqual('No data');
738
+ });
739
+ it('should call :noContentRenderer if :rowCount is 0', function () {
740
+ var list = findDOMNode(render(getMarkup({
741
+ noContentRenderer: function noContentRenderer() {
742
+ return /*#__PURE__*/React.createElement("div", null, "No data");
743
+ },
744
+ rowCount: 0
745
+ })));
746
+ expect(list.textContent).toEqual('No data');
747
+ });
748
+
749
+ // Sanity check for bvaughn/react-virtualized/pull/348
750
+ it('should render an empty body if :rowCount or :columnCount changes to 0', function () {
751
+ function noContentRenderer() {
752
+ return /*#__PURE__*/React.createElement("div", null, "No data");
753
+ }
754
+ var list = findDOMNode(render(getMarkup({
755
+ noContentRenderer: noContentRenderer
756
+ })));
757
+ expect(list.textContent).not.toEqual('No data');
758
+ list = findDOMNode(render(getMarkup({
759
+ noContentRenderer: noContentRenderer,
760
+ rowCount: 0
761
+ })));
762
+ expect(list.textContent).toEqual('No data');
763
+ list = findDOMNode(render(getMarkup({
764
+ noContentRenderer: noContentRenderer
765
+ })));
766
+ expect(list.textContent).not.toEqual('No data');
767
+ list = findDOMNode(render(getMarkup({
768
+ columnCount: 0,
769
+ noContentRenderer: noContentRenderer
770
+ })));
771
+ expect(list.textContent).toEqual('No data');
772
+ });
773
+ it('should render an empty body if :columnCount is 0 and there is no :noContentRenderer', function () {
774
+ var list = findDOMNode(render(getMarkup({
775
+ columnCount: 0
776
+ })));
777
+ expect(list.textContent).toEqual('');
778
+ });
779
+ it('should render an empty body if :rowCount is 0 and there is no :noContentRenderer', function () {
780
+ var list = findDOMNode(render(getMarkup({
781
+ rowCount: 0
782
+ })));
783
+ expect(list.textContent).toEqual('');
784
+ });
785
+ it('should render an empty body there is a :noContentRenderer but :height or :width are 0', function () {
786
+ var list = findDOMNode(render(getMarkup({
787
+ height: 0,
788
+ noContentRenderer: function noContentRenderer() {
789
+ return /*#__PURE__*/React.createElement("div", null, "No data");
790
+ }
791
+ })));
792
+ expect(list.textContent).toEqual('');
793
+ list = findDOMNode(render(getMarkup({
794
+ noContentRenderer: function noContentRenderer() {
795
+ return /*#__PURE__*/React.createElement("div", null, "No data");
796
+ },
797
+ width: 0
798
+ })));
799
+ expect(list.textContent).toEqual('');
800
+ });
801
+ });
802
+ describe('onSectionRendered', function () {
803
+ it('should call :onSectionRendered if at least one cell is rendered', function () {
804
+ var columnStartIndex, columnStopIndex, rowStartIndex, rowStopIndex;
805
+ render(getMarkup({
806
+ onSectionRendered: function onSectionRendered(params) {
807
+ var _params;
808
+ return _params = params, columnStartIndex = _params.columnStartIndex, columnStopIndex = _params.columnStopIndex, rowStartIndex = _params.rowStartIndex, rowStopIndex = _params.rowStopIndex, _params;
809
+ }
810
+ }));
811
+ expect(columnStartIndex).toEqual(0);
812
+ expect(columnStopIndex).toEqual(3);
813
+ expect(rowStartIndex).toEqual(0);
814
+ expect(rowStopIndex).toEqual(4);
815
+ });
816
+ it('should not call :onSectionRendered unless the column or row start or stop indices have changed', function () {
817
+ var numCalls = 0;
818
+ var columnStartIndex, columnStopIndex, rowStartIndex, rowStopIndex;
819
+ var onSectionRendered = function onSectionRendered(params) {
820
+ columnStartIndex = params.columnStartIndex;
821
+ columnStopIndex = params.columnStopIndex;
822
+ rowStartIndex = params.rowStartIndex;
823
+ rowStopIndex = params.rowStopIndex;
824
+ numCalls++;
825
+ };
826
+ render(getMarkup({
827
+ onSectionRendered: onSectionRendered
828
+ }));
829
+ expect(numCalls).toEqual(1);
830
+ expect(columnStartIndex).toEqual(0);
831
+ expect(columnStopIndex).toEqual(3);
832
+ expect(rowStartIndex).toEqual(0);
833
+ expect(rowStopIndex).toEqual(4);
834
+ render(getMarkup({
835
+ onSectionRendered: onSectionRendered
836
+ }));
837
+ expect(numCalls).toEqual(1);
838
+ expect(columnStartIndex).toEqual(0);
839
+ expect(columnStopIndex).toEqual(3);
840
+ expect(rowStartIndex).toEqual(0);
841
+ expect(rowStopIndex).toEqual(4);
842
+ });
843
+ it('should call :onSectionRendered if the row or column start or stop indices have changed', function () {
844
+ var numCalls = 0;
845
+ var columnStartIndex, columnStopIndex, rowStartIndex, rowStopIndex;
846
+ var onSectionRendered = function onSectionRendered(params) {
847
+ columnStartIndex = params.columnStartIndex;
848
+ columnStopIndex = params.columnStopIndex;
849
+ rowStartIndex = params.rowStartIndex;
850
+ rowStopIndex = params.rowStopIndex;
851
+ numCalls++;
852
+ };
853
+ render(getMarkup({
854
+ onSectionRendered: onSectionRendered
855
+ }));
856
+ expect(columnStartIndex).toEqual(0);
857
+ expect(columnStopIndex).toEqual(3);
858
+ expect(rowStartIndex).toEqual(0);
859
+ expect(rowStopIndex).toEqual(4);
860
+ render(getMarkup({
861
+ height: 50,
862
+ onSectionRendered: onSectionRendered
863
+ }));
864
+ expect(numCalls).toEqual(2);
865
+ expect(columnStartIndex).toEqual(0);
866
+ expect(columnStopIndex).toEqual(3);
867
+ expect(rowStartIndex).toEqual(0);
868
+ expect(rowStopIndex).toEqual(2);
869
+ render(getMarkup({
870
+ height: 50,
871
+ onSectionRendered: onSectionRendered,
872
+ width: 100
873
+ }));
874
+ expect(numCalls).toEqual(3);
875
+ expect(columnStartIndex).toEqual(0);
876
+ expect(columnStopIndex).toEqual(1);
877
+ expect(rowStartIndex).toEqual(0);
878
+ expect(rowStopIndex).toEqual(2);
879
+ });
880
+ it('should not call :onSectionRendered if no cells are rendered', function () {
881
+ var numCalls = 0;
882
+ render(getMarkup({
883
+ height: 0,
884
+ onSectionRendered: function onSectionRendered() {
885
+ return numCalls++;
886
+ }
887
+ }));
888
+ expect(numCalls).toEqual(0);
889
+ });
890
+ });
891
+ describe(':scrollLeft and :scrollTop properties', function () {
892
+ it('should render correctly when an initial :scrollLeft and :scrollTop properties are specified', function () {
893
+ var columnStartIndex, columnStopIndex, rowStartIndex, rowStopIndex;
894
+ findDOMNode(render(getMarkup({
895
+ onSectionRendered: function onSectionRendered(params) {
896
+ var _params2;
897
+ return _params2 = params, columnStartIndex = _params2.columnStartIndex, columnStopIndex = _params2.columnStopIndex, rowStartIndex = _params2.rowStartIndex, rowStopIndex = _params2.rowStopIndex, _params2;
898
+ },
899
+ scrollLeft: 250,
900
+ scrollTop: 100
901
+ })));
902
+ expect(rowStartIndex).toEqual(5);
903
+ expect(rowStopIndex).toEqual(9);
904
+ expect(columnStartIndex).toEqual(5);
905
+ expect(columnStopIndex).toEqual(8);
906
+ });
907
+ it('should render correctly when :scrollLeft and :scrollTop properties are updated', function () {
908
+ var columnStartIndex, columnStopIndex, rowStartIndex, rowStopIndex;
909
+ render(getMarkup({
910
+ onSectionRendered: function onSectionRendered(params) {
911
+ var _params3;
912
+ return _params3 = params, columnStartIndex = _params3.columnStartIndex, columnStopIndex = _params3.columnStopIndex, rowStartIndex = _params3.rowStartIndex, rowStopIndex = _params3.rowStopIndex, _params3;
913
+ }
914
+ }));
915
+ expect(rowStartIndex).toEqual(0);
916
+ expect(rowStopIndex).toEqual(4);
917
+ expect(columnStartIndex).toEqual(0);
918
+ expect(columnStopIndex).toEqual(3);
919
+ render(getMarkup({
920
+ onSectionRendered: function onSectionRendered(params) {
921
+ var _params4;
922
+ return _params4 = params, columnStartIndex = _params4.columnStartIndex, columnStopIndex = _params4.columnStopIndex, rowStartIndex = _params4.rowStartIndex, rowStopIndex = _params4.rowStopIndex, _params4;
923
+ },
924
+ scrollLeft: 250,
925
+ scrollTop: 100
926
+ }));
927
+ expect(rowStartIndex).toEqual(5);
928
+ expect(rowStopIndex).toEqual(9);
929
+ expect(columnStartIndex).toEqual(5);
930
+ expect(columnStopIndex).toEqual(8);
931
+ });
932
+ });
933
+ describe('styles, classNames, ids, and roles', function () {
934
+ it('should use the expected global CSS classNames', function () {
935
+ var rendered = findDOMNode(render(getMarkup()));
936
+ expect(rendered.className).toEqual('ReactVirtualized__Grid');
937
+ });
938
+ it('should use a custom :className if specified', function () {
939
+ var rendered = findDOMNode(render(getMarkup({
940
+ className: 'foo'
941
+ })));
942
+ expect(rendered.className).toContain('foo');
943
+ });
944
+ it('should use a custom :id if specified', function () {
945
+ var rendered = findDOMNode(render(getMarkup({
946
+ id: 'bar'
947
+ })));
948
+ expect(rendered.getAttribute('id')).toEqual('bar');
949
+ });
950
+ it('should use a custom :style if specified', function () {
951
+ var style = {
952
+ backgroundColor: 'red'
953
+ };
954
+ var rendered = findDOMNode(render(getMarkup({
955
+ style: style
956
+ })));
957
+ expect(rendered.style.backgroundColor).toEqual('red');
958
+ });
959
+ it('should use a custom :containerStyle if specified', function () {
960
+ var containerStyle = {
961
+ backgroundColor: 'red'
962
+ };
963
+ var rendered = findDOMNode(render(getMarkup({
964
+ containerStyle: containerStyle
965
+ })));
966
+ expect(rendered.querySelector('.ReactVirtualized__Grid__innerScrollContainer').style.backgroundColor).toEqual('red');
967
+ });
968
+ it('should have the gridcell role', function () {
969
+ var containerStyle = {
970
+ backgroundColor: 'red'
971
+ };
972
+ var rendered = findDOMNode(render(getMarkup({
973
+ containerStyle: containerStyle
974
+ })));
975
+ expect(rendered.querySelectorAll('[role="gridcell"]').length).toEqual(20);
976
+ });
977
+ });
978
+ describe('onScroll', function () {
979
+ it('should trigger callback when component is mounted', function () {
980
+ var onScrollCalls = [];
981
+ render(getMarkup({
982
+ onScroll: function onScroll(params) {
983
+ return onScrollCalls.push(params);
984
+ },
985
+ scrollLeft: 50,
986
+ scrollTop: 100
987
+ }));
988
+ expect(onScrollCalls).toEqual([{
989
+ clientHeight: 100,
990
+ clientWidth: 200,
991
+ scrollHeight: 2000,
992
+ scrollLeft: 50,
993
+ scrollTop: 100,
994
+ scrollWidth: 2500
995
+ }]);
996
+ });
997
+ it('should trigger callback when component scrolls horizontally', function () {
998
+ var onScrollCalls = [];
999
+ var grid = render(getMarkup({
1000
+ onScroll: function onScroll(params) {
1001
+ return onScrollCalls.push(params);
1002
+ }
1003
+ }));
1004
+ simulateScroll({
1005
+ grid: grid,
1006
+ scrollLeft: 100,
1007
+ scrollTop: 0
1008
+ });
1009
+ expect(onScrollCalls.length).toEqual(2);
1010
+ expect(onScrollCalls[1]).toEqual({
1011
+ clientHeight: 100,
1012
+ clientWidth: 200,
1013
+ scrollHeight: 2000,
1014
+ scrollLeft: 100,
1015
+ scrollTop: 0,
1016
+ scrollWidth: 2500
1017
+ });
1018
+ });
1019
+ it('should trigger callback when component scrolls vertically', function () {
1020
+ var onScrollCalls = [];
1021
+ var grid = render(getMarkup({
1022
+ onScroll: function onScroll(params) {
1023
+ return onScrollCalls.push(params);
1024
+ }
1025
+ }));
1026
+ simulateScroll({
1027
+ grid: grid,
1028
+ scrollLeft: 0,
1029
+ scrollTop: 100
1030
+ });
1031
+ expect(onScrollCalls.length).toEqual(2);
1032
+ expect(onScrollCalls[1]).toEqual({
1033
+ clientHeight: 100,
1034
+ clientWidth: 200,
1035
+ scrollHeight: 2000,
1036
+ scrollLeft: 0,
1037
+ scrollTop: 100,
1038
+ scrollWidth: 2500
1039
+ });
1040
+ });
1041
+ it('should trigger callback with scrollLeft of 0 when total columns width is less than width', function () {
1042
+ var onScrollCalls = [];
1043
+ var grid = render(getMarkup({
1044
+ columnCount: 1,
1045
+ columnWidth: 50,
1046
+ onScroll: function onScroll(params) {
1047
+ return onScrollCalls.push(params);
1048
+ },
1049
+ scrollLeft: 0,
1050
+ scrollTop: 10,
1051
+ width: 200
1052
+ }));
1053
+ simulateScroll({
1054
+ grid: grid,
1055
+ scrollLeft: 0,
1056
+ scrollTop: 0
1057
+ });
1058
+ expect(onScrollCalls.length).toEqual(2);
1059
+ expect(onScrollCalls[1]).toEqual({
1060
+ clientHeight: 100,
1061
+ clientWidth: 200,
1062
+ scrollHeight: 2000,
1063
+ scrollLeft: 0,
1064
+ scrollTop: 0,
1065
+ scrollWidth: 50
1066
+ });
1067
+ });
1068
+ it('should trigger callback with scrollTop of 0 when total rows height is less than height', function () {
1069
+ var onScrollCalls = [];
1070
+ var grid = render(getMarkup({
1071
+ rowCount: 1,
1072
+ rowHeight: 50,
1073
+ onScroll: function onScroll(params) {
1074
+ return onScrollCalls.push(params);
1075
+ },
1076
+ scrollLeft: 0,
1077
+ scrollTop: 10,
1078
+ height: 200
1079
+ }));
1080
+ simulateScroll({
1081
+ grid: grid,
1082
+ scrollLeft: 0,
1083
+ scrollTop: 0
1084
+ });
1085
+ expect(onScrollCalls.length).toEqual(2);
1086
+ expect(onScrollCalls[1]).toEqual({
1087
+ clientHeight: 200,
1088
+ clientWidth: 200,
1089
+ scrollHeight: 50,
1090
+ scrollLeft: 0,
1091
+ scrollTop: 0,
1092
+ scrollWidth: 2500
1093
+ });
1094
+ });
1095
+
1096
+ // Support use-cases like WindowScroller; enable them to stay in sync with scroll-to-cell changes.
1097
+ it('should trigger when :scrollToColumn or :scrollToRow are changed via props', function () {
1098
+ var onScrollCalls = [];
1099
+ render(getMarkup());
1100
+ render(getMarkup({
1101
+ onScroll: function onScroll(params) {
1102
+ return onScrollCalls.push(params);
1103
+ },
1104
+ scrollToColumn: 24,
1105
+ scrollToRow: 49
1106
+ }));
1107
+ expect(onScrollCalls).toEqual([{
1108
+ clientHeight: 100,
1109
+ clientWidth: 200,
1110
+ scrollHeight: 2000,
1111
+ scrollLeft: 1050,
1112
+ scrollTop: 900,
1113
+ scrollWidth: 2500
1114
+ }]);
1115
+ });
1116
+ });
1117
+ describe('overscanColumnCount & overscanRowCount', function () {
1118
+ function createHelper() {
1119
+ var _columnOverscanStartIndex, _columnOverscanStopIndex, _columnStartIndex, _columnStopIndex, _rowOverscanStartIndex, _rowOverscanStopIndex, _rowStartIndex, _rowStopIndex;
1120
+ function onSectionRendered(params) {
1121
+ _columnOverscanStartIndex = params.columnOverscanStartIndex;
1122
+ _columnOverscanStopIndex = params.columnOverscanStopIndex;
1123
+ _columnStartIndex = params.columnStartIndex;
1124
+ _columnStopIndex = params.columnStopIndex;
1125
+ _rowOverscanStartIndex = params.rowOverscanStartIndex;
1126
+ _rowOverscanStopIndex = params.rowOverscanStopIndex;
1127
+ _rowStartIndex = params.rowStartIndex;
1128
+ _rowStopIndex = params.rowStopIndex;
1129
+ }
1130
+ return {
1131
+ columnOverscanStartIndex: function columnOverscanStartIndex() {
1132
+ return _columnOverscanStartIndex;
1133
+ },
1134
+ columnOverscanStopIndex: function columnOverscanStopIndex() {
1135
+ return _columnOverscanStopIndex;
1136
+ },
1137
+ columnStartIndex: function columnStartIndex() {
1138
+ return _columnStartIndex;
1139
+ },
1140
+ columnStopIndex: function columnStopIndex() {
1141
+ return _columnStopIndex;
1142
+ },
1143
+ onSectionRendered: onSectionRendered,
1144
+ rowOverscanStartIndex: function rowOverscanStartIndex() {
1145
+ return _rowOverscanStartIndex;
1146
+ },
1147
+ rowOverscanStopIndex: function rowOverscanStopIndex() {
1148
+ return _rowOverscanStopIndex;
1149
+ },
1150
+ rowStartIndex: function rowStartIndex() {
1151
+ return _rowStartIndex;
1152
+ },
1153
+ rowStopIndex: function rowStopIndex() {
1154
+ return _rowStopIndex;
1155
+ }
1156
+ };
1157
+ }
1158
+ it('should not overscan if disabled', function () {
1159
+ var helper = createHelper();
1160
+ render(getMarkup({
1161
+ onSectionRendered: helper.onSectionRendered
1162
+ }));
1163
+ expect(helper.columnOverscanStartIndex()).toEqual(helper.columnStartIndex());
1164
+ expect(helper.columnOverscanStopIndex()).toEqual(helper.columnStopIndex());
1165
+ expect(helper.rowOverscanStartIndex()).toEqual(helper.rowStartIndex());
1166
+ expect(helper.rowOverscanStopIndex()).toEqual(helper.rowStopIndex());
1167
+ });
1168
+ it('should overscan the specified amount', function () {
1169
+ var helper = createHelper();
1170
+ render(getMarkup({
1171
+ onSectionRendered: helper.onSectionRendered,
1172
+ overscanColumnCount: 2,
1173
+ overscanRowCount: 5,
1174
+ scrollToColumn: 25,
1175
+ scrollToRow: 50
1176
+ }));
1177
+ expect(helper.columnOverscanStartIndex()).toEqual(22);
1178
+ expect(helper.columnOverscanStopIndex()).toEqual(27);
1179
+ expect(helper.columnStartIndex()).toEqual(22);
1180
+ expect(helper.columnStopIndex()).toEqual(25);
1181
+ expect(helper.rowOverscanStartIndex()).toEqual(46);
1182
+ expect(helper.rowOverscanStopIndex()).toEqual(55);
1183
+ expect(helper.rowStartIndex()).toEqual(46);
1184
+ expect(helper.rowStopIndex()).toEqual(50);
1185
+ });
1186
+ it('should not overscan beyond the bounds of the grid', function () {
1187
+ var helper = createHelper();
1188
+ render(getMarkup({
1189
+ onSectionRendered: helper.onSectionRendered,
1190
+ columnCount: 6,
1191
+ overscanColumnCount: 10,
1192
+ overscanRowCount: 10,
1193
+ rowCount: 5
1194
+ }));
1195
+ expect(helper.columnOverscanStartIndex()).toEqual(0);
1196
+ expect(helper.columnOverscanStopIndex()).toEqual(5);
1197
+ expect(helper.columnStartIndex()).toEqual(0);
1198
+ expect(helper.columnStopIndex()).toEqual(3);
1199
+ expect(helper.rowOverscanStartIndex()).toEqual(0);
1200
+ expect(helper.rowOverscanStopIndex()).toEqual(4);
1201
+ expect(helper.rowStartIndex()).toEqual(0);
1202
+ expect(helper.rowStopIndex()).toEqual(4);
1203
+ });
1204
+ it('should set the correct scroll direction', function () {
1205
+ // Do not pass in the initial state as props, otherwise the internal state is forbidden from updating itself
1206
+ var grid = render(getMarkup());
1207
+
1208
+ // Simulate a scroll to set the initial internal state
1209
+ simulateScroll({
1210
+ grid: grid,
1211
+ scrollLeft: 50,
1212
+ scrollTop: 50
1213
+ });
1214
+ expect(grid.state.scrollDirectionHorizontal).toEqual(SCROLL_DIRECTION_FORWARD);
1215
+ expect(grid.state.scrollDirectionVertical).toEqual(SCROLL_DIRECTION_FORWARD);
1216
+ simulateScroll({
1217
+ grid: grid,
1218
+ scrollLeft: 0,
1219
+ scrollTop: 0
1220
+ });
1221
+ expect(grid.state.scrollDirectionHorizontal).toEqual(SCROLL_DIRECTION_BACKWARD);
1222
+ expect(grid.state.scrollDirectionVertical).toEqual(SCROLL_DIRECTION_BACKWARD);
1223
+ simulateScroll({
1224
+ grid: grid,
1225
+ scrollLeft: 100,
1226
+ scrollTop: 100
1227
+ });
1228
+ expect(grid.state.scrollDirectionHorizontal).toEqual(SCROLL_DIRECTION_FORWARD);
1229
+ expect(grid.state.scrollDirectionVertical).toEqual(SCROLL_DIRECTION_FORWARD);
1230
+ });
1231
+ it('should set the correct scroll direction when scroll position is updated from props', function () {
1232
+ var grid = render(getMarkup({
1233
+ scrollLeft: 50,
1234
+ scrollTop: 50
1235
+ }));
1236
+ expect(grid.state.scrollDirectionHorizontal).toEqual(SCROLL_DIRECTION_FORWARD);
1237
+ expect(grid.state.scrollDirectionVertical).toEqual(SCROLL_DIRECTION_FORWARD);
1238
+ grid = render(getMarkup({
1239
+ scrollLeft: 0,
1240
+ scrollTop: 0
1241
+ }));
1242
+ expect(grid.state.scrollDirectionHorizontal).toEqual(SCROLL_DIRECTION_BACKWARD);
1243
+ expect(grid.state.scrollDirectionVertical).toEqual(SCROLL_DIRECTION_BACKWARD);
1244
+ grid = render(getMarkup({
1245
+ scrollLeft: 100,
1246
+ scrollTop: 100
1247
+ }));
1248
+ expect(grid.state.scrollDirectionHorizontal).toEqual(SCROLL_DIRECTION_FORWARD);
1249
+ expect(grid.state.scrollDirectionVertical).toEqual(SCROLL_DIRECTION_FORWARD);
1250
+ });
1251
+ it('should not reset scroll direction for one axis when scrolled in another', function () {
1252
+ // Do not pass in the initial state as props, otherwise the internal state is forbidden from updating itself
1253
+ var grid = render(getMarkup());
1254
+
1255
+ // Simulate a scroll to set the initial internal state
1256
+ simulateScroll({
1257
+ grid: grid,
1258
+ scrollLeft: 0,
1259
+ scrollTop: 5
1260
+ });
1261
+ expect(grid.state.scrollDirectionHorizontal).toEqual(SCROLL_DIRECTION_FORWARD);
1262
+ expect(grid.state.scrollDirectionVertical).toEqual(SCROLL_DIRECTION_FORWARD);
1263
+ simulateScroll({
1264
+ grid: grid,
1265
+ scrollLeft: 5,
1266
+ scrollTop: 5
1267
+ });
1268
+ expect(grid.state.scrollDirectionHorizontal).toEqual(SCROLL_DIRECTION_FORWARD);
1269
+ expect(grid.state.scrollDirectionVertical).toEqual(SCROLL_DIRECTION_FORWARD);
1270
+ simulateScroll({
1271
+ grid: grid,
1272
+ scrollLeft: 5,
1273
+ scrollTop: 0
1274
+ });
1275
+ expect(grid.state.scrollDirectionHorizontal).toEqual(SCROLL_DIRECTION_FORWARD);
1276
+ expect(grid.state.scrollDirectionVertical).toEqual(SCROLL_DIRECTION_BACKWARD);
1277
+ simulateScroll({
1278
+ grid: grid,
1279
+ scrollLeft: 0,
1280
+ scrollTop: 0
1281
+ });
1282
+ expect(grid.state.scrollDirectionHorizontal).toEqual(SCROLL_DIRECTION_BACKWARD);
1283
+ expect(grid.state.scrollDirectionVertical).toEqual(SCROLL_DIRECTION_BACKWARD);
1284
+ });
1285
+ it('should overscan in the direction being scrolled', /*#__PURE__*/function () {
1286
+ var _ref5 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(done) {
1287
+ var helper, onSectionRenderedResolve, onSectionRendered, grid, onSectionRenderedPromise;
1288
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
1289
+ while (1) switch (_context.prev = _context.next) {
1290
+ case 0:
1291
+ onSectionRendered = function _onSectionRendered(params) {
1292
+ helper.onSectionRendered(params);
1293
+ if (onSectionRenderedResolve) {
1294
+ onSectionRenderedResolve();
1295
+ }
1296
+ };
1297
+ helper = createHelper();
1298
+ grid = render(getMarkup({
1299
+ onSectionRendered: onSectionRendered,
1300
+ overscanColumnCount: 2,
1301
+ overscanRowCount: 5
1302
+ })); // Wait until the onSectionRendered handler / debouncer has processed
1303
+ onSectionRenderedPromise = new Promise(function (resolve) {
1304
+ onSectionRenderedResolve = resolve;
1305
+ });
1306
+ simulateScroll({
1307
+ grid: grid,
1308
+ scrollLeft: 200,
1309
+ scrollTop: 200
1310
+ });
1311
+ _context.next = 7;
1312
+ return onSectionRenderedPromise;
1313
+ case 7:
1314
+ // It should overscan in the direction being scrolled while scroll is in progress
1315
+ expect(helper.columnOverscanStartIndex()).toEqual(4);
1316
+ expect(helper.columnOverscanStopIndex()).toEqual(9);
1317
+ expect(helper.columnStartIndex()).toEqual(4);
1318
+ expect(helper.columnStopIndex()).toEqual(7);
1319
+ expect(helper.rowOverscanStartIndex()).toEqual(10);
1320
+ expect(helper.rowOverscanStopIndex()).toEqual(19);
1321
+ expect(helper.rowStartIndex()).toEqual(10);
1322
+ expect(helper.rowStopIndex()).toEqual(14);
1323
+
1324
+ // Wait until the onSectionRendered handler / debouncer has processed
1325
+ onSectionRenderedPromise = new Promise(function (resolve) {
1326
+ onSectionRenderedResolve = resolve;
1327
+ });
1328
+ simulateScroll({
1329
+ grid: grid,
1330
+ scrollLeft: 100,
1331
+ scrollTop: 100
1332
+ });
1333
+ _context.next = 19;
1334
+ return onSectionRenderedPromise;
1335
+ case 19:
1336
+ // It reset overscan once scrolling has finished
1337
+ expect(helper.columnOverscanStartIndex()).toEqual(0);
1338
+ expect(helper.columnOverscanStopIndex()).toEqual(5);
1339
+ expect(helper.columnStartIndex()).toEqual(2);
1340
+ expect(helper.columnStopIndex()).toEqual(5);
1341
+ expect(helper.rowOverscanStartIndex()).toEqual(0);
1342
+ expect(helper.rowOverscanStopIndex()).toEqual(9);
1343
+ expect(helper.rowStartIndex()).toEqual(5);
1344
+ expect(helper.rowStopIndex()).toEqual(9);
1345
+ done();
1346
+ case 28:
1347
+ case "end":
1348
+ return _context.stop();
1349
+ }
1350
+ }, _callee);
1351
+ }));
1352
+ return function (_x) {
1353
+ return _ref5.apply(this, arguments);
1354
+ };
1355
+ }());
1356
+ });
1357
+ describe('cellRangeRenderer', function () {
1358
+ it('should use a custom :cellRangeRenderer if specified', function () {
1359
+ var cellRangeRendererCalled = 0;
1360
+ var cellRangeRendererParams;
1361
+ var rendered = findDOMNode(render(getMarkup({
1362
+ cellRangeRenderer: function cellRangeRenderer(params) {
1363
+ cellRangeRendererParams = params;
1364
+ cellRangeRendererCalled++;
1365
+ return [/*#__PURE__*/React.createElement("div", {
1366
+ key: "0"
1367
+ }, "Fake content")];
1368
+ }
1369
+ })));
1370
+ expect(cellRangeRendererCalled).toEqual(1);
1371
+ expect(cellRangeRendererParams.columnStartIndex).toEqual(0);
1372
+ expect(cellRangeRendererParams.columnStopIndex).toEqual(3);
1373
+ expect(cellRangeRendererParams.rowStartIndex).toEqual(0);
1374
+ expect(cellRangeRendererParams.rowStopIndex).toEqual(4);
1375
+ expect(rendered.textContent).toContain('Fake content');
1376
+ });
1377
+ });
1378
+ describe('estimated row and column sizes', function () {
1379
+ it('should not estimate sizes if actual sizes are numbers', function () {
1380
+ var grid = render(getMarkup({
1381
+ columnWidth: 100,
1382
+ estimatedColumnSize: 150,
1383
+ estimatedRowSize: 15,
1384
+ rowHeight: 20
1385
+ }));
1386
+ expect(Grid._getEstimatedColumnSize(grid.props)).toEqual(100);
1387
+ expect(Grid._getEstimatedRowSize(grid.props)).toEqual(20);
1388
+ });
1389
+ it('should estimate row and column sizes if actual sizes are functions', function () {
1390
+ var grid = render(getMarkup({
1391
+ columnWidth: function columnWidth() {
1392
+ return 100;
1393
+ },
1394
+ estimatedColumnSize: 150,
1395
+ estimatedRowSize: 15,
1396
+ rowHeight: function rowHeight() {
1397
+ return 20;
1398
+ }
1399
+ }));
1400
+ expect(Grid._getEstimatedColumnSize(grid.props)).toEqual(150);
1401
+ expect(Grid._getEstimatedRowSize(grid.props)).toEqual(15);
1402
+ });
1403
+ });
1404
+ it('should pass the cellRenderer an :isScrolling flag when scrolling is in progress', /*#__PURE__*/function () {
1405
+ var _ref6 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(done) {
1406
+ var cellRendererCalls, cellRenderer, grid;
1407
+ return _regeneratorRuntime.wrap(function _callee2$(_context2) {
1408
+ while (1) switch (_context2.prev = _context2.next) {
1409
+ case 0:
1410
+ cellRenderer = function _cellRenderer(_ref7) {
1411
+ var columnIndex = _ref7.columnIndex,
1412
+ isScrolling = _ref7.isScrolling,
1413
+ key = _ref7.key,
1414
+ rowIndex = _ref7.rowIndex,
1415
+ style = _ref7.style;
1416
+ cellRendererCalls.push(isScrolling);
1417
+ return defaultCellRenderer({
1418
+ columnIndex: columnIndex,
1419
+ key: key,
1420
+ rowIndex: rowIndex,
1421
+ style: style
1422
+ });
1423
+ };
1424
+ cellRendererCalls = [];
1425
+ grid = render(getMarkup({
1426
+ cellRenderer: cellRenderer
1427
+ }));
1428
+ expect(cellRendererCalls[0]).toEqual(false);
1429
+ cellRendererCalls.splice(0);
1430
+
1431
+ // Give React time to process the queued setState()
1432
+ _context2.next = 7;
1433
+ return new Promise(function (resolve) {
1434
+ return setTimeout(resolve, 1);
1435
+ });
1436
+ case 7:
1437
+ simulateScroll({
1438
+ grid: grid,
1439
+ scrollTop: 100
1440
+ });
1441
+ expect(cellRendererCalls[0]).toEqual(true);
1442
+ done();
1443
+ case 10:
1444
+ case "end":
1445
+ return _context2.stop();
1446
+ }
1447
+ }, _callee2);
1448
+ }));
1449
+ return function (_x2) {
1450
+ return _ref6.apply(this, arguments);
1451
+ };
1452
+ }());
1453
+ it('should pass the cellRenderer an :isScrolling flag based on props override', function () {
1454
+ var cellRenderer = jest.fn();
1455
+ cellRenderer.mockImplementation(function (_ref8) {
1456
+ var key = _ref8.key,
1457
+ style = _ref8.style;
1458
+ return /*#__PURE__*/React.createElement("div", {
1459
+ key: key,
1460
+ style: style
1461
+ });
1462
+ });
1463
+ render(getMarkup({
1464
+ cellRenderer: cellRenderer,
1465
+ isScrolling: true
1466
+ }));
1467
+ expect(cellRenderer).toHaveBeenCalled();
1468
+ expect(cellRenderer.mock.calls[0][0].isScrolling).toBe(true);
1469
+ cellRenderer.mockReset();
1470
+ render(getMarkup({
1471
+ cellRenderer: cellRenderer,
1472
+ isScrolling: false,
1473
+ width: DEFAULT_WIDTH + 1
1474
+ }));
1475
+ expect(cellRenderer).toHaveBeenCalled();
1476
+ expect(cellRenderer.mock.calls[0][0].isScrolling).toBe(false);
1477
+ });
1478
+ it('should pass the cellRenderer an :isVisible flag', function () {
1479
+ var cellRendererCalls = [];
1480
+ function cellRenderer(props) {
1481
+ cellRendererCalls.push(props);
1482
+ return defaultCellRenderer(props);
1483
+ }
1484
+ render(getMarkup({
1485
+ cellRenderer: cellRenderer,
1486
+ height: DEFAULT_ROW_HEIGHT,
1487
+ overscanColumnCount: 1,
1488
+ overscanRowCount: 1,
1489
+ width: DEFAULT_COLUMN_WIDTH
1490
+ }));
1491
+ cellRendererCalls.forEach(function (props) {
1492
+ expect(props.isVisible).toEqual(props.columnIndex === 0 && props.rowIndex === 0); // Only the first cell is visible
1493
+ });
1494
+ });
1495
+ describe('cell caching', function () {
1496
+ it('should not cache cells if the Grid is not scrolling', function () {
1497
+ var cellRendererCalls = [];
1498
+ function cellRenderer(_ref9) {
1499
+ var columnIndex = _ref9.columnIndex,
1500
+ key = _ref9.key,
1501
+ rowIndex = _ref9.rowIndex,
1502
+ style = _ref9.style;
1503
+ cellRendererCalls.push({
1504
+ columnIndex: columnIndex,
1505
+ rowIndex: rowIndex
1506
+ });
1507
+ return defaultCellRenderer({
1508
+ columnIndex: columnIndex,
1509
+ key: key,
1510
+ rowIndex: rowIndex,
1511
+ style: style
1512
+ });
1513
+ }
1514
+ var props = {
1515
+ cellRenderer: cellRenderer,
1516
+ columnWidth: 100,
1517
+ height: 40,
1518
+ rowHeight: 20,
1519
+ scrollToRow: 0,
1520
+ width: 100
1521
+ };
1522
+ render(getMarkup(_objectSpread(_objectSpread({}, props), {}, {
1523
+ scrollToRow: 0
1524
+ })));
1525
+ expect(cellRendererCalls).toEqual([{
1526
+ columnIndex: 0,
1527
+ rowIndex: 0
1528
+ }, {
1529
+ columnIndex: 0,
1530
+ rowIndex: 1
1531
+ }]);
1532
+ cellRendererCalls.splice(0);
1533
+ render(getMarkup(_objectSpread(_objectSpread({}, props), {}, {
1534
+ scrollToRow: 1
1535
+ })));
1536
+ expect(cellRendererCalls).toEqual([{
1537
+ columnIndex: 0,
1538
+ rowIndex: 0
1539
+ }, {
1540
+ columnIndex: 0,
1541
+ rowIndex: 1
1542
+ }]);
1543
+ });
1544
+ it('should not cache cells if the offsets are not adjusted', function () {
1545
+ var cellRendererCalls = [];
1546
+ function cellRenderer(_ref10) {
1547
+ var columnIndex = _ref10.columnIndex,
1548
+ key = _ref10.key,
1549
+ rowIndex = _ref10.rowIndex,
1550
+ style = _ref10.style;
1551
+ cellRendererCalls.push({
1552
+ columnIndex: columnIndex,
1553
+ rowIndex: rowIndex
1554
+ });
1555
+ return defaultCellRenderer({
1556
+ columnIndex: columnIndex,
1557
+ key: key,
1558
+ rowIndex: rowIndex,
1559
+ style: style
1560
+ });
1561
+ }
1562
+ var props = {
1563
+ cellRenderer: cellRenderer,
1564
+ columnWidth: 100,
1565
+ height: 40,
1566
+ rowHeight: 20,
1567
+ rowCount: 100000,
1568
+ scrollToRow: 0,
1569
+ width: 100
1570
+ };
1571
+ render(getMarkup(_objectSpread(_objectSpread({}, props), {}, {
1572
+ scrollToRow: 0
1573
+ })));
1574
+ expect(cellRendererCalls).toEqual([{
1575
+ columnIndex: 0,
1576
+ rowIndex: 0
1577
+ }, {
1578
+ columnIndex: 0,
1579
+ rowIndex: 1
1580
+ }]);
1581
+ cellRendererCalls.splice(0);
1582
+ render(getMarkup(_objectSpread(_objectSpread({}, props), {}, {
1583
+ scrollToRow: 1
1584
+ })));
1585
+ expect(cellRendererCalls).toEqual([{
1586
+ columnIndex: 0,
1587
+ rowIndex: 0
1588
+ }, {
1589
+ columnIndex: 0,
1590
+ rowIndex: 1
1591
+ }]);
1592
+ });
1593
+ it('should cache a cell once it has been rendered while scrolling', function () {
1594
+ var cellRendererCalls = [];
1595
+ function cellRenderer(_ref11) {
1596
+ var columnIndex = _ref11.columnIndex,
1597
+ key = _ref11.key,
1598
+ rowIndex = _ref11.rowIndex,
1599
+ style = _ref11.style;
1600
+ cellRendererCalls.push({
1601
+ columnIndex: columnIndex,
1602
+ rowIndex: rowIndex
1603
+ });
1604
+ return defaultCellRenderer({
1605
+ columnIndex: columnIndex,
1606
+ key: key,
1607
+ rowIndex: rowIndex,
1608
+ style: style
1609
+ });
1610
+ }
1611
+ var props = {
1612
+ cellRenderer: cellRenderer,
1613
+ columnWidth: 100,
1614
+ height: 40,
1615
+ rowHeight: 20,
1616
+ width: 100
1617
+ };
1618
+ var grid = render(getMarkup(_objectSpread(_objectSpread({}, props), {}, {
1619
+ scrollToRow: 0
1620
+ })));
1621
+ expect(cellRendererCalls).toEqual([{
1622
+ columnIndex: 0,
1623
+ rowIndex: 0
1624
+ }, {
1625
+ columnIndex: 0,
1626
+ rowIndex: 1
1627
+ }]);
1628
+ simulateScroll({
1629
+ grid: grid,
1630
+ scrollTop: 1
1631
+ });
1632
+ cellRendererCalls.splice(0);
1633
+
1634
+ // Rows 0-2 have already rendered but row 3 is not yet visible
1635
+ // This means that only row 3 should be newly-created
1636
+ // The others should come from the cache
1637
+ render(getMarkup(_objectSpread(_objectSpread({}, props), {}, {
1638
+ scrollToRow: 3
1639
+ })));
1640
+ expect(cellRendererCalls).toEqual([{
1641
+ columnIndex: 0,
1642
+ rowIndex: 3
1643
+ }]);
1644
+ });
1645
+ it('should clear cache once :isScrolling is false', /*#__PURE__*/function () {
1646
+ var _ref12 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee3(done) {
1647
+ var cellRendererCalls, cellRenderer, props, grid;
1648
+ return _regeneratorRuntime.wrap(function _callee3$(_context3) {
1649
+ while (1) switch (_context3.prev = _context3.next) {
1650
+ case 0:
1651
+ cellRenderer = function _cellRenderer2(_ref13) {
1652
+ var columnIndex = _ref13.columnIndex,
1653
+ key = _ref13.key,
1654
+ rowIndex = _ref13.rowIndex,
1655
+ style = _ref13.style;
1656
+ cellRendererCalls.push({
1657
+ columnIndex: columnIndex,
1658
+ rowIndex: rowIndex
1659
+ });
1660
+ return defaultCellRenderer({
1661
+ columnIndex: columnIndex,
1662
+ key: key,
1663
+ rowIndex: rowIndex,
1664
+ style: style
1665
+ });
1666
+ };
1667
+ cellRendererCalls = [];
1668
+ props = {
1669
+ cellRenderer: cellRenderer,
1670
+ columnWidth: 100,
1671
+ height: 40,
1672
+ rowHeight: 20,
1673
+ scrollToRow: 0,
1674
+ width: 100
1675
+ };
1676
+ grid = render(getMarkup(props));
1677
+ expect(cellRendererCalls).toEqual([{
1678
+ columnIndex: 0,
1679
+ rowIndex: 0
1680
+ }, {
1681
+ columnIndex: 0,
1682
+ rowIndex: 1
1683
+ }]);
1684
+ simulateScroll({
1685
+ grid: grid,
1686
+ scrollTop: 1
1687
+ });
1688
+
1689
+ // Allow scrolling timeout to complete so that cell cache is reset
1690
+ _context3.next = 8;
1691
+ return new Promise(function (resolve) {
1692
+ return setTimeout(resolve, DEFAULT_SCROLLING_RESET_TIME_INTERVAL * 2);
1693
+ });
1694
+ case 8:
1695
+ cellRendererCalls.splice(0);
1696
+ render(getMarkup(_objectSpread(_objectSpread({}, props), {}, {
1697
+ scrollToRow: 1
1698
+ })));
1699
+ expect(cellRendererCalls.length).not.toEqual(0);
1700
+ done();
1701
+ case 12:
1702
+ case "end":
1703
+ return _context3.stop();
1704
+ }
1705
+ }, _callee3);
1706
+ }));
1707
+ return function (_x3) {
1708
+ return _ref12.apply(this, arguments);
1709
+ };
1710
+ }());
1711
+ it('should clear cache once :isScrolling via props is false', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee4() {
1712
+ var cellRenderer, props, scrollingStyle;
1713
+ return _regeneratorRuntime.wrap(function _callee4$(_context4) {
1714
+ while (1) switch (_context4.prev = _context4.next) {
1715
+ case 0:
1716
+ cellRenderer = jest.fn();
1717
+ cellRenderer.mockImplementation(function (params) {
1718
+ return /*#__PURE__*/React.createElement("div", {
1719
+ key: params.key,
1720
+ style: params.style
1721
+ });
1722
+ });
1723
+ props = {
1724
+ autoHeight: true,
1725
+ cellRenderer: cellRenderer,
1726
+ columnCount: 1,
1727
+ isScrolling: true,
1728
+ rowCount: 1
1729
+ };
1730
+ render(getMarkup(props));
1731
+ render(getMarkup(props));
1732
+ expect(cellRenderer).toHaveBeenCalledTimes(1); // Due to cell cache
1733
+ scrollingStyle = cellRenderer.mock.calls[0][0].style;
1734
+ cellRenderer.mockReset();
1735
+ render(getMarkup(_objectSpread(_objectSpread({}, props), {}, {
1736
+ isScrolling: false
1737
+ })));
1738
+ expect(cellRenderer.mock.calls[0][0].style).toBe(scrollingStyle);
1739
+ expect(cellRenderer).toHaveBeenCalledTimes(1); // Reset cache
1740
+
1741
+ cellRenderer.mockReset();
1742
+ render(getMarkup(_objectSpread(_objectSpread({}, props), {}, {
1743
+ isScrolling: true
1744
+ })));
1745
+ expect(cellRenderer.mock.calls[0][0].style).not.toBe(scrollingStyle);
1746
+ expect(cellRenderer).toHaveBeenCalledTimes(1); // Only cached when scrolling
1747
+ case 15:
1748
+ case "end":
1749
+ return _context4.stop();
1750
+ }
1751
+ }, _callee4);
1752
+ })));
1753
+ it('should clear cache if :recomputeGridSize is called', function () {
1754
+ var cellRendererCalls = [];
1755
+ function cellRenderer(_ref15) {
1756
+ var columnIndex = _ref15.columnIndex,
1757
+ key = _ref15.key,
1758
+ rowIndex = _ref15.rowIndex,
1759
+ style = _ref15.style;
1760
+ cellRendererCalls.push({
1761
+ columnIndex: columnIndex,
1762
+ rowIndex: rowIndex
1763
+ });
1764
+ return defaultCellRenderer({
1765
+ columnIndex: columnIndex,
1766
+ key: key,
1767
+ rowIndex: rowIndex,
1768
+ style: style
1769
+ });
1770
+ }
1771
+ var props = {
1772
+ cellRenderer: cellRenderer,
1773
+ columnWidth: 100,
1774
+ height: 40,
1775
+ rowHeight: 20,
1776
+ scrollTop: 0,
1777
+ width: 100
1778
+ };
1779
+ var grid = render(getMarkup(props));
1780
+ expect(cellRendererCalls).toEqual([{
1781
+ columnIndex: 0,
1782
+ rowIndex: 0
1783
+ }, {
1784
+ columnIndex: 0,
1785
+ rowIndex: 1
1786
+ }]);
1787
+ simulateScroll({
1788
+ grid: grid,
1789
+ scrollTop: 1
1790
+ });
1791
+ cellRendererCalls.splice(0);
1792
+ grid.recomputeGridSize();
1793
+ expect(cellRendererCalls.length).not.toEqual(0);
1794
+ });
1795
+ it('should not clear cache if :isScrollingOptOut is true', function () {
1796
+ var cellRendererCalls = [];
1797
+ function cellRenderer(_ref16) {
1798
+ var columnIndex = _ref16.columnIndex,
1799
+ key = _ref16.key,
1800
+ rowIndex = _ref16.rowIndex,
1801
+ style = _ref16.style;
1802
+ cellRendererCalls.push({
1803
+ columnIndex: columnIndex,
1804
+ rowIndex: rowIndex
1805
+ });
1806
+ return defaultCellRenderer({
1807
+ columnIndex: columnIndex,
1808
+ key: key,
1809
+ rowIndex: rowIndex,
1810
+ style: style
1811
+ });
1812
+ }
1813
+ var props = {
1814
+ cellRenderer: cellRenderer,
1815
+ columnWidth: 100,
1816
+ height: 40,
1817
+ rowHeight: 20,
1818
+ scrollTop: 0,
1819
+ width: 100,
1820
+ isScrollingOptOut: true
1821
+ };
1822
+ render(getMarkup(props));
1823
+ render(getMarkup(props));
1824
+ expect(cellRendererCalls).toEqual([{
1825
+ columnIndex: 0,
1826
+ rowIndex: 0
1827
+ }, {
1828
+ columnIndex: 0,
1829
+ rowIndex: 1
1830
+ }]);
1831
+ cellRendererCalls.splice(0);
1832
+ render(getMarkup(_objectSpread(_objectSpread({}, props), {}, {
1833
+ isScrolling: false
1834
+ })));
1835
+
1836
+ // Visible cells are cached
1837
+ expect(cellRendererCalls.length).toEqual(0);
1838
+ render(getMarkup(_objectSpread(_objectSpread({}, props), {}, {
1839
+ isScrolling: true
1840
+ })));
1841
+
1842
+ // Only cleared non-visible cells
1843
+ expect(cellRendererCalls.length).toEqual(0);
1844
+ });
1845
+ it('should not trigger render by _debounceScrollEndedCallback if process slow table', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee5() {
1846
+ var scrollingResetTimeInterval, cellRangeRendererCalls, cellRangeRenderer, props, grid, i;
1847
+ return _regeneratorRuntime.wrap(function _callee5$(_context5) {
1848
+ while (1) switch (_context5.prev = _context5.next) {
1849
+ case 0:
1850
+ cellRangeRenderer = function _cellRangeRenderer(props) {
1851
+ var startTime = Date.now();
1852
+ while (Date.now() - startTime <= scrollingResetTimeInterval); // imitate very slow render
1853
+ cellRangeRendererCalls++;
1854
+ return defaultCellRangeRenderer(props);
1855
+ };
1856
+ scrollingResetTimeInterval = 50;
1857
+ cellRangeRendererCalls = 0;
1858
+ props = {
1859
+ scrollingResetTimeInterval: scrollingResetTimeInterval,
1860
+ cellRangeRenderer: cellRangeRenderer
1861
+ };
1862
+ grid = render(getMarkup(props));
1863
+ render(getMarkup(props));
1864
+ expect(cellRangeRendererCalls).toEqual(1);
1865
+ i = 1;
1866
+ case 8:
1867
+ if (!(i <= 5)) {
1868
+ _context5.next = 17;
1869
+ break;
1870
+ }
1871
+ cellRangeRendererCalls = 0;
1872
+ simulateScroll({
1873
+ grid: grid,
1874
+ scrollTop: i
1875
+ });
1876
+ // small wait for maybe early _debounceScrollEndedCallback
1877
+ _context5.next = 13;
1878
+ return new Promise(function (resolve) {
1879
+ return setTimeout(resolve, scrollingResetTimeInterval / 2);
1880
+ });
1881
+ case 13:
1882
+ expect(cellRangeRendererCalls).toEqual(1);
1883
+ case 14:
1884
+ i++;
1885
+ _context5.next = 8;
1886
+ break;
1887
+ case 17:
1888
+ cellRangeRendererCalls = 0;
1889
+ // wait for real _debounceScrollEndedCallback
1890
+ _context5.next = 20;
1891
+ return new Promise(function (resolve) {
1892
+ return setTimeout(resolve, scrollingResetTimeInterval * 1.5);
1893
+ });
1894
+ case 20:
1895
+ expect(cellRangeRendererCalls).toEqual(1);
1896
+ case 21:
1897
+ case "end":
1898
+ return _context5.stop();
1899
+ }
1900
+ }, _callee5);
1901
+ })));
1902
+ it('should support a custom :scrollingResetTimeInterval prop', /*#__PURE__*/function () {
1903
+ var _ref18 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee6(done) {
1904
+ var cellRendererCalls, scrollingResetTimeInterval, cellRenderer, props, grid;
1905
+ return _regeneratorRuntime.wrap(function _callee6$(_context6) {
1906
+ while (1) switch (_context6.prev = _context6.next) {
1907
+ case 0:
1908
+ cellRenderer = function _cellRenderer3(_ref19) {
1909
+ var columnIndex = _ref19.columnIndex,
1910
+ key = _ref19.key,
1911
+ rowIndex = _ref19.rowIndex,
1912
+ style = _ref19.style;
1913
+ cellRendererCalls.push({
1914
+ columnIndex: columnIndex,
1915
+ rowIndex: rowIndex
1916
+ });
1917
+ return defaultCellRenderer({
1918
+ columnIndex: columnIndex,
1919
+ key: key,
1920
+ rowIndex: rowIndex,
1921
+ style: style
1922
+ });
1923
+ };
1924
+ cellRendererCalls = [];
1925
+ scrollingResetTimeInterval = DEFAULT_SCROLLING_RESET_TIME_INTERVAL * 2;
1926
+ props = {
1927
+ cellRenderer: cellRenderer,
1928
+ scrollingResetTimeInterval: scrollingResetTimeInterval
1929
+ };
1930
+ grid = render(getMarkup(props));
1931
+ expect(cellRendererCalls.length > 0).toEqual(true);
1932
+ simulateScroll({
1933
+ grid: grid,
1934
+ scrollTop: 1
1935
+ });
1936
+ _context6.next = 9;
1937
+ return new Promise(function (resolve) {
1938
+ return setTimeout(resolve, DEFAULT_SCROLLING_RESET_TIME_INTERVAL);
1939
+ });
1940
+ case 9:
1941
+ cellRendererCalls.splice(0);
1942
+ render(getMarkup(_objectSpread(_objectSpread({}, props), {}, {
1943
+ className: 'foo'
1944
+ })));
1945
+ expect(cellRendererCalls.length).toEqual(0);
1946
+ _context6.next = 14;
1947
+ return new Promise(function (resolve) {
1948
+ return setTimeout(resolve, DEFAULT_SCROLLING_RESET_TIME_INTERVAL * 2);
1949
+ });
1950
+ case 14:
1951
+ cellRendererCalls.splice(0);
1952
+ render(getMarkup(_objectSpread(_objectSpread({}, props), {}, {
1953
+ className: 'bar'
1954
+ })));
1955
+ expect(cellRendererCalls.length).not.toEqual(0);
1956
+ done();
1957
+ case 18:
1958
+ case "end":
1959
+ return _context6.stop();
1960
+ }
1961
+ }, _callee6);
1962
+ }));
1963
+ return function (_x4) {
1964
+ return _ref18.apply(this, arguments);
1965
+ };
1966
+ }());
1967
+ });
1968
+ describe('measureAllCells', function () {
1969
+ it('should measure any unmeasured columns and rows', function () {
1970
+ var grid = render(getMarkup({
1971
+ columnCount: 10,
1972
+ columnWidth: function columnWidth() {
1973
+ return 100;
1974
+ },
1975
+ estimatedColumnSize: 150,
1976
+ estimatedRowSize: 15,
1977
+ height: 0,
1978
+ rowCount: 10,
1979
+ rowHeight: function rowHeight() {
1980
+ return 20;
1981
+ },
1982
+ width: 0
1983
+ }));
1984
+ expect(grid.state.instanceProps.columnSizeAndPositionManager.getTotalSize()).toEqual(1500);
1985
+ expect(grid.state.instanceProps.rowSizeAndPositionManager.getTotalSize()).toEqual(150);
1986
+ grid.measureAllCells();
1987
+ expect(grid.state.instanceProps.columnSizeAndPositionManager.getTotalSize()).toEqual(1000);
1988
+ expect(grid.state.instanceProps.rowSizeAndPositionManager.getTotalSize()).toEqual(200);
1989
+ });
1990
+ });
1991
+ describe('recomputeGridSize', function () {
1992
+ it('should recompute cell sizes and other values when called', function () {
1993
+ var columnIndices = [];
1994
+ var rowIndices = [];
1995
+ function columnWidth(_ref20) {
1996
+ var index = _ref20.index;
1997
+ columnIndices.push(index);
1998
+ return 10;
1999
+ }
2000
+ function rowHeight(_ref21) {
2001
+ var index = _ref21.index;
2002
+ rowIndices.push(index);
2003
+ return 10;
2004
+ }
2005
+ var props = {
2006
+ columnCount: 50,
2007
+ columnWidth: columnWidth,
2008
+ height: 50,
2009
+ rowHeight: rowHeight,
2010
+ rowCount: 50,
2011
+ width: 100
2012
+ };
2013
+ var component = render(getMarkup(props));
2014
+ columnIndices.splice(0);
2015
+ rowIndices.splice(0);
2016
+ component.recomputeGridSize();
2017
+
2018
+ // Only the rows required to fill the current viewport will be rendered
2019
+ expect(columnIndices[0]).toEqual(0);
2020
+ expect(columnIndices[columnIndices.length - 1]).toEqual(9);
2021
+ expect(rowIndices[0]).toEqual(0);
2022
+ expect(rowIndices[rowIndices.length - 1]).toEqual(4);
2023
+ columnIndices.splice(0);
2024
+ rowIndices.splice(0);
2025
+ component.recomputeGridSize({
2026
+ columnIndex: 4,
2027
+ rowIndex: 2
2028
+ });
2029
+
2030
+ // Only the rows required to fill the current viewport will be rendered
2031
+ expect(columnIndices[0]).toEqual(4);
2032
+ expect(columnIndices[columnIndices.length - 1]).toEqual(9);
2033
+ expect(rowIndices[0]).toEqual(2);
2034
+ expect(rowIndices[rowIndices.length - 1]).toEqual(4);
2035
+ });
2036
+ });
2037
+ describe('autoContainerWidth', function () {
2038
+ it('should set the innerScrollContainer width to auto to better support single-column HOCs', function () {
2039
+ var props = {
2040
+ autoContainerWidth: true
2041
+ };
2042
+ var rendered = findDOMNode(render(getMarkup(props)));
2043
+ expect(rendered.querySelector('.ReactVirtualized__Grid__innerScrollContainer').style.width).toEqual('auto');
2044
+ });
2045
+ it('should set the innerScrollContainer width to :totalColumnsWidth unless :autoContainerWidth', function () {
2046
+ var props = {
2047
+ autoContainerWidth: false
2048
+ };
2049
+ var rendered = findDOMNode(render(getMarkup(props)));
2050
+ expect(rendered.querySelector('.ReactVirtualized__Grid__innerScrollContainer').style.width).toEqual('2500px'); // 50 columns x 50px
2051
+ });
2052
+ });
2053
+ describe('autoHeight', function () {
2054
+ it('should set the container height to auto to adjust to innerScrollContainer height', function () {
2055
+ var props = {
2056
+ autoHeight: true
2057
+ };
2058
+ var rendered = findDOMNode(render(getMarkup(props)));
2059
+ expect(rendered.style.height).toEqual('auto');
2060
+ });
2061
+ it('should have container height still affecting number of rows rendered', function () {
2062
+ var props = {
2063
+ height: 500,
2064
+ autoHeight: true
2065
+ };
2066
+ var rendered = findDOMNode(render(getMarkup(props)));
2067
+ expect(rendered.querySelectorAll('.gridItem').length).toEqual(100); // 25 rows x 4 columns
2068
+ });
2069
+ it('should have innerScrollContainer height to be equal number of rows * rowHeight', function () {
2070
+ var props = {
2071
+ autoHeight: true
2072
+ };
2073
+ var grid = render(getMarkup(props));
2074
+ var rendered = findDOMNode(grid);
2075
+ expect(rendered.querySelector('.ReactVirtualized__Grid__innerScrollContainer').style.height).toEqual('2000px'); // 100 rows * 20px rowHeight
2076
+ expect(grid.state.instanceProps.rowSizeAndPositionManager.getTotalSize()).toEqual(2000);
2077
+ });
2078
+ });
2079
+ describe('autoWidth', function () {
2080
+ it('should set the container width to auto to adjust to innerScrollContainer width', function () {
2081
+ var props = {
2082
+ autoWidth: true
2083
+ };
2084
+ var rendered = findDOMNode(render(getMarkup(props)));
2085
+ expect(rendered.style.width).toEqual('auto');
2086
+ });
2087
+ it('should have container width still affecting number of columns rendered', function () {
2088
+ var props = {
2089
+ width: 500,
2090
+ autoWidth: true
2091
+ };
2092
+ var rendered = findDOMNode(render(getMarkup(props)));
2093
+ expect(rendered.querySelectorAll('.gridItem').length).toEqual(50); // 5 rows x 10 columns
2094
+ });
2095
+ it('should have innerScrollContainer width to be equal number of columns * columnWidth', function () {
2096
+ var props = {
2097
+ autoWidth: true
2098
+ };
2099
+ var grid = render(getMarkup(props));
2100
+ var rendered = findDOMNode(grid);
2101
+ expect(rendered.querySelector('.ReactVirtualized__Grid__innerScrollContainer').style.width).toEqual('2500px'); // 50 columns * 50px columnWidth
2102
+ expect(grid.state.instanceProps.columnSizeAndPositionManager.getTotalSize()).toEqual(2500);
2103
+ });
2104
+ });
2105
+ describe('tabIndex', function () {
2106
+ it('should be focusable by default', function () {
2107
+ var rendered = findDOMNode(render(getMarkup()));
2108
+ expect(rendered.tabIndex).toEqual(0);
2109
+ });
2110
+ it('should allow tabIndex to be overridden', function () {
2111
+ var rendered = findDOMNode(render(getMarkup({
2112
+ tabIndex: -1
2113
+ })));
2114
+ expect(rendered.tabIndex).toEqual(-1);
2115
+ });
2116
+ });
2117
+ describe('role', function () {
2118
+ it('should have grid role by default', function () {
2119
+ var rendered = findDOMNode(render(getMarkup()));
2120
+ expect(rendered.getAttribute('role')).toEqual('grid');
2121
+ });
2122
+ it('should allow role to be overridden', function () {
2123
+ var role = null;
2124
+ var rendered = findDOMNode(render(getMarkup({
2125
+ role: role
2126
+ })));
2127
+ expect(rendered.getAttribute('role')).toEqual(role);
2128
+ });
2129
+ });
2130
+ describe('pure', function () {
2131
+ it('should not re-render unless props have changed', function () {
2132
+ var cellRendererCalled = false;
2133
+ function cellRenderer(_ref22) {
2134
+ var key = _ref22.key,
2135
+ style = _ref22.style;
2136
+ cellRendererCalled = true;
2137
+ return /*#__PURE__*/React.createElement("div", {
2138
+ key: key,
2139
+ style: style
2140
+ });
2141
+ }
2142
+ var markup = getMarkup({
2143
+ cellRenderer: cellRenderer
2144
+ });
2145
+ render(markup);
2146
+ expect(cellRendererCalled).toEqual(true);
2147
+ cellRendererCalled = false;
2148
+ render(markup);
2149
+ expect(cellRendererCalled).toEqual(false);
2150
+ });
2151
+ it('should not re-render grid components if they extend PureComponent', function () {
2152
+ var componentUpdates = 0;
2153
+ var GridComponent = /*#__PURE__*/function (_React$PureComponent) {
2154
+ function GridComponent() {
2155
+ _classCallCheck(this, GridComponent);
2156
+ return _callSuper(this, GridComponent, arguments);
2157
+ }
2158
+ _inherits(GridComponent, _React$PureComponent);
2159
+ return _createClass(GridComponent, [{
2160
+ key: "componentDidUpdate",
2161
+ value: function componentDidUpdate() {
2162
+ componentUpdates++;
2163
+ }
2164
+ }, {
2165
+ key: "render",
2166
+ value: function render() {
2167
+ var _this$props = this.props,
2168
+ columnIndex = _this$props.columnIndex,
2169
+ rowIndex = _this$props.rowIndex,
2170
+ style = _this$props.style;
2171
+ return /*#__PURE__*/React.createElement("div", {
2172
+ className: "gridItem",
2173
+ style: style
2174
+ }, "row:".concat(rowIndex, ", column:").concat(columnIndex));
2175
+ }
2176
+ }]);
2177
+ }(React.PureComponent);
2178
+ function cellRenderer(_ref23) {
2179
+ var columnIndex = _ref23.columnIndex,
2180
+ key = _ref23.key,
2181
+ rowIndex = _ref23.rowIndex,
2182
+ style = _ref23.style;
2183
+ return /*#__PURE__*/React.createElement(GridComponent, {
2184
+ key: key,
2185
+ columnIndex: columnIndex,
2186
+ rowIndex: rowIndex,
2187
+ style: style
2188
+ });
2189
+ }
2190
+ var props = {
2191
+ cellRenderer: cellRenderer,
2192
+ columnWidth: 100,
2193
+ height: 40,
2194
+ rowHeight: 20,
2195
+ scrollTop: 0,
2196
+ width: 100
2197
+ };
2198
+ var grid = render(getMarkup(props));
2199
+ simulateScroll({
2200
+ grid: grid,
2201
+ scrollToIndex: 1
2202
+ });
2203
+ expect(componentUpdates).toEqual(0);
2204
+ });
2205
+ it('should clear all but the visible rows from the style cache once :isScrolling is false', /*#__PURE__*/function () {
2206
+ var _ref24 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee7(done) {
2207
+ var props, grid;
2208
+ return _regeneratorRuntime.wrap(function _callee7$(_context7) {
2209
+ while (1) switch (_context7.prev = _context7.next) {
2210
+ case 0:
2211
+ props = {
2212
+ columnWidth: 50,
2213
+ height: 100,
2214
+ overscanColumnCount: 0,
2215
+ overscanRowCount: 0,
2216
+ rowHeight: 50,
2217
+ width: 100
2218
+ };
2219
+ grid = render(getMarkup(props));
2220
+ expect(Object.keys(grid._styleCache).length).toBe(4);
2221
+ simulateScroll({
2222
+ grid: grid,
2223
+ scrollTop: 50
2224
+ });
2225
+ expect(Object.keys(grid._styleCache).length).toBe(6);
2226
+
2227
+ // Allow scrolling timeout to complete so that cell cache is reset
2228
+ _context7.next = 7;
2229
+ return new Promise(function (resolve) {
2230
+ return setTimeout(resolve, DEFAULT_SCROLLING_RESET_TIME_INTERVAL * 2);
2231
+ });
2232
+ case 7:
2233
+ expect(Object.keys(grid._styleCache).length).toBe(4);
2234
+ done();
2235
+ case 9:
2236
+ case "end":
2237
+ return _context7.stop();
2238
+ }
2239
+ }, _callee7);
2240
+ }));
2241
+ return function (_x5) {
2242
+ return _ref24.apply(this, arguments);
2243
+ };
2244
+ }());
2245
+ it('should clear style cache if :recomputeGridSize is called', function () {
2246
+ var props = {
2247
+ columnWidth: 50,
2248
+ height: 100,
2249
+ overscanColumnCount: 0,
2250
+ overscanRowCount: 0,
2251
+ rowHeight: 50,
2252
+ width: 100
2253
+ };
2254
+ var grid = render(getMarkup(props));
2255
+ expect(Object.keys(grid._styleCache).length).toBe(4);
2256
+ render(getMarkup(_objectSpread(_objectSpread({}, props), {}, {
2257
+ scrollTop: 50
2258
+ })));
2259
+ expect(Object.keys(grid._styleCache).length).toBe(6);
2260
+ grid.recomputeGridSize();
2261
+ expect(Object.keys(grid._styleCache).length).toBe(4);
2262
+ });
2263
+ it('should clear style cache if cell sizes change', function () {
2264
+ var cellRendererCalls = [];
2265
+ function cellRenderer(params) {
2266
+ cellRendererCalls.push(params);
2267
+ return /*#__PURE__*/React.createElement("div", {
2268
+ key: params.key,
2269
+ style: params.style
2270
+ });
2271
+ }
2272
+ var props = {
2273
+ cellRenderer: cellRenderer,
2274
+ columnWidth: 100,
2275
+ height: 100,
2276
+ overscanColumnCount: 0,
2277
+ overscanRowCount: 0,
2278
+ rowHeight: 100,
2279
+ width: 100
2280
+ };
2281
+ render(getMarkup(props));
2282
+ expect(cellRendererCalls.length).toEqual(1);
2283
+ expect(cellRendererCalls[0].style.width).toEqual(100);
2284
+ render(getMarkup(_objectSpread(_objectSpread({}, props), {}, {
2285
+ columnWidth: 50,
2286
+ width: 50
2287
+ })));
2288
+ expect(cellRendererCalls.length).toEqual(2);
2289
+ expect(cellRendererCalls[1].style.width).toEqual(50);
2290
+ });
2291
+ });
2292
+ it('should not pull from the style cache while scrolling if there is an offset adjustment', function () {
2293
+ var cellRendererCalls = [];
2294
+ function cellRenderer(params) {
2295
+ cellRendererCalls.push(params);
2296
+ return /*#__PURE__*/React.createElement("div", {
2297
+ key: params.key,
2298
+ style: params.style
2299
+ });
2300
+ }
2301
+ var grid = render(getMarkup({
2302
+ cellRenderer: cellRenderer,
2303
+ width: 100,
2304
+ height: 100,
2305
+ rowHeight: 100,
2306
+ columnWidth: 100,
2307
+ rowCount: getMaxElementSize() * 2 / 100,
2308
+ // lots of offset
2309
+ scrollTop: 2000
2310
+ }));
2311
+ simulateScroll({
2312
+ grid: grid,
2313
+ scrollTop: 2100
2314
+ });
2315
+
2316
+ // cellRendererCalls[0] is the element at rowIndex 0
2317
+ // only two calls. Since the scrollTop is updated in getDerivedStateFromProps
2318
+ var firstProps = cellRendererCalls[0];
2319
+ var secondProps = cellRendererCalls[1];
2320
+ expect(cellRendererCalls.length).toEqual(2);
2321
+ expect(firstProps.style).not.toBe(secondProps.style);
2322
+ });
2323
+ it('should only cache styles when a :deferredMeasurementCache is provided if the cell has already been measured', function () {
2324
+ var cache = new CellMeasurerCache({
2325
+ fixedWidth: true
2326
+ });
2327
+ cache.set(0, 0, 100, 100);
2328
+ cache.set(1, 1, 100, 100);
2329
+ var grid = render(getMarkup({
2330
+ columnCount: 2,
2331
+ deferredMeasurementCache: cache,
2332
+ rowCount: 2
2333
+ }));
2334
+ var keys = Object.keys(grid._styleCache);
2335
+ expect(keys).toEqual(['0-0', '1-1']);
2336
+ });
2337
+ describe('DEV warnings', function () {
2338
+ it('should warn about cells that forget to include the :style property', function () {
2339
+ spyOn(console, 'warn');
2340
+ function cellRenderer(params) {
2341
+ return /*#__PURE__*/React.createElement("div", {
2342
+ key: params.key
2343
+ });
2344
+ }
2345
+ render(getMarkup({
2346
+ cellRenderer: cellRenderer
2347
+ }));
2348
+ expect(console.warn).toHaveBeenCalledWith('Rendered cell should include style property for positioning.');
2349
+ expect(console.warn).toHaveBeenCalledTimes(1);
2350
+ });
2351
+ it('should warn about CellMeasurer measured cells that forget to include the :style property', function () {
2352
+ spyOn(console, 'warn');
2353
+ var cache = new CellMeasurerCache({
2354
+ fixedWidth: true
2355
+ });
2356
+ var cellRenderer = jest.fn();
2357
+ cellRenderer.mockImplementation(function (params) {
2358
+ return /*#__PURE__*/React.createElement(CellMeasurer, {
2359
+ cache: cache,
2360
+ columnIndex: params.columnIndex,
2361
+ key: params.key,
2362
+ parent: params.parent,
2363
+ rowIndex: params.rowIndex,
2364
+ style: params.style
2365
+ }, /*#__PURE__*/React.createElement("div", null));
2366
+ });
2367
+ render(getMarkup({
2368
+ cellRenderer: cellRenderer,
2369
+ columnCount: 1,
2370
+ deferredMeasurementCache: cache,
2371
+ rowCount: 1
2372
+ }));
2373
+ expect(console.warn).toHaveBeenCalledWith('Rendered cell should include style property for positioning.');
2374
+ expect(console.warn).toHaveBeenCalledTimes(1);
2375
+ });
2376
+ });
2377
+ describe('deferredMeasurementCache', function () {
2378
+ it('invalidateCellSizeAfterRender should invalidate cache and refresh displayed cells after mount', function () {
2379
+ var cache = new CellMeasurerCache({
2380
+ fixedWidth: true
2381
+ });
2382
+ var invalidateCellSizeAfterRender = true;
2383
+ var cellRenderer = jest.fn();
2384
+ cellRenderer.mockImplementation(function (params) {
2385
+ // Don't get stuck in a loop
2386
+ if (invalidateCellSizeAfterRender) {
2387
+ invalidateCellSizeAfterRender = false;
2388
+ params.parent.invalidateCellSizeAfterRender({
2389
+ columnIndex: 1,
2390
+ rowIndex: 0
2391
+ });
2392
+ }
2393
+ return /*#__PURE__*/React.createElement("div", {
2394
+ key: params.key,
2395
+ style: params.style
2396
+ });
2397
+ });
2398
+ var props = {
2399
+ cellRenderer: cellRenderer,
2400
+ columnCount: 2,
2401
+ deferredMeasurementCache: cache,
2402
+ rowCount: 2
2403
+ };
2404
+ render(getMarkup(props));
2405
+
2406
+ // 4 times for initial render + 4 once cellCache was cleared
2407
+ expect(cellRenderer).toHaveBeenCalledTimes(8);
2408
+ });
2409
+ it('should invalidate cache and refresh displayed cells after update', function () {
2410
+ var cache = new CellMeasurerCache({
2411
+ fixedWidth: true
2412
+ });
2413
+ var cellRenderer = jest.fn();
2414
+ cellRenderer.mockImplementation(function (params) {
2415
+ return /*#__PURE__*/React.createElement("div", {
2416
+ key: params.key,
2417
+ style: params.style
2418
+ });
2419
+ });
2420
+ var props = {
2421
+ cellRenderer: cellRenderer,
2422
+ columnCount: 2,
2423
+ deferredMeasurementCache: cache,
2424
+ rowCount: 2
2425
+ };
2426
+ var grid = render(getMarkup(props));
2427
+ expect(cellRenderer).toHaveBeenCalledTimes(4);
2428
+ var invalidateCellSizeAfterRender = false;
2429
+ cellRenderer.mockReset();
2430
+ cellRenderer.mockImplementation(function (params) {
2431
+ // Don't get stuck in a loop
2432
+ if (invalidateCellSizeAfterRender) {
2433
+ invalidateCellSizeAfterRender = false;
2434
+ params.parent.invalidateCellSizeAfterRender({
2435
+ columnIndex: 1,
2436
+ rowIndex: 0
2437
+ });
2438
+ }
2439
+ return /*#__PURE__*/React.createElement("div", {
2440
+ key: params.key,
2441
+ style: params.style
2442
+ });
2443
+ });
2444
+ invalidateCellSizeAfterRender = true;
2445
+ grid.recomputeGridSize();
2446
+
2447
+ // 4 times for initial render + 4 once cellCache was cleared
2448
+ expect(cellRenderer).toHaveBeenCalledTimes(8);
2449
+ });
2450
+ it('should not cache cells until they have been measured by CellMeasurer', function () {
2451
+ var cache = new CellMeasurerCache({
2452
+ fixedWidth: true
2453
+ });
2454
+
2455
+ // Fake measure cell 0,0 but not cell 0,1
2456
+ cache.set(0, 0, 100, 30);
2457
+ var cellRenderer = jest.fn();
2458
+ cellRenderer.mockImplementation(function (params) {
2459
+ return /*#__PURE__*/React.createElement("div", {
2460
+ key: params.key,
2461
+ style: params.style
2462
+ });
2463
+ });
2464
+ var props = {
2465
+ cellRenderer: cellRenderer,
2466
+ columnCount: 2,
2467
+ deferredMeasurementCache: cache,
2468
+ rowCount: 1
2469
+ };
2470
+
2471
+ // Trigger 2 renders
2472
+ // The second render should re-use the style for cell 0,0
2473
+ // But should not re-use the style for cell 0,1 since it was not measured
2474
+ var grid = render(getMarkup(props));
2475
+ grid.forceUpdate();
2476
+
2477
+ // 0,0 - 0,1 - 0,0 - 0,1
2478
+ expect(cellRenderer).toHaveBeenCalledTimes(4);
2479
+ var style00A = cellRenderer.mock.calls[0][0].style;
2480
+ var style01A = cellRenderer.mock.calls[1][0].style;
2481
+ var style00B = cellRenderer.mock.calls[2][0].style;
2482
+ var style01B = cellRenderer.mock.calls[3][0].style;
2483
+ expect(style00A).toBe(style00B);
2484
+ expect(style01A).not.toBe(style01B);
2485
+ });
2486
+ });
2487
+ describe('onScrollbarPresenceChange', function () {
2488
+ it('should not trigger on-mount if scrollbars are hidden', function () {
2489
+ var onScrollbarPresenceChange = jest.fn();
2490
+ render(getMarkup({
2491
+ columnCount: 1,
2492
+ getScrollbarSize: getScrollbarSize20,
2493
+ onScrollbarPresenceChange: onScrollbarPresenceChange,
2494
+ rowCount: 1
2495
+ }));
2496
+ expect(onScrollbarPresenceChange).not.toHaveBeenCalled();
2497
+ });
2498
+ it('should trigger on-mount if scrollbars are visible', function () {
2499
+ var onScrollbarPresenceChange = jest.fn();
2500
+ render(getMarkup({
2501
+ columnCount: 100,
2502
+ getScrollbarSize: getScrollbarSize20,
2503
+ onScrollbarPresenceChange: onScrollbarPresenceChange,
2504
+ rowCount: 100
2505
+ }));
2506
+ expect(onScrollbarPresenceChange).toHaveBeenCalled();
2507
+ var args = onScrollbarPresenceChange.mock.calls[0][0];
2508
+ expect(args.horizontal).toBe(true);
2509
+ expect(args.size).toBe(getScrollbarSize20());
2510
+ expect(args.vertical).toBe(true);
2511
+ });
2512
+ it('should trigger on-update if scrollbar visibility has changed', function () {
2513
+ var onScrollbarPresenceChange = jest.fn();
2514
+ render(getMarkup({
2515
+ columnCount: 1,
2516
+ getScrollbarSize: getScrollbarSize20,
2517
+ onScrollbarPresenceChange: onScrollbarPresenceChange,
2518
+ rowCount: 1
2519
+ }));
2520
+ expect(onScrollbarPresenceChange).not.toHaveBeenCalled();
2521
+ render(getMarkup({
2522
+ columnCount: 100,
2523
+ getScrollbarSize: getScrollbarSize20,
2524
+ onScrollbarPresenceChange: onScrollbarPresenceChange,
2525
+ rowCount: 100
2526
+ }));
2527
+ expect(onScrollbarPresenceChange).toHaveBeenCalled();
2528
+ var args = onScrollbarPresenceChange.mock.calls[0][0];
2529
+ expect(args.horizontal).toBe(true);
2530
+ expect(args.size).toBe(getScrollbarSize20());
2531
+ expect(args.vertical).toBe(true);
2532
+ });
2533
+ it('should not trigger on-update if scrollbar visibility does not change', function () {
2534
+ var onScrollbarPresenceChange = jest.fn();
2535
+ render(getMarkup({
2536
+ columnCount: 1,
2537
+ getScrollbarSize: getScrollbarSize20,
2538
+ onScrollbarPresenceChange: onScrollbarPresenceChange,
2539
+ rowCount: 1
2540
+ }));
2541
+ expect(onScrollbarPresenceChange).not.toHaveBeenCalled();
2542
+ render(getMarkup({
2543
+ columnCount: 2,
2544
+ getScrollbarSize: getScrollbarSize20,
2545
+ onScrollbarPresenceChange: onScrollbarPresenceChange,
2546
+ rowCount: 2
2547
+ }));
2548
+ expect(onScrollbarPresenceChange).not.toHaveBeenCalled();
2549
+ });
2550
+ });
2551
+ it('should not complain when using react-test-renderer', function () {
2552
+ var instance = TestRenderer.create(getMarkup()).getInstance();
2553
+ expect(instance).toBeTruthy();
2554
+ });
2555
+ });