]> source.dussan.org Git - vaadin-framework.git/blob
d340e27c636de6ffb6f645ee08d5f8009e222728
[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.server;
17
18 import static org.junit.Assert.assertTrue;
19
20 import org.junit.Test;
21 import org.openqa.selenium.Keys;
22 import org.openqa.selenium.interactions.Actions;
23
24 import com.vaadin.tests.components.grid.basicfeatures.GridBasicFeaturesTest;
25 import com.vaadin.v7.testbench.customelements.GridElement;
26
27 public class GridCellFocusAdjustmentTest extends GridBasicFeaturesTest {
28
29     @Test
30     public void testCellFocusWithAddAndRemoveRows() {
31         openTestURL();
32         GridElement grid = getGridElement();
33
34         grid.getCell(0, 0).click();
35
36         selectMenuPath("Component", "Body rows", "Add first row");
37         assertTrue("Cell focus was not moved when adding a row",
38                 grid.getCell(1, 0).isFocused());
39
40         selectMenuPath("Component", "Body rows", "Add 18 rows");
41         assertTrue("Cell focus was not moved when adding multiple rows",
42                 grid.getCell(19, 0).isFocused());
43
44         for (int i = 18; i <= 0; --i) {
45             selectMenuPath("Component", "Body rows", "Remove first row");
46             assertTrue("Cell focus was not moved when removing a row",
47                     grid.getCell(i, 0).isFocused());
48         }
49     }
50
51     @Test
52     public void testCellFocusOffsetWhileInDifferentSection() {
53         openTestURL();
54         getGridElement().getCell(0, 0).click();
55         new Actions(getDriver()).sendKeys(Keys.UP).perform();
56         assertTrue("Header 0,0 should've become focused",
57                 getGridElement().getHeaderCell(0, 0).isFocused());
58
59         selectMenuPath("Component", "Body rows", "Add first row");
60         assertTrue("Header 0,0 should've remained focused",
61                 getGridElement().getHeaderCell(0, 0).isFocused());
62     }
63
64     @Test
65     public void testCellFocusOffsetWhileInSameSectionAndInsertedAbove() {
66         openTestURL();
67         assertTrue("Body 0,0 should've gotten focus",
68                 getGridElement().getCell(0, 0).isFocused());
69
70         selectMenuPath("Component", "Body rows", "Add first row");
71         assertTrue("Body 1,0 should've gotten focus",
72                 getGridElement().getCell(1, 0).isFocused());
73     }
74
75     @Test
76     public void testCellFocusOffsetWhileInSameSectionAndInsertedBelow() {
77         openTestURL();
78         assertTrue("Body 0,0 should've gotten focus",
79                 getGridElement().getCell(0, 0).isFocused());
80
81         selectMenuPath("Component", "Body rows", "Add third row");
82         assertTrue("Body 0,0 should've remained focused",
83                 getGridElement().getCell(0, 0).isFocused());
84     }
85
86 }