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