diff options
author | Guillermo Alvarez <guillermo@vaadin.com> | 2014-10-16 15:40:51 +0300 |
---|---|---|
committer | Sauli Tähkäpää <sauli@vaadin.com> | 2014-11-10 11:50:16 +0200 |
commit | 4590c4ef22d729f94fed940c7889d8f7d614e3d1 (patch) | |
tree | 4a0a230d26955b8499673e7265501f7073b83d1b /uitest | |
parent | 9bc7760539339b3be38ebc63d137b16a83d7afe5 (diff) | |
download | vaadin-framework-4590c4ef22d729f94fed940c7889d8f7d614e3d1.tar.gz vaadin-framework-4590c4ef22d729f94fed940c7889d8f7d614e3d1.zip |
New tests for Removing and re-adding all rows in Table (#14581)
Refactor of test into separate tests.
Addition of new cases to test when a new container is added and
when all items are removed and only one item is added
Change-Id: I6103404d1f21c02d7469f61ce942f7379b00a17b
Diffstat (limited to 'uitest')
2 files changed, 123 insertions, 105 deletions
diff --git a/uitest/src/com/vaadin/tests/components/table/TableRepairsScrollPositionOnReAddingAllRows.java b/uitest/src/com/vaadin/tests/components/table/TableRepairsScrollPositionOnReAddingAllRows.java index df06580dae..bee0839663 100644 --- a/uitest/src/com/vaadin/tests/components/table/TableRepairsScrollPositionOnReAddingAllRows.java +++ b/uitest/src/com/vaadin/tests/components/table/TableRepairsScrollPositionOnReAddingAllRows.java @@ -115,11 +115,11 @@ public class TableRepairsScrollPositionOnReAddingAllRows extends AbstractTestUI } }); - Button buttonReplaceByWholeSubsetPlusOnNew = new Button( + Button buttonReplaceByWholeSubsetPlusOneNew = new Button( "Replace rows by whole subset plus one new item"); - buttonReplaceByWholeSubsetPlusOnNew - .setId("buttonReplaceByWholeSubsetPlusOnNew"); - buttonReplaceByWholeSubsetPlusOnNew + buttonReplaceByWholeSubsetPlusOneNew + .setId("buttonReplaceByWholeSubsetPlusOneNew"); + buttonReplaceByWholeSubsetPlusOneNew .addClickListener(new ClickListener() { @Override @@ -136,6 +136,40 @@ public class TableRepairsScrollPositionOnReAddingAllRows extends AbstractTestUI } }); + Button buttonRemoveAllAddOne = new Button( + "Remove all items and add only one new item"); + buttonRemoveAllAddOne.setId("buttonRemoveAllAddOne"); + buttonRemoveAllAddOne.addClickListener(new ClickListener() { + + @Override + public void buttonClick(com.vaadin.ui.Button.ClickEvent event) { + cont.removeAllItems(); + TableItem ti = new TableItem(); + ti.setName("Item_" + 20); + cont.addBean(ti); + } + }); + + // This should be the last test as it changes the table datasource + Button buttonReplaceByNewDatasource = new Button( + "Remove all items and add new datasource"); + buttonReplaceByNewDatasource.setId("buttonReplaceByNewDatasource"); + buttonReplaceByNewDatasource.addClickListener(new ClickListener() { + + @Override + public void buttonClick(com.vaadin.ui.Button.ClickEvent event) { + cont.removeAllItems(); + BeanItemContainer<TableItem> newContainer = new BeanItemContainer<TableItem>( + TableItem.class); + for (int i = 0; i < 50; i++) { + TableItem ti = new TableItem(); + ti.setName("Item_" + i); + newContainer.addBean(ti); + } + table.setContainerDataSource(newContainer); + } + }); + for (int i = 0; i < 80; i++) { TableItem ti = new TableItem(); ti.setName("Item_" + i); @@ -147,7 +181,9 @@ public class TableRepairsScrollPositionOnReAddingAllRows extends AbstractTestUI getLayout().addComponent(buttonReplaceByAnotherCollectionViaAddAll); getLayout().addComponent(buttonReplaceByAnotherCollectionViaAdd); getLayout().addComponent(buttonReplaceBySubsetOfSmallerSize); - getLayout().addComponent(buttonReplaceByWholeSubsetPlusOnNew); + getLayout().addComponent(buttonReplaceByWholeSubsetPlusOneNew); + getLayout().addComponent(buttonRemoveAllAddOne); + getLayout().addComponent(buttonReplaceByNewDatasource); getLayout().addComponent(buttonRestore); getLayout().addComponent(table); } diff --git a/uitest/src/com/vaadin/tests/components/table/TableRepairsScrollPositionOnReAddingAllRowsTest.java b/uitest/src/com/vaadin/tests/components/table/TableRepairsScrollPositionOnReAddingAllRowsTest.java index a3e7f29dfe..4ca3ed406b 100644 --- a/uitest/src/com/vaadin/tests/components/table/TableRepairsScrollPositionOnReAddingAllRowsTest.java +++ b/uitest/src/com/vaadin/tests/components/table/TableRepairsScrollPositionOnReAddingAllRowsTest.java @@ -18,17 +18,10 @@ package com.vaadin.tests.components.table; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.number.IsCloseTo.closeTo; +import org.junit.Before; import org.junit.Test; -import org.openqa.selenium.By; -import org.openqa.selenium.JavascriptExecutor; -import org.openqa.selenium.WebDriver; -import org.openqa.selenium.WebElement; -import org.openqa.selenium.support.ui.ExpectedCondition; -import com.vaadin.testbench.commands.TestBenchCommandExecutor; import com.vaadin.testbench.elements.TableElement; -import com.vaadin.testbench.screenshot.ImageComparison; -import com.vaadin.testbench.screenshot.ReferenceNameGenerator; import com.vaadin.tests.tb3.MultiBrowserTest; /** @@ -40,138 +33,127 @@ import com.vaadin.tests.tb3.MultiBrowserTest; public class TableRepairsScrollPositionOnReAddingAllRowsTest extends MultiBrowserTest { - @Test - public void testScrollRepairsAfterReAddingAllRows() - throws InterruptedException { - openTestURL(); - - WebElement row0 = $(TableElement.class).first().getCell(0, 0); - int rowLocation0 = row0.getLocation().getY(); + private int rowLocation0; - // case 1 - scrollUp(); + @Override + @Before + public void setup() throws Exception { + super.setup(); + openTestURL(); - waitUntilNot(new ExpectedCondition<Boolean>() { - @Override - public Boolean apply(WebDriver input) { - return $(TableElement.class).first().getCell(48, 0) == null; - } - }, 10); + rowLocation0 = getCellY(0); + scrollToBottom(); + } - WebElement row = $(TableElement.class).first().getCell(48, 0); - int rowLocation = row.getLocation().getY(); + @Test + public void testReAddAllViaAddAll() { + int rowLocation = getCellY(70); // This button is for re-adding all rows (original itemIds) at once // (removeAll() + addAll()) hitButton("buttonReAddAllViaAddAll"); - row = $(TableElement.class).first().getCell(48, 0); - int newRowLocation = row.getLocation().getY(); + int newRowLocation = getCellY(70); - // ranged check because IE9 consistently misses the mark by 1 pixel - assertThat( + assertCloseTo( "Scroll position should be the same as before Re-Adding rows via addAll()", - (double) newRowLocation, - closeTo(rowLocation, row.getSize().height + 1)); - - // case 2 - scrollUp(); + newRowLocation, rowLocation); - waitUntilNot(new ExpectedCondition<Boolean>() { - @Override - public Boolean apply(WebDriver input) { - return $(TableElement.class).first().getCell(48, 0) == null; - } - }, 10); + } - row = $(TableElement.class).first().getCell(48, 0); - rowLocation = row.getLocation().getY(); + @Test + public void testReplaceByAnotherCollectionViaAddAll() { + int rowLocation = getCellY(70); // This button is for replacing all rows at once (removeAll() + // addAll()) hitButton("buttonReplaceByAnotherCollectionViaAddAll"); - row = $(TableElement.class).first().getCell(48, 0); - newRowLocation = row.getLocation().getY(); + // new collection has one less element + int newRowLocation = getCellY(69); - // ranged check because IE9 consistently misses the mark by 1 pixel - assertThat( + assertCloseTo( "Scroll position should be the same as before Replacing rows via addAll()", - (double) newRowLocation, - closeTo(rowLocation, row.getSize().height + 1)); + newRowLocation, rowLocation); + } + + @Test + public void testReplaceByAnotherCollectionViaAdd() { - // case 3 // This button is for replacing all rows one by one (removeAll() + add() // + add()..) hitButton("buttonReplaceByAnotherCollectionViaAdd"); - row = $(TableElement.class).first().getCell(0, 0); - newRowLocation = row.getLocation().getY(); + int newRowLocation = getCellY(0); - // ranged check because IE9 consistently misses the mark by 1 pixel - assertThat("Scroll position should be 0", (double) newRowLocation, - closeTo(rowLocation0, 1)); - - // case 4 - // This button is for restoring initial list and for scrolling to 0 - // position - hitButton("buttonRestore"); - scrollUp(); - - waitUntilNot(new ExpectedCondition<Boolean>() { - @Override - public Boolean apply(WebDriver input) { - return $(TableElement.class).first().getCell(48, 0) == null; - } - }, 10); + assertCloseTo("Scroll position should be 0", newRowLocation, + rowLocation0); + } + @Test + public void testReplaceBySubsetOfSmallerSize() { // This button is for replacing all rows at once but the count of rows // is less then first index to scroll hitButton("buttonReplaceBySubsetOfSmallerSize"); - row = $(TableElement.class).first().getCell(5, 0); + int newRowLocation = getCellY(5); - newRowLocation = row.getLocation().getY(); + assertCloseTo("Scroll position should be 0", newRowLocation, + rowLocation0); + } - // ranged check because IE9 consistently misses the mark by 1 pixel - assertThat("Scroll position should be 0", (double) newRowLocation, - closeTo(rowLocation0, 1)); + @Test + public void testReplaceByWholeSubsetPlusOneNew() { + int rowLocation = getCellY(70); - // case 5 - // This button is for restoring initial list and for scrolling to 0 - // position - hitButton("buttonRestore"); - scrollUp(); + // This button is for replacing by whole original sub-set of items plus + // one new + hitButton("buttonReplaceByWholeSubsetPlusOneNew"); - waitUntilNot(new ExpectedCondition<Boolean>() { - @Override - public Boolean apply(WebDriver input) { - return $(TableElement.class).first().getCell(48, 0) == null; - } - }, 10); + int newRowLocation = getCellY(70); - row = $(TableElement.class).first().getCell(48, 0); - rowLocation = row.getLocation().getY(); + assertCloseTo("Scroll position should be the same as before Replacing", + newRowLocation, rowLocation); - // This button is for replacing by whole original sub-set of items plus - // one new - hitButton("buttonReplaceByWholeSubsetPlusOnNew"); + } - row = $(TableElement.class).first().getCell(48, 0); - newRowLocation = row.getLocation().getY(); + @Test + public void testRemoveAllAddOne() { + // This button is for removing all and then adding only one new item + hitButton("buttonRemoveAllAddOne"); - // ranged check because IE9 consistently misses the mark by 1 pixel - assertThat("Scroll position should be the same as before Replacing", - (double) newRowLocation, - closeTo(rowLocation, row.getSize().height + 1)); + int newRowLocation = getCellY(0); + + assertCloseTo("Scroll position should be 0", newRowLocation, + rowLocation0); + } + + @Test + public void testReplaceByNewDatasource() { + // This button is for remove all items and add new datasource + hitButton("buttonReplaceByNewDatasource"); + + int newRowLocation = getCellY(0); + + assertCloseTo("Scroll position should be 0", newRowLocation, + rowLocation0); + } + + private TableElement getTable() { + return $(TableElement.class).first(); + } + private void scrollToBottom() { + scrollTable(getTable(), 80, 70); } - private void scrollUp() { - WebElement actualElement = getDriver().findElement( - By.className("v-table-body-wrapper")); - JavascriptExecutor js = new TestBenchCommandExecutor(getDriver(), - new ImageComparison(), new ReferenceNameGenerator()); - js.executeScript("arguments[0].scrollTop = " + 1205, actualElement); + private int getCellY(int row) { + return getTable().getCell(row, 0).getLocation().getY(); } + + private void assertCloseTo(String reason, int actual, int expected) { + // ranged check because IE9 consistently misses the mark by 1 pixel + assertThat(reason, (double) actual, closeTo(expected, 1)); + } + } |