1 package com.vaadin.tests.components.grid.basicfeatures.server;
3 import static org.junit.Assert.assertEquals;
4 import static org.junit.Assert.assertTrue;
6 import org.junit.Before;
8 import org.openqa.selenium.By;
9 import org.openqa.selenium.Dimension;
10 import org.openqa.selenium.interactions.Actions;
12 import com.vaadin.testbench.elements.GridElement.GridCellElement;
13 import com.vaadin.testbench.parallel.TestCategory;
14 import com.vaadin.tests.components.grid.basicfeatures.GridBasicFeatures;
15 import com.vaadin.tests.components.grid.basicfeatures.GridBasicFeaturesTest;
18 public class GridColumnResizeTest extends GridBasicFeaturesTest {
21 public void before() {
26 public void testResizeHandlesPresentInDefaultHeader() {
27 for (int i = 0; i < GridBasicFeatures.COLUMNS; ++i) {
28 assertResizable(i, true);
33 public void testResizeHandlesNotInNonDefaultHeader() {
34 selectMenuPath("Component", "Header", "Prepend row");
36 for (int i = 0; i < GridBasicFeatures.COLUMNS; ++i) {
37 assertResizable(getGridElement().getHeaderCell(0, i), false);
38 assertResizable(getGridElement().getHeaderCell(1, i), true);
43 public void testResizeHandlesNotInFooter() {
44 selectMenuPath("Component", "Footer", "Visible");
45 for (int i = 0; i < GridBasicFeatures.COLUMNS; ++i) {
46 assertResizable(getGridElement().getFooterCell(0, i), false);
51 public void testToggleSetResizable() {
52 selectMenuPath("Component", "Columns", "Column 1", "Resizable");
54 for (int i = 0; i < GridBasicFeatures.COLUMNS; ++i) {
55 assertResizable(i, i != 1);
58 selectMenuPath("Component", "Columns", "Column 1", "Resizable");
60 for (int i = 0; i < GridBasicFeatures.COLUMNS; ++i) {
61 assertResizable(i, true);
66 public void testResizeFirstColumn() {
67 dragResizeColumn(0, -1, -10);
68 assertTrue("Log should contain a resize event",
69 logContainsText("ColumnResizeEvent: isUserOriginated? true"));
73 public void testDragHandleStraddlesColumns() {
74 dragResizeColumn(0, 4, -10);
75 assertTrue("Log should contain a resize event",
76 logContainsText("ColumnResizeEvent: isUserOriginated? true"));
80 public void testColumnPixelSizesSetOnResize() {
81 selectMenuPath("Component", "Columns", "All columns auto width");
82 dragResizeColumn(0, -1, -10);
83 for (String msg : getLogs()) {
84 assertTrue("Log should contain a resize event",
85 msg.contains("ColumnResizeEvent: isUserOriginated? true"));
90 public void testResizeWithWidgetHeader() {
91 selectMenuPath("Component", "Columns", "Column 0", "Column 0 Width",
93 selectMenuPath("Component", "Columns", "Column 0", "Header Type",
96 // IE9 and IE10 sometimes have a 1px gap between resize handle parts, so
98 dragResizeColumn(0, 1, 10);
100 assertTrue("Log should contain a resize event",
101 logContainsText("ColumnResizeEvent: isUserOriginated? true"));
104 private void dragResizeColumn(int columnIndex, int posX, int offset) {
105 GridCellElement headerCell = getGridElement().getHeaderCell(0,
107 Dimension size = headerCell.getSize();
108 new Actions(getDriver())
109 .moveToElement(headerCell, size.getWidth() + posX,
110 size.getHeight() / 2)
111 .clickAndHold().moveByOffset(offset, 0).release().perform();
114 private void assertResizable(int columnIndex, boolean resizable) {
115 assertResizable(getGridElement().getHeaderCell(0, columnIndex),
119 private void assertResizable(GridCellElement cell, boolean resizable) {
120 assertEquals("Header resize handle present", resizable,
121 cell.isElementPresent(
122 By.cssSelector("div.v-grid-column-resize-handle")));
126 public void testShrinkColumnToZero() {
128 GridCellElement cell = getGridElement().getCell(0, 1);
129 dragResizeColumn(1, 0, cell.getSize().getWidth());
131 assertGreaterOrEqual("Cell got too small.", cell.getSize().getWidth(),
136 public void testShrinkColumnToZeroWithHiddenColumn() {
138 selectMenuPath("Component", "Columns",
139 "Toggle all column hidden state");
140 // Hides although already hidden
141 toggleColumnHidden(0);
143 toggleColumnHidden(0);
144 // Hides although already hidden
145 toggleColumnHidden(2);
147 toggleColumnHidden(2);
148 GridCellElement cell = getGridElement().getCell(0, 1);
149 dragResizeColumn(1, 0, -cell.getSize().getWidth());
150 assertGreaterOrEqual("Cell got too small.", cell.getSize().getWidth(),
152 assertEquals(getGridElement().getCell(0, 0).getLocation().getY(),
153 getGridElement().getCell(0, 1).getLocation().getY());