2 * Copyright 2000-2014 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.client;
18 import static org.junit.Assert.assertEquals;
19 import static org.junit.Assert.assertFalse;
20 import static org.junit.Assert.assertTrue;
22 import java.util.ArrayList;
23 import java.util.List;
25 import org.junit.Test;
27 import com.vaadin.testbench.elements.GridElement;
28 import com.vaadin.testbench.elements.GridElement.GridCellElement;
29 import com.vaadin.testbench.elements.NotificationElement;
30 import com.vaadin.tests.components.grid.basicfeatures.GridBasicClientFeaturesTest;
31 import com.vaadin.tests.widgetset.client.grid.GridBasicClientFeaturesWidget;
33 public class GridClientColumnPropertiesTest extends GridBasicClientFeaturesTest {
36 public void initialColumnWidths() {
39 for (int col = 0; col < GridBasicClientFeaturesWidget.COLUMNS; col++) {
40 int width = getGridElement().getCell(0, col).getSize().getWidth();
42 // Growing column widths
43 int expectedWidth = 50 + col * 25;
44 assertEquals("column " + col + " has incorrect width",
45 expectedWidth, width);
51 public void testChangingColumnWidth() {
54 selectMenuPath("Component", "Columns", "Column 0", "Width", "50px");
55 int width = getGridElement().getCell(0, 0).getSize().getWidth();
56 assertEquals(50, width);
58 selectMenuPath("Component", "Columns", "Column 0", "Width", "200px");
59 width = getGridElement().getCell(0, 0).getSize().getWidth();
60 assertEquals(200, width);
62 selectMenuPath("Component", "Columns", "Column 0", "Width", "auto");
63 int autoWidth = getGridElement().getCell(0, 0).getSize().getWidth();
64 assertLessThan("Automatic sizing should've shrunk the column",
69 public void testFrozenColumns() {
72 assertFalse(cellIsFrozen(0, 0));
73 assertFalse(cellIsFrozen(0, 1));
75 selectMenuPath("Component", "State", "Frozen column count", "1 columns");
77 assertTrue(cellIsFrozen(1, 0));
78 assertFalse(cellIsFrozen(1, 1));
80 selectMenuPath("Component", "State", "Selection mode", "multi");
82 assertTrue(cellIsFrozen(1, 1));
83 assertFalse(cellIsFrozen(1, 2));
85 selectMenuPath("Component", "State", "Frozen column count", "0 columns");
87 assertTrue(cellIsFrozen(1, 0));
88 assertFalse(cellIsFrozen(1, 1));
90 selectMenuPath("Component", "State", "Frozen column count",
93 assertFalse(cellIsFrozen(1, 0));
97 public void testBrokenRenderer() {
101 GridElement gridElement = getGridElement();
103 // Scroll first row out of view
104 gridElement.getRow(50);
106 // Enable broken renderer for the first row
107 selectMenuPath("Component", "Columns", "Column 0", "Broken renderer");
109 // Shouldn't have an error notification yet
110 assertFalse("Notification was present",
111 isElementPresent(NotificationElement.class));
113 // Scroll broken row into view and enjoy the chaos
114 gridElement.getRow(0);
116 assertTrue("Notification was not present",
117 isElementPresent(NotificationElement.class));
119 assertFalse("Text in broken cell should have old value",
120 "(0, 0)".equals(gridElement.getCell(0, 0).getText()));
122 assertEquals("Neighbour cell should be updated", "(0, 1)", gridElement
123 .getCell(0, 1).getText());
125 assertEquals("Neighbour cell should be updated", "(1, 0)", gridElement
126 .getCell(1, 0).getText());
130 public void testColumnWidths_onColumnReorder_columnWidthsKeptTheSame() {
133 GridElement gridElement = getGridElement();
134 List<GridCellElement> headerCells = gridElement.getHeaderCells(0);
136 final List<Integer> columnWidths = new ArrayList<Integer>();
137 for (GridCellElement cell : headerCells) {
138 columnWidths.add(cell.getSize().getWidth());
142 selectMenuPath("Component", "State", "Reverse grid columns");
145 gridElement = getGridElement();
146 headerCells = gridElement.getHeaderCells(0);
147 final int size = headerCells.size();
148 // skip last column since there is a bug in the width of the last column
149 for (int i = 0; i < size - 1; i++) {
151 "Column widths don't match after reset, index after flip "
154 Integer.valueOf(headerCells.get(size - 1 - i).getSize()
160 private boolean cellIsFrozen(int row, int col) {
161 return getGridElement().getCell(row, col).isFrozen();