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.v7.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.GridCellElement;
28 import com.vaadin.tests.widgetset.client.v7.grid.GridBasicClientFeaturesWidget;
29 import com.vaadin.testbench.elements.NotificationElement;
30 import com.vaadin.v7.testbench.customelements.GridElement;
31 import com.vaadin.v7.tests.components.grid.basicfeatures.GridBasicClientFeaturesTest;
33 public class GridClientColumnPropertiesTest
34 extends GridBasicClientFeaturesTest {
37 public void initialColumnWidths() {
40 for (int col = 0; col < GridBasicClientFeaturesWidget.COLUMNS; col++) {
41 int width = getGridElement().getCell(0, col).getSize().getWidth();
43 // Growing column widths
44 int expectedWidth = 50 + col * 25;
45 assertEquals("column " + col + " has incorrect width",
46 expectedWidth, width);
52 public void testChangingColumnWidth() {
55 selectMenuPath("Component", "Columns", "Column 0", "Width", "50px");
56 int width = getGridElement().getCell(0, 0).getSize().getWidth();
57 assertEquals(50, width);
59 selectMenuPath("Component", "Columns", "Column 0", "Width", "200px");
60 width = getGridElement().getCell(0, 0).getSize().getWidth();
61 assertEquals(200, width);
63 selectMenuPath("Component", "Columns", "Column 0", "Width", "auto");
64 int autoWidth = getGridElement().getCell(0, 0).getSize().getWidth();
65 assertLessThan("Automatic sizing should've shrunk the column",
70 public void testFrozenColumns() {
73 assertFalse(cellIsFrozen(0, 0));
74 assertFalse(cellIsFrozen(0, 1));
76 selectMenuPath("Component", "State", "Frozen column count",
79 assertTrue(cellIsFrozen(1, 0));
80 assertFalse(cellIsFrozen(1, 1));
82 selectMenuPath("Component", "State", "Selection mode", "multi");
84 assertTrue(cellIsFrozen(1, 1));
85 assertFalse(cellIsFrozen(1, 2));
87 selectMenuPath("Component", "State", "Frozen column count",
90 assertTrue(cellIsFrozen(1, 0));
91 assertFalse(cellIsFrozen(1, 1));
93 selectMenuPath("Component", "State", "Frozen column count",
96 assertFalse(cellIsFrozen(1, 0));
100 public void testFrozenColumns_columnsReordered_frozenColumnsKept() {
103 selectMenuPath("Component", "State", "Frozen column count",
106 assertTrue(cellIsFrozen(1, 0));
107 assertTrue(cellIsFrozen(1, 1));
108 assertFalse(cellIsFrozen(1, 2));
110 selectMenuPath("Component", "State", "Reverse grid columns");
112 assertTrue(cellIsFrozen(1, 0));
113 assertTrue(cellIsFrozen(1, 1));
114 assertFalse(cellIsFrozen(1, 2));
118 public void testBrokenRenderer() {
122 GridElement gridElement = getGridElement();
124 // Scroll first row out of view
125 gridElement.getRow(50);
127 // Enable broken renderer for the first row
128 selectMenuPath("Component", "Columns", "Column 0", "Broken renderer");
130 // Shouldn't have an error notification yet
131 assertFalse("Notification was present",
132 isElementPresent(NotificationElement.class));
134 // Scroll broken row into view and enjoy the chaos
135 gridElement.getRow(0);
137 assertTrue("Notification was not present",
138 isElementPresent(NotificationElement.class));
140 assertFalse("Text in broken cell should have old value",
141 "(0, 0)".equals(gridElement.getCell(0, 0).getText()));
143 assertEquals("Neighbour cell should be updated", "(0, 1)",
144 gridElement.getCell(0, 1).getText());
146 assertEquals("Neighbour cell should be updated", "(1, 0)",
147 gridElement.getCell(1, 0).getText());
151 public void testColumnWidths_onColumnReorder_columnWidthsKeptTheSame() {
154 GridElement gridElement = getGridElement();
155 List<GridCellElement> headerCells = gridElement.getHeaderCells(0);
157 final List<Integer> columnWidths = new ArrayList<Integer>();
158 for (GridCellElement cell : headerCells) {
159 columnWidths.add(cell.getSize().getWidth());
163 selectMenuPath("Component", "State", "Reverse grid columns");
166 gridElement = getGridElement();
167 headerCells = gridElement.getHeaderCells(0);
168 final int size = headerCells.size();
169 for (int i = 0; i < size; i++) {
170 // Avoid issues with inaccuracies regarding subpixels.
172 "Column widths don't match after reset, index after flip "
175 headerCells.get(size - 1 - i).getSize().getWidth(), 1.0d);
180 private boolean cellIsFrozen(int row, int col) {
181 return getGridElement().getCell(row, col).isFrozen();