]> source.dussan.org Git - vaadin-framework.git/blob
1e10f7abdf3b47dd30d1a641c1986a74a76e8119
[vaadin-framework.git] /
1 /*
2  * Copyright 2000-2016 Vaadin Ltd.
3  *
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
6  * the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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
14  * the License.
15  */
16 package com.vaadin.tests.components.grid.basicfeatures.client;
17
18 import static org.junit.Assert.assertFalse;
19 import static org.junit.Assert.assertTrue;
20
21 import org.junit.Test;
22 import org.openqa.selenium.Keys;
23 import org.openqa.selenium.interactions.Actions;
24
25 import com.vaadin.testbench.By;
26 import com.vaadin.testbench.elements.GridElement.GridCellElement;
27 import com.vaadin.tests.components.grid.basicfeatures.GridBasicClientFeaturesTest;
28
29 public class GridClientSelectionTest extends GridBasicClientFeaturesTest {
30
31     @Test
32     public void testChangeSelectionMode() {
33         openTestURL();
34
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)"));
41     }
42
43     @Test
44     public void testSelectAllCheckbox() {
45         openTestURL();
46
47         setSelectionModelMulti();
48         selectMenuPath("Component", "DataSource",
49                 "Reset with 100 rows of Data");
50         GridCellElement header = getGridElement().getHeaderCell(0, 0);
51
52         assertTrue("No checkbox", header.isElementPresent(By.tagName("input")));
53         header.findElement(By.tagName("input")).click();
54
55         for (int i = 0; i < 100; i += 10) {
56             assertTrue("Row " + i + " was not selected.",
57                     getGridElement().getRow(i).isSelected());
58         }
59
60         header.findElement(By.tagName("input")).click();
61         assertFalse("Row 52 was still selected",
62                 getGridElement().getRow(52).isSelected());
63     }
64
65     @Test
66     public void testSelectAllCheckboxWhenChangingModels() {
67         openTestURL();
68
69         GridCellElement header;
70         header = getGridElement().getHeaderCell(0, 0);
71         assertFalse(
72                 "Check box shouldn't have been in header for None Selection Model",
73                 header.isElementPresent(By.tagName("input")));
74
75         setSelectionModelMulti();
76         header = getGridElement().getHeaderCell(0, 0);
77         assertTrue("Multi Selection Model should have select all checkbox",
78                 header.isElementPresent(By.tagName("input")));
79
80         setSelectionModelSingle(true);
81         header = getGridElement().getHeaderCell(0, 0);
82         assertFalse(
83                 "Check box shouldn't have been in header for Single Selection Model",
84                 header.isElementPresent(By.tagName("input")));
85
86         setSelectionModelNone();
87         header = getGridElement().getHeaderCell(0, 0);
88         assertFalse(
89                 "Check box shouldn't have been in header for None Selection Model",
90                 header.isElementPresent(By.tagName("input")));
91
92     }
93
94     @Test
95     public void testDeselectAllowedMouseInput() {
96         openTestURL();
97
98         setSelectionModelSingle(true);
99
100         getGridElement().getCell(5, 1).click();
101
102         assertTrue("Row 5 should be selected after clicking", isRowSelected(5));
103
104         getGridElement().getCell(7, 1).click();
105
106         assertFalse("Row 5 should be deselected after clicking another row",
107                 isRowSelected(5));
108         assertTrue("Row 7 should be selected after clicking", isRowSelected(7));
109
110         getGridElement().getCell(7, 1).click();
111
112         assertFalse("Row should be deselected after clicking again",
113                 isRowSelected(7));
114     }
115
116     @Test
117     public void testDeselectAllowedKeyboardInput() {
118         openTestURL();
119
120         setSelectionModelSingle(true);
121
122         getGridElement().getHeaderCell(0, 0).click();
123
124         new Actions(getDriver()).sendKeys(Keys.ARROW_DOWN).perform();
125
126         new Actions(getDriver()).sendKeys(Keys.SPACE).perform();
127
128         assertTrue("Row 0 should be selected after pressing space",
129                 isRowSelected(0));
130
131         new Actions(getDriver()).sendKeys(Keys.ARROW_DOWN).perform();
132
133         new Actions(getDriver()).sendKeys(Keys.SPACE).perform();
134
135         assertFalse(
136                 "Row 0 should be deselected after pressing space another row",
137                 isRowSelected(0));
138         assertTrue("Row 1 should be selected after pressing space",
139                 isRowSelected(1));
140
141         new Actions(getDriver()).sendKeys(Keys.SPACE).perform();
142
143         assertFalse("Row should be deselected after pressing space again",
144                 isRowSelected(1));
145     }
146
147     @Test
148     public void testDeselectNotAllowedMouseInput() {
149         openTestURL();
150
151         setSelectionModelSingle(false);
152
153         getGridElement().getCell(5, 1).click();
154
155         assertTrue("Row 5 should be selected after clicking", isRowSelected(5));
156
157         getGridElement().getCell(7, 1).click();
158
159         assertFalse("Row 5 should be deselected after clicking another row",
160                 isRowSelected(5));
161         assertTrue("Row 7 should be selected after clicking", isRowSelected(7));
162
163         getGridElement().getCell(7, 1).click();
164
165         assertTrue("Row should remain selected after clicking again",
166                 isRowSelected(7));
167     }
168
169     @Test
170     public void testDeselectNotAllowedKeyboardInput() {
171         openTestURL();
172
173         setSelectionModelSingle(false);
174
175         getGridElement().getHeaderCell(0, 0).click();
176         new Actions(getDriver()).sendKeys(Keys.ARROW_DOWN).perform();
177
178         new Actions(getDriver()).sendKeys(Keys.SPACE).perform();
179
180         assertTrue("Row 0 should be selected after pressing space",
181                 isRowSelected(0));
182
183         new Actions(getDriver()).sendKeys(Keys.ARROW_DOWN).perform();
184
185         new Actions(getDriver()).sendKeys(Keys.SPACE).perform();
186
187         assertFalse(
188                 "Row 0 should be deselected after pressing space another row",
189                 isRowSelected(0));
190         assertTrue("Row 1 should be selected after pressing space",
191                 isRowSelected(1));
192
193         new Actions(getDriver()).sendKeys(Keys.SPACE).perform();
194
195         assertTrue("Row should remain selected after pressing space again",
196                 isRowSelected(1));
197     }
198
199     @Test
200     public void testChangeSelectionModelUpdatesUI() {
201         openTestURL();
202
203         setSelectionModelSingle(true);
204         getGridElement().getCell(5, 1).click();
205         assertTrue("Row 5 should be selected after clicking", isRowSelected(5));
206         setSelectionModelNone();
207         assertFalse(
208                 "Row 5 should not be selected after changing selection model",
209                 isRowSelected(5));
210
211     }
212 }