Skip to content

Commit

Permalink
✅ (VirtualizedList) add broken test case based on issue example
Browse files Browse the repository at this point in the history
This test case is based on this issue: #33529
  • Loading branch information
Antoine Doubovetzky committed Apr 20, 2022
1 parent a129595 commit 2265f04
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 0 deletions.
49 changes: 49 additions & 0 deletions Libraries/Lists/__tests__/VirtualizedList-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -928,6 +928,55 @@ it('adjusts render area with non-zero initialScrollIndex after scrolled', () =>
expect(component).toMatchSnapshot();
});

it('renders new items when data is updated with non-zero initialScrollIndex', () => {
const items = generateItems(2);
const ITEM_HEIGHT = 10;

let component;
ReactTestRenderer.act(() => {
component = ReactTestRenderer.create(
<VirtualizedList
initialNumToRender={5}
initialScrollIndex={1}
windowSize={10}
maxToRenderPerBatch={10}
{...baseItemProps(items)}
{...fixedHeightItemLayoutProps(ITEM_HEIGHT)}
/>,
);
});

ReactTestRenderer.act(() => {
simulateLayout(component, {
viewport: {width: 10, height: 50},
content: {width: 10, height: 200},
});
performAllBatches();
});

const newItems = generateItems(4);

ReactTestRenderer.act(() => {
component.update(
<VirtualizedList
initialNumToRender={5}
initialScrollIndex={1}
windowSize={10}
maxToRenderPerBatch={10}
{...baseItemProps(newItems)}
{...fixedHeightItemLayoutProps(ITEM_HEIGHT)}
/>,
);
});

ReactTestRenderer.act(() => {
performAllBatches();
});

// We expect all the items to be rendered
expect(component).toMatchSnapshot();
});

it('renders initialNumToRender cells when virtualization disabled', () => {
const items = generateItems(10);
const ITEM_HEIGHT = 10;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3250,6 +3250,68 @@ exports[`renders items before initialScrollIndex on first batch tick when virtua
</RCTScrollView>
`;

exports[`renders new items when data is updated with non-zero initialScrollIndex 1`] = `
<RCTScrollView
data={
Array [
Object {
"key": 0,
},
Object {
"key": 1,
},
Object {
"key": 2,
},
Object {
"key": 3,
},
]
}
getItem={[Function]}
getItemCount={[Function]}
getItemLayout={[Function]}
initialNumToRender={5}
initialScrollIndex={1}
maxToRenderPerBatch={10}
onContentSizeChange={[Function]}
onLayout={[Function]}
onMomentumScrollBegin={[Function]}
onMomentumScrollEnd={[Function]}
onScroll={[Function]}
onScrollBeginDrag={[Function]}
onScrollEndDrag={[Function]}
renderItem={[Function]}
scrollEventThrottle={50}
stickyHeaderIndices={Array []}
windowSize={10}
>
<View>
<View
style={null}
>
<MockCellItem
value={0}
/>
</View>
<View
style={null}
>
<MockCellItem
value={1}
/>
</View>
<View
style={
Object {
"height": 20,
}
}
/>
</View>
</RCTScrollView>
`;

exports[`renders no spacers up to initialScrollIndex on first render when virtualization disabled 1`] = `
<RCTScrollView
data={
Expand Down

0 comments on commit 2265f04

Please sign in to comment.