diff --git a/vaadin-grid-flow-parent/vaadin-grid-flow-integration-tests/src/test/java/com/vaadin/flow/component/grid/it/ComponentColumnWithHeightIT.java b/vaadin-grid-flow-parent/vaadin-grid-flow-integration-tests/src/test/java/com/vaadin/flow/component/grid/it/ComponentColumnWithHeightIT.java index ccae958aa5c..e5440fb6e9e 100644 --- a/vaadin-grid-flow-parent/vaadin-grid-flow-integration-tests/src/test/java/com/vaadin/flow/component/grid/it/ComponentColumnWithHeightIT.java +++ b/vaadin-grid-flow-parent/vaadin-grid-flow-integration-tests/src/test/java/com/vaadin/flow/component/grid/it/ComponentColumnWithHeightIT.java @@ -54,15 +54,14 @@ public void shouldPositionItemsCorrectlyAfterUpdatingComponentRenderers() { @Test public void shouldPositionItemsCorrectlyAfterScrollingToEnd() { - int initialLastRow = grid.getRowCount() - 1; - grid.scrollToRow(initialLastRow); + var initialLastRow = grid.getRowCount() - 1; + var row = grid.getRow(initialLastRow, true); + var expectedPosition = row.getLocation().y + row.getSize().height; add.click(); // Expect the y position of the last row to equal the y position + the // height of the previous row - Assert.assertEquals( - grid.getRow(initialLastRow).getLocation().y - + grid.getRow(initialLastRow).getSize().height, + Assert.assertEquals(expectedPosition, grid.getRow(initialLastRow + 1).getLocation().y); } } diff --git a/vaadin-grid-flow-parent/vaadin-grid-testbench/src/main/java/com/vaadin/flow/component/grid/testbench/GridElement.java b/vaadin-grid-flow-parent/vaadin-grid-testbench/src/main/java/com/vaadin/flow/component/grid/testbench/GridElement.java index 438ac6c1297..6f29d8ee58e 100644 --- a/vaadin-grid-flow-parent/vaadin-grid-testbench/src/main/java/com/vaadin/flow/component/grid/testbench/GridElement.java +++ b/vaadin-grid-flow-parent/vaadin-grid-testbench/src/main/java/com/vaadin/flow/component/grid/testbench/GridElement.java @@ -234,15 +234,40 @@ public List getRows(int firstRowIndex, int lastRowIndex) } /** - * Gets the tr element for the given row index. + * Gets the {@code tr} element for the given row index. * * @param rowIndex * the row index - * @return the tr element for the row + * @return the {@code tr} element for the row, or {@code null} if the row is + * not in viewport * @throws IndexOutOfBoundsException * if no row with given index exists */ public GridTRElement getRow(int rowIndex) throws IndexOutOfBoundsException { + return getRow(rowIndex, false); + } + + /** + * Gets the {@code tr} element for the given row index. + *

+ * Returns {@code null} if the row is not in viewport and the provided + * {@code scroll} parameter is {@code false}. + * + * @param rowIndex + * the row index + * @param scroll + * whether to scroll to the row index + * @return the {@code tr} element for the row, or {@code null} if the row is + * not in viewport and the provided {@code scroll} parameter is + * {@code false} + * @throws IndexOutOfBoundsException + * if no row with given index exists + */ + public GridTRElement getRow(int rowIndex, boolean scroll) + throws IndexOutOfBoundsException { + if (scroll && !isRowInView(rowIndex)) { + scrollToFlatRow(rowIndex); + } var rows = getRows(rowIndex, rowIndex); return rows.size() == 1 ? rows.get(0) : null; }