From 0e7755958b46434185cb1e6e2ec8aa6932b32f34 Mon Sep 17 00:00:00 2001 From: Pekka Hyvönen Date: Mon, 23 Mar 2015 13:42:07 +0200 Subject: API for column hiding toggle caption in Grid (#17272) Fixes column toggle not getting a caption when a hidable column is added. Fixes column toggle not getting a caption on columns with widget in header. Change-Id: Ie10ada793a3635302603f684f232cadaef74a982 --- .../grid/basicfeatures/GridBasicFeatures.java | 31 +++++++++++--- .../grid/basicfeatures/GridColumnReorderTest.java | 2 +- .../server/GridColumnVisibilityTest.java | 50 +++++++++++++++++++--- 3 files changed, 70 insertions(+), 13 deletions(-) (limited to 'uitest') diff --git a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridBasicFeatures.java b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridBasicFeatures.java index d3b1237cf9..6f4c7df38c 100644 --- a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridBasicFeatures.java +++ b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridBasicFeatures.java @@ -768,17 +768,23 @@ public class GridBasicFeatures extends AbstractComponentTest { new Command() { boolean wasHidable; + boolean wasHidden; + String wasColumnHidingToggleCaption; @Override public void execute(Grid grid, String value, Object data) { String columnProperty = getColumnProperty((Integer) data); - if (grid.getColumn(columnProperty) == null) { - grid.addColumn(columnProperty); - grid.getColumn(columnProperty).setHidable( - wasHidable); + Column column = grid.getColumn(columnProperty); + if (column == null) { + column = grid.addColumn(columnProperty); + column.setHidable(wasHidable); + column.setHidden(wasHidden); + column.setHidingToggleCaption(wasColumnHidingToggleCaption); } else { - wasHidable = grid.getColumn(columnProperty) - .isHidable(); + wasHidable = column.isHidable(); + wasHidden = column.isHidden(); + wasColumnHidingToggleCaption = column + .getHidingToggleCaption(); grid.removeColumn(columnProperty); } } @@ -840,6 +846,19 @@ public class GridBasicFeatures extends AbstractComponentTest { grid.getColumn(propertyId).setHidden(hidden); } }, getColumnProperty(c)); + createClickAction("Change hiding toggle caption", + getColumnProperty(c), new Command() { + int count = 0; + + @Override + public void execute(Grid grid, String value, Object data) { + final String columnProperty = getColumnProperty((Integer) data); + grid.getColumn(columnProperty) + .setHidingToggleCaption( + columnProperty + " caption " + + count++); + } + }, null, c); createCategory("Column " + c + " Width", getColumnProperty(c)); diff --git a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridColumnReorderTest.java b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridColumnReorderTest.java index 68ba5f5c54..d779a5c81a 100644 --- a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridColumnReorderTest.java +++ b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridColumnReorderTest.java @@ -369,7 +369,7 @@ public class GridColumnReorderTest extends GridBasicClientFeaturesTest { assertColumnHeaderOrder(1, 3, 4, 5, 2); // when then - dragAndDropColumnHeader(0, 1, 3, CellSide.RIGHT); + dragAndDropColumnHeader(0, 1, 4, CellSide.LEFT); assertColumnHeaderOrder(1, 4, 3, 5, 2); dragAndDropColumnHeader(0, 2, 4, CellSide.LEFT); diff --git a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridColumnVisibilityTest.java b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridColumnVisibilityTest.java index 37eda1c28f..7942650576 100644 --- a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridColumnVisibilityTest.java +++ b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridColumnVisibilityTest.java @@ -24,7 +24,6 @@ import static org.junit.Assert.assertTrue; import java.util.List; import org.junit.Before; -import org.junit.Ignore; import org.junit.Test; import org.openqa.selenium.By; import org.openqa.selenium.WebElement; @@ -139,12 +138,15 @@ public class GridColumnVisibilityTest extends GridBasicFeaturesTest { } @Test - @Ignore - // known issue, column caption not passed to toggle when added again - public void testColumnHiding_whenHidableColumnAdded_toggleAdded() { + public void testColumnHiding_whenHidableColumnAdded_toggleWithCorrectCaptionAdded() { selectMenuPath("Component", "Size", "Width", "100%"); toggleColumnHidable(0); toggleColumnHidable(1); + toggleColumnHidingToggleCaptionChange(0); + getSidebarOpenButton().click(); + assertEquals("Column 0 caption 0", getColumnHidingToggle(0).getText()); + getSidebarOpenButton().click(); + addRemoveColumn(0); addRemoveColumn(4); addRemoveColumn(5); @@ -163,7 +165,43 @@ public class GridColumnVisibilityTest extends GridBasicFeaturesTest { assertColumnHeaderOrder(1, 2, 3, 11, 0); getSidebarOpenButton().click(); - assertNotNull(getColumnHidingToggle(0)); + assertEquals("Column 0 caption 0", getColumnHidingToggle(0).getText()); + } + + @Test + public void testColumnHidingToggleCaption_settingToggleCaption_updatesToggle() { + toggleColumnHidable(1); + getSidebarOpenButton().click(); + assertEquals("column 1", getGridElement().getHeaderCell(0, 1).getText() + .toLowerCase()); + assertEquals("Column 1", getColumnHidingToggle(1).getText()); + + toggleColumnHidingToggleCaptionChange(1); + assertEquals("column 1", getGridElement().getHeaderCell(0, 1).getText() + .toLowerCase()); + assertEquals("Column 1 caption 0", getColumnHidingToggle(1).getText()); + + toggleColumnHidingToggleCaptionChange(1); + assertEquals("Column 1 caption 1", getColumnHidingToggle(1).getText()); + } + + @Test + public void testColumnHidingToggleCaption_settingWidgetToHeader_toggleCaptionStays() { + toggleColumnHidable(1); + getSidebarOpenButton().click(); + assertEquals("column 1", getGridElement().getHeaderCell(0, 1).getText() + .toLowerCase()); + assertEquals("Column 1", getColumnHidingToggle(1).getText()); + + selectMenuPath("Component", "Columns", "Column 1", "Header Type", + "Widget Header"); + + assertEquals("Column 1", getColumnHidingToggle(1).getText()); + } + + private void toggleColumnHidingToggleCaptionChange(int index) { + selectMenuPath("Component", "Columns", "Column " + index, + "Change hiding toggle caption"); } @Test @@ -264,7 +302,7 @@ public class GridColumnVisibilityTest extends GridBasicFeaturesTest { List elements = sidebar.findElements(By .className("column-hiding-toggle")); for (WebElement e : elements) { - if (("Column " + columnIndex).equalsIgnoreCase(e.getText())) { + if ((e.getText().toLowerCase()).startsWith("column " + columnIndex)) { return e; } } -- cgit v1.2.3