diff options
author | Teemu Suo-Anttila <tsuoanttila@users.noreply.github.com> | 2018-01-25 14:36:51 +0200 |
---|---|---|
committer | Teemu Suo-Anttila <tsuoanttila@users.noreply.github.com> | 2018-01-31 14:27:32 +0200 |
commit | 8bc470f4404d21a65520d4eae50b434dbe92985a (patch) | |
tree | 482c9cf96339fdd64a638f8118519490b263acb6 /uitest | |
parent | 5c9fc0f1ebd1e25fd36ad28af90cbadbb5b3adb5 (diff) | |
download | vaadin-framework-8bc470f4404d21a65520d4eae50b434dbe92985a.tar.gz vaadin-framework-8bc470f4404d21a65520d4eae50b434dbe92985a.zip |
Fix Grid not updating selected item immediately (#10569)
Diffstat (limited to 'uitest')
-rw-r--r-- | uitest/src/main/java/com/vaadin/tests/data/DataProviderRefresh.java | 22 | ||||
-rw-r--r-- | uitest/src/test/java/com/vaadin/tests/data/DataProviderRefreshTest.java | 5 |
2 files changed, 22 insertions, 5 deletions
diff --git a/uitest/src/main/java/com/vaadin/tests/data/DataProviderRefresh.java b/uitest/src/main/java/com/vaadin/tests/data/DataProviderRefresh.java index 9f1591407c..faec5084f7 100644 --- a/uitest/src/main/java/com/vaadin/tests/data/DataProviderRefresh.java +++ b/uitest/src/main/java/com/vaadin/tests/data/DataProviderRefresh.java @@ -3,16 +3,17 @@ package com.vaadin.tests.data; import java.io.Serializable; import java.util.ArrayList; import java.util.List; +import java.util.Optional; import java.util.stream.Stream; import com.vaadin.data.provider.AbstractDataProvider; import com.vaadin.data.provider.Query; import com.vaadin.server.VaadinRequest; -import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.tests.components.AbstractTestUIWithLog; import com.vaadin.ui.Button; import com.vaadin.ui.Grid; -public class DataProviderRefresh extends AbstractTestUI { +public class DataProviderRefresh extends AbstractTestUIWithLog { public static class Bean implements Serializable { @@ -96,9 +97,10 @@ public class DataProviderRefresh extends AbstractTestUI { } } + private Grid<Bean> grid = new Grid<>(); + @Override protected void setup(VaadinRequest request) { - Grid<Bean> grid = new Grid<>(); List<Bean> arrayList = new ArrayList<>(); Bean foo = new Bean("Foo", 10); arrayList.add(foo); @@ -108,9 +110,19 @@ public class DataProviderRefresh extends AbstractTestUI { grid.setDataProvider(dataProvider); grid.addColumn(Object::toString).setCaption("toString"); addComponent(grid); - addComponent(new Button("Replace item", - event -> dataProvider.refreshItem(new Bean("Bar", 10)))); + addComponent(new Button("Replace item", event -> { + dataProvider.refreshItem(new Bean("Bar", 10)); + logSelectedItem(grid.asSingleSelect().getValue()); + })); addComponent(new Button("Select old", event -> grid.select(foo))); + grid.asSingleSelect().addValueChangeListener(e -> { + logSelectedItem(e.getValue()); + }); } + private void logSelectedItem(Bean bean) { + Optional.ofNullable(bean) + .map(b -> "Currently selected: " + b.toString()) + .ifPresent(this::log); + } } diff --git a/uitest/src/test/java/com/vaadin/tests/data/DataProviderRefreshTest.java b/uitest/src/test/java/com/vaadin/tests/data/DataProviderRefreshTest.java index bbb31535a8..03e566a741 100644 --- a/uitest/src/test/java/com/vaadin/tests/data/DataProviderRefreshTest.java +++ b/uitest/src/test/java/com/vaadin/tests/data/DataProviderRefreshTest.java @@ -2,8 +2,11 @@ package com.vaadin.tests.data; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; +import static org.hamcrest.CoreMatchers.*; + import org.junit.Test; import com.vaadin.testbench.elements.ButtonElement; @@ -21,12 +24,14 @@ public class DataProviderRefreshTest extends SingleBrowserTest { // Select item before replace $(ButtonElement.class).caption("Select old").first().click(); assertTrue("Row should be selected", grid.getRow(0).isSelected()); + assertThat(getLogRow(0), containsString("{ Foo, 10 }")); $(ButtonElement.class).caption("Replace item").first().click(); assertTrue("Row should still be selected after item replace", grid.getRow(0).isSelected()); assertEquals("Grid content was not updated.", "{ Bar, 10 }", grid.getCell(0, 0).getText()); + assertThat(getLogRow(0), containsString("{ Bar, 10 }")); // Deselect row grid.getCell(0, 0).click(); |