summaryrefslogtreecommitdiffstats
path: root/uitest
diff options
context:
space:
mode:
authorIlia Motornyi <elmot@vaadin.com>2018-02-15 15:33:05 +0200
committerGitHub <noreply@github.com>2018-02-15 15:33:05 +0200
commit6d84351fee4bdb6e877d9100c8645e6c6044864e (patch)
treee11270aa15b3b348b9ee3ff8714fc126b4a6af34 /uitest
parentfd4dedf921f6cf0f80bfedac8474562b41325e56 (diff)
downloadvaadin-framework-6d84351fee4bdb6e877d9100c8645e6c6044864e.tar.gz
vaadin-framework-6d84351fee4bdb6e877d9100c8645e6c6044864e.zip
Allow configuring content modes for Grid cell tooltips (#10632)
* Allow configuring content modes for Grid cell tooltips
Diffstat (limited to 'uitest')
-rw-r--r--uitest/src/main/java/com/vaadin/v7/tests/components/grid/basicfeatures/GridBasicFeatures.java43
-rw-r--r--uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/GridDescriptionGeneratorTest.java83
2 files changed, 114 insertions, 12 deletions
diff --git a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/basicfeatures/GridBasicFeatures.java b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/basicfeatures/GridBasicFeatures.java
index 700a79d14a..354222ce4f 100644
--- a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/basicfeatures/GridBasicFeatures.java
+++ b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/basicfeatures/GridBasicFeatures.java
@@ -30,6 +30,7 @@ import java.util.Random;
import com.vaadin.annotations.Theme;
import com.vaadin.shared.data.sort.SortDirection;
+import com.vaadin.shared.ui.ContentMode;
import com.vaadin.tests.components.AbstractComponentTest;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
@@ -138,7 +139,7 @@ public class GridBasicFeatures extends AbstractComponentTest<Grid> {
@Override
public String getDescription(RowReference row) {
- return "Row tooltip for row " + row.getItemId();
+ return "<b>Row</b> tooltip\n for row " + row.getItemId();
}
};
@@ -147,7 +148,7 @@ public class GridBasicFeatures extends AbstractComponentTest<Grid> {
@Override
public String getDescription(CellReference cell) {
if ("Column 0".equals(cell.getPropertyId())) {
- return "Cell tooltip for row " + cell.getItemId()
+ return "<b>Cell</b> tooltip\n for row " + cell.getItemId()
+ ", column 0";
} else {
return null;
@@ -668,22 +669,40 @@ public class GridBasicFeatures extends AbstractComponentTest<Grid> {
}
});
- createBooleanAction("Row description generator", "State", false,
- new Command<Grid, Boolean>() {
+ LinkedHashMap<String, ContentMode> contentModes = new LinkedHashMap<String, ContentMode>();
+ contentModes.put("None", null);
+ // Abusing an unused value for this special case
+ contentModes.put("Plain text", ContentMode.TEXT);
+ contentModes.put("Preformatted(Default)", ContentMode.PREFORMATTED);
+ contentModes.put("HTML", ContentMode.HTML);
+ createSelectAction("Row description generator", "State", contentModes,
+ "None", new Command<Grid, ContentMode>() {
@Override
- public void execute(Grid c, Boolean value, Object data) {
- c.setRowDescriptionGenerator(
- value ? rowDescriptionGenerator : null);
+ public void execute(Grid grid, ContentMode mode, Object data) {
+ if (mode == null) {
+ grid.setRowDescriptionGenerator(null);
+ } else if (mode == ContentMode.PREFORMATTED) {
+ grid.setRowDescriptionGenerator(rowDescriptionGenerator);
+ } else {
+ grid.setRowDescriptionGenerator(
+ rowDescriptionGenerator, mode);
+ }
}
});
- createBooleanAction("Cell description generator", "State", false,
- new Command<Grid, Boolean>() {
+ createSelectAction("Cell description generator", "State",
+ contentModes, "None", new Command<Grid, ContentMode>() {
@Override
- public void execute(Grid c, Boolean value, Object data) {
- c.setCellDescriptionGenerator(
- value ? cellDescriptionGenerator : null);
+ public void execute(Grid grid, ContentMode mode, Object data) {
+ if (mode == null) {
+ grid.setCellDescriptionGenerator(null);
+ } else if (mode == ContentMode.PREFORMATTED) {
+ grid.setCellDescriptionGenerator(cellDescriptionGenerator);
+ } else {
+ grid.setCellDescriptionGenerator(
+ cellDescriptionGenerator, mode);
+ }
}
});
diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/GridDescriptionGeneratorTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/GridDescriptionGeneratorTest.java
index 9e31a0e096..41dbcca649 100644
--- a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/GridDescriptionGeneratorTest.java
+++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/GridDescriptionGeneratorTest.java
@@ -16,6 +16,7 @@
package com.vaadin.v7.tests.components.grid.basicfeatures;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.util.List;
@@ -75,6 +76,88 @@ public class GridDescriptionGeneratorTest extends GridBasicFeaturesTest {
assertEquals("Tooltip text", "Row tooltip for row 5", tooltipText);
}
+ @Test
+ public void testContentTypes() {
+ openTestURL();
+
+ selectCellGenerator("Default");
+ showCellTooltip(1, 0);
+ /*
+ * When porting this to the v7 version in Framework 8, the default
+ * should be changed to PREFORMATTED to preserve the more secure default
+ * that has accidentally been used there.
+ */
+ assertHtmlTooltipShown();
+
+ selectRowGenerator("Default");
+ showCellTooltip(1, 1);
+ /*
+ * When porting this to the v7 version in Framework 8, the default
+ * should be changed to PREFORMATTED to preserve the more secure default
+ * that has accidentally been used there.
+ */
+ assertHtmlTooltipShown();
+
+ selectCellGenerator("Plain text");
+ showCellTooltip(2, 0);
+ assertPlainTooltipShown();
+
+ selectRowGenerator("Plain text");
+ showCellTooltip(2, 1);
+ assertPlainTooltipShown();
+
+ selectCellGenerator("Preformatted");
+ showCellTooltip(3, 0);
+ assertPreTooltipShown();
+
+ selectRowGenerator("Preformatted");
+ showCellTooltip(3, 1);
+ assertPreTooltipShown();
+
+ selectCellGenerator("HTML");
+ showCellTooltip(4, 0);
+ assertHtmlTooltipShown();
+
+ selectRowGenerator("HTML");
+ showCellTooltip(4, 1);
+ assertHtmlTooltipShown();
+ }
+
+ private void assertPreTooltipShown() {
+ assertTrue("Tooltip should contain <b> as text", getTooltipText()
+ .contains("<b>"));
+ assertTrue("Tooltip should contain a newline", getTooltipText()
+ .contains("\n"));
+ }
+
+ private void assertPlainTooltipShown() {
+ assertTrue("Tooltip should contain <b> as text", getTooltipText()
+ .contains("<b>"));
+ assertFalse("Tooltip should not contain a newline", getTooltipText()
+ .contains("\n"));
+ }
+
+ private void assertHtmlTooltipShown() {
+ assertTrue("Tooltip should contain <b> tag",
+ isElementPresent(By.cssSelector(".v-tooltip-text b")));
+ }
+
+ private void showCellTooltip(int row, int col) {
+ getGridElement().getCell(row, col).showTooltip();
+ }
+
+ private void selectCellGenerator(String name) {
+ selectMenuPath("Component", "State", "Cell description generator", name);
+ }
+
+ private void selectRowGenerator(String name) {
+ selectMenuPath("Component", "State", "Row description generator", name);
+ }
+
+ private String getTooltipText() {
+ return findElement(By.className("v-tooltip-text")).getText();
+ }
+
@Override
public List<DesiredCapabilities> getBrowsersToTest() {
return getBrowsersExcludingFirefox();