summaryrefslogtreecommitdiffstats
path: root/uitest
diff options
context:
space:
mode:
authorIlia Motornyi <elmot@vaadin.com>2017-06-21 11:14:17 +0300
committerHenri Sara <henri.sara@gmail.com>2017-06-21 11:14:17 +0300
commit8ac8f5fc783bc3bf20456a24dd9bf76e4192e546 (patch)
treeb566cd8722b64475aa26f135c4af14f20ac73966 /uitest
parent3f4e2325b78d563f0c3ed1ececa7d2f3a0569c68 (diff)
downloadvaadin-framework-8ac8f5fc783bc3bf20456a24dd9bf76e4192e546.tar.gz
vaadin-framework-8ac8f5fc783bc3bf20456a24dd9bf76e4192e546.zip
Fix keymapper reverse mapping (#9535)
Fixes #9470
Diffstat (limited to 'uitest')
-rw-r--r--uitest/src/main/java/com/vaadin/tests/data/GridRefreshWithGetId.java109
-rw-r--r--uitest/src/test/java/com/vaadin/tests/data/GridRefreshWithGetIdTest.java27
2 files changed, 136 insertions, 0 deletions
diff --git a/uitest/src/main/java/com/vaadin/tests/data/GridRefreshWithGetId.java b/uitest/src/main/java/com/vaadin/tests/data/GridRefreshWithGetId.java
new file mode 100644
index 0000000000..b37956d126
--- /dev/null
+++ b/uitest/src/main/java/com/vaadin/tests/data/GridRefreshWithGetId.java
@@ -0,0 +1,109 @@
+package com.vaadin.tests.data;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import com.vaadin.annotations.Widgetset;
+import com.vaadin.data.provider.ListDataProvider;
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.AbstractTestUI;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Grid;
+
+@Widgetset("com.vaadin.DefaultWidgetSet")
+public class GridRefreshWithGetId extends AbstractTestUI {
+
+ private static class TestObject {
+
+ private final int id;
+ private String name;
+
+ public TestObject(int id, String name) {
+ this.id = id;
+ this.name = name;
+ }
+
+ public int getId() {
+ return id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ /**
+ * The class intentionally has strange {@code hashCode()} and {@code equals()}
+ * implementation to ensure if {@code Grid} relies on bean id rather than on
+ * bean hashcode/equals identification.
+ *
+ * {@see Object.equals}
+ */
+ @Override
+ public boolean equals(Object o) {
+ if (this == o)
+ return true;
+ if (o == null || getClass() != o.getClass())
+ return false;
+
+ TestObject myObject = (TestObject) o;
+
+ if (id != myObject.id)
+ return false;
+ return name != null ? name.equals(myObject.name)
+ : myObject.name == null;
+ }
+
+ /**
+ * The class intentionally has strange {@code hashCode()} and {@code equals()}
+ * implementation to ensure if {@code Grid} relies on bean id rather than on
+ * bean hashcode/equals identification.
+ *
+ * {@see Object.hashCode}
+ */
+ @Override
+ public int hashCode() {
+ int result = id;
+ result = 31 * result + (name != null ? name.hashCode() : 0);
+ return result;
+ }
+ }
+
+ @Override
+ protected void setup(VaadinRequest request) {
+ List<TestObject> data = new ArrayList<>();
+ data.add(new TestObject(0, "blue"));
+ data.add(new TestObject(1, "red"));
+ data.add(new TestObject(2, "green"));
+ data.add(new TestObject(3, "yellow"));
+ data.add(new TestObject(4, "purple"));
+
+ ListDataProvider<TestObject> dataProvider = new ListDataProvider<TestObject>(
+ data) {
+
+ @Override
+ public Object getId(TestObject item) {
+ return item.getId();
+ }
+ };
+
+ Grid<TestObject> grid = new Grid<>();
+ grid.setDataProvider(dataProvider);
+ addComponent(grid);
+
+ grid.addColumn(myObject -> {
+ return myObject.getName();
+ });
+
+ Button button = new Button("Change green to black");
+ button.addClickListener(event1 -> {
+ TestObject myObject = data.get(2);
+ myObject.setName("black");
+ dataProvider.refreshItem(myObject);
+ });
+ addComponent(button);
+ }
+}
diff --git a/uitest/src/test/java/com/vaadin/tests/data/GridRefreshWithGetIdTest.java b/uitest/src/test/java/com/vaadin/tests/data/GridRefreshWithGetIdTest.java
new file mode 100644
index 0000000000..c3bda4f3ca
--- /dev/null
+++ b/uitest/src/test/java/com/vaadin/tests/data/GridRefreshWithGetIdTest.java
@@ -0,0 +1,27 @@
+package com.vaadin.tests.data;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import com.vaadin.testbench.elements.ButtonElement;
+import com.vaadin.testbench.elements.GridElement;
+import com.vaadin.tests.tb3.SingleBrowserTest;
+
+public class GridRefreshWithGetIdTest extends SingleBrowserTest {
+
+ @Test
+ public void testDataIdentifiedAndUpdated() {
+ openTestURL();
+ // Select item
+ GridElement grid = $(GridElement.class).first();
+ grid.getCell(2, 0).click();
+ Assert.assertTrue("Row should be selected",
+ grid.getRow(2).isSelected());
+ Assert.assertEquals("green", grid.getCell(2, 0).getText());
+ $(ButtonElement.class).first().click();
+ Assert.assertTrue("Row was no longer selected",
+ grid.getRow(2).isSelected());
+ Assert.assertEquals("black", grid.getCell(2, 0).getText());
+ }
+
+}