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.assertEquals;
19 import static org.junit.Assert.assertTrue;
21 import org.junit.Before;
22 import org.junit.Test;
23 import org.openqa.selenium.By;
24 import org.openqa.selenium.Dimension;
25 import org.openqa.selenium.interactions.Actions;
27 import com.vaadin.testbench.elements.GridElement.GridCellElement;
28 import com.vaadin.testbench.parallel.TestCategory;
29 import com.vaadin.tests.components.grid.basicfeatures.GridBasicFeatures;
30 import com.vaadin.tests.components.grid.basicfeatures.GridBasicFeaturesTest;
33 public class GridColumnResizeTest extends GridBasicFeaturesTest {
36 public void before() {
41 public void testResizeHandlesPresentInDefaultHeader() {
42 for (int i = 0; i < GridBasicFeatures.COLUMNS; ++i) {
43 assertResizable(i, true);
48 public void testResizeHandlesNotInNonDefaultHeader() {
49 selectMenuPath("Component", "Header", "Prepend row");
51 for (int i = 0; i < GridBasicFeatures.COLUMNS; ++i) {
52 assertResizable(getGridElement().getHeaderCell(0, i), false);
53 assertResizable(getGridElement().getHeaderCell(1, i), true);
58 public void testResizeHandlesNotInFooter() {
59 selectMenuPath("Component", "Footer", "Visible");
60 for (int i = 0; i < GridBasicFeatures.COLUMNS; ++i) {
61 assertResizable(getGridElement().getFooterCell(0, i), false);
66 public void testToggleSetResizable() {
67 selectMenuPath("Component", "Columns", "Column 1", "Resizable");
69 for (int i = 0; i < GridBasicFeatures.COLUMNS; ++i) {
70 assertResizable(i, i != 1);
73 selectMenuPath("Component", "Columns", "Column 1", "Resizable");
75 for (int i = 0; i < GridBasicFeatures.COLUMNS; ++i) {
76 assertResizable(i, true);
81 public void testResizeFirstColumn() {
82 dragResizeColumn(0, -1, -10);
83 assertTrue("Log should contain a resize event",
84 logContainsText("ColumnResizeEvent: isUserOriginated? true"));
88 public void testDragHandleStraddlesColumns() {
89 dragResizeColumn(0, 4, -10);
90 assertTrue("Log should contain a resize event",
91 logContainsText("ColumnResizeEvent: isUserOriginated? true"));
95 public void testColumnPixelSizesSetOnResize() {
96 selectMenuPath("Component", "Columns", "All columns auto width");
97 dragResizeColumn(0, -1, -10);
98 for (String msg : getLogs()) {
99 assertTrue("Log should contain a resize event",
100 msg.contains("ColumnResizeEvent: isUserOriginated? true"));
105 public void testResizeWithWidgetHeader() {
106 selectMenuPath("Component", "Columns", "Column 0", "Column 0 Width",
108 selectMenuPath("Component", "Columns", "Column 0", "Header Type",
111 // IE9 and IE10 sometimes have a 1px gap between resize handle parts, so
113 dragResizeColumn(0, 1, 10);
115 assertTrue("Log should contain a resize event",
116 logContainsText("ColumnResizeEvent: isUserOriginated? true"));
119 private void dragResizeColumn(int columnIndex, int posX, int offset) {
120 GridCellElement headerCell = getGridElement().getHeaderCell(0,
122 Dimension size = headerCell.getSize();
123 new Actions(getDriver())
124 .moveToElement(headerCell, size.getWidth() + posX,
125 size.getHeight() / 2)
126 .clickAndHold().moveByOffset(offset, 0).release().perform();
129 private void assertResizable(int columnIndex, boolean resizable) {
130 assertResizable(getGridElement().getHeaderCell(0, columnIndex),
134 private void assertResizable(GridCellElement cell, boolean resizable) {
135 assertEquals("Header resize handle present", resizable,
136 cell.isElementPresent(
137 By.cssSelector("div.v-grid-column-resize-handle")));
141 public void testShrinkColumnToZero() {
143 GridCellElement cell = getGridElement().getCell(0, 1);
144 dragResizeColumn(1, 0, cell.getSize().getWidth());
146 assertGreaterOrEqual("Cell got too small.", cell.getSize().getWidth(),