summaryrefslogtreecommitdiffstats
path: root/uitest
diff options
context:
space:
mode:
authorArtur <artur@vaadin.com>2017-01-30 13:47:55 +0200
committerGitHub <noreply@github.com>2017-01-30 13:47:55 +0200
commit131e4f34bddf99d61a76fcd49890490c78c3efa8 (patch)
tree1276e94ddbec6a8fc612bedf87835cd366e5f0a5 /uitest
parent870a4d9ab386de41b0c5e344d16ebfd9c13b2951 (diff)
downloadvaadin-framework-131e4f34bddf99d61a76fcd49890490c78c3efa8.tar.gz
vaadin-framework-131e4f34bddf99d61a76fcd49890490c78c3efa8.zip
Make it possible to disallow user selection in Grid (#8144)
Fixes #7880
Diffstat (limited to 'uitest')
-rw-r--r--uitest/src/main/java/com/vaadin/tests/components/grid/basicfeatures/GridBasicFeatures.java30
-rw-r--r--uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/server/GridSelectionTest.java157
2 files changed, 181 insertions, 6 deletions
diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/basicfeatures/GridBasicFeatures.java b/uitest/src/main/java/com/vaadin/tests/components/grid/basicfeatures/GridBasicFeatures.java
index e3fdd68ed6..6f1986720b 100644
--- a/uitest/src/main/java/com/vaadin/tests/components/grid/basicfeatures/GridBasicFeatures.java
+++ b/uitest/src/main/java/com/vaadin/tests/components/grid/basicfeatures/GridBasicFeatures.java
@@ -75,6 +75,7 @@ import com.vaadin.ui.Grid.RowReference;
import com.vaadin.ui.Grid.RowStyleGenerator;
import com.vaadin.ui.Grid.SelectionMode;
import com.vaadin.ui.Grid.SelectionModel;
+import com.vaadin.ui.Grid.SelectionModel.HasUserSelectionAllowed;
import com.vaadin.ui.Label;
import com.vaadin.ui.Notification;
import com.vaadin.ui.Panel;
@@ -108,6 +109,7 @@ public class GridBasicFeatures extends AbstractComponentTest<Grid> {
private int containerDelay = 0;
private boolean singleSelectAllowDeselect = true;
+ private boolean allowUserSelection = true;
private IndexedContainer ds;
private Grid grid;
@@ -509,6 +511,9 @@ public class GridBasicFeatures extends AbstractComponentTest<Grid> {
} else {
grid.removeSelectionListener(selectionListener);
}
+
+ ((HasUserSelectionAllowed) grid.getSelectionModel())
+ .setUserSelectionAllowed(allowUserSelection);
}
});
@@ -804,6 +809,17 @@ public class GridBasicFeatures extends AbstractComponentTest<Grid> {
}
}
});
+ createBooleanAction("Allow user selection", "State", allowUserSelection,
+ new Command<Grid, Boolean>() {
+ @Override
+ public void execute(Grid c, Boolean value, Object data) {
+ allowUserSelection = value.booleanValue();
+
+ SelectionModel model = c.getSelectionModel();
+ ((HasUserSelectionAllowed) model)
+ .setUserSelectionAllowed(allowUserSelection);
+ }
+ });
createBooleanAction("Column Reordering Allowed", "State", false,
new Command<Grid, Boolean>() {
@@ -1268,12 +1284,14 @@ public class GridBasicFeatures extends AbstractComponentTest<Grid> {
}
}, null);
- createBooleanAction("Simple resize mode", "Columns", false, new Command<Grid, Boolean>() {
- @Override
- public void execute(Grid g, Boolean value, Object data) {
- g.setColumnResizeMode(value ? ColumnResizeMode.SIMPLE : ColumnResizeMode.ANIMATED);
- }
- });
+ createBooleanAction("Simple resize mode", "Columns", false,
+ new Command<Grid, Boolean>() {
+ @Override
+ public void execute(Grid g, Boolean value, Object data) {
+ g.setColumnResizeMode(value ? ColumnResizeMode.SIMPLE
+ : ColumnResizeMode.ANIMATED);
+ }
+ });
}
private static String getColumnProperty(int c) {
diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/server/GridSelectionTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/server/GridSelectionTest.java
index 642514393e..b185d52c5b 100644
--- a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/server/GridSelectionTest.java
+++ b/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/server/GridSelectionTest.java
@@ -483,6 +483,10 @@ public class GridSelectionTest extends GridBasicFeaturesTest {
selectMenuPath("Component", "Body rows", "Select first row");
}
+ private void toggleUserSelectionAllowed() {
+ selectMenuPath("Component", "State", "Allow user selection");
+ }
+
private GridRowElement getRow(int i) {
return getGridElement().getRow(i);
}
@@ -526,4 +530,157 @@ public class GridSelectionTest extends GridBasicFeaturesTest {
getGridElement().getCell(0, 0).click();
assertTrue("row should become selected", getRow(0).isSelected());
}
+
+ @Test
+ public void singleSelectUserSelectionDisallowedSpaceSelectionNoOp() {
+ openTestURL();
+ setSelectionModelSingle();
+ getGridElement().focus();
+ getGridElement().sendKeys(Keys.DOWN, Keys.SPACE);
+ assertTrue("row was selected when selection was allowed",
+ getRow(1).isSelected());
+ toggleUserSelectionAllowed();
+ getGridElement().sendKeys(Keys.SPACE);
+ assertTrue("deselect disallowed", getRow(1).isSelected());
+ getGridElement().sendKeys(Keys.DOWN, Keys.SPACE);
+ assertFalse("select disallowed", getRow(2).isSelected());
+ assertTrue("old selection remains", getRow(1).isSelected());
+ toggleUserSelectionAllowed();
+ getGridElement().sendKeys(Keys.SPACE);
+ assertTrue("select allowed again", getRow(2).isSelected());
+ assertFalse("old selection removed", getRow(1).isSelected());
+
+ }
+
+ @Test
+ public void singleSelectUserSelectionDisallowedClickSelectionNoOp() {
+ openTestURL();
+ setSelectionModelSingle();
+ getGridElement().getCell(1, 0).click();
+ assertTrue("selection allowed, should have been selected",
+ getRow(1).isSelected());
+ toggleUserSelectionAllowed();
+ getGridElement().getCell(1, 0).click();
+ assertTrue("deselect disallowed, should remain selected",
+ getRow(1).isSelected());
+ getGridElement().getCell(2, 0).click();
+ assertFalse("select disallowed, should not have been selected",
+ getRow(2).isSelected());
+ assertTrue("select disallowed, old selection should have remained",
+ getRow(1).isSelected());
+ toggleUserSelectionAllowed();
+ getGridElement().getCell(2, 0).click();
+ assertTrue("select allowed again, row should have been selected",
+ getRow(2).isSelected());
+ assertFalse("old selection removed", getRow(1).isSelected());
+
+ }
+
+ @Test
+ public void multiSelectUserSelectionDisallowedSpaceSelectionNoOp() {
+ openTestURL();
+ setSelectionModelMulti();
+ getGridElement().focus();
+ getGridElement().sendKeys(Keys.DOWN, Keys.SPACE);
+ assertTrue("selection allowed, should have been selected",
+ getRow(1).isSelected());
+ toggleUserSelectionAllowed();
+ getGridElement().sendKeys(Keys.SPACE);
+ assertTrue("deselect disallowed, should remain selected",
+ getRow(1).isSelected());
+ getGridElement().sendKeys(Keys.DOWN, Keys.SPACE);
+ assertFalse("select disallowed, should not have been selected",
+ getRow(2).isSelected());
+ assertTrue("select disallowed, old selection should have remained",
+ getRow(1).isSelected());
+
+ toggleUserSelectionAllowed();
+ getGridElement().sendKeys(Keys.SPACE);
+ assertTrue("select allowed again, row should have been selected",
+ getRow(2).isSelected());
+ assertTrue(
+ "select allowed again but old selection should have remained",
+ getRow(1).isSelected());
+ }
+
+ @Test
+ public void multiSelectUserSelectionDisallowedCheckboxSelectionNoOp() {
+ openTestURL();
+ setSelectionModelMulti();
+ assertTrue(getSelectionCheckbox(0).isEnabled());
+ toggleUserSelectionAllowed();
+ assertFalse(getSelectionCheckbox(0).isEnabled());
+
+ // Select by clicking on checkbox (should always fail as it is disabled)
+ getSelectionCheckbox(0).click();
+ assertFalse(getGridElement().getRow(0).isSelected());
+ // Select by clicking on cell (should fail)
+ getGridElement().getCell(0, 0).click();
+ assertFalse(getGridElement().getRow(0).isSelected());
+
+ toggleUserSelectionAllowed();
+ assertTrue(getSelectionCheckbox(0).isEnabled());
+ getSelectionCheckbox(0).click();
+ assertTrue(getGridElement().getRow(0).isSelected());
+ }
+
+ @Test
+ public void multiSelectUserSelectionDisallowedCheckboxSelectAllNoOp() {
+ openTestURL();
+ setSelectionModelMulti();
+
+ assertTrue(getSelectAllCheckbox().isEnabled());
+ toggleUserSelectionAllowed();
+ assertFalse(getSelectAllCheckbox().isEnabled());
+
+ // Select all by clicking on checkbox (should not select)
+ getSelectAllCheckbox().click();
+ assertFalse(getSelectAllCheckbox().isSelected());
+ assertFalse(getGridElement().getRow(0).isSelected());
+ assertFalse(getGridElement().getRow(10).isSelected());
+
+ // Select all by clicking on header cell (should not select)
+ getGridElement().getHeaderCell(0, 0).click();
+ assertFalse(getSelectAllCheckbox().isSelected());
+ assertFalse(getGridElement().getRow(0).isSelected());
+ assertFalse(getGridElement().getRow(10).isSelected());
+
+ toggleUserSelectionAllowed();
+
+ assertTrue(getSelectAllCheckbox().isEnabled());
+ getSelectAllCheckbox().click();
+ assertTrue(getGridElement().getRow(0).isSelected());
+ assertTrue(getGridElement().getRow(10).isSelected());
+ }
+
+ @Test
+ public void singleSelectUserSelectionDisallowedServerSelect() {
+ openTestURL();
+ setSelectionModelSingle();
+ toggleUserSelectionAllowed();
+
+ toggleFirstRowSelection();
+ assertTrue(getGridElement().getRow(0).isSelected());
+ }
+
+ @Test
+ public void multiSelectUserSelectionDisallowedServerSelect() {
+ openTestURL();
+ setSelectionModelMulti();
+ toggleUserSelectionAllowed();
+
+ toggleFirstRowSelection();
+ assertTrue(getGridElement().getRow(0).isSelected());
+ }
+
+ private WebElement getSelectAllCheckbox() {
+ return getGridElement().getHeaderCell(0, 0)
+ .findElement(By.tagName("input"));
+ }
+
+ private WebElement getSelectionCheckbox(int row) {
+ return getGridElement().getCell(row, 0)
+ .findElement(By.tagName("input"));
+ }
+
}