diff options
Diffstat (limited to 'uitest')
4 files changed, 131 insertions, 5 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 3b58e6c75e..9b07cc106e 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 @@ -9,6 +9,7 @@ import com.vaadin.annotations.Widgetset; import com.vaadin.data.HierarchyData; import com.vaadin.data.provider.DataProvider; import com.vaadin.data.provider.InMemoryHierarchicalDataProvider; +import com.vaadin.server.SerializablePredicate; import com.vaadin.tests.components.AbstractComponentTest; import com.vaadin.ui.TreeGrid; @@ -38,7 +39,8 @@ public class TreeGridBasicFeatures extends AbstractComponentTest<TreeGrid> { grid.addColumn(HierarchicalTestBean::toString).setCaption("String") .setId("string"); grid.addColumn(HierarchicalTestBean::getDepth).setCaption("Depth") - .setId("depth"); + .setId("depth").setDescriptionGenerator( + t -> "Hierarchy depth: " + t.getDepth()); grid.addColumn(HierarchicalTestBean::getIndex) .setCaption("Index on this depth").setId("index"); grid.setHierarchyColumn("string"); @@ -54,6 +56,7 @@ public class TreeGridBasicFeatures extends AbstractComponentTest<TreeGrid> { createDataProviderSelect(); createHierarchyColumnSelect(); + createCollapseAllowedSelect(); createListenerMenu(); } @@ -103,6 +106,18 @@ public class TreeGridBasicFeatures extends AbstractComponentTest<TreeGrid> { (treeGrid, value, data) -> treeGrid.setHierarchyColumn(value)); } + private void createCollapseAllowedSelect() { + LinkedHashMap<String, SerializablePredicate<HierarchicalTestBean>> options = new LinkedHashMap<>(); + options.put("all allowed", t -> true); + options.put("all disabled", t -> false); + options.put("depth 0 disabled", t -> t.getDepth() != 0); + options.put("depth 1 disabled", t -> t.getDepth() != 1); + + createSelectAction("Collapse allowed", CATEGORY_FEATURES, options, + "all allowed", (treeGrid, value, data) -> treeGrid + .setItemCollapseAllowedProvider(value)); + } + @SuppressWarnings("unchecked") private void createListenerMenu() { createListenerAction("Collapse listener", "State", diff --git a/uitest/src/test/java/com/vaadin/tests/components/treegrid/TreeGridBasicFeaturesTest.java b/uitest/src/test/java/com/vaadin/tests/components/treegrid/TreeGridBasicFeaturesTest.java index 215bef95d2..cda2ba5966 100644 --- a/uitest/src/test/java/com/vaadin/tests/components/treegrid/TreeGridBasicFeaturesTest.java +++ b/uitest/src/test/java/com/vaadin/tests/components/treegrid/TreeGridBasicFeaturesTest.java @@ -127,7 +127,7 @@ public class TreeGridBasicFeaturesTest extends MultiBrowserTest { Assert.assertFalse(logContainsText("Item expanded: 0 | 0")); Assert.assertFalse(logContainsText("Item collapsed: 0 | 0")); - grid.collapseWithClick(0); + grid.expandWithClick(0); Assert.assertTrue(logContainsText("Item expanded: 0 | 0")); Assert.assertFalse(logContainsText("Item collapsed: 0 | 0")); @@ -140,7 +140,7 @@ public class TreeGridBasicFeaturesTest extends MultiBrowserTest { selectMenuPath("Component", "State", "Expand listener"); selectMenuPath("Component", "State", "Collapse listener"); - grid.collapseWithClick(1); + grid.expandWithClick(1); grid.collapseWithClick(1); Assert.assertFalse(logContainsText("Item expanded: 0 | 1")); diff --git a/uitest/src/test/java/com/vaadin/tests/components/treegrid/TreeGridCollapseDisabledTest.java b/uitest/src/test/java/com/vaadin/tests/components/treegrid/TreeGridCollapseDisabledTest.java new file mode 100644 index 0000000000..dbb8e38b2a --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/components/treegrid/TreeGridCollapseDisabledTest.java @@ -0,0 +1,111 @@ +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 TreeGridCollapseDisabledTest extends SingleBrowserTest { + + private TreeGridElement grid; + + @Override + protected Class<?> getUIClass() { + return TreeGridBasicFeatures.class; + } + + @Before + public void before() { + openTestURL(); + grid = $(TreeGridElement.class).first(); + } + + @Test + public void collapse_disabled_for_all() { + selectMenuPath("Component", "Features", "Collapse allowed", + "all disabled"); + + // Assert first and second row can be expanded, but not collapsed + assertExpandRow(0); + assertCollapseRowDisabled(0); + + assertExpandRow(1); + assertCollapseRowDisabled(1); + } + + @Test + public void collapse_disabled_for_depth0() { + selectMenuPath("Component", "Features", "Collapse allowed", + "depth 0 disabled"); + + // Assert first row expands + assertExpandRow(0); + + // Assert second row expands and collapses + assertExpandRow(1); + assertCollapseRow(1); + + // Assert first row does not collapse + assertCollapseRowDisabled(0); + } + + @Test + public void collapse_disabled_for_depth1() { + selectMenuPath("Component", "Features", "Collapse allowed", + "depth 1 disabled"); + + // Assert first row expands + assertExpandRow(0); + + // Assert second row expands but does not collapse + assertExpandRow(1); + assertCollapseRowDisabled(1); + + // Assert first row still collapses + assertCollapseRow(0); + } + + @Test + public void collapse_disabled_mode_change_with_expanded_rows() { + // Assert first row expands + assertExpandRow(0); + + // Assert second row expands and collapses + assertExpandRow(1); + assertCollapseRow(1); + + selectMenuPath("Component", "Features", "Collapse allowed", + "depth 1 disabled"); + + Assert.assertTrue("First row should still be expanded", + grid.isRowExpanded(0, 0)); + + // Assert second row expands but does not collapse + assertExpandRow(1); + assertCollapseRowDisabled(1); + + // Assert first row still collapses + assertCollapseRow(0); + } + + private void assertExpandRow(int row) { + Assert.assertFalse(grid.isRowExpanded(row, 0)); + grid.expandWithClick(row); + Assert.assertTrue(grid.isRowExpanded(row, 0)); + } + + private void assertCollapseRow(int row) { + Assert.assertTrue("Row not expanded", grid.isRowExpanded(row, 0)); + grid.collapseWithClick(row); + Assert.assertFalse("Row did not collapse", grid.isRowExpanded(row, 0)); + } + + private void assertCollapseRowDisabled(int row) { + Assert.assertTrue("Row not expanded", grid.isRowExpanded(row, 0)); + grid.collapseWithClick(row); + Assert.assertTrue("Row should not collapse", + grid.isRowExpanded(row, 0)); + } +} diff --git a/uitest/src/test/java/com/vaadin/tests/components/treegrid/TreeGridScrollingTest.java b/uitest/src/test/java/com/vaadin/tests/components/treegrid/TreeGridScrollingTest.java index be7953ba35..b4bc65e1ce 100644 --- a/uitest/src/test/java/com/vaadin/tests/components/treegrid/TreeGridScrollingTest.java +++ b/uitest/src/test/java/com/vaadin/tests/components/treegrid/TreeGridScrollingTest.java @@ -129,7 +129,7 @@ public class TreeGridScrollingTest extends SingleBrowserTest { verifyRow(1, 1, 0); verifyRow(0, 0, 0); - grid.expandWithClick(3); + grid.collapseWithClick(3); verifyRow(0, 0, 0); verifyRow(1, 1, 0); @@ -144,7 +144,7 @@ public class TreeGridScrollingTest extends SingleBrowserTest { verifyRow(1, 1, 0); verifyRow(0, 0, 0); - grid.expandWithClick(0); + grid.collapseWithClick(0); verifyRow(0, 0, 0); verifyRow(10, 0, 10); |