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 org.junit.Test;
24 import com.vaadin.testbench.elements.GridElement;
25 import com.vaadin.testbench.elements.NotificationElement;
26 import com.vaadin.tests.components.grid.basicfeatures.GridBasicClientFeaturesTest;
27 import com.vaadin.tests.widgetset.client.grid.GridBasicClientFeaturesWidget;
29 public class GridClientColumnPropertiesTest extends GridBasicClientFeaturesTest {
32 public void initialColumnWidths() {
35 for (int col = 0; col < GridBasicClientFeaturesWidget.COLUMNS; col++) {
36 int width = getGridElement().getCell(0, col).getSize().getWidth();
38 // Growing column widths
39 int expectedWidth = 50 + col * 25;
40 assertEquals("column " + col + " has incorrect width",
41 expectedWidth, width);
47 public void testChangingColumnWidth() {
50 selectMenuPath("Component", "Columns", "Column 0", "Width", "50px");
51 int width = getGridElement().getCell(0, 0).getSize().getWidth();
52 assertEquals(50, width);
54 selectMenuPath("Component", "Columns", "Column 0", "Width", "200px");
55 width = getGridElement().getCell(0, 0).getSize().getWidth();
56 assertEquals(200, width);
58 selectMenuPath("Component", "Columns", "Column 0", "Width", "auto");
59 int autoWidth = getGridElement().getCell(0, 0).getSize().getWidth();
60 assertLessThan("Automatic sizing should've shrunk the column",
65 public void testFrozenColumns() {
68 assertFalse(cellIsFrozen(0, 0));
69 assertFalse(cellIsFrozen(0, 1));
71 selectMenuPath("Component", "State", "Frozen column count", "1 columns");
73 assertTrue(cellIsFrozen(1, 0));
74 assertFalse(cellIsFrozen(1, 1));
76 selectMenuPath("Component", "State", "Selection mode", "multi");
78 assertTrue(cellIsFrozen(1, 1));
79 assertFalse(cellIsFrozen(1, 2));
81 selectMenuPath("Component", "State", "Frozen column count", "0 columns");
83 assertTrue(cellIsFrozen(1, 0));
84 assertFalse(cellIsFrozen(1, 1));
86 selectMenuPath("Component", "State", "Frozen column count",
89 assertFalse(cellIsFrozen(1, 0));
93 public void testBrokenRenderer() {
97 GridElement gridElement = getGridElement();
99 // Scroll first row out of view
100 gridElement.getRow(50);
102 // Enable broken renderer for the first row
103 selectMenuPath("Component", "Columns", "Column 0", "Broken renderer");
105 // Shouldn't have an error notification yet
106 assertFalse("Notification was present",
107 isElementPresent(NotificationElement.class));
109 // Scroll broken row into view and enjoy the chaos
110 gridElement.getRow(0);
112 assertTrue("Notification was not present",
113 isElementPresent(NotificationElement.class));
115 assertFalse("Text in broken cell should have old value",
116 "(0, 0)".equals(gridElement.getCell(0, 0).getText()));
118 assertEquals("Neighbour cell should be updated", "(0, 1)", gridElement
119 .getCell(0, 1).getText());
121 assertEquals("Neighbour cell should be updated", "(1, 0)", gridElement
122 .getCell(1, 0).getText());
125 private boolean cellIsFrozen(int row, int col) {
126 return getGridElement().getCell(row, col).isFrozen();