]> source.dussan.org Git - vaadin-framework.git/commitdiff
Fix empty data source client-side events
authorTeemu Suo-Anttila <teemusa@vaadin.com>
Tue, 6 Sep 2016 12:34:12 +0000 (15:34 +0300)
committerVaadin Code Review <review@vaadin.com>
Wed, 7 Sep 2016 05:54:52 +0000 (05:54 +0000)
Change-Id: I7e84fd01cf2ec46b18af960712226a48f600f623

client/src/main/java/com/vaadin/client/data/AbstractRemoteDataSource.java
uitest/src/main/java/com/vaadin/tests/data/DummyData.java
uitest/src/test/java/com/vaadin/tests/data/DummyDataTest.java

index 9cc32998b2a826c4f24f51d704202a90ee922da6..33f96e009c15dcc7525e57a7b3e382962957fe8b 100644 (file)
@@ -287,7 +287,14 @@ public abstract class AbstractRemoteDataSource<T> implements DataSource<T> {
             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();
 
index 60b3af7681fc56b1f905d13925bb965e353169a1..8b4083d834c248198b9db82f2f7a4ff5ed27ec8c 100644 (file)
@@ -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);
     }
 }
index 48001ef27fcfe28da61e27799c9a48e0cddeb93e..1e9f0f9ade9a2d90a353a349accb8df53db9cd10 100644 (file)
@@ -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());
+    }
+
 }