Skip to content

Commit b766798

Browse files
web-padawanclaude
andauthored
test: re-enable undefined-size grid scroll regression checks (#9760)
## Description Re-enable the disabled steps in the ItemCountUnknownGridIT scroll-to-end test and drop the stale FIXME. The grid no longer fetches extra earlier ranges after the item count shrinks from an estimate to the real size, so assert that scrolling around after the size is adjusted keeps the size and does not trigger unnecessary fetches. Related to vaadin/flow#9166 ## Type of change - Test --------- Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent f6a149b commit b766798

2 files changed

Lines changed: 30 additions & 8 deletions

File tree

vaadin-grid-flow-parent/vaadin-grid-flow-integration-tests/src/test/java/com/vaadin/flow/component/grid/dataview/AbstractItemCountGridIT.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,8 @@ protected void open(int size) {
5656
protected void doScroll(int rowToScroll, int expectedRows, int fetchIndex,
5757
int start, int end) {
5858
grid.scrollToRow(rowToScroll);
59-
// FIXME when grid reduces size, it does currently some extra fetches
60-
// -> not checking the requested items until this is fixed
61-
// verifyFetchForUndefinedSizeCallback(fetchIndex,
62-
// Range.between(start, end));
59+
// A single scroll may fetch several pages, so only the resulting row
60+
// count is asserted here. fetchIndex/start/end document the range.
6361
verifyRows(expectedRows);
6462
}
6563

@@ -100,6 +98,20 @@ protected void verifyRows(int size) {
10098
grid.getRowCount());
10199
}
102100

101+
protected int getFetchQueryCount() {
102+
return findElements(By.cssSelector("[id^='log-']")).size();
103+
}
104+
105+
/**
106+
* Returns the start offset of the fetch query logged at the given index.
107+
* Log entries are formatted as {@code "<index>:Range [<start>..<end>]"}.
108+
*/
109+
protected int getFetchedOffset(int index) {
110+
String text = findElement(By.id("log-" + index)).getText();
111+
return Integer.parseInt(
112+
text.substring(text.indexOf('[') + 1, text.indexOf("..")));
113+
}
114+
103115
protected void verifyFetchForUndefinedSizeCallback(int index, Range range) {
104116
WebElement log = findElement(By.id("log-" + index));
105117
Assert.assertEquals("Invalid range for index " + index,

vaadin-grid-flow-parent/vaadin-grid-flow-integration-tests/src/test/java/com/vaadin/flow/component/grid/dataview/ItemCountUnknownGridIT.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,20 @@ public void undefinedSizeGrid_defaultPageSizeEvenToDatasetSize_scrollingToEnd()
4848
// scroll to actual end, no more items returned and size is adjusted
4949
doScroll(500, 500, 5, 450, 500);
5050
Assert.assertEquals(499, grid.getLastVisibleRowIndex());
51-
// TODO #1038 test further after grid is note fetching extra stuff when
52-
// size has been adjusted to less than what it is
53-
// doScroll(0, 500, 6, 0, 100);
54-
// doScroll(450, 500, 7, 400, 500);
51+
52+
// After the size is adjusted down, scrolling back and forth keeps the
53+
// size and only fetches the visited viewports (near the top and near
54+
// row 450) - never the ranges in between.
55+
int fetchesBefore = getFetchQueryCount();
56+
doScroll(0, 500, 6, 0, 100);
57+
doScroll(450, 500, 7, 400, 500);
58+
for (int i = fetchesBefore; i < getFetchQueryCount(); i++) {
59+
int offset = getFetchedOffset(i);
60+
Assert.assertTrue(
61+
"Refetched an off-viewport range at offset " + offset
62+
+ " after the size was adjusted",
63+
offset < 150 || offset >= 350);
64+
}
5565
}
5666

5767
@Test

0 commit comments

Comments
 (0)