diff options
author | Henrik Paul <henrik@vaadin.com> | 2014-11-21 13:41:40 +0200 |
---|---|---|
committer | Teemu Suo-Anttila <teemusa@vaadin.com> | 2014-11-27 12:42:59 +0000 |
commit | fbfca1e9fc7a77e02c4262f0dfbe7ff408633499 (patch) | |
tree | b648f7c7c38586dfbfdf76a70bcece7a573531c0 /uitest/src | |
parent | 227bd83276810ffbae87b582c985b2702595cf42 (diff) | |
download | vaadin-framework-fbfca1e9fc7a77e02c4262f0dfbe7ff408633499.tar.gz vaadin-framework-fbfca1e9fc7a77e02c4262f0dfbe7ff408633499.zip |
Removing more than pageful in Escalator doesn't break anymore (#13334)
Change-Id: I4872766d9ed49d4a0765d28ed00e84cecf24dda4
Diffstat (limited to 'uitest/src')
3 files changed, 157 insertions, 1 deletions
diff --git a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/EscalatorBasicClientFeaturesTest.java b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/EscalatorBasicClientFeaturesTest.java index bc5815cd91..31a142d556 100644 --- a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/EscalatorBasicClientFeaturesTest.java +++ b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/EscalatorBasicClientFeaturesTest.java @@ -38,6 +38,8 @@ public abstract class EscalatorBasicClientFeaturesTest extends MultiBrowserTest protected static final String ADD_ONE_ROW_TO_BEGINNING = "Add one row to beginning"; protected static final String REMOVE_ONE_COLUMN_FROM_BEGINNING = "Remove one column from beginning"; protected static final String REMOVE_ONE_ROW_FROM_BEGINNING = "Remove one row from beginning"; + protected static final String REMOVE_50_ROWS_FROM_BOTTOM = "Remove 50 rows from bottom"; + protected static final String REMOVE_50_ROWS_FROM_ALMOST_BOTTOM = "Remove 50 rows from almost bottom"; protected static final String ADD_ONE_OF_EACH_ROW = "Add one of each row"; protected static final String RESIZE_FIRST_COLUMN_TO_MAX_WIDTH = "Resize first column to max width"; @@ -75,30 +77,72 @@ public abstract class EscalatorBasicClientFeaturesTest extends MultiBrowserTest } } + /** + * @param row + * the index of the row element in the section. If negative, the + * calculation starts from the end (-1 is the last, -2 is the + * second-to-last etc) + */ protected WebElement getHeaderRow(int row) { return getRow("thead", row); } + /** + * @param row + * the index of the row element in the section. If negative, the + * calculation starts from the end (-1 is the last, -2 is the + * second-to-last etc) + */ protected WebElement getBodyRow(int row) { return getRow("tbody", row); } + /** + * @param row + * the index of the row element in the section. If negative, the + * calculation starts from the end (-1 is the last, -2 is the + * second-to-last etc) + */ protected WebElement getFooterRow(int row) { return getRow("tfoot", row); } + /** + * @param row + * the index of the row element in the section. If negative, the + * calculation starts from the end (-1 is the last, -2 is the + * second-to-last etc) + */ protected WebElement getHeaderCell(int row, int col) { return getCell("thead", row, col); } + /** + * @param row + * the index of the row element in the section. If negative, the + * calculation starts from the end (-1 is the last, -2 is the + * second-to-last etc) + */ protected WebElement getBodyCell(int row, int col) { return getCell("tbody", row, col); } + /** + * @param row + * the index of the row element in the section. If negative, the + * calculation starts from the end (-1 is the last, -2 is the + * second-to-last etc) + */ protected WebElement getFooterCell(int row, int col) { return getCell("tfoot", row, col); } + /** + * @param row + * the index of the row element in the section. If negative, the + * calculation starts from the end (-1 is the last, -2 is the + * second-to-last etc) + */ private WebElement getCell(String sectionTag, int row, int col) { WebElement rowElement = getRow(sectionTag, row); if (rowElement != null) { @@ -112,12 +156,26 @@ public abstract class EscalatorBasicClientFeaturesTest extends MultiBrowserTest } } + /** + * @param row + * the index of the row element in the section. If negative, the + * calculation starts from the end (-1 is the last, -2 is the + * second-to-last etc) + */ private WebElement getRow(String sectionTag, int row) { WebElement escalator = getEscalator(); WebElement tableSection = escalator.findElement(By.tagName(sectionTag)); try { - return tableSection.findElement(By.xpath("tr[" + (row + 1) + "]")); + if (row >= 0) { + int fromFirst = row + 1; + return tableSection.findElement(By.xpath("tr[" + fromFirst + + "]")); + } else { + int fromLast = Math.abs(row + 1); + return tableSection.findElement(By.xpath("tr[last() - " + + fromLast + "]")); + } } catch (NoSuchElementException e) { return null; } diff --git a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/EscalatorRowColumnTest.java b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/EscalatorRowColumnTest.java index d4c5e37797..831524b4fb 100644 --- a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/EscalatorRowColumnTest.java +++ b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/EscalatorRowColumnTest.java @@ -15,6 +15,7 @@ */ package com.vaadin.tests.components.grid.basicfeatures; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; @@ -24,6 +25,12 @@ import org.openqa.selenium.By; public class EscalatorRowColumnTest extends EscalatorBasicClientFeaturesTest { + /** + * The scroll position of the Escalator when scrolled all the way down, to + * reveal the 100:th row. + */ + private static final int BOTTOM_SCROLL_POSITION = 1857; + @Test public void testInit() { openTestURL(); @@ -214,4 +221,87 @@ public class EscalatorRowColumnTest extends EscalatorBasicClientFeaturesTest { assertNotEquals("Column width should've changed", originalWidth, newWidth); } + + @Test + public void testRemoveMoreThanPagefulAtBottomWhileScrolledToBottom() + throws Exception { + openTestURL(); + selectMenuPath(GENERAL, POPULATE_COLUMN_ROW); + + scrollVerticallyTo(BOTTOM_SCROLL_POSITION); + selectMenuPath(COLUMNS_AND_ROWS, BODY_ROWS, REMOVE_50_ROWS_FROM_BOTTOM); + assertEquals("Row 49: 0,49", getBodyCell(-1, 0).getText()); + + scrollVerticallyTo(0); + + // let the DOM organize itself + Thread.sleep(500); + + // if something goes wrong, it'll explode before this. + assertEquals("Row 0: 0,0", getBodyCell(0, 0).getText()); + } + + @Test + public void testRemoveMoreThanPagefulAtBottomWhileScrolledAlmostToBottom() + throws Exception { + openTestURL(); + selectMenuPath(GENERAL, POPULATE_COLUMN_ROW); + + // bottom minus 15 rows. + scrollVerticallyTo(BOTTOM_SCROLL_POSITION - 15 * 20); + selectMenuPath(COLUMNS_AND_ROWS, BODY_ROWS, REMOVE_50_ROWS_FROM_BOTTOM); + assertEquals("Row 49: 0,49", getBodyCell(-1, 0).getText()); + + scrollVerticallyTo(0); + + // let the DOM organize itself + Thread.sleep(500); + + // if something goes wrong, it'll explode before this. + assertEquals("Row 0: 0,0", getBodyCell(0, 0).getText()); + } + + @Test + public void testRemoveMoreThanPagefulNearBottomWhileScrolledToBottom() + throws Exception { + openTestURL(); + selectMenuPath(GENERAL, POPULATE_COLUMN_ROW); + + scrollVerticallyTo(BOTTOM_SCROLL_POSITION); + selectMenuPath(COLUMNS_AND_ROWS, BODY_ROWS, + REMOVE_50_ROWS_FROM_ALMOST_BOTTOM); + assertEquals("Row 49: 0,99", getBodyCell(-1, 0).getText()); + + scrollVerticallyTo(0); + + // let the DOM organize itself + Thread.sleep(500); + + // if something goes wrong, it'll explode before this. + assertEquals("Row 0: 0,0", getBodyCell(0, 0).getText()); + } + + @Test + public void testRemoveMoreThanPagefulNearBottomWhileScrolledAlmostToBottom() + throws Exception { + openTestURL(); + selectMenuPath(GENERAL, POPULATE_COLUMN_ROW); + + // bottom minus 15 rows. + scrollVerticallyTo(BOTTOM_SCROLL_POSITION - 15 * 20); + selectMenuPath(COLUMNS_AND_ROWS, BODY_ROWS, + REMOVE_50_ROWS_FROM_ALMOST_BOTTOM); + + // let the DOM organize itself + Thread.sleep(500); + assertEquals("Row 49: 0,99", getBodyCell(-1, 0).getText()); + + scrollVerticallyTo(0); + + // let the DOM organize itself + Thread.sleep(500); + + // if something goes wrong, it'll explode before this. + assertEquals("Row 0: 0,0", getBodyCell(0, 0).getText()); + } } diff --git a/uitest/src/com/vaadin/tests/widgetset/client/grid/EscalatorBasicClientFeaturesWidget.java b/uitest/src/com/vaadin/tests/widgetset/client/grid/EscalatorBasicClientFeaturesWidget.java index b1a5498081..13f275c858 100644 --- a/uitest/src/com/vaadin/tests/widgetset/client/grid/EscalatorBasicClientFeaturesWidget.java +++ b/uitest/src/com/vaadin/tests/widgetset/client/grid/EscalatorBasicClientFeaturesWidget.java @@ -514,6 +514,14 @@ public class EscalatorBasicClientFeaturesWidget extends .getRowCount() - 50, 50); } }, menupath); + addMenuCommand("Remove 50 rows from almost bottom", + new ScheduledCommand() { + @Override + public void execute() { + removeRows(escalator.getBody(), escalator.getBody() + .getRowCount() - 60, 50); + } + }, menupath); addMenuCommand("Remove all, insert 30 and scroll 40px", new ScheduledCommand() { @Override |