aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnna Koskinen <Ansku@users.noreply.github.com>2020-08-11 17:08:39 +0300
committerGitHub <noreply@github.com>2020-08-11 17:08:39 +0300
commit79329344a0fb758112211dd722bc9fc00a69585d (patch)
tree89ad76cbfed47871fa59878ea9ab8ec83e729df2
parent55ccf28d5d286aee19479e81bb348120af992d98 (diff)
downloadvaadin-framework-79329344a0fb758112211dd722bc9fc00a69585d.tar.gz
vaadin-framework-79329344a0fb758112211dd722bc9fc00a69585d.zip
Add a regression test for Table's RowGenerator feature. (#12069) (#12071)
There used to be a TB2 test for this once upon a time, but for some reason that never got converted into a TB3 test before getting removed.
-rw-r--r--uitest/src/test/java/com/vaadin/tests/VerifyBrowserVersionTest.java2
-rw-r--r--uitest/src/test/java/com/vaadin/tests/components/table/TableGeneratedRowsTest.java167
2 files changed, 168 insertions, 1 deletions
diff --git a/uitest/src/test/java/com/vaadin/tests/VerifyBrowserVersionTest.java b/uitest/src/test/java/com/vaadin/tests/VerifyBrowserVersionTest.java
index 4fc4106bde..c259e34837 100644
--- a/uitest/src/test/java/com/vaadin/tests/VerifyBrowserVersionTest.java
+++ b/uitest/src/test/java/com/vaadin/tests/VerifyBrowserVersionTest.java
@@ -25,7 +25,7 @@ public class VerifyBrowserVersionTest extends MultiBrowserTest {
// Chrome version does not necessarily match the desired version
// because of auto updates...
browserIdentifier = getExpectedUserAgentString(
- getDesiredCapabilities()) + "83";
+ getDesiredCapabilities()) + "84";
} else if (BrowserUtil.isFirefox(getDesiredCapabilities())) {
browserIdentifier = getExpectedUserAgentString(
getDesiredCapabilities()) + "75";
diff --git a/uitest/src/test/java/com/vaadin/tests/components/table/TableGeneratedRowsTest.java b/uitest/src/test/java/com/vaadin/tests/components/table/TableGeneratedRowsTest.java
new file mode 100644
index 0000000000..7ea56b91af
--- /dev/null
+++ b/uitest/src/test/java/com/vaadin/tests/components/table/TableGeneratedRowsTest.java
@@ -0,0 +1,167 @@
+package com.vaadin.tests.components.table;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import org.junit.Test;
+import org.openqa.selenium.By;
+import org.openqa.selenium.WebElement;
+
+import com.vaadin.testbench.TestBenchElement;
+import com.vaadin.testbench.elements.TableElement;
+import com.vaadin.tests.tb3.MultiBrowserTest;
+
+@SuppressWarnings("deprecation")
+public class TableGeneratedRowsTest extends MultiBrowserTest {
+
+ @Override
+ protected Class<?> getUIClass() {
+ return Tables.class;
+ }
+
+ @Test
+ public void changeRowGenerator() {
+ openTestURL();
+
+ TableElement table = $(TableElement.class).first();
+
+ /* No row generator */
+
+ TestBenchElement cell = table.getCell(4, 0);
+ int tableWidth = table.getSize().getWidth();
+ int cellWidth = cell.getSize().getWidth();
+ int buffer = 40; // for paddings, borders, scrollbars, and bit extra
+ int bufferedTableWidth = tableWidth - buffer;
+ String text = cell.getText();
+
+ assertFalse("Unexpected cell contents without applying row generator: "
+ + text, text != null && text.startsWith("FOOBARBAZ"));
+ assertLessThan(
+ "Cell shouldn't be spanned without applying row generator: "
+ + cellWidth + " isn't less than " + (tableWidth / 10),
+ cellWidth, tableWidth / 10);
+
+ /* Spanned row generator */
+
+ selectMenuPath("Component", "Features", "Row generator",
+ "Every fifth row, spanned");
+
+ cell = table.getCell(4, 0);
+ cellWidth = cell.getSize().getWidth();
+ text = cell.getText();
+
+ assertTrue(
+ "Unexpected cell contents for spanned generated row: " + text,
+ text != null && text.startsWith("FOOBARBAZ"));
+ assertLessThanOrEqual(
+ "Spanned cell isn't wide enough for spanned generated row: "
+ + cellWidth + " isn't more than " + bufferedTableWidth,
+ bufferedTableWidth, cellWidth);
+
+ /* Non-spanned row generator */
+
+ selectMenuPath("Component", "Features", "Row generator",
+ "Every tenth row, no spanning");
+
+ cell = table.getCell(4, 0);
+ cellWidth = cell.getSize().getWidth();
+ text = cell.getText();
+
+ assertFalse(
+ "Unexpected cell contents after replacing spanned row generator: "
+ + text,
+ text != null && text.startsWith("FOOBARBAZ"));
+ assertLessThan(
+ "Cell shouldn't be spanned anymore after replacing spanned row generator: "
+ + cellWidth + " isn't less than " + (tableWidth / 10),
+ cellWidth, tableWidth / 10);
+
+ cell = table.getCell(9, 0);
+ cellWidth = cell.getSize().getWidth();
+ text = cell.getText();
+
+ assertTrue("Unexpected cell contents for non-spanned generated row: "
+ + text, text != null && text.startsWith("FOO0"));
+ assertLessThan(
+ "Unexpected cell width for non-spanned generated row: "
+ + cellWidth + " isn't less than " + (tableWidth / 10),
+ cellWidth, tableWidth / 10);
+
+ /* Spanned and html formatted row generator */
+
+ selectMenuPath("Component", "Features", "Row generator",
+ "Every eight row, spanned, html formatted");
+
+ cell = table.getCell(9, 0);
+ cellWidth = cell.getSize().getWidth();
+ text = cell.getText();
+
+ assertFalse(
+ "Unexpected cell contents after replacing non-spanned row generator: "
+ + text,
+ text != null && text.startsWith("FOO0"));
+ assertLessThan(
+ "Unexpected cell width after replacing non-spanned row generator: "
+ + cellWidth + " isn't less than " + (tableWidth / 10),
+ cellWidth, tableWidth / 10);
+
+ cell = table.getCell(7, 0);
+ cellWidth = cell.getSize().getWidth();
+ text = cell.getText();
+
+ assertTrue("Unexpected contents for spanned and html formatted cell: "
+ + text, text != null && text.startsWith("FOO BAR BAZ"));
+ assertLessThanOrEqual(
+ "Spanned and html formatted cell isn't wide enough: "
+ + cellWidth + " isn't more than " + bufferedTableWidth,
+ bufferedTableWidth, cellWidth);
+
+ WebElement bazSpan = cell.findElement(By.tagName("span"));
+ if (bazSpan == null) {
+ fail("Unexpected styling: no span found");
+ } else {
+ String bazStyle = bazSpan.getAttribute("style");
+ assertTrue("Unexpected styling: " + bazStyle,
+ bazStyle != null && bazStyle.contains("color: red"));
+ }
+
+ /* Spanned row generator for all rows */
+
+ selectMenuPath("Component", "Features", "Row generator",
+ "Every row, spanned");
+
+ for (int i = 0; i < 10; ++i) {
+ cell = table.getCell(i, 0);
+ cellWidth = cell.getSize().getWidth();
+ text = cell.getText();
+
+ assertTrue(
+ "Unexpected cell contents with every row spanned: " + text,
+ text != null && text.startsWith("SPANNED"));
+ assertLessThanOrEqual(
+ "Spanned cell isn't wide enough with every row spanned: "
+ + cellWidth + " isn't more than "
+ + bufferedTableWidth,
+ bufferedTableWidth, cellWidth);
+ }
+
+ /* No row generator */
+
+ selectMenuPath("Component", "Features", "Row generator", "None");
+
+ for (int i = 0; i < 10; ++i) {
+ cell = table.getCell(i, 0);
+ cellWidth = cell.getSize().getWidth();
+ text = cell.getText();
+
+ assertFalse(
+ "Unexpected cell contents without row generator: " + text,
+ text != null && text.startsWith("SPANNED"));
+ assertLessThan(
+ "Unexpected cell width without row generator: " + cellWidth
+ + " isn't less than " + (tableWidth / 10),
+ cellWidth, tableWidth / 10);
+ }
+ }
+}