diff options
author | Teemu Suo-Anttila <tsuoanttila@users.noreply.github.com> | 2017-06-13 17:00:53 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-06-13 17:00:53 +0300 |
commit | af5c46b6e064721b6639e6fab2e6e21988c713c1 (patch) | |
tree | f19a7f775486ac41cc127a5c02c5d60c2b81d217 /uitest | |
parent | cb1a2b99472faabba3596d673dbdbc377fb1628a (diff) | |
download | vaadin-framework-af5c46b6e064721b6639e6fab2e6e21988c713c1.tar.gz vaadin-framework-af5c46b6e064721b6639e6fab2e6e21988c713c1.zip |
Allow changing the renderer of hierarchy column in TreeGrid (#9514)
Addresses #9465
Diffstat (limited to 'uitest')
-rw-r--r-- | uitest/src/main/java/com/vaadin/tests/components/treegrid/TreeGridBasicFeatures.java | 24 | ||||
-rw-r--r-- | uitest/src/test/java/com/vaadin/tests/components/treegrid/TreeGridBasicFeaturesTest.java | 64 |
2 files changed, 50 insertions, 38 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 0c29f71294..2ac0c0673d 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 @@ -4,6 +4,7 @@ import java.util.Arrays; import java.util.LinkedHashMap; import java.util.List; import java.util.Optional; +import java.util.function.Consumer; import java.util.stream.Stream; import com.vaadin.annotations.Theme; @@ -17,9 +18,12 @@ import com.vaadin.server.SerializablePredicate; import com.vaadin.shared.Range; import com.vaadin.tests.components.AbstractComponentTest; import com.vaadin.tests.data.bean.HierarchicalTestBean; +import com.vaadin.ui.Grid.Column; import com.vaadin.ui.Grid.SelectionMode; import com.vaadin.ui.ItemCollapseAllowedProvider; import com.vaadin.ui.TreeGrid; +import com.vaadin.ui.renderers.HtmlRenderer; +import com.vaadin.ui.renderers.TextRenderer; @Theme("valo") @Widgetset("com.vaadin.DefaultWidgetSet") @@ -29,6 +33,7 @@ public class TreeGridBasicFeatures extends AbstractComponentTest<TreeGrid> { private TreeDataProvider<HierarchicalTestBean> inMemoryDataProvider; private LazyHierarchicalDataProvider lazyDataProvider; private HierarchicalDataProvider<HierarchicalTestBean, ?> loggingDataProvider; + private Column<HierarchicalTestBean, String> hierarchyColumn; @Override public TreeGrid getComponent() { @@ -45,8 +50,9 @@ public class TreeGridBasicFeatures extends AbstractComponentTest<TreeGrid> { initializeDataProviders(); grid = new TreeGrid<>(); grid.setSizeFull(); - grid.addColumn(HierarchicalTestBean::toString).setCaption("String") - .setId("string"); + hierarchyColumn = grid.addColumn(HierarchicalTestBean::toString); + hierarchyColumn.setCaption("String").setId("string").setStyleGenerator( + t -> hierarchyColumn.getRenderer().getClass().getSimpleName()); grid.addColumn(HierarchicalTestBean::getDepth).setCaption("Depth") .setId("depth").setDescriptionGenerator( t -> "Hierarchy depth: " + t.getDepth()); @@ -66,6 +72,7 @@ public class TreeGridBasicFeatures extends AbstractComponentTest<TreeGrid> { createDataProviderSelect(); createHierarchyColumnSelect(); createCollapseAllowedSelect(); + createRendererSelect(); createExpandMenu(); createCollapseMenu(); createListenerMenu(); @@ -94,8 +101,7 @@ public class TreeGridBasicFeatures extends AbstractComponentTest<TreeGrid> { inMemoryDataProvider = new TreeDataProvider<>(data); lazyDataProvider = new LazyHierarchicalDataProvider(3, 2); - loggingDataProvider = new TreeDataProvider<HierarchicalTestBean>( - data) { + loggingDataProvider = new TreeDataProvider<HierarchicalTestBean>(data) { @Override public Stream<HierarchicalTestBean> fetchChildren( @@ -152,6 +158,16 @@ public class TreeGridBasicFeatures extends AbstractComponentTest<TreeGrid> { .setItemCollapseAllowedProvider(value)); } + private void createRendererSelect() { + LinkedHashMap<String, Consumer<Column<?, String>>> options = new LinkedHashMap<>(); + options.put("text", c -> c.setRenderer(new TextRenderer())); + options.put("html", c -> c.setRenderer(new HtmlRenderer())); + + createSelectAction("Hierarchy column renderer", CATEGORY_FEATURES, + options, "text", + (treeGrid, consumer, data) -> consumer.accept(hierarchyColumn)); + } + @SuppressWarnings("unchecked") private void createExpandMenu() { createCategory("Server-side expand", CATEGORY_FEATURES); 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 c73418675a..43c08415df 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 @@ -136,58 +136,48 @@ public class TreeGridBasicFeaturesTest extends MultiBrowserTest { new Actions(getDriver()).sendKeys(Keys.RIGHT).perform(); assertEquals(6, grid.getRowCount()); assertCellTexts(1, 0, new String[] { "1 | 0", "1 | 1", "1 | 2" }); - assertTrue( - grid.getRow(0).hasClassName("v-treegrid-row-focused")); - assertFalse( - grid.getRow(1).hasClassName("v-treegrid-row-focused")); + assertTrue(grid.getRow(0).hasClassName("v-treegrid-row-focused")); + assertFalse(grid.getRow(1).hasClassName("v-treegrid-row-focused")); // Should navigate 2 times down to "1 | 1" new Actions(getDriver()).sendKeys(Keys.DOWN, Keys.DOWN).perform(); assertEquals(6, grid.getRowCount()); assertCellTexts(1, 0, new String[] { "1 | 0", "1 | 1", "1 | 2" }); - assertFalse( - grid.getRow(0).hasClassName("v-treegrid-row-focused")); - assertFalse( - grid.getRow(1).hasClassName("v-treegrid-row-focused")); - assertTrue( - grid.getRow(2).hasClassName("v-treegrid-row-focused")); + assertFalse(grid.getRow(0).hasClassName("v-treegrid-row-focused")); + assertFalse(grid.getRow(1).hasClassName("v-treegrid-row-focused")); + assertTrue(grid.getRow(2).hasClassName("v-treegrid-row-focused")); // Should expand "1 | 1" without moving focus new Actions(getDriver()).sendKeys(Keys.RIGHT).perform(); assertEquals(9, grid.getRowCount()); assertCellTexts(2, 0, new String[] { "1 | 1", "2 | 0", "2 | 1", "2 | 2", "1 | 2" }); - assertTrue( - grid.getRow(2).hasClassName("v-treegrid-row-focused")); + assertTrue(grid.getRow(2).hasClassName("v-treegrid-row-focused")); // Should collapse "1 | 1" new Actions(getDriver()).sendKeys(Keys.LEFT).perform(); assertEquals(6, grid.getRowCount()); assertCellTexts(2, 0, new String[] { "1 | 1", "1 | 2", "0 | 1" }); - assertTrue( - grid.getRow(2).hasClassName("v-treegrid-row-focused")); + assertTrue(grid.getRow(2).hasClassName("v-treegrid-row-focused")); // Should navigate to "0 | 0" new Actions(getDriver()).sendKeys(Keys.LEFT).perform(); assertEquals(6, grid.getRowCount()); assertCellTexts(0, 0, new String[] { "0 | 0", "1 | 0", "1 | 1", "1 | 2", "0 | 1" }); - assertTrue( - grid.getRow(0).hasClassName("v-treegrid-row-focused")); + assertTrue(grid.getRow(0).hasClassName("v-treegrid-row-focused")); // Should collapse "0 | 0" new Actions(getDriver()).sendKeys(Keys.LEFT).perform(); assertEquals(3, grid.getRowCount()); assertCellTexts(0, 0, new String[] { "0 | 0", "0 | 1", "0 | 2" }); - assertTrue( - grid.getRow(0).hasClassName("v-treegrid-row-focused")); + assertTrue(grid.getRow(0).hasClassName("v-treegrid-row-focused")); // Nothing should happen new Actions(getDriver()).sendKeys(Keys.LEFT).perform(); assertEquals(3, grid.getRowCount()); assertCellTexts(0, 0, new String[] { "0 | 0", "0 | 1", "0 | 2" }); - assertTrue( - grid.getRow(0).hasClassName("v-treegrid-row-focused")); + assertTrue(grid.getRow(0).hasClassName("v-treegrid-row-focused")); assertNoErrorNotifications(); } @@ -205,12 +195,9 @@ public class TreeGridBasicFeaturesTest extends MultiBrowserTest { new Actions(getDriver()).sendKeys(Keys.DOWN, Keys.DOWN).perform(); assertEquals(6, grid.getRowCount()); assertCellTexts(1, 0, new String[] { "1 | 0", "1 | 1", "1 | 2" }); - assertFalse( - grid.getRow(0).hasClassName("v-treegrid-row-focused")); - assertFalse( - grid.getRow(1).hasClassName("v-treegrid-row-focused")); - assertTrue( - grid.getRow(2).hasClassName("v-treegrid-row-focused")); + assertFalse(grid.getRow(0).hasClassName("v-treegrid-row-focused")); + assertFalse(grid.getRow(1).hasClassName("v-treegrid-row-focused")); + assertTrue(grid.getRow(2).hasClassName("v-treegrid-row-focused")); // Should select "1 | 1" without moving focus new Actions(getDriver()).sendKeys(Keys.SPACE).perform(); @@ -218,19 +205,15 @@ public class TreeGridBasicFeaturesTest extends MultiBrowserTest { // Should move focus but not selection new Actions(getDriver()).sendKeys(Keys.UP).perform(); - assertTrue( - grid.getRow(1).hasClassName("v-treegrid-row-focused")); - assertFalse( - grid.getRow(2).hasClassName("v-treegrid-row-focused")); + assertTrue(grid.getRow(1).hasClassName("v-treegrid-row-focused")); + assertFalse(grid.getRow(2).hasClassName("v-treegrid-row-focused")); assertFalse(grid.getRow(1).hasClassName("v-treegrid-row-selected")); assertTrue(grid.getRow(2).hasClassName("v-treegrid-row-selected")); // Should select "1 | 0" without moving focus new Actions(getDriver()).sendKeys(Keys.SPACE).perform(); - assertTrue( - grid.getRow(1).hasClassName("v-treegrid-row-focused")); - assertFalse( - grid.getRow(2).hasClassName("v-treegrid-row-focused")); + assertTrue(grid.getRow(1).hasClassName("v-treegrid-row-focused")); + assertFalse(grid.getRow(2).hasClassName("v-treegrid-row-focused")); assertTrue(grid.getRow(1).hasClassName("v-treegrid-row-selected")); assertFalse(grid.getRow(2).hasClassName("v-treegrid-row-selected")); @@ -339,6 +322,19 @@ public class TreeGridBasicFeaturesTest extends MultiBrowserTest { assertEquals(9, grid.getRowCount()); } + @Test + public void change_renderer_of_hierarchy_column() { + assertTrue("Cell style names should contain renderer name", grid + .getCell(0, 0).getAttribute("class").contains("TextRenderer")); + selectMenuPath("Component", "Features", "Hierarchy column renderer", + "html"); + assertTrue("Cell style names should contain renderer name", grid + .getCell(0, 0).getAttribute("class").contains("HtmlRenderer")); + + grid.expandWithClick(0); + assertEquals("Not expanded", "1 | 0", grid.getCell(1, 0).getText()); + } + private void assertCellTexts(int startRowIndex, int cellIndex, String[] cellTexts) { int index = startRowIndex; |