summaryrefslogtreecommitdiffstats
path: root/uitest
diff options
context:
space:
mode:
authorAhmed Ashour <asashour@yahoo.com>2017-10-23 09:05:44 +0200
committerPéter Török <31210544+torok-peter@users.noreply.github.com>2017-10-23 10:05:44 +0300
commit46d1a95f046739a8e158f4fcec4e06fbf3656a11 (patch)
treeb559ab939194baf4a6569f938124c6e17b7d4918 /uitest
parentb394dec430792e6514992f651d1f512bdf32b914 (diff)
downloadvaadin-framework-46d1a95f046739a8e158f4fcec4e06fbf3656a11.tar.gz
vaadin-framework-46d1a95f046739a8e158f4fcec4e06fbf3656a11.zip
Grid column to be sortable when implemented/supported (Fixes #8792). (#10190)
* Grid column to be sortable when implemented/supported * Fix GridDeclarativeTest * Parameterize to Grid<Person> * Revert Parameterize to Grid<Person>, JDK with generics. * Assertions for other columns * Fix test Fixes #8792
Diffstat (limited to 'uitest')
-rw-r--r--uitest/src/main/java/com/vaadin/tests/components/grid/GridResizeTerror.java2
-rw-r--r--uitest/src/main/java/com/vaadin/tests/components/grid/GridSingleColumn.java4
-rw-r--r--uitest/src/main/java/com/vaadin/tests/components/grid/GridSortWhenPossible.java103
-rw-r--r--uitest/src/test/java/com/vaadin/tests/components/grid/GridAriaRowcountTest.java8
-rw-r--r--uitest/src/test/java/com/vaadin/tests/components/grid/GridEditorEventsTest.java13
-rw-r--r--uitest/src/test/java/com/vaadin/tests/components/grid/GridSelectionTest.java1
-rw-r--r--uitest/src/test/java/com/vaadin/tests/components/grid/GridSortWhenPossibleTest.java175
-rw-r--r--uitest/src/test/java/com/vaadin/tests/components/grid/basics/GridBasicDetailsTest.java29
8 files changed, 303 insertions, 32 deletions
diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/GridResizeTerror.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridResizeTerror.java
index c960d2363a..437d7b7c4e 100644
--- a/uitest/src/main/java/com/vaadin/tests/components/grid/GridResizeTerror.java
+++ b/uitest/src/main/java/com/vaadin/tests/components/grid/GridResizeTerror.java
@@ -30,8 +30,6 @@ public class GridResizeTerror extends UI {
protected void init(VaadinRequest request) {
Grid<Integer> grid = new Grid<>();
- int cols = 10;
-
IntStream.range(0, 10).forEach(i -> grid.addColumn(item -> "Data" + i));
grid.setItems(IntStream.range(0, 500).boxed());
diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/GridSingleColumn.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridSingleColumn.java
index 105da4f96f..cac1969467 100644
--- a/uitest/src/main/java/com/vaadin/tests/components/grid/GridSingleColumn.java
+++ b/uitest/src/main/java/com/vaadin/tests/components/grid/GridSingleColumn.java
@@ -21,7 +21,6 @@ import com.vaadin.data.ValueProvider;
import com.vaadin.server.VaadinRequest;
import com.vaadin.tests.components.AbstractReindeerTestUI;
import com.vaadin.ui.Grid;
-import com.vaadin.ui.Grid.Column;
import com.vaadin.ui.Grid.SelectionMode;
public class GridSingleColumn extends AbstractReindeerTestUI {
@@ -33,8 +32,7 @@ public class GridSingleColumn extends AbstractReindeerTestUI {
grid.setItems(IntStream.range(0, 100).mapToObj(indx -> "cell"));
- Column<String, String> column = grid.addColumn(ValueProvider.identity())
- .setCaption("Header");
+ grid.addColumn(ValueProvider.identity()).setCaption("Header");
addComponent(grid);
grid.scrollTo(50);
diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/GridSortWhenPossible.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridSortWhenPossible.java
new file mode 100644
index 0000000000..92881c7457
--- /dev/null
+++ b/uitest/src/main/java/com/vaadin/tests/components/grid/GridSortWhenPossible.java
@@ -0,0 +1,103 @@
+/*
+ * Copyright 2000-2016 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.tests.components.grid;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+
+import com.vaadin.data.provider.CallbackDataProvider;
+import com.vaadin.data.provider.QuerySortOrder;
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.shared.data.sort.SortDirection;
+import com.vaadin.tests.components.AbstractTestUI;
+import com.vaadin.tests.data.bean.Person;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.CheckBox;
+import com.vaadin.ui.Grid;
+import com.vaadin.ui.renderers.NumberRenderer;
+
+public class GridSortWhenPossible extends AbstractTestUI {
+
+ private List<Person> persons;
+
+ @Override
+ protected void setup(VaadinRequest request) {
+ persons = Collections.unmodifiableList(Arrays.asList(
+ createPerson("a", 4, true), createPerson("b", 5, false),
+ createPerson("c", 3, false), createPerson("a", 6, false),
+ createPerson("a", 2, true), createPerson("c", 7, false),
+ createPerson("b", 1, true)));
+
+ CheckBox inMemoryCheckBox = new CheckBox("In memory");
+ addComponent(inMemoryCheckBox);
+ addComponent(new Button("Create Grid",
+ e -> addComponent(getGrid(inMemoryCheckBox.getValue()))));
+ }
+
+ private final Grid<Person> getGrid(boolean inMemory) {
+ Grid<Person> grid = new Grid<>();
+ grid.addColumn(Person::getFirstName).setId("name");
+ grid.addColumn(Person::getAge, new NumberRenderer()).setId("age");
+ grid.addColumn(Person::getDeceased);
+
+ if (inMemory) {
+ grid.setItems(persons);
+ } else {
+ grid.setDataProvider(new CallbackDataProvider<>(query -> {
+ List<Person> list = new ArrayList<>(persons);
+ if (!query.getSortOrders().isEmpty()) {
+ QuerySortOrder order = query.getSortOrders().get(0);
+
+ Comparator<Person> comparator;
+ if ("name".equals(order.getSorted())) {
+ comparator = Comparator.comparing(Person::getFirstName);
+ } else {
+ comparator = Comparator.comparing(Person::getAge);
+ }
+
+ if (order.getDirection() == SortDirection.DESCENDING) {
+ comparator = comparator.reversed();
+ }
+ Collections.sort(list, comparator);
+ }
+ return list.stream();
+ }, query -> persons.size()));
+ }
+ return grid;
+ }
+
+ private Person createPerson(String name, int age, boolean deceased) {
+ Person person = new Person();
+ person.setFirstName(name);
+ person.setAge(age);
+ person.setDeceased(deceased);
+ return person;
+
+ }
+
+ @Override
+ public String getTestDescription() {
+ return "Grid columns are sorted, only when sorting is implemented";
+ }
+
+ @Override
+ public Integer getTicketNumber() {
+ return 8792;
+ }
+}
diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/GridAriaRowcountTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/GridAriaRowcountTest.java
index 2c8ddb3b01..db15fa33c8 100644
--- a/uitest/src/test/java/com/vaadin/tests/components/grid/GridAriaRowcountTest.java
+++ b/uitest/src/test/java/com/vaadin/tests/components/grid/GridAriaRowcountTest.java
@@ -15,10 +15,13 @@
*/
package com.vaadin.tests.components.grid;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+
import com.vaadin.testbench.elements.ButtonElement;
import com.vaadin.testbench.elements.GridElement;
import com.vaadin.tests.tb3.SingleBrowserTest;
-import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@@ -77,6 +80,7 @@ public class GridAriaRowcountTest extends SingleBrowserTest {
}
private boolean containsRows(int rowcount) {
- return grid.getHTML().contains("aria-rowcount=\"" + String.valueOf(rowcount) + "\"");
+ return grid.getHTML()
+ .contains("aria-rowcount=\"" + String.valueOf(rowcount) + "\"");
}
}
diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/GridEditorEventsTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/GridEditorEventsTest.java
index 989b0a52d5..26c33c2d64 100644
--- a/uitest/src/test/java/com/vaadin/tests/components/grid/GridEditorEventsTest.java
+++ b/uitest/src/test/java/com/vaadin/tests/components/grid/GridEditorEventsTest.java
@@ -17,7 +17,6 @@ package com.vaadin.tests.components.grid;
import static org.junit.Assert.assertEquals;
-import org.junit.Assert;
import org.junit.Test;
import org.openqa.selenium.WebElement;
@@ -41,18 +40,14 @@ public class GridEditorEventsTest extends MultiBrowserTest {
GridEditorElement editor = updateField(index, grid, "foo");
editor.save();
- assertEquals((index * 4 + 1) + ". editor is opened",
- getLogRow(1));
- assertEquals((index * 4 + 2) + ". editor is saved",
- getLogRow(0));
+ assertEquals((index * 4 + 1) + ". editor is opened", getLogRow(1));
+ assertEquals((index * 4 + 2) + ". editor is saved", getLogRow(0));
editor = updateField(index, grid, "bar");
editor.cancel();
- assertEquals((index * 4 + 3) + ". editor is opened",
- getLogRow(1));
- assertEquals((index * 4 + 4) + ". editor is canceled",
- getLogRow(0));
+ assertEquals((index * 4 + 3) + ". editor is opened", getLogRow(1));
+ assertEquals((index * 4 + 4) + ". editor is canceled", getLogRow(0));
}
private GridEditorElement updateField(int index, GridElement grid,
diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/GridSelectionTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/GridSelectionTest.java
index 7a11b3375e..09d19ef81a 100644
--- a/uitest/src/test/java/com/vaadin/tests/components/grid/GridSelectionTest.java
+++ b/uitest/src/test/java/com/vaadin/tests/components/grid/GridSelectionTest.java
@@ -6,7 +6,6 @@ import static org.junit.Assert.assertTrue;
import java.util.Arrays;
import java.util.HashSet;
-import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import org.openqa.selenium.Keys;
diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/GridSortWhenPossibleTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/GridSortWhenPossibleTest.java
new file mode 100644
index 0000000000..aede22d367
--- /dev/null
+++ b/uitest/src/test/java/com/vaadin/tests/components/grid/GridSortWhenPossibleTest.java
@@ -0,0 +1,175 @@
+/*
+ * Copyright 2000-2016 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.tests.components.grid;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+
+import com.vaadin.testbench.elements.ButtonElement;
+import com.vaadin.testbench.elements.CheckBoxElement;
+import com.vaadin.testbench.elements.GridElement;
+import com.vaadin.tests.tb3.MultiBrowserTest;
+
+public class GridSortWhenPossibleTest extends MultiBrowserTest {
+
+ @Test
+ public void inMemory() throws InterruptedException {
+ openTestURL();
+ $(CheckBoxElement.class).first().click();
+ $(ButtonElement.class).first().click();
+
+ GridElement grid = $(GridElement.class).first();
+ assertRow(grid, 0, "a", "4", true);
+ assertRow(grid, 1, "b", "5", false);
+ assertRow(grid, 2, "c", "3", false);
+ assertRow(grid, 3, "a", "6", false);
+ assertRow(grid, 4, "a", "2", true);
+ assertRow(grid, 5, "c", "7", false);
+ assertRow(grid, 6, "b", "1", true);
+
+ grid.getHeaderCell(0, 0).click();
+ assertTrue("First column should be sorted ascending",
+ grid.getHeaderCell(0, 0).getAttribute("class")
+ .contains("sort-asc"));
+ assertFalse("Second column should not be sorted", grid
+ .getHeaderCell(0, 1).getAttribute("class").contains("sort-"));
+ assertFalse("Third column should not be sorted", grid
+ .getHeaderCell(0, 2).getAttribute("class").contains("sort-"));
+
+ assertRow(grid, 0, "a", "4", true);
+ assertRow(grid, 1, "a", "6", false);
+ assertRow(grid, 2, "a", "2", true);
+ assertRow(grid, 3, "b", "5", false);
+ assertRow(grid, 4, "b", "1", true);
+ assertRow(grid, 5, "c", "3", false);
+ assertRow(grid, 6, "c", "7", false);
+
+ grid.getHeaderCell(0, 1).click();
+
+ assertFalse("First column should not be sorted", grid
+ .getHeaderCell(0, 0).getAttribute("class").contains("sort-"));
+ assertTrue("Second column should be sorted ascending",
+ grid.getHeaderCell(0, 1).getAttribute("class")
+ .contains("sort-asc"));
+ assertFalse("Third column should not be sorted", grid
+ .getHeaderCell(0, 2).getAttribute("class").contains("sort-"));
+
+ assertRow(grid, 0, "b", "1", true);
+ assertRow(grid, 1, "a", "2", true);
+ assertRow(grid, 2, "c", "3", false);
+ assertRow(grid, 3, "a", "4", true);
+ assertRow(grid, 4, "b", "5", false);
+ assertRow(grid, 5, "a", "6", false);
+ assertRow(grid, 6, "c", "7", false);
+
+ grid.getHeaderCell(0, 2).click();
+
+ assertFalse("First column should not be sorted", grid
+ .getHeaderCell(0, 0).getAttribute("class").contains("sort-"));
+ assertFalse("Second column should not be sorted", grid
+ .getHeaderCell(0, 1).getAttribute("class").contains("sort-"));
+ assertTrue("Third column should be sorted ascending",
+ grid.getHeaderCell(0, 2).getAttribute("class")
+ .contains("sort-asc"));
+
+ assertRow(grid, 0, "b", "5", false);
+ assertRow(grid, 1, "c", "3", false);
+ assertRow(grid, 2, "a", "6", false);
+ assertRow(grid, 3, "c", "7", false);
+ assertRow(grid, 4, "a", "4", true);
+ assertRow(grid, 5, "a", "2", true);
+ assertRow(grid, 6, "b", "1", true);
+ }
+
+ @Test
+ public void lazyLoading() throws InterruptedException {
+ openTestURL();
+ $(ButtonElement.class).first().click();
+
+ GridElement grid = $(GridElement.class).first();
+ assertRow(grid, 0, "a", "4", true);
+ assertRow(grid, 1, "b", "5", false);
+ assertRow(grid, 2, "c", "3", false);
+ assertRow(grid, 3, "a", "6", false);
+ assertRow(grid, 4, "a", "2", true);
+ assertRow(grid, 5, "c", "7", false);
+ assertRow(grid, 6, "b", "1", true);
+
+ grid.getHeaderCell(0, 0).click();
+
+ assertTrue("First column should be sorted ascending",
+ grid.getHeaderCell(0, 0).getAttribute("class")
+ .contains("sort-asc"));
+ assertFalse("Second column should not be sorted", grid
+ .getHeaderCell(0, 1).getAttribute("class").contains("sort-"));
+ assertFalse("Third column should not be sorted", grid
+ .getHeaderCell(0, 2).getAttribute("class").contains("sort-"));
+
+ assertRow(grid, 0, "a", "4", true);
+ assertRow(grid, 1, "a", "6", false);
+ assertRow(grid, 2, "a", "2", true);
+ assertRow(grid, 3, "b", "5", false);
+ assertRow(grid, 4, "b", "1", true);
+ assertRow(grid, 5, "c", "3", false);
+ assertRow(grid, 6, "c", "7", false);
+
+ grid.getHeaderCell(0, 1).click();
+
+ assertFalse("First column should not be sorted", grid
+ .getHeaderCell(0, 0).getAttribute("class").contains("sort-"));
+ assertTrue("Second column should be sorted ascending",
+ grid.getHeaderCell(0, 1).getAttribute("class")
+ .contains("sort-asc"));
+ assertFalse("Third column should not be sorted", grid
+ .getHeaderCell(0, 2).getAttribute("class").contains("sort-"));
+
+ assertRow(grid, 0, "b", "1", true);
+ assertRow(grid, 1, "a", "2", true);
+ assertRow(grid, 2, "c", "3", false);
+ assertRow(grid, 3, "a", "4", true);
+ assertRow(grid, 4, "b", "5", false);
+ assertRow(grid, 5, "a", "6", false);
+ assertRow(grid, 6, "c", "7", false);
+
+ grid.getHeaderCell(0, 2).click();
+
+ assertFalse("First column should not be sorted", grid
+ .getHeaderCell(0, 0).getAttribute("class").contains("sort-"));
+ assertTrue("Second column should be sorted ascending",
+ grid.getHeaderCell(0, 1).getAttribute("class")
+ .contains("sort-asc"));
+ assertFalse("Third column should not be sorted", grid
+ .getHeaderCell(0, 2).getAttribute("class").contains("sort-"));
+
+ assertRow(grid, 0, "b", "1", true);
+ assertRow(grid, 1, "a", "2", true);
+ assertRow(grid, 2, "c", "3", false);
+ assertRow(grid, 3, "a", "4", true);
+ assertRow(grid, 4, "b", "5", false);
+ assertRow(grid, 5, "a", "6", false);
+ assertRow(grid, 6, "c", "7", false);
+ }
+
+ private void assertRow(GridElement grid, int row, Object... values) {
+ for (int col = 0; col < values.length; col++) {
+ assertEquals(String.valueOf(values[col]),
+ grid.getCell(row, col).getText());
+ }
+ }
+}
diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/basics/GridBasicDetailsTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/basics/GridBasicDetailsTest.java
index 614de92071..3cc1906dcc 100644
--- a/uitest/src/test/java/com/vaadin/tests/components/grid/basics/GridBasicDetailsTest.java
+++ b/uitest/src/test/java/com/vaadin/tests/components/grid/basics/GridBasicDetailsTest.java
@@ -6,7 +6,6 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
-import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.NoSuchElementException;
@@ -23,20 +22,20 @@ public class GridBasicDetailsTest extends GridBasicsTest {
* awkward with two scroll commands back to back.
*/
private static final int ALMOST_LAST_INDEX = 995;
- private static final String[] OPEN_ALMOST_LAST_ITEM_DETAILS = {
- "Component", "Details", "Open " + ALMOST_LAST_INDEX };
- private static final String[] OPEN_FIRST_ITEM_DETAILS = {
- "Component", "Details", "Open First" };
- private static final String[] TOGGLE_FIRST_ITEM_DETAILS = {
- "Component", "Details", "Toggle First" };
- private static final String[] DETAILS_GENERATOR_NULL = {
- "Component", "Details", "Generators", "NULL" };
- private static final String[] DETAILS_GENERATOR_WATCHING = {
- "Component", "Details", "Generators", "\"Watching\"" };
- private static final String[] DETAILS_GENERATOR_PERSISTING = {
- "Component", "Details", "Generators", "Persisting" };
- private static final String[] CHANGE_HIERARCHY = { "Component",
- "Details", "Generators", "- Change Component" };
+ private static final String[] OPEN_ALMOST_LAST_ITEM_DETAILS = { "Component",
+ "Details", "Open " + ALMOST_LAST_INDEX };
+ private static final String[] OPEN_FIRST_ITEM_DETAILS = { "Component",
+ "Details", "Open First" };
+ private static final String[] TOGGLE_FIRST_ITEM_DETAILS = { "Component",
+ "Details", "Toggle First" };
+ private static final String[] DETAILS_GENERATOR_NULL = { "Component",
+ "Details", "Generators", "NULL" };
+ private static final String[] DETAILS_GENERATOR_WATCHING = { "Component",
+ "Details", "Generators", "\"Watching\"" };
+ private static final String[] DETAILS_GENERATOR_PERSISTING = { "Component",
+ "Details", "Generators", "Persisting" };
+ private static final String[] CHANGE_HIERARCHY = { "Component", "Details",
+ "Generators", "- Change Component" };
@Override
@Before