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.server;
18 import static org.junit.Assert.assertTrue;
20 import org.junit.Test;
21 import org.openqa.selenium.Keys;
22 import org.openqa.selenium.interactions.Actions;
24 import com.vaadin.tests.components.grid.basicfeatures.GridBasicFeaturesTest;
25 import com.vaadin.v7.testbench.customelements.GridElement;
27 public class GridCellFocusAdjustmentTest extends GridBasicFeaturesTest {
30 public void testCellFocusWithAddAndRemoveRows() {
32 GridElement grid = getGridElement();
34 grid.getCell(0, 0).click();
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());
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());
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());
52 public void testCellFocusOffsetWhileInDifferentSection() {
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());
59 selectMenuPath("Component", "Body rows", "Add first row");
60 assertTrue("Header 0,0 should've remained focused",
61 getGridElement().getHeaderCell(0, 0).isFocused());
65 public void testCellFocusOffsetWhileInSameSectionAndInsertedAbove() {
67 assertTrue("Body 0,0 should've gotten focus",
68 getGridElement().getCell(0, 0).isFocused());
70 selectMenuPath("Component", "Body rows", "Add first row");
71 assertTrue("Body 1,0 should've gotten focus",
72 getGridElement().getCell(1, 0).isFocused());
76 public void testCellFocusOffsetWhileInSameSectionAndInsertedBelow() {
78 assertTrue("Body 0,0 should've gotten focus",
79 getGridElement().getCell(0, 0).isFocused());
81 selectMenuPath("Component", "Body rows", "Add third row");
82 assertTrue("Body 0,0 should've remained focused",
83 getGridElement().getCell(0, 0).isFocused());