-
Notifications
You must be signed in to change notification settings - Fork 290
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Scroll to an exact position when clicking the scrollbar track doesn't…
… work in case of variable row heights and isVerticalScrollExact = true (#712) Co-authored-by: Daniela Buzatu <[email protected]>
- Loading branch information
1 parent
9614676
commit 149f0ef
Showing
2 changed files
with
98 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { initializeRowHeightsAndOffsets } from '../../src/reducers'; | ||
import { assert } from 'chai'; | ||
import clone from 'lodash/clone'; | ||
|
||
describe('initializeRowHeightsAndOffsets', function () { | ||
let oldState; | ||
let newState; | ||
beforeEach(function () { | ||
const createInternalStateGetter = () => { | ||
const internalState = {}; | ||
return () => internalState; | ||
}; | ||
oldState = { | ||
getInternal: createInternalStateGetter(), | ||
rowSettings: { | ||
rowsCount: 80, | ||
rowHeight: 125, | ||
subRowHeight: 0, | ||
rowHeightGetter: (rowIndex) => (rowIndex % 2 == 0 ? 100 : 200), | ||
subRowHeightGetter: () => 0, | ||
}, | ||
}; | ||
newState = clone(oldState); | ||
newState.getInternal = createInternalStateGetter(); | ||
}); | ||
it('if isVerticalScrollExact = false then rowheight is used instead of rowHeightGetter() for all the rows', function () { | ||
initializeRowHeightsAndOffsets(newState); | ||
for (let rowIdx = 0; rowIdx < 80; rowIdx++) { | ||
assert.strictEqual( | ||
newState.getInternal().storedHeights[rowIdx], | ||
125, | ||
'expected stored height of 125 for each row' | ||
); | ||
assert.strictEqual( | ||
newState.getInternal().rowOffsetIntervalTree.get(rowIdx), | ||
125, | ||
'expected row offsets for each row to be set to 125' | ||
); | ||
} | ||
assert.strictEqual( | ||
newState.scrollContentHeight, | ||
10000, | ||
'expected scrollContentHeight to be 10000' | ||
); | ||
}); | ||
|
||
it('if isVerticalScrollExact = true then rowHeightGetter() is used for all the rows', function () { | ||
newState.isVerticalScrollExact = true; | ||
initializeRowHeightsAndOffsets(newState); | ||
for (let rowIdx = 0; rowIdx < 80; rowIdx++) { | ||
const expectedRowHeight = rowIdx % 2 == 0 ? 100 : 200; | ||
assert.strictEqual( | ||
newState.getInternal().storedHeights[rowIdx], | ||
expectedRowHeight, | ||
'expected stored height of ' + expectedRowHeight + ' for row ' + rowIdx | ||
); | ||
assert.strictEqual( | ||
newState.getInternal().rowOffsetIntervalTree.get(rowIdx), | ||
expectedRowHeight, | ||
'expected row offsets for row ' + | ||
rowIdx + | ||
' to be set to ' + | ||
expectedRowHeight | ||
); | ||
} | ||
assert.strictEqual( | ||
newState.scrollContentHeight, | ||
12000, | ||
'expected scrollContentHeight to be 12000' | ||
); | ||
}); | ||
}); |