aboutsummaryrefslogtreecommitdiffstats
path: root/uitest
diff options
context:
space:
mode:
authorLeif Åstrand <leif@vaadin.com>2015-02-05 21:04:36 +0200
committerLeif Åstrand <leif@vaadin.com>2015-02-06 12:59:49 +0200
commitfa5f781429fe06f6c662f1a44d0514f9477f5ce0 (patch)
treec251cefb51d6570631d7309d3afebe9df80d968a /uitest
parent276797fad8642c68b2201f3752d025a231519e8f (diff)
downloadvaadin-framework-fa5f781429fe06f6c662f1a44d0514f9477f5ce0.tar.gz
vaadin-framework-fa5f781429fe06f6c662f1a44d0514f9477f5ce0.zip
Add API for controlling deselection for single select model (#16567)
Change-Id: Ieb245205b3a311a4563f39bc48baadc44e218b61
Diffstat (limited to 'uitest')
-rw-r--r--uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridBasicFeatures.java20
-rw-r--r--uitest/src/com/vaadin/tests/components/grid/basicfeatures/client/GridClientSelectionTest.java130
-rw-r--r--uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridSelectionTest.java35
-rw-r--r--uitest/src/com/vaadin/tests/widgetset/client/grid/GridBasicClientFeaturesWidget.java10
4 files changed, 190 insertions, 5 deletions
diff --git a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridBasicFeatures.java b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridBasicFeatures.java
index fe4a31d9e7..0c335f58b2 100644
--- a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridBasicFeatures.java
+++ b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridBasicFeatures.java
@@ -57,6 +57,7 @@ import com.vaadin.ui.Grid.MultiSelectionModel;
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.renderer.DateRenderer;
import com.vaadin.ui.renderer.HtmlRenderer;
import com.vaadin.ui.renderer.NumberRenderer;
@@ -82,6 +83,8 @@ public class GridBasicFeatures extends AbstractComponentTest<Grid> {
private int containerDelay = 0;
+ private boolean singleSelectAllowDeselect = true;
+
private IndexedContainer ds;
private Grid grid;
private SelectionListener selectionListener = new SelectionListener() {
@@ -320,6 +323,9 @@ public class GridBasicFeatures extends AbstractComponentTest<Grid> {
grid.setSelectionMode(selectionMode);
if (selectionMode == SelectionMode.SINGLE) {
grid.addSelectionListener(selectionListener);
+
+ ((SelectionModel.Single) grid.getSelectionModel())
+ .setDeselectAllowed(singleSelectAllowDeselect);
} else {
grid.removeSelectionListener(selectionListener);
}
@@ -488,6 +494,20 @@ public class GridBasicFeatures extends AbstractComponentTest<Grid> {
}
});
+
+ createBooleanAction("Single select allow deselect", "State",
+ singleSelectAllowDeselect, new Command<Grid, Boolean>() {
+ @Override
+ public void execute(Grid c, Boolean value, Object data) {
+ singleSelectAllowDeselect = value.booleanValue();
+
+ SelectionModel model = c.getSelectionModel();
+ if (model instanceof SelectionModel.Single) {
+ ((SelectionModel.Single) model)
+ .setDeselectAllowed(singleSelectAllowDeselect);
+ }
+ }
+ });
}
protected void createHeaderActions() {
diff --git a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/client/GridClientSelectionTest.java b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/client/GridClientSelectionTest.java
index d4c10da626..dccf2c0974 100644
--- a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/client/GridClientSelectionTest.java
+++ b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/client/GridClientSelectionTest.java
@@ -19,6 +19,8 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
+import org.openqa.selenium.Keys;
+import org.openqa.selenium.interactions.Actions;
import com.vaadin.testbench.By;
import com.vaadin.testbench.elements.GridElement.GridCellElement;
@@ -74,7 +76,7 @@ public class GridClientSelectionTest extends GridBasicClientFeaturesTest {
assertTrue("Multi Selection Model should have select all checkbox",
header.isElementPresent(By.tagName("input")));
- setSelectionModelSingle();
+ setSelectionModelSingle(true);
header = getGridElement().getHeaderCell(0, 0);
assertFalse(
"Check box shouldn't have been in header for Single Selection Model",
@@ -88,15 +90,133 @@ public class GridClientSelectionTest extends GridBasicClientFeaturesTest {
}
+ @Test
+ public void testDeselectAllowedMouseInput() {
+ openTestURL();
+
+ setSelectionModelSingle(true);
+
+ getGridElement().getCell(5, 1).click();
+
+ assertTrue("Row 5 should be selected after clicking", isRowSelected(5));
+
+ getGridElement().getCell(7, 1).click();
+
+ assertFalse("Row 5 should be deselected after clicking another row",
+ isRowSelected(5));
+ assertTrue("Row 7 should be selected after clicking", isRowSelected(7));
+
+ getGridElement().getCell(7, 1).click();
+
+ assertFalse("Row should be deselected after clicking again",
+ isRowSelected(7));
+ }
+
+ @Test
+ public void testDeselectAllowedKeyboardInput() {
+ openTestURL();
+
+ setSelectionModelSingle(true);
+
+ getGridElement().getHeaderCell(0, 1).click();
+
+ new Actions(getDriver()).sendKeys(Keys.ARROW_DOWN).perform();
+
+ new Actions(getDriver()).sendKeys(Keys.SPACE).perform();
+
+ assertTrue("Row 0 should be selected after pressing space",
+ isRowSelected(0));
+
+ new Actions(getDriver()).sendKeys(Keys.ARROW_DOWN).perform();
+
+ new Actions(getDriver()).sendKeys(Keys.SPACE).perform();
+
+ assertFalse(
+ "Row 0 should be deselected after pressing space another row",
+ isRowSelected(0));
+ assertTrue("Row 1 should be selected after pressing space",
+ isRowSelected(1));
+
+ new Actions(getDriver()).sendKeys(Keys.SPACE).perform();
+
+ assertFalse("Row should be deselected after pressing space again",
+ isRowSelected(1));
+ }
+
+ @Test
+ public void testDeselectNotAllowedMouseInput() {
+ openTestURL();
+
+ setSelectionModelSingle(false);
+
+ getGridElement().getCell(5, 1).click();
+
+ assertTrue("Row 5 should be selected after clicking", isRowSelected(5));
+
+ getGridElement().getCell(7, 1).click();
+
+ assertFalse("Row 5 should be deselected after clicking another row",
+ isRowSelected(5));
+ assertTrue("Row 7 should be selected after clicking", isRowSelected(7));
+
+ getGridElement().getCell(7, 1).click();
+
+ assertTrue("Row should remain selected after clicking again",
+ isRowSelected(7));
+ }
+
+ @Test
+ public void testDeselectNotAllowedKeyboardInput() {
+ openTestURL();
+
+ setSelectionModelSingle(false);
+
+ getGridElement().getHeaderCell(0, 1).click();
+ new Actions(getDriver()).sendKeys(Keys.ARROW_DOWN).perform();
+
+ new Actions(getDriver()).sendKeys(Keys.SPACE).perform();
+
+ assertTrue("Row 0 should be selected after pressing space",
+ isRowSelected(0));
+
+ new Actions(getDriver()).sendKeys(Keys.ARROW_DOWN).perform();
+
+ new Actions(getDriver()).sendKeys(Keys.SPACE).perform();
+
+ assertFalse(
+ "Row 0 should be deselected after pressing space another row",
+ isRowSelected(0));
+ assertTrue("Row 1 should be selected after pressing space",
+ isRowSelected(1));
+
+ new Actions(getDriver()).sendKeys(Keys.SPACE).perform();
+
+ assertTrue("Row should remain selected after pressing space again",
+ isRowSelected(1));
+ }
+
+ private boolean isRowSelected(int index) {
+ boolean selected = getGridElement().getRow(index).isSelected();
+ return selected;
+ }
+
private void setSelectionModelMulti() {
- selectMenuPath("Component", "State", "Selection mode", "multi");
+ setSelectionModel("multi");
}
- private void setSelectionModelSingle() {
- selectMenuPath("Component", "State", "Selection mode", "single");
+ private void setSelectionModelSingle(boolean deselectAllowed) {
+ String mode = "single";
+ if (!deselectAllowed) {
+ mode += " (no deselect)";
+ }
+ setSelectionModel(mode);
}
private void setSelectionModelNone() {
- selectMenuPath("Component", "State", "Selection mode", "none");
+ setSelectionModel("none");
+ }
+
+ private void setSelectionModel(String model) {
+ selectMenuPath("Component", "State", "Selection mode", model);
}
}
diff --git a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridSelectionTest.java b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridSelectionTest.java
index 3dbf613ba0..b4eb473d4b 100644
--- a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridSelectionTest.java
+++ b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridSelectionTest.java
@@ -270,6 +270,41 @@ public class GridSelectionTest extends GridBasicFeaturesTest {
}
+ @Test
+ public void testToggleDeselectAllowed() {
+ openTestURL();
+
+ setSelectionModelSingle();
+ // Deselect allowed already enabled
+
+ getGridElement().getCell(5, 1).click();
+ getGridElement().getCell(5, 1).click();
+ assertFalse("Row should be not selected after two clicks", getRow(5)
+ .isSelected());
+
+ selectMenuPath("Component", "State", "Single select allow deselect");
+ getGridElement().getCell(5, 1).click();
+ getGridElement().getCell(5, 1).click();
+ assertTrue("Row should be selected after two clicks", getRow(5)
+ .isSelected());
+
+ selectMenuPath("Component", "State", "Single select allow deselect");
+ getGridElement().getCell(5, 1).click();
+ assertFalse("Row should be not selected after another click", getRow(5)
+ .isSelected());
+
+ // Also verify that state is updated together with the model
+ setSelectionModelNone();
+ selectMenuPath("Component", "State", "Single select allow deselect");
+ setSelectionModelSingle();
+
+ getGridElement().getCell(5, 1).click();
+ getGridElement().getCell(5, 1).click();
+
+ assertTrue("Row should stay selected after two clicks", getRow(5)
+ .isSelected());
+ }
+
private void setSelectionModelMulti() {
selectMenuPath("Component", "State", "Selection mode", "multi");
}
diff --git a/uitest/src/com/vaadin/tests/widgetset/client/grid/GridBasicClientFeaturesWidget.java b/uitest/src/com/vaadin/tests/widgetset/client/grid/GridBasicClientFeaturesWidget.java
index 232a3a780e..0452aa65d1 100644
--- a/uitest/src/com/vaadin/tests/widgetset/client/grid/GridBasicClientFeaturesWidget.java
+++ b/uitest/src/com/vaadin/tests/widgetset/client/grid/GridBasicClientFeaturesWidget.java
@@ -66,6 +66,7 @@ import com.vaadin.client.widget.grid.events.HeaderKeyPressHandler;
import com.vaadin.client.widget.grid.events.HeaderKeyUpHandler;
import com.vaadin.client.widget.grid.events.ScrollEvent;
import com.vaadin.client.widget.grid.events.ScrollHandler;
+import com.vaadin.client.widget.grid.selection.SelectionModel;
import com.vaadin.client.widget.grid.selection.SelectionModel.None;
import com.vaadin.client.widgets.Grid;
import com.vaadin.client.widgets.Grid.Column;
@@ -468,6 +469,15 @@ public class GridBasicClientFeaturesWidget extends
}
}, selectionModePath);
+ addMenuCommand("single (no deselect)", new ScheduledCommand() {
+ @Override
+ public void execute() {
+ grid.setSelectionMode(SelectionMode.SINGLE);
+ ((SelectionModel.Single<?>) grid.getSelectionModel())
+ .setDeselectAllowed(false);
+ }
+ }, selectionModePath);
+
addMenuCommand("none", new ScheduledCommand() {
@Override
public void execute() {