From 400818bff226f60e37ee30ed3a0ffe7e845dcf67 Mon Sep 17 00:00:00 2001 From: Teemu Suo-Anttila Date: Tue, 6 Sep 2016 15:34:12 +0300 Subject: [PATCH] Fix empty data source client-side events Change-Id: I7e84fd01cf2ec46b18af960712226a48f600f623 --- .../client/data/AbstractRemoteDataSource.java | 9 ++++++- .../java/com/vaadin/tests/data/DummyData.java | 3 +++ .../com/vaadin/tests/data/DummyDataTest.java | 24 +++++++++++++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/client/src/main/java/com/vaadin/client/data/AbstractRemoteDataSource.java b/client/src/main/java/com/vaadin/client/data/AbstractRemoteDataSource.java index 9cc32998b2..33f96e009c 100644 --- a/client/src/main/java/com/vaadin/client/data/AbstractRemoteDataSource.java +++ b/client/src/main/java/com/vaadin/client/data/AbstractRemoteDataSource.java @@ -287,7 +287,14 @@ public abstract class AbstractRemoteDataSource implements DataSource { dropFromCache(cached); cached = Range.between(0, 0); - handleMissingRows(getMaxCacheRange()); + Range maxCacheRange = getMaxCacheRange(); + if (!maxCacheRange.isEmpty()) { + handleMissingRows(maxCacheRange); + } else { + // There is nothing to fetch. We're done here. + getHandlers().forEach(dch -> dch + .dataAvailable(cached.getStart(), cached.length())); + } } else { discardStaleCacheEntries(); diff --git a/uitest/src/main/java/com/vaadin/tests/data/DummyData.java b/uitest/src/main/java/com/vaadin/tests/data/DummyData.java index 60b3af7681..8b4083d834 100644 --- a/uitest/src/main/java/com/vaadin/tests/data/DummyData.java +++ b/uitest/src/main/java/com/vaadin/tests/data/DummyData.java @@ -112,6 +112,9 @@ public class DummyData extends AbstractTestUIWithLog { controls.addComponent(new Button("Reset data source", e -> { dummy.setDataSource(new LoggingDataSource(items)); })); + controls.addComponent(new Button("Remove all data", e -> { + dummy.setDataSource(new LoggingDataSource(Collections.emptyList())); + })); addComponent(dummy); } } diff --git a/uitest/src/test/java/com/vaadin/tests/data/DummyDataTest.java b/uitest/src/test/java/com/vaadin/tests/data/DummyDataTest.java index 48001ef27f..1e9f0f9ade 100644 --- a/uitest/src/test/java/com/vaadin/tests/data/DummyDataTest.java +++ b/uitest/src/test/java/com/vaadin/tests/data/DummyDataTest.java @@ -10,11 +10,17 @@ import org.junit.Test; import org.openqa.selenium.WebElement; import com.vaadin.testbench.By; +import com.vaadin.testbench.elements.AbstractComponentElement; import com.vaadin.testbench.elements.ButtonElement; +import com.vaadin.testbench.elementsbase.ServerClass; import com.vaadin.tests.tb3.SingleBrowserTest; public class DummyDataTest extends SingleBrowserTest { + @ServerClass("com.vaadin.tests.data.DummyData.DummyComponent") + public static class DummyElement extends AbstractComponentElement { + } + @Before public void setUp() { setDebug(true); @@ -57,4 +63,22 @@ public class DummyDataTest extends SingleBrowserTest { assertEquals("DataSource change should only cause 1 request", "3. Backend request #0", getLogRow(0)); } + + @Test + public void testEmptyAndRestoreContent() { + assertEquals("Unexpected amount of content on init.", 300, + $(DummyElement.class).first() + .findElements(By.className("v-label")).size()); + // Change to an empty data source + $(ButtonElement.class).get(2).click(); + assertEquals("Empty data source did not work as expected.", 0, + $(DummyElement.class).first() + .findElements(By.className("v-label")).size()); + // Change back to logging data source + $(ButtonElement.class).get(1).click(); + assertEquals("Data was not correctly restored.", 300, + $(DummyElement.class).first() + .findElements(By.className("v-label")).size()); + } + } -- 2.39.5