aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenrik Paul <henrik@vaadin.com>2015-01-13 16:25:18 +0200
committerHenrik Paul <henrik@vaadin.com>2015-01-15 09:38:53 +0000
commitd444a90ffacd016f9c61141abe5d97774fafd838 (patch)
treef7b26ccc438a11b8fd9c7a7dd44219b44bf1b243
parent3f46830b28100ed918570bf46523c592580643be (diff)
downloadvaadin-framework-d444a90ffacd016f9c61141abe5d97774fafd838.tar.gz
vaadin-framework-d444a90ffacd016f9c61141abe5d97774fafd838.zip
Uses userOriginated for sort event (#16194)
Change-Id: I5db2e23818322bed63848a02f62c982846ab617e
-rw-r--r--server/src/com/vaadin/ui/Grid.java3
-rw-r--r--uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridSortingTest.java41
2 files changed, 42 insertions, 2 deletions
diff --git a/server/src/com/vaadin/ui/Grid.java b/server/src/com/vaadin/ui/Grid.java
index 0d74c01027..175c326f14 100644
--- a/server/src/com/vaadin/ui/Grid.java
+++ b/server/src/com/vaadin/ui/Grid.java
@@ -48,7 +48,6 @@ import com.vaadin.data.Property;
import com.vaadin.data.RpcDataProviderExtension;
import com.vaadin.data.RpcDataProviderExtension.DataProviderKeyMapper;
import com.vaadin.data.fieldgroup.FieldGroup;
-import com.vaadin.data.fieldgroup.FieldGroup.BindException;
import com.vaadin.data.fieldgroup.FieldGroup.CommitException;
import com.vaadin.data.fieldgroup.FieldGroupFieldFactory;
import com.vaadin.data.sort.Sort;
@@ -3748,7 +3747,7 @@ public class Grid extends AbstractComponent implements SelectionNotifier,
}
sortOrder.addAll(order);
- sort(false);
+ sort(userOriginated);
}
/**
diff --git a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridSortingTest.java b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridSortingTest.java
index ffd6ef2959..7e805595c6 100644
--- a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridSortingTest.java
+++ b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridSortingTest.java
@@ -17,18 +17,27 @@ package com.vaadin.tests.components.grid.basicfeatures.server;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+
import org.junit.Test;
import org.openqa.selenium.Keys;
+import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
import com.vaadin.shared.data.sort.SortDirection;
+import com.vaadin.testbench.By;
import com.vaadin.testbench.elements.GridElement;
import com.vaadin.testbench.elements.GridElement.GridCellElement;
+import com.vaadin.tests.annotations.TestCategory;
import com.vaadin.tests.components.grid.basicfeatures.GridBasicFeatures;
import com.vaadin.tests.components.grid.basicfeatures.GridBasicFeaturesTest;
+@TestCategory("grid")
public class GridSortingTest extends GridBasicFeaturesTest {
private static class SortInfo {
@@ -68,6 +77,7 @@ public class GridSortingTest extends GridBasicFeaturesTest {
// String.
// First cells for first 3 rows are (9, 0), (99, 0) and (999, 0)
sortBy("Column 9, DESC");
+ assertLastSortIsUserOriginated(false);
// Verify that programmatic sorting calls are identified as originating
// from API
@@ -135,6 +145,8 @@ public class GridSortingTest extends GridBasicFeaturesTest {
// Click header twice to sort descending
GridCellElement header = grid.getHeaderCell(0, 9);
header.click();
+ assertLastSortIsUserOriginated(true);
+
assertColumnsAreSortedAs(_(9, 1, SortDirection.ASCENDING));
grid.getHeaderCell(0, 9).click();
assertColumnsAreSortedAs(_(9, 1, SortDirection.DESCENDING));
@@ -211,6 +223,7 @@ public class GridSortingTest extends GridBasicFeaturesTest {
// Sort ASCENDING on first column
sendKey(Keys.ENTER);
+ assertLastSortIsUserOriginated(true);
assertColumnsAreSortedAs(_(1, SortDirection.ASCENDING));
// Move to next column
@@ -331,4 +344,32 @@ public class GridSortingTest extends GridBasicFeaturesTest {
private void sortBy(String column) {
selectMenuPath("Component", "State", "Sort by column", column);
}
+
+ private void assertLastSortIsUserOriginated(boolean isUserOriginated) {
+ List<WebElement> userOriginatedMessages = getDriver()
+ .findElements(
+ By.xpath("//*[contains(text(),'SortOrderChangeEvent: isUserOriginated')]"));
+
+ Collections.sort(userOriginatedMessages, new Comparator<WebElement>() {
+ @Override
+ public int compare(WebElement o1, WebElement o2) {
+ return o1.getText().compareTo(o2.getText());
+ }
+ });
+
+ String newestEntry = userOriginatedMessages.get(
+ userOriginatedMessages.size() - 1).getText();
+
+ String[] parts = newestEntry.split(" ");
+ boolean wasUserOriginated = Boolean
+ .parseBoolean(parts[parts.length - 1]);
+ if (isUserOriginated) {
+ assertTrue("expected the sort to be user originated, but wasn't",
+ wasUserOriginated);
+ } else {
+ assertFalse(
+ "expected the sort not to be user originated, but it was",
+ wasUserOriginated);
+ }
+ }
}