Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 55 additions & 45 deletions packages/virtualized-lists/Lists/__tests__/VirtualizedList-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1836,56 +1836,49 @@ it('retains initial render region when an item is appended', async () => {
expect(component).toMatchSnapshot();
});

// TODO: Revisit this test case after upgrading to React 19.
skipTestSilenceLinter(
'retains batch render region when an item is appended',
async () => {
const items = generateItems(10);
const ITEM_HEIGHT = 10;
it('retains batch render region when an item is appended', async () => {
const items = generateItems(10);
const ITEM_HEIGHT = 10;

let component;
await act(() => {
component = create(
<VirtualizedList
initialNumToRender={1}
maxToRenderPerBatch={1}
{...baseItemProps(items)}
{...fixedHeightItemLayoutProps(ITEM_HEIGHT)}
/>,
);
});
let component;
await act(() => {
component = create(
<VirtualizedList
initialNumToRender={1}
maxToRenderPerBatch={1}
{...baseItemProps(items)}
{...fixedHeightItemLayoutProps(ITEM_HEIGHT)}
/>,
);
});

await act(() => {
simulateLayout(component, {
viewport: {width: 10, height: 50},
content: {width: 10, height: 100},
});
performAllBatches();
await act(() => {
simulateLayout(component, {
viewport: {width: 10, height: 50},
content: {width: 10, height: 100},
});
});

await act(async () => {
await jest.runAllTimersAsync();
});
await advanceUntilLastCellIndexRendered(component, items.length - 1);

await act(() => {
component.update(
<VirtualizedList
initialNumToRender={1}
maxToRenderPerBatch={1}
{...baseItemProps(items)}
{...fixedHeightItemLayoutProps(ITEM_HEIGHT)}
data={generateItems(11)}
/>,
);
});
await act(() => {
component.update(
<VirtualizedList
initialNumToRender={1}
maxToRenderPerBatch={1}
{...baseItemProps(items)}
{...fixedHeightItemLayoutProps(ITEM_HEIGHT)}
data={generateItems(11)}
/>,
);
});

// Adding an item to the list after batch render should keep the existing
// rendered items rendered. We batch render 10 items, then add an 11th. Expect
// the first ten items to be present, with a spacer for the 11th until the
// next batch render.
expect(component).toMatchSnapshot();
},
);
// Adding an item to the list after batch render should keep the existing
// rendered items rendered. We batch render 10 items, then add an 11th. Expect
// the first ten items to be present, with a spacer for the 11th until the
// next batch render.
expect(component).toMatchSnapshot();
});

it('constrains batch render region when an item is removed', async () => {
const items = generateItems(10);
Expand Down Expand Up @@ -2639,13 +2632,30 @@ async function advanceUntilRenderAreaChanged(component) {
}

await act(() => {
jest.advanceTimersToNextTimer(1);
performNextBatch();
});
}

throw new Error(`Render area did not change`);
}

async function advanceUntilLastCellIndexRendered(component, targetLastIndex) {
const instance = component.getInstance();
const MAX_TIMER_STEPS = 20;

for (let step = 0; step < MAX_TIMER_STEPS; step++) {
if (instance.state.cellsAroundViewport.last === targetLastIndex) {
return;
}

await act(() => {
performNextBatch();
});
}

throw new Error(`Target last index ${targetLastIndex} not rendered`);
}

function performAllBatches() {
jest.runAllTimers();
}
Expand Down
Loading