diff options
author | Teemu Suo-Anttila <tsuoanttila@users.noreply.github.com> | 2017-03-24 13:04:09 +0200 |
---|---|---|
committer | Henri Sara <henri.sara@gmail.com> | 2017-03-24 13:04:09 +0200 |
commit | 0bee1dc5f8bb5314b3b71fd077709dd4f2701742 (patch) | |
tree | 8b7194d343ddbd760106186aeb13758e5c6663fb /uitest | |
parent | e905e2bb8057d19128bc5bd052d73ee8f29687a8 (diff) | |
download | vaadin-framework-0bee1dc5f8bb5314b3b71fd077709dd4f2701742.tar.gz vaadin-framework-0bee1dc5f8bb5314b3b71fd077709dd4f2701742.zip |
Improve caching when expanding nodes in hierarchical data (#8902)
Fixes #8790
Diffstat (limited to 'uitest')
2 files changed, 79 insertions, 0 deletions
diff --git a/uitest/src/main/java/com/vaadin/tests/components/treegrid/TreeGridBasicFeatures.java b/uitest/src/main/java/com/vaadin/tests/components/treegrid/TreeGridBasicFeatures.java index 9b07cc106e..ae011355c9 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/treegrid/TreeGridBasicFeatures.java +++ b/uitest/src/main/java/com/vaadin/tests/components/treegrid/TreeGridBasicFeatures.java @@ -3,13 +3,18 @@ package com.vaadin.tests.components.treegrid; import java.util.Arrays; import java.util.LinkedHashMap; import java.util.List; +import java.util.Optional; +import java.util.stream.Stream; import com.vaadin.annotations.Theme; import com.vaadin.annotations.Widgetset; import com.vaadin.data.HierarchyData; import com.vaadin.data.provider.DataProvider; +import com.vaadin.data.provider.HierarchicalDataProvider; +import com.vaadin.data.provider.HierarchicalQuery; import com.vaadin.data.provider.InMemoryHierarchicalDataProvider; import com.vaadin.server.SerializablePredicate; +import com.vaadin.shared.Range; import com.vaadin.tests.components.AbstractComponentTest; import com.vaadin.ui.TreeGrid; @@ -20,6 +25,7 @@ public class TreeGridBasicFeatures extends AbstractComponentTest<TreeGrid> { private TreeGrid<HierarchicalTestBean> grid; private InMemoryHierarchicalDataProvider<HierarchicalTestBean> inMemoryDataProvider; private LazyHierarchicalDataProvider lazyDataProvider; + private HierarchicalDataProvider<HierarchicalTestBean, ?> loggingDataProvider; @Override public TreeGrid getComponent() { @@ -82,6 +88,26 @@ public class TreeGridBasicFeatures extends AbstractComponentTest<TreeGrid> { inMemoryDataProvider = new InMemoryHierarchicalDataProvider<>(data); lazyDataProvider = new LazyHierarchicalDataProvider(3, 2); + loggingDataProvider = new InMemoryHierarchicalDataProvider<HierarchicalTestBean>( + data) { + + @Override + public Stream<HierarchicalTestBean> fetchChildren( + HierarchicalQuery<HierarchicalTestBean, SerializablePredicate<HierarchicalTestBean>> query) { + Optional<HierarchicalTestBean> parentOptional = query + .getParentOptional(); + if (parentOptional.isPresent()) { + log("Children request: " + parentOptional.get() + " ; " + + Range.withLength(query.getOffset(), + query.getLimit())); + } else { + log("Root node request: " + Range + .withLength(query.getOffset(), query.getLimit())); + } + return super.fetchChildren(query); + } + }; + } @SuppressWarnings("unchecked") @@ -90,6 +116,7 @@ public class TreeGridBasicFeatures extends AbstractComponentTest<TreeGrid> { LinkedHashMap<String, DataProvider> options = new LinkedHashMap<>(); options.put("LazyHierarchicalDataProvider", lazyDataProvider); options.put("InMemoryHierarchicalDataProvider", inMemoryDataProvider); + options.put("LoggingDataProvider", loggingDataProvider); createSelectAction("Set data provider", CATEGORY_FEATURES, options, "LazyHierarchicalDataProvider", diff --git a/uitest/src/test/java/com/vaadin/tests/components/treegrid/TreeGridExpandDataRequestTest.java b/uitest/src/test/java/com/vaadin/tests/components/treegrid/TreeGridExpandDataRequestTest.java new file mode 100644 index 0000000000..677a395e1c --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/components/treegrid/TreeGridExpandDataRequestTest.java @@ -0,0 +1,52 @@ +package com.vaadin.tests.components.treegrid; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import com.vaadin.testbench.elements.TreeGridElement; +import com.vaadin.tests.tb3.SingleBrowserTest; + +public class TreeGridExpandDataRequestTest extends SingleBrowserTest { + + @Override + protected Class<?> getUIClass() { + return TreeGridBasicFeatures.class; + } + + TreeGridElement grid; + + @Before + public void before() { + openTestURL(); + grid = $(TreeGridElement.class).first(); + selectMenuPath("Component", "Features", "Set data provider", + "LoggingDataProvider"); + clearLog(); + } + + private void clearLog() { + selectMenuPath("Settings", "Clear log"); + } + + @Test + public void expand_node0_does_not_request_root_nodes() { + grid.expandWithClick(0); + Assert.assertFalse("Log should not contain request for root nodes.", + logContainsText("Root node request: ")); + } + + @Test + public void expand_node0_after_node1_does_not_request_children_of_node1() { + grid.expandWithClick(1); + Assert.assertFalse("Log should not contain request for root nodes.", + logContainsText("Root node request: ")); + clearLog(); + grid.expandWithClick(0); + Assert.assertFalse( + "Log should not contain request for children of '0 | 1'.", + logContainsText("Children request: 0 | 1")); + Assert.assertFalse("Log should not contain request for root nodes.", + logContainsText("Root node request: ")); + } +} |