summaryrefslogtreecommitdiffstats
path: root/uitest
diff options
context:
space:
mode:
authorTeemu Suo-Anttila <tsuoanttila@users.noreply.github.com>2017-05-16 09:36:22 +0300
committerPekka Hyvönen <pekka@vaadin.com>2017-05-16 09:36:22 +0300
commit04e7259fb497e47bcd6d664e87c243db5badd934 (patch)
tree92a82bdc081308162205d734fe0c3e4eefe5725b /uitest
parente788fa906b968a298414e60cbb15cc7d6389b8a1 (diff)
downloadvaadin-framework-04e7259fb497e47bcd6d664e87c243db5badd934.tar.gz
vaadin-framework-04e7259fb497e47bcd6d664e87c243db5badd934.zip
Add events and functionality to Tree (#9318)
* Add ItemClick event to Tree * Add collapse provider and style generator to Tree
Diffstat (limited to 'uitest')
-rw-r--r--uitest/src/main/java/com/vaadin/tests/components/tree/TreeBasicFeatures.java39
-rw-r--r--uitest/src/test/java/com/vaadin/tests/components/tree/TreeBasicFeaturesTest.java37
2 files changed, 76 insertions, 0 deletions
diff --git a/uitest/src/main/java/com/vaadin/tests/components/tree/TreeBasicFeatures.java b/uitest/src/main/java/com/vaadin/tests/components/tree/TreeBasicFeatures.java
index a2078c237e..e0fa469fa8 100644
--- a/uitest/src/main/java/com/vaadin/tests/components/tree/TreeBasicFeatures.java
+++ b/uitest/src/main/java/com/vaadin/tests/components/tree/TreeBasicFeatures.java
@@ -11,11 +11,13 @@ import com.vaadin.icons.VaadinIcons;
import com.vaadin.server.ClassResource;
import com.vaadin.server.ThemeResource;
import com.vaadin.server.VaadinRequest;
+import com.vaadin.shared.Registration;
import com.vaadin.tests.components.AbstractTestUIWithLog;
import com.vaadin.tests.data.bean.HierarchicalTestBean;
import com.vaadin.ui.Component;
import com.vaadin.ui.IconGenerator;
import com.vaadin.ui.MenuBar;
+import com.vaadin.ui.MenuBar.Command;
import com.vaadin.ui.MenuBar.MenuItem;
import com.vaadin.ui.Tree;
import com.vaadin.ui.VerticalLayout;
@@ -66,6 +68,43 @@ public class TreeBasicFeatures extends AbstractTestUIWithLog {
MenuItem componentMenu = menu.addItem("Component", null);
createIconMenu(componentMenu.addItem("Icons", null));
createCaptionMenu(componentMenu.addItem("Captions", null));
+ componentMenu.addItem("Item Click Listener", new Command() {
+
+ private Registration registration;
+
+ @Override
+ public void menuSelected(MenuItem selectedItem) {
+ removeRegistration();
+
+ if (selectedItem.isChecked()) {
+ registration = tree.addItemClickListener(
+ e -> log("ItemClick: " + e.getItem()));
+ }
+ }
+
+ private void removeRegistration() {
+ if (registration != null) {
+ registration.remove();
+ registration = null;
+ }
+ }
+
+ }).setCheckable(true);
+ MenuItem collapseAllowed = componentMenu.addItem("Collapse Allowed",
+ menuItem -> tree.setItemCollapseAllowedProvider(
+ t -> menuItem.isChecked()));
+ collapseAllowed.setCheckable(true);
+
+ // Simulate the first click
+ collapseAllowed.setChecked(true);
+ collapseAllowed.getCommand().menuSelected(collapseAllowed);
+
+ componentMenu
+ .addItem("Style Generator",
+ menuItem -> tree.setStyleGenerator(menuItem.isChecked()
+ ? t -> "level" + t.getDepth() : t -> null))
+ .setCheckable(true);
+
return menu;
}
diff --git a/uitest/src/test/java/com/vaadin/tests/components/tree/TreeBasicFeaturesTest.java b/uitest/src/test/java/com/vaadin/tests/components/tree/TreeBasicFeaturesTest.java
index 682c2028d5..8d95bf5ef6 100644
--- a/uitest/src/test/java/com/vaadin/tests/components/tree/TreeBasicFeaturesTest.java
+++ b/uitest/src/test/java/com/vaadin/tests/components/tree/TreeBasicFeaturesTest.java
@@ -10,6 +10,7 @@ import org.openqa.selenium.By;
import com.vaadin.testbench.TestBenchElement;
import com.vaadin.testbench.elements.TreeElement;
+import com.vaadin.testbench.elements.TreeGridElement;
import com.vaadin.tests.tb3.MultiBrowserTest;
public class TreeBasicFeaturesTest extends MultiBrowserTest {
@@ -127,4 +128,40 @@ public class TreeBasicFeaturesTest extends MultiBrowserTest {
assertNoErrorNotifications();
}
+
+ @Test
+ public void tree_item_click() {
+ selectMenuPath("Component", "Item Click Listener");
+ $(TreeElement.class).first().getItem(1).click();
+ Assert.assertTrue(logContainsText("ItemClick: 0 | 1"));
+ }
+
+ @Test
+ public void tree_style_generator() {
+ selectMenuPath("Component", "Style Generator");
+ TreeElement tree = $(TreeElement.class).first();
+ Assert.assertTrue("Style name not present",
+ tree.wrap(TreeGridElement.class).getRow(0).getAttribute("class")
+ .contains("level0"));
+ tree.expand(0);
+ Assert.assertTrue("Style name not present",
+ tree.wrap(TreeGridElement.class).getRow(1).getAttribute("class")
+ .contains("level1"));
+ tree.expand(1);
+ Assert.assertTrue("Style name not present",
+ tree.wrap(TreeGridElement.class).getRow(2).getAttribute("class")
+ .contains("level2"));
+ }
+
+ @Test
+ public void tree_disable_collapse() {
+ selectMenuPath("Component", "Collapse Allowed");
+ TreeElement tree = $(TreeElement.class).first();
+ tree.expand(0);
+ tree.expand(1);
+ Assert.assertEquals("2 | 0", tree.getItem(2).getText());
+ tree.collapse(1);
+ Assert.assertEquals("Tree should prevent collapsing all nodes.",
+ "2 | 0", tree.getItem(2).getText());
+ }
}