diff --git a/vaadin-grid-flow-parent/vaadin-grid-flow-integration-tests/src/test/java/com/vaadin/flow/component/grid/dataview/AbstractItemCountGridIT.java b/vaadin-grid-flow-parent/vaadin-grid-flow-integration-tests/src/test/java/com/vaadin/flow/component/grid/dataview/AbstractItemCountGridIT.java index c8478e8616a..95178f13a6f 100644 --- a/vaadin-grid-flow-parent/vaadin-grid-flow-integration-tests/src/test/java/com/vaadin/flow/component/grid/dataview/AbstractItemCountGridIT.java +++ b/vaadin-grid-flow-parent/vaadin-grid-flow-integration-tests/src/test/java/com/vaadin/flow/component/grid/dataview/AbstractItemCountGridIT.java @@ -56,10 +56,8 @@ protected void open(int size) { protected void doScroll(int rowToScroll, int expectedRows, int fetchIndex, int start, int end) { grid.scrollToRow(rowToScroll); - // FIXME when grid reduces size, it does currently some extra fetches - // -> not checking the requested items until this is fixed - // verifyFetchForUndefinedSizeCallback(fetchIndex, - // Range.between(start, end)); + // A single scroll may fetch several pages, so only the resulting row + // count is asserted here. fetchIndex/start/end document the range. verifyRows(expectedRows); } @@ -100,6 +98,20 @@ protected void verifyRows(int size) { grid.getRowCount()); } + protected int getFetchQueryCount() { + return findElements(By.cssSelector("[id^='log-']")).size(); + } + + /** + * Returns the start offset of the fetch query logged at the given index. + * Log entries are formatted as {@code ":Range [..]"}. + */ + protected int getFetchedOffset(int index) { + String text = findElement(By.id("log-" + index)).getText(); + return Integer.parseInt( + text.substring(text.indexOf('[') + 1, text.indexOf(".."))); + } + protected void verifyFetchForUndefinedSizeCallback(int index, Range range) { WebElement log = findElement(By.id("log-" + index)); Assert.assertEquals("Invalid range for index " + index, diff --git a/vaadin-grid-flow-parent/vaadin-grid-flow-integration-tests/src/test/java/com/vaadin/flow/component/grid/dataview/ItemCountUnknownGridIT.java b/vaadin-grid-flow-parent/vaadin-grid-flow-integration-tests/src/test/java/com/vaadin/flow/component/grid/dataview/ItemCountUnknownGridIT.java index 21b0e1c5938..31ca71eb7e0 100644 --- a/vaadin-grid-flow-parent/vaadin-grid-flow-integration-tests/src/test/java/com/vaadin/flow/component/grid/dataview/ItemCountUnknownGridIT.java +++ b/vaadin-grid-flow-parent/vaadin-grid-flow-integration-tests/src/test/java/com/vaadin/flow/component/grid/dataview/ItemCountUnknownGridIT.java @@ -48,10 +48,20 @@ public void undefinedSizeGrid_defaultPageSizeEvenToDatasetSize_scrollingToEnd() // scroll to actual end, no more items returned and size is adjusted doScroll(500, 500, 5, 450, 500); Assert.assertEquals(499, grid.getLastVisibleRowIndex()); - // TODO #1038 test further after grid is note fetching extra stuff when - // size has been adjusted to less than what it is - // doScroll(0, 500, 6, 0, 100); - // doScroll(450, 500, 7, 400, 500); + + // After the size is adjusted down, scrolling back and forth keeps the + // size and only fetches the visited viewports (near the top and near + // row 450) - never the ranges in between. + int fetchesBefore = getFetchQueryCount(); + doScroll(0, 500, 6, 0, 100); + doScroll(450, 500, 7, 400, 500); + for (int i = fetchesBefore; i < getFetchQueryCount(); i++) { + int offset = getFetchedOffset(i); + Assert.assertTrue( + "Refetched an off-viewport range at offset " + offset + + " after the size was adjusted", + offset < 150 || offset >= 350); + } } @Test