summaryrefslogtreecommitdiffstats
path: root/uitest
diff options
context:
space:
mode:
authorAleksi Hietanen <aleksi@vaadin.com>2017-01-10 15:56:37 +0200
committerPekka Hyvönen <pekka@vaadin.com>2017-01-10 15:56:37 +0200
commitae54094346c40be3a058e41c942236383362ffd0 (patch)
treec0c747dbc5cd2112e736e798fb685232ffff08ba /uitest
parent9ee9273b6d1dc6f521f7b9ee02743636c69cff53 (diff)
downloadvaadin-framework-ae54094346c40be3a058e41c942236383362ffd0.tar.gz
vaadin-framework-ae54094346c40be3a058e41c942236383362ffd0.zip
Correctly reset DataCommunicator when its DataProvider is changed (#8138)
* Correctly reset DataCommunicator when its DataProvider is changed * Improve ReplaceDataProviderTest * Remove return type from AbstractListing.readItems
Diffstat (limited to 'uitest')
-rw-r--r--uitest/src/main/java/com/vaadin/tests/data/ReplaceDataProvider.java67
-rw-r--r--uitest/src/test/java/com/vaadin/tests/data/ReplaceDataProviderTest.java53
2 files changed, 120 insertions, 0 deletions
diff --git a/uitest/src/main/java/com/vaadin/tests/data/ReplaceDataProvider.java b/uitest/src/main/java/com/vaadin/tests/data/ReplaceDataProvider.java
new file mode 100644
index 0000000000..8a33cae95d
--- /dev/null
+++ b/uitest/src/main/java/com/vaadin/tests/data/ReplaceDataProvider.java
@@ -0,0 +1,67 @@
+package com.vaadin.tests.data;
+
+import java.util.List;
+import java.util.stream.Collectors;
+import java.util.stream.IntStream;
+
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.AbstractTestUI;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Grid;
+
+public class ReplaceDataProvider extends AbstractTestUI {
+
+ private static class TestClass {
+ public String someField;
+ public int hash;
+
+ public TestClass(int hash) {
+ this.hash = hash;
+ someField = "a";
+ }
+
+ @Override
+ public int hashCode() {
+ return hash;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ return true;
+ }
+ }
+
+ @Override
+ protected void setup(VaadinRequest request) {
+ Grid<TestClass> grid = new Grid<>();
+ grid.addColumn(item -> item.someField);
+
+ List<TestClass> listOfClasses = IntStream.range(0, 10)
+ .mapToObj(TestClass::new).collect(Collectors.toList());
+ for (int i = 0; i < 10; i++) {
+ listOfClasses.add(new TestClass(10));
+ }
+
+ grid.setItems(listOfClasses);
+
+ Button replaceBtn = new Button("replace data provider");
+ replaceBtn.addClickListener(clickEvent -> {
+ List<TestClass> newList = IntStream.range(0, 10)
+ .mapToObj(TestClass::new).collect(Collectors.toList());
+ newList.get(0).someField = "b";
+ grid.setItems(newList);
+ });
+
+ Button replaceAndSelectBtn = new Button(
+ "replace data provider and select second");
+ replaceAndSelectBtn.addClickListener(clickEvent -> {
+ List<TestClass> newList = IntStream.range(0, 10)
+ .mapToObj(TestClass::new).collect(Collectors.toList());
+ newList.get(0).someField = "b";
+ grid.setItems(newList);
+ grid.getSelectionModel().select(newList.get(1));
+ });
+
+ addComponents(replaceBtn, replaceAndSelectBtn, grid);
+ }
+}
diff --git a/uitest/src/test/java/com/vaadin/tests/data/ReplaceDataProviderTest.java b/uitest/src/test/java/com/vaadin/tests/data/ReplaceDataProviderTest.java
new file mode 100644
index 0000000000..7fa495cf24
--- /dev/null
+++ b/uitest/src/test/java/com/vaadin/tests/data/ReplaceDataProviderTest.java
@@ -0,0 +1,53 @@
+package com.vaadin.tests.data;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.vaadin.testbench.elements.ButtonElement;
+import com.vaadin.testbench.elements.GridElement;
+import com.vaadin.tests.tb3.SingleBrowserTest;
+
+public class ReplaceDataProviderTest extends SingleBrowserTest {
+
+ @Before
+ public void setUp() {
+ openTestURL();
+ }
+
+ @Test
+ public void test_grid_data_communication_with_replaced_data_provider() {
+ GridElement grid = $(GridElement.class).first();
+ ButtonElement replaceDataProviderButton = $(ButtonElement.class)
+ .first();
+
+ Assert.assertEquals(20, grid.getRowCount());
+ grid.getCell(0, 0).click();
+ assertCellText("a", 0, 0);
+
+ replaceDataProviderButton.click();
+
+ Assert.assertEquals(10, grid.getRowCount());
+ assertCellText("b", 0, 0);
+ for (int i = 1; i < 10; i++) {
+ assertCellText("a", i, 0);
+ }
+
+ Assert.assertFalse(grid.getRow(0).isSelected());
+
+ grid.getCell(0, 0).click();
+ assertCellText("b", 0, 0);
+
+ // This button should replace the data provider and do a server side
+ // select on the second item
+ $(ButtonElement.class).get(1).click();
+ grid.getRow(1).isSelected();
+ }
+
+ private void assertCellText(String text, int rowIndex, int colIndex) {
+ String firstCellText = $(GridElement.class).first()
+ .getCell(rowIndex, colIndex)
+ .getText();
+ Assert.assertEquals(text, firstCellText);
+ }
+}