summaryrefslogtreecommitdiffstats
path: root/uitest
diff options
context:
space:
mode:
authorTeemu Suo-Anttila <tsuoanttila@users.noreply.github.com>2017-11-10 15:46:57 +0100
committerPéter Török <31210544+torok-peter@users.noreply.github.com>2017-11-10 16:46:57 +0200
commit37bd6b1a32c9d5d6a53755de8bb1a94556b4471b (patch)
treebe2f97ccada0e6c261536450da29e62bf5d871c9 /uitest
parentfe2b4d941fdfe06fbb79d3e9168618592136c337 (diff)
downloadvaadin-framework-37bd6b1a32c9d5d6a53755de8bb1a94556b4471b.tar.gz
vaadin-framework-37bd6b1a32c9d5d6a53755de8bb1a94556b4471b.zip
Add ContentMode for row and cell descriptions in Grid (#10282)
Diffstat (limited to 'uitest')
-rw-r--r--uitest/src/main/java/com/vaadin/tests/components/grid/basics/GridBasics.java72
-rw-r--r--uitest/src/test/java/com/vaadin/tests/components/grid/basics/GridDescriptionGeneratorTest.java127
2 files changed, 170 insertions, 29 deletions
diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/basics/GridBasics.java b/uitest/src/main/java/com/vaadin/tests/components/grid/basics/GridBasics.java
index 5c580c89f3..ef7533d082 100644
--- a/uitest/src/main/java/com/vaadin/tests/components/grid/basics/GridBasics.java
+++ b/uitest/src/main/java/com/vaadin/tests/components/grid/basics/GridBasics.java
@@ -23,6 +23,7 @@ import com.vaadin.event.selection.SingleSelectionEvent;
import com.vaadin.server.VaadinRequest;
import com.vaadin.shared.Registration;
import com.vaadin.shared.data.sort.SortDirection;
+import com.vaadin.shared.ui.ContentMode;
import com.vaadin.shared.ui.grid.ColumnResizeMode;
import com.vaadin.shared.ui.grid.HeightMode;
import com.vaadin.tests.components.AbstractTestUIWithLog;
@@ -42,6 +43,7 @@ import com.vaadin.ui.SingleSelect;
import com.vaadin.ui.StyleGenerator;
import com.vaadin.ui.TextField;
import com.vaadin.ui.VerticalLayout;
+import com.vaadin.ui.components.grid.DescriptionGenerator;
import com.vaadin.ui.components.grid.DetailsGenerator;
import com.vaadin.ui.components.grid.FooterCell;
import com.vaadin.ui.components.grid.FooterRow;
@@ -256,8 +258,7 @@ public class GridBasics extends AbstractTestUIWithLog {
private void onSingleSelect(SingleSelectionEvent<DataObject> event) {
log("SingleSelectionEvent: Selected: "
+ (event.getSelectedItem().isPresent()
- ? event.getSelectedItem().get().toString()
- : "none"));
+ ? event.getSelectedItem().get().toString() : "none"));
}
private void onMultiSelect(MultiSelectionEvent<DataObject> event) {
@@ -268,8 +269,7 @@ public class GridBasics extends AbstractTestUIWithLog {
String addedRow = firstAdded.isPresent() ? firstAdded.get().toString()
: "none";
String removedRow = firstRemoved.isPresent()
- ? firstRemoved.get().toString()
- : "none";
+ ? firstRemoved.get().toString() : "none";
log("SelectionEvent: Added " + addedRow + ", Removed " + removedRow);
}
@@ -363,11 +363,9 @@ public class GridBasics extends AbstractTestUIWithLog {
}
columnsMenu.addItem("Clear sort", item -> grid.clearSortOrder());
- columnsMenu
- .addItem("Simple resize mode",
- item -> grid.setColumnResizeMode(
- item.isChecked() ? ColumnResizeMode.SIMPLE
- : ColumnResizeMode.ANIMATED))
+ columnsMenu.addItem("Simple resize mode",
+ item -> grid.setColumnResizeMode(item.isChecked()
+ ? ColumnResizeMode.SIMPLE : ColumnResizeMode.ANIMATED))
.setCheckable(true);
}
@@ -405,18 +403,10 @@ public class GridBasics extends AbstractTestUIWithLog {
}
createRowStyleMenu(stateMenu.addItem("Row style generator", null));
createCellStyleMenu(stateMenu.addItem("Cell style generator", null));
- stateMenu.addItem("Row description generator",
- item -> grid.setDescriptionGenerator(item.isChecked()
- ? t -> "Row tooltip for row " + t.getRowNumber()
- : null))
- .setCheckable(true);
- stateMenu.addItem("Cell description generator",
- item -> grid.getColumns().stream().findFirst().ifPresent(
- c -> c.setDescriptionGenerator(item.isChecked()
- ? t -> "Cell tooltip for row "
- + t.getRowNumber() + ", Column 0"
- : null)))
- .setCheckable(true);
+ createRowDescriptionMenu(
+ stateMenu.addItem("Row description generator", null));
+ createCellDescriptionMenu(
+ stateMenu.addItem("Cell description generator", null));
stateMenu.addItem("Item click listener", new Command() {
private Registration registration = null;
@@ -430,8 +420,7 @@ public class GridBasics extends AbstractTestUIWithLog {
!grid.isDetailsVisible(event.getItem()));
log("Item click on row "
+ event.getItem().getRowNumber() + ", Column '"
- + event.getColumn().getCaption()
- + "'");
+ + event.getColumn().getCaption() + "'");
});
log("Registered an item click listener.");
}
@@ -481,6 +470,43 @@ public class GridBasics extends AbstractTestUIWithLog {
stateMenu.addItem("Set focus", item -> grid.focus());
}
+ private void createRowDescriptionMenu(MenuItem rowDescriptionMenu) {
+ DescriptionGenerator<DataObject> description = t -> "Row tooltip for row <b>"
+ + t.getRowNumber() + "</b>";
+ DescriptionGenerator<DataObject> halfEmpty = t -> t.getRowNumber()
+ % 2 == 0 ? description.apply(t) : null;
+
+ addGridMethodMenu(rowDescriptionMenu, "Remove descriptions", null,
+ g -> grid.setDescriptionGenerator(null));
+ addGridMethodMenu(rowDescriptionMenu, "Preformatted", description,
+ generator -> grid.setDescriptionGenerator(generator));
+ addGridMethodMenu(rowDescriptionMenu, "HTML", description,
+ generator -> grid.setDescriptionGenerator(generator,
+ ContentMode.HTML));
+ addGridMethodMenu(rowDescriptionMenu, "Even rows HTML", halfEmpty,
+ generator -> grid.setDescriptionGenerator(generator,
+ ContentMode.HTML));
+ }
+
+ private void createCellDescriptionMenu(MenuItem cellDescriptionMenu) {
+ Column<DataObject, ?> column = grid.getColumns().get(0);
+ DescriptionGenerator<DataObject> description = t -> "Cell tooltip for row <b>"
+ + t.getRowNumber() + "</b>, " + column.getCaption();
+ DescriptionGenerator<DataObject> halfEmpty = t -> t.getRowNumber()
+ % 2 == 0 ? description.apply(t) : null;
+
+ addGridMethodMenu(cellDescriptionMenu, "Remove descriptions", null,
+ g -> column.setDescriptionGenerator(null));
+ addGridMethodMenu(cellDescriptionMenu, "Preformatted", description,
+ generator -> column.setDescriptionGenerator(generator));
+ addGridMethodMenu(cellDescriptionMenu, "HTML", description,
+ generator -> column.setDescriptionGenerator(generator,
+ ContentMode.HTML));
+ addGridMethodMenu(cellDescriptionMenu, "Even rows HTML", halfEmpty,
+ generator -> column.setDescriptionGenerator(generator,
+ ContentMode.HTML));
+ }
+
private void createRowStyleMenu(MenuItem rowStyleMenu) {
addGridMethodMenu(rowStyleMenu, ROW_STYLE_GENERATOR_NONE,
(StyleGenerator<DataObject>) t -> null,
diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/basics/GridDescriptionGeneratorTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/basics/GridDescriptionGeneratorTest.java
index 58ded39798..3cbb3da26d 100644
--- a/uitest/src/test/java/com/vaadin/tests/components/grid/basics/GridDescriptionGeneratorTest.java
+++ b/uitest/src/test/java/com/vaadin/tests/components/grid/basics/GridDescriptionGeneratorTest.java
@@ -24,9 +24,28 @@ import org.openqa.selenium.By;
public class GridDescriptionGeneratorTest extends GridBasicsTest {
@Test
- public void testCellDescription() {
+ public void testPreformattedCellDescription() {
openTestURL();
- selectMenuPath("Component", "State", "Cell description generator");
+ selectMenuPath("Component", "State", "Cell description generator",
+ "Preformatted");
+
+ getGridElement().getCell(1, 0).showTooltip();
+ String tooltipText = findElement(By.className("v-tooltip-text"))
+ .getText();
+ assertEquals("Tooltip text", "Cell tooltip for row <b>1</b>, Column 0",
+ tooltipText);
+
+ getGridElement().getCell(1, 1).showTooltip();
+ assertTrue("Tooltip should not be present in cell (1, 1) ",
+ findElement(By.className("v-tooltip-text")).getText()
+ .isEmpty());
+ }
+
+ @Test
+ public void testHTMLCellDescription() {
+ openTestURL();
+ selectMenuPath("Component", "State", "Cell description generator",
+ "HTML");
getGridElement().getCell(1, 0).showTooltip();
String tooltipText = findElement(By.className("v-tooltip-text"))
@@ -41,9 +60,46 @@ public class GridDescriptionGeneratorTest extends GridBasicsTest {
}
@Test
- public void testRowDescription() {
+ public void testHTMLCellDescriptionOnEvenRows() {
+ openTestURL();
+ selectMenuPath("Component", "State", "Cell description generator",
+ "Even rows HTML");
+
+ getGridElement().getCell(0, 0).showTooltip();
+ String tooltipText = findElement(By.className("v-tooltip-text"))
+ .getText();
+ assertEquals("Tooltip text", "Cell tooltip for row 0, Column 0",
+ tooltipText);
+
+ getGridElement().getCell(1, 0).showTooltip();
+ assertTrue("Tooltip should not be present in cell (1, 0) ",
+ findElement(By.className("v-tooltip-text")).getText()
+ .isEmpty());
+ }
+
+ @Test
+ public void testPreformattedRowDescription() {
+ openTestURL();
+ selectMenuPath("Component", "State", "Row description generator",
+ "Preformatted");
+
+ getGridElement().getCell(5, 3).showTooltip();
+ String tooltipText = findElement(By.className("v-tooltip-text"))
+ .getText();
+ assertEquals("Tooltip text", "Row tooltip for row <b>5</b>",
+ tooltipText);
+
+ getGridElement().getCell(15, 3).showTooltip();
+ tooltipText = findElement(By.className("v-tooltip-text")).getText();
+ assertEquals("Tooltip text", "Row tooltip for row <b>15</b>",
+ tooltipText);
+ }
+
+ @Test
+ public void testHTMLRowDescription() {
openTestURL();
- selectMenuPath("Component", "State", "Row description generator");
+ selectMenuPath("Component", "State", "Row description generator",
+ "HTML");
getGridElement().getCell(5, 3).showTooltip();
String tooltipText = findElement(By.className("v-tooltip-text"))
@@ -56,10 +112,29 @@ public class GridDescriptionGeneratorTest extends GridBasicsTest {
}
@Test
+ public void testHTMLRowDescriptionOnEvenRows() {
+ openTestURL();
+ selectMenuPath("Component", "State", "Row description generator",
+ "Even rows HTML");
+
+ getGridElement().getCell(4, 3).showTooltip();
+ String tooltipText = findElement(By.className("v-tooltip-text"))
+ .getText();
+ assertEquals("Tooltip text", "Row tooltip for row 4", tooltipText);
+
+ getGridElement().getCell(5, 3).showTooltip();
+ assertTrue("Tooltip should not be present on row 5",
+ findElement(By.className("v-tooltip-text")).getText()
+ .isEmpty());
+ }
+
+ @Test
public void testRowAndCellDescription() {
openTestURL();
- selectMenuPath("Component", "State", "Row description generator");
- selectMenuPath("Component", "State", "Cell description generator");
+ selectMenuPath("Component", "State", "Row description generator",
+ "HTML");
+ selectMenuPath("Component", "State", "Cell description generator",
+ "HTML");
getGridElement().getCell(5, 0).showTooltip();
String tooltipText = findElement(By.className("v-tooltip-text"))
@@ -71,4 +146,44 @@ public class GridDescriptionGeneratorTest extends GridBasicsTest {
tooltipText = findElement(By.className("v-tooltip-text")).getText();
assertEquals("Tooltip text", "Row tooltip for row 5", tooltipText);
}
+
+ @Test
+ public void testRemoveCellDescription() {
+ selectMenuPath("Component", "State", "Cell description generator",
+ "HTML");
+
+ getGridElement().getCell(1, 0).showTooltip();
+ String tooltipText = findElement(By.className("v-tooltip-text"))
+ .getText();
+ assertEquals("Tooltip text", "Cell tooltip for row 1, Column 0",
+ tooltipText);
+
+ selectMenuPath("Component", "State", "Cell description generator",
+ "Remove descriptions");
+
+ getGridElement().getCell(1, 0).showTooltip();
+ assertTrue("Tooltip should not be present in cell (1, 0) ",
+ findElement(By.className("v-tooltip-text")).getText()
+ .isEmpty());
+ }
+
+ @Test
+ public void testRemoveRowDescription() {
+ openTestURL();
+ selectMenuPath("Component", "State", "Row description generator",
+ "HTML");
+
+ getGridElement().getCell(5, 3).showTooltip();
+ String tooltipText = findElement(By.className("v-tooltip-text"))
+ .getText();
+ assertEquals("Tooltip text", "Row tooltip for row 5", tooltipText);
+
+ selectMenuPath("Component", "State", "Row description generator",
+ "Remove descriptions");
+
+ getGridElement().getCell(5, 3).showTooltip();
+ assertTrue("Tooltip should not be present on row 5",
+ findElement(By.className("v-tooltip-text")).getText()
+ .isEmpty());
+ }
}