2 * Copyright 2000-2016 Vaadin Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 * use this file except in compliance with the License. You may obtain a copy of
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 * License for the specific language governing permissions and limitations under
16 package com.vaadin.tests.components.grid.basicfeatures.client;
18 import static org.junit.Assert.assertFalse;
19 import static org.junit.Assert.assertTrue;
21 import org.junit.Test;
22 import org.openqa.selenium.Keys;
23 import org.openqa.selenium.interactions.Actions;
25 import com.vaadin.testbench.By;
26 import com.vaadin.testbench.elements.GridElement.GridCellElement;
27 import com.vaadin.tests.components.grid.basicfeatures.GridBasicClientFeaturesTest;
29 public class GridClientSelectionTest extends GridBasicClientFeaturesTest {
32 public void testChangeSelectionMode() {
35 setSelectionModelNone();
36 assertTrue("First column was selection column",
37 getGridElement().getCell(0, 0).getText().equals("(0, 0)"));
38 setSelectionModelMulti();
39 assertTrue("First column was not selection column",
40 getGridElement().getCell(0, 1).getText().equals("(0, 0)"));
44 public void testSelectAllCheckbox() {
47 setSelectionModelMulti();
48 selectMenuPath("Component", "DataSource",
49 "Reset with 100 rows of Data");
50 GridCellElement header = getGridElement().getHeaderCell(0, 0);
52 assertTrue("No checkbox", header.isElementPresent(By.tagName("input")));
53 header.findElement(By.tagName("input")).click();
55 for (int i = 0; i < 100; i += 10) {
56 assertTrue("Row " + i + " was not selected.",
57 getGridElement().getRow(i).isSelected());
60 header.findElement(By.tagName("input")).click();
61 assertFalse("Row 52 was still selected",
62 getGridElement().getRow(52).isSelected());
66 public void testSelectAllCheckboxWhenChangingModels() {
69 GridCellElement header;
70 header = getGridElement().getHeaderCell(0, 0);
72 "Check box shouldn't have been in header for None Selection Model",
73 header.isElementPresent(By.tagName("input")));
75 setSelectionModelMulti();
76 header = getGridElement().getHeaderCell(0, 0);
77 assertTrue("Multi Selection Model should have select all checkbox",
78 header.isElementPresent(By.tagName("input")));
80 setSelectionModelSingle(true);
81 header = getGridElement().getHeaderCell(0, 0);
83 "Check box shouldn't have been in header for Single Selection Model",
84 header.isElementPresent(By.tagName("input")));
86 setSelectionModelNone();
87 header = getGridElement().getHeaderCell(0, 0);
89 "Check box shouldn't have been in header for None Selection Model",
90 header.isElementPresent(By.tagName("input")));
95 public void testDeselectAllowedMouseInput() {
98 setSelectionModelSingle(true);
100 getGridElement().getCell(5, 1).click();
102 assertTrue("Row 5 should be selected after clicking", isRowSelected(5));
104 getGridElement().getCell(7, 1).click();
106 assertFalse("Row 5 should be deselected after clicking another row",
108 assertTrue("Row 7 should be selected after clicking", isRowSelected(7));
110 getGridElement().getCell(7, 1).click();
112 assertFalse("Row should be deselected after clicking again",
117 public void testDeselectAllowedKeyboardInput() {
120 setSelectionModelSingle(true);
122 getGridElement().getHeaderCell(0, 0).click();
124 new Actions(getDriver()).sendKeys(Keys.ARROW_DOWN).perform();
126 new Actions(getDriver()).sendKeys(Keys.SPACE).perform();
128 assertTrue("Row 0 should be selected after pressing space",
131 new Actions(getDriver()).sendKeys(Keys.ARROW_DOWN).perform();
133 new Actions(getDriver()).sendKeys(Keys.SPACE).perform();
136 "Row 0 should be deselected after pressing space another row",
138 assertTrue("Row 1 should be selected after pressing space",
141 new Actions(getDriver()).sendKeys(Keys.SPACE).perform();
143 assertFalse("Row should be deselected after pressing space again",
148 public void testDeselectNotAllowedMouseInput() {
151 setSelectionModelSingle(false);
153 getGridElement().getCell(5, 1).click();
155 assertTrue("Row 5 should be selected after clicking", isRowSelected(5));
157 getGridElement().getCell(7, 1).click();
159 assertFalse("Row 5 should be deselected after clicking another row",
161 assertTrue("Row 7 should be selected after clicking", isRowSelected(7));
163 getGridElement().getCell(7, 1).click();
165 assertTrue("Row should remain selected after clicking again",
170 public void testDeselectNotAllowedKeyboardInput() {
173 setSelectionModelSingle(false);
175 getGridElement().getHeaderCell(0, 0).click();
176 new Actions(getDriver()).sendKeys(Keys.ARROW_DOWN).perform();
178 new Actions(getDriver()).sendKeys(Keys.SPACE).perform();
180 assertTrue("Row 0 should be selected after pressing space",
183 new Actions(getDriver()).sendKeys(Keys.ARROW_DOWN).perform();
185 new Actions(getDriver()).sendKeys(Keys.SPACE).perform();
188 "Row 0 should be deselected after pressing space another row",
190 assertTrue("Row 1 should be selected after pressing space",
193 new Actions(getDriver()).sendKeys(Keys.SPACE).perform();
195 assertTrue("Row should remain selected after pressing space again",
200 public void testChangeSelectionModelUpdatesUI() {
203 setSelectionModelSingle(true);
204 getGridElement().getCell(5, 1).click();
205 assertTrue("Row 5 should be selected after clicking", isRowSelected(5));
206 setSelectionModelNone();
208 "Row 5 should not be selected after changing selection model",