]> source.dussan.org Git - vaadin-framework.git/blob
5b4e9abbe90ac179961ae37680d3f6db521856e7
[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.assertEquals;
19 import static org.junit.Assert.assertTrue;
20
21 import java.io.IOException;
22 import java.util.Arrays;
23 import java.util.List;
24
25 import org.junit.Assert;
26 import org.junit.Test;
27 import org.openqa.selenium.Keys;
28 import org.openqa.selenium.interactions.Actions;
29
30 import com.vaadin.testbench.By;
31 import com.vaadin.testbench.elements.GridElement.GridCellElement;
32 import com.vaadin.tests.components.grid.basicfeatures.GridBasicClientFeaturesTest;
33
34 public class GridClientKeyEventsTest extends GridBasicClientFeaturesTest {
35
36     private List<String> eventOrder = Arrays.asList("Down", "Up", "Press");
37
38     @Test
39     public void testBodyKeyEvents() throws IOException {
40         openTestURL();
41
42         getGridElement().getCell(2, 2).click();
43
44         new Actions(getDriver()).sendKeys("a").perform();
45
46         for (int i = 0; i < 3; ++i) {
47             assertEquals("Body key event handler was not called.",
48                     "(2, 2) event: GridKey" + eventOrder.get(i) + "Event:["
49                             + (eventOrder.get(i).equals("Press") ? "a" : 65)
50                             + "]",
51                     findElements(By.className("v-label")).get(i * 3).getText());
52
53             assertTrue("Header key event handler got called unexpectedly.",
54                     findElements(By.className("v-label")).get(i * 3 + 1)
55                             .getText().isEmpty());
56             assertTrue("Footer key event handler got called unexpectedly.",
57                     findElements(By.className("v-label")).get(i * 3 + 2)
58                             .getText().isEmpty());
59         }
60
61     }
62
63     @Test
64     public void testHeaderKeyEvents() throws IOException {
65         openTestURL();
66
67         getGridElement().getHeaderCell(0, 2).click();
68
69         new Actions(getDriver()).sendKeys("a").perform();
70
71         for (int i = 0; i < 3; ++i) {
72             assertEquals("Header key event handler was not called.",
73                     "(0, 2) event: GridKey" + eventOrder.get(i) + "Event:["
74                             + (eventOrder.get(i).equals("Press") ? "a" : 65)
75                             + "]",
76                     findElements(By.className("v-label")).get(i * 3 + 1)
77                             .getText());
78
79             assertTrue("Body key event handler got called unexpectedly.",
80                     findElements(By.className("v-label")).get(i * 3).getText()
81                             .isEmpty());
82             assertTrue("Footer key event handler got called unexpectedly.",
83                     findElements(By.className("v-label")).get(i * 3 + 2)
84                             .getText().isEmpty());
85         }
86     }
87
88     @Test
89     public void selectAllUsingKeyboard() {
90         openTestURL();
91
92         selectMenuPath("Component", "Header", "Prepend row");
93         selectMenuPath("Component", "Header", "Append row");
94         selectMenuPath("Component", "State", "Selection mode", "multi");
95
96         // IE8 does not handle 1k rows well with assertions enabled. Less rows!
97         selectMenuPath("Component", "DataSource",
98                 "Reset with 100 rows of Data");
99
100         // Focus cell above select all checkbox
101         getGridElement().getHeaderCell(0, 0).click();
102         Assert.assertFalse(isRowSelected(1));
103         new Actions(getDriver()).sendKeys(" ").perform();
104         Assert.assertFalse(isRowSelected(1));
105
106         // Move down to select all checkbox cell
107         new Actions(getDriver()).sendKeys(Keys.ARROW_DOWN).perform();
108         Assert.assertFalse(isRowSelected(1));
109         new Actions(getDriver()).sendKeys(" ").perform(); // select all
110         Assert.assertTrue(isRowSelected(1));
111         new Actions(getDriver()).sendKeys(" ").perform(); // deselect all
112         Assert.assertFalse(isRowSelected(1));
113
114         // Move down to header below select all checkbox cell
115         new Actions(getDriver()).sendKeys(Keys.ARROW_DOWN).perform();
116         Assert.assertFalse(isRowSelected(1));
117         new Actions(getDriver()).sendKeys(" ").perform(); // deselect all
118         Assert.assertFalse(isRowSelected(1));
119
120     }
121
122     @Test
123     public void testFooterKeyEvents() throws IOException {
124         openTestURL();
125
126         selectMenuPath("Component", "Footer", "Append row");
127         getGridElement().getFooterCell(0, 2).click();
128
129         new Actions(getDriver()).sendKeys("a").perform();
130
131         for (int i = 0; i < 3; ++i) {
132             assertEquals("Footer key event handler was not called.",
133                     "(0, 2) event: GridKey" + eventOrder.get(i) + "Event:["
134                             + (eventOrder.get(i).equals("Press") ? "a" : 65)
135                             + "]",
136                     findElements(By.className("v-label")).get(i * 3 + 2)
137                             .getText());
138
139             assertTrue("Body key event handler got called unexpectedly.",
140                     findElements(By.className("v-label")).get(i * 3).getText()
141                             .isEmpty());
142             assertTrue("Header key event handler got called unexpectedly.",
143                     findElements(By.className("v-label")).get(i * 3 + 1)
144                             .getText().isEmpty());
145
146         }
147     }
148
149     @Test
150     public void testNoKeyEventsFromWidget() {
151         openTestURL();
152
153         selectMenuPath("Component", "Columns", "Column 2", "Header Type",
154                 "Widget Header");
155         GridCellElement header = getGridElement().getHeaderCell(0, 2);
156         header.findElement(By.tagName("button")).click();
157         new Actions(getDriver()).sendKeys(Keys.ENTER).perform();
158
159         for (int i = 0; i < 3; ++i) {
160             assertTrue("Header key event handler got called unexpectedly.",
161                     findElements(By.className("v-label")).get(i * 3 + 1)
162                             .getText().isEmpty());
163
164         }
165     }
166
167 }