Skip to content

Commit

Permalink
Added test for style caching when in deferred measurement mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Vaughn committed Feb 15, 2017
1 parent 30b2112 commit 38cb0a4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
17 changes: 17 additions & 0 deletions source/Grid/Grid.jest.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { findDOMNode } from 'react-dom'
import { Simulate } from 'react-addons-test-utils'
import { render } from '../TestUtils'
import Grid, { DEFAULT_SCROLLING_RESET_TIME_INTERVAL } from './Grid'
import CellMeasurerCache from '../CellMeasurer/CellMeasurerCache'
import { SCROLL_DIRECTION_BACKWARD, SCROLL_DIRECTION_FORWARD } from './utils/getOverscanIndices'
import { DEFAULT_MAX_SCROLL_SIZE } from './utils/ScalingCellSizeAndPositionManager'

Expand Down Expand Up @@ -1551,6 +1552,22 @@ describe('Grid', () => {
expect(firstProps.style).not.toBe(secondProps.style)
})

it('should only cache styles when a :deferredMeasurementCache is provided if the cell has already been measured', () => {
const cache = new CellMeasurerCache()
cache.set(0, 0, 100, 100)
cache.set(1, 1, 100, 100)

const grid = render(getMarkup({
columnCount: 2,
deferredMeasurementCache: cache,
rowCount: 2
}))

const keys = Object.keys(grid._styleCache)

expect(keys).toEqual(['0-0', '1-1'])
})

it('should warn about cells that forget to include the :style property', () => {
spyOn(console, 'warn')

Expand Down
1 change: 0 additions & 1 deletion source/Grid/defaultCellRangeRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ export default function defaultCellRangeRenderer ({
} else {
// In deferred mode, cells will be initially rendered before we know their size.
// Don't interfere with CellMeasurer's measurements by setting an invalid size.
// @TODO (bvaughn) Add automated test coverage for this.
if (
deferredMode &&
!deferredMeasurementCache.has(rowIndex, columnIndex)
Expand Down

0 comments on commit 38cb0a4

Please sign in to comment.