summaryrefslogtreecommitdiffstats
path: root/uitest
diff options
context:
space:
mode:
authorTeemu Suo-Anttila <teemusa@vaadin.com>2016-08-22 16:39:50 +0300
committerVaadin Code Review <review@vaadin.com>2016-08-24 12:11:31 +0000
commit87e0a08b6059add166b46b8b4379791a40ff0ede (patch)
tree7dbe56876a7befbbe9985343b165ee91f65ed4c4 /uitest
parentfa2a40b38e8f06632f9b89c9acea1ed0d40c3410 (diff)
downloadvaadin-framework-87e0a08b6059add166b46b8b4379791a40ff0ede.tar.gz
vaadin-framework-87e0a08b6059add166b46b8b4379791a40ff0ede.zip
Add a typed version of the Grid component
Change-Id: I00cbe80ac72787de0c4cc88e1c223badc2c4ae89
Diffstat (limited to 'uitest')
-rw-r--r--uitest/src/main/java/com/vaadin/tests/components/grid/basics/DataObject.java93
-rw-r--r--uitest/src/main/java/com/vaadin/tests/components/grid/basics/GridBasics.java32
-rw-r--r--uitest/src/test/java/com/vaadin/tests/components/grid/basics/GridBasicsTest.java45
-rw-r--r--uitest/src/test/java/com/vaadin/tests/components/grid/basics/GridContentTest.java17
-rw-r--r--uitest/src/test/java/com/vaadin/tests/components/grid/basics/GridSortingTest.java52
5 files changed, 239 insertions, 0 deletions
diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/basics/DataObject.java b/uitest/src/main/java/com/vaadin/tests/components/grid/basics/DataObject.java
new file mode 100644
index 0000000000..ebcdc34d7f
--- /dev/null
+++ b/uitest/src/main/java/com/vaadin/tests/components/grid/basics/DataObject.java
@@ -0,0 +1,93 @@
+package com.vaadin.tests.components.grid.basics;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.Random;
+
+class DataObject {
+
+ private static final int ROWS = 1000;
+
+ private Integer rowNumber;
+ private String coordinates;
+ private String htmlString;
+ private Integer smallRandom;
+ private Integer bigRandom;
+ private Date date;
+
+ public Integer getRowNumber() {
+ return rowNumber;
+ }
+
+ public void setRowNumber(Integer rowNumber) {
+ this.rowNumber = rowNumber;
+ }
+
+ public String getCoordinates() {
+ return coordinates;
+ }
+
+ public void setCoordinates(String coordinates) {
+ this.coordinates = coordinates;
+ }
+
+ public String getHtmlString() {
+ return htmlString;
+ }
+
+ public void setHtmlString(String htmlString) {
+ this.htmlString = htmlString;
+ }
+
+ public Integer getSmallRandom() {
+ return smallRandom;
+ }
+
+ public void setSmallRandom(Integer smallRandom) {
+ this.smallRandom = smallRandom;
+ }
+
+ public Integer getBigRandom() {
+ return bigRandom;
+ }
+
+ public void setBigRandom(Integer bigRandom) {
+ this.bigRandom = bigRandom;
+ }
+
+ public Date getDate() {
+ return date;
+ }
+
+ public void setDate(Date date) {
+ this.date = date;
+ }
+
+ static List<DataObject> generateObjects() {
+ List<DataObject> data = new ArrayList<>();
+
+ {
+ Random rand = new Random();
+ rand.setSeed(13334);
+ long timestamp = 0;
+ for (int row = 0; row < ROWS; row++) {
+ DataObject obj = new DataObject();
+ obj.setRowNumber(row);
+ obj.setCoordinates("(" + row + ", " + 0 + ")");
+ obj.setHtmlString("<b>" + row + "</b>");
+ // Random numbers
+ obj.setBigRandom(rand.nextInt());
+ obj.setSmallRandom(rand.nextInt(5));
+
+ obj.setDate(new Date(timestamp));
+ timestamp += 91250000; // a bit over a day, just to get
+ // variation
+
+ data.add(obj);
+ }
+ }
+ return data;
+ }
+
+}
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
new file mode 100644
index 0000000000..8ef56e7f64
--- /dev/null
+++ b/uitest/src/main/java/com/vaadin/tests/components/grid/basics/GridBasics.java
@@ -0,0 +1,32 @@
+package com.vaadin.tests.components.grid.basics;
+
+import java.util.Date;
+import java.util.List;
+
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.AbstractTestUIWithLog;
+import com.vaadin.ui.Grid;
+
+public class GridBasics extends AbstractTestUIWithLog {
+
+ private Grid<DataObject> grid;
+
+ @Override
+ protected void setup(VaadinRequest request) {
+ List<DataObject> data = DataObject.generateObjects();
+
+ // Create grid
+ grid = new Grid<>();
+ grid.setItems(data);
+
+ grid.addColumn("Row Number", Integer.class, DataObject::getRowNumber);
+ grid.addColumn("Date", Date.class, DataObject::getDate);
+ grid.addColumn("HTML String", String.class, DataObject::getHtmlString);
+ grid.addColumn("Big Random", Integer.class, DataObject::getBigRandom);
+ grid.addColumn("Small Random", Integer.class,
+ DataObject::getSmallRandom);
+
+ addComponent(grid);
+ }
+
+}
diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/basics/GridBasicsTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/basics/GridBasicsTest.java
new file mode 100644
index 0000000000..63f2c60f21
--- /dev/null
+++ b/uitest/src/test/java/com/vaadin/tests/components/grid/basics/GridBasicsTest.java
@@ -0,0 +1,45 @@
+package com.vaadin.tests.components.grid.basics;
+
+import java.util.List;
+import java.util.stream.Stream;
+
+import org.junit.Before;
+import org.openqa.selenium.remote.DesiredCapabilities;
+
+import com.vaadin.testbench.elements.GridElement;
+import com.vaadin.testbench.parallel.Browser;
+import com.vaadin.tests.tb3.MultiBrowserTest;
+
+/**
+ * Base class for all {@link GridBasics} UI tests
+ */
+public abstract class GridBasicsTest extends MultiBrowserTest {
+
+ /* Identical List of test data */
+ private List<DataObject> testData;
+
+ @Override
+ public List<DesiredCapabilities> getBrowsersToTest() {
+ // Most tests are run with only one browser.
+ return getBrowserCapabilities(Browser.PHANTOMJS);
+ }
+
+ @Override
+ protected Class<?> getUIClass() {
+ return GridBasics.class;
+ }
+
+ @Before
+ public void setUp() {
+ openTestURL();
+ testData = DataObject.generateObjects();
+ }
+
+ protected GridElement getGrid() {
+ return $(GridElement.class).first();
+ }
+
+ protected Stream<DataObject> getTestData() {
+ return testData.stream();
+ }
+}
diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/basics/GridContentTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/basics/GridContentTest.java
new file mode 100644
index 0000000000..315282439a
--- /dev/null
+++ b/uitest/src/test/java/com/vaadin/tests/components/grid/basics/GridContentTest.java
@@ -0,0 +1,17 @@
+package com.vaadin.tests.components.grid.basics;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class GridContentTest extends GridBasicsTest {
+
+ @Test(expected = AssertionError.class)
+ public void testHtmlRenderer() {
+ DataObject first = getTestData().findFirst().orElse(null);
+ Assert.assertEquals("Text content should match row number",
+ first.getRowNumber().toString(),
+ getGrid().getCell(0, 2).getText());
+ Assert.assertEquals("HTML content did not match", first.getHtmlString(),
+ getGrid().getCell(0, 2).getAttribute("innerHTML"));
+ }
+}
diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/basics/GridSortingTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/basics/GridSortingTest.java
new file mode 100644
index 0000000000..e9cd744719
--- /dev/null
+++ b/uitest/src/test/java/com/vaadin/tests/components/grid/basics/GridSortingTest.java
@@ -0,0 +1,52 @@
+package com.vaadin.tests.components.grid.basics;
+
+import java.util.Comparator;
+import java.util.List;
+import java.util.stream.Collectors;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.openqa.selenium.Keys;
+import org.openqa.selenium.remote.DesiredCapabilities;
+
+public class GridSortingTest extends GridBasicsTest {
+
+ public static final Comparator<DataObject> BIG_RANDOM = Comparator
+ .comparing(DataObject::getBigRandom);
+ public static final Comparator<DataObject> SMALL_RANDOM = Comparator
+ .comparing(DataObject::getSmallRandom);
+
+ @Override
+ public List<DesiredCapabilities> getBrowsersToTest() {
+ return getBrowsersSupportingShiftClick();
+ }
+
+ @Test
+ public void testSortBySingleColumnByUser() {
+ getGrid().getHeaderCell(0, 3).click();
+ int i = 0;
+ for (Integer rowNumber : getTestData().sorted(BIG_RANDOM)
+ .map(DataObject::getRowNumber).limit(5)
+ .collect(Collectors.toList())) {
+ Assert.assertEquals(
+ "Grid was not sorted as expected, row number mismatch",
+ rowNumber.toString(), getGrid().getCell(i++, 0).getText());
+ }
+ }
+
+ @Test
+ public void testSortByMultipleColumnsByUser() {
+ getGrid().getHeaderCell(0, 4).click();
+ getGrid().getHeaderCell(0, 3).click(15, 15, Keys.SHIFT);
+
+ int i = 0;
+ for (Integer rowNumber : getTestData()
+ .sorted(SMALL_RANDOM.thenComparing(BIG_RANDOM))
+ .map(DataObject::getRowNumber).limit(5)
+ .collect(Collectors.toList())) {
+ Assert.assertEquals(
+ "Grid was not sorted as expected, row number mismatch",
+ rowNumber.toString(), getGrid().getCell(i++, 0).getText());
+ }
+ }
+}