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.assertFalse;
20 import static org.junit.Assert.assertNotNull;
21 import static org.junit.Assert.assertNull;
22 import static org.junit.Assert.assertTrue;
24 import org.junit.Before;
25 import org.junit.Test;
27 import com.vaadin.testbench.parallel.TestCategory;
28 import com.vaadin.tests.components.grid.basicfeatures.GridBasicFeaturesTest;
31 public class GridColumnVisibilityTest extends GridBasicFeaturesTest {
33 private static final String[] TOGGLE_LISTENER = new String[] { "Component",
34 "State", "ColumnVisibilityChangeListener" };
35 private static final String[] TOGGLE_HIDE_COLUMN_0 = new String[] {
36 "Component", "Columns", "Column 0", "Hidden" };
38 private static final String COLUMN_0_BECAME_HIDDEN_MSG = "Visibility "
39 + "changed: propertyId: Column 0, isHidden: true";
40 private static final String COLUMN_0_BECAME_UNHIDDEN_MSG = "Visibility "
41 + "changed: propertyId: Column 0, isHidden: false";
42 private static final String USER_ORIGINATED_TRUE = "userOriginated: true";
43 private static final String USER_ORIGINATED_FALSE = "userOriginated: false";
51 public void columnIsNotShownWhenHidden() {
52 assertEquals("column 0",
53 getGridElement().getHeaderCell(0, 0).getText().toLowerCase());
55 selectMenuPath(TOGGLE_HIDE_COLUMN_0);
56 assertEquals("column 1",
57 getGridElement().getHeaderCell(0, 0).getText().toLowerCase());
61 public void columnIsShownWhenUnhidden() {
62 selectMenuPath(TOGGLE_HIDE_COLUMN_0);
63 selectMenuPath(TOGGLE_HIDE_COLUMN_0);
64 assertEquals("column 0",
65 getGridElement().getHeaderCell(0, 0).getText().toLowerCase());
69 public void registeringListener() {
70 assertFalse(logContainsText(COLUMN_0_BECAME_HIDDEN_MSG));
71 selectMenuPath(TOGGLE_LISTENER);
72 assertFalse(logContainsText(COLUMN_0_BECAME_HIDDEN_MSG));
74 selectMenuPath(TOGGLE_HIDE_COLUMN_0);
75 assertTrue(logContainsText(COLUMN_0_BECAME_HIDDEN_MSG));
76 assertTrue(logContainsText(USER_ORIGINATED_FALSE));
78 selectMenuPath(TOGGLE_HIDE_COLUMN_0);
79 assertTrue(logContainsText(COLUMN_0_BECAME_UNHIDDEN_MSG));
80 assertTrue(logContainsText(USER_ORIGINATED_FALSE));
84 public void deregisteringListener() {
85 selectMenuPath(TOGGLE_LISTENER);
86 selectMenuPath(TOGGLE_HIDE_COLUMN_0);
88 selectMenuPath(TOGGLE_LISTENER);
89 selectMenuPath(TOGGLE_HIDE_COLUMN_0);
90 assertFalse(logContainsText(COLUMN_0_BECAME_UNHIDDEN_MSG));
94 public void testColumnHiding_userOriginated_correctParams() {
95 selectMenuPath(TOGGLE_LISTENER);
96 toggleColumnHidable(0);
97 assertColumnHeaderOrder(0, 1, 2, 3);
99 getSidebarOpenButton().click();
100 getColumnHidingToggle(0).click();
101 getSidebarOpenButton().click();
103 assertColumnHeaderOrder(1, 2, 3);
104 assertTrue(logContainsText(COLUMN_0_BECAME_HIDDEN_MSG));
105 assertTrue(logContainsText(USER_ORIGINATED_TRUE));
107 getSidebarOpenButton().click();
108 getColumnHidingToggle(0).click();
109 getSidebarOpenButton().click();
111 assertColumnHeaderOrder(0, 1, 2, 3);
112 assertTrue(logContainsText(COLUMN_0_BECAME_UNHIDDEN_MSG));
113 assertTrue(logContainsText(USER_ORIGINATED_TRUE));
115 getSidebarOpenButton().click();
116 getColumnHidingToggle(0).click();
117 getSidebarOpenButton().click();
119 assertColumnHeaderOrder(1, 2, 3);
120 assertTrue(logContainsText(COLUMN_0_BECAME_HIDDEN_MSG));
121 assertTrue(logContainsText(USER_ORIGINATED_TRUE));
125 public void testColumnHiding_whenHidableColumnRemoved_toggleRemoved() {
126 toggleColumnHidable(0);
127 toggleColumnHidable(1);
128 getSidebarOpenButton().click();
129 assertNotNull(getColumnHidingToggle(0));
133 assertNull(getColumnHidingToggle(0));
137 public void testColumnHiding_whenHidableColumnAdded_toggleWithCorrectCaptionAdded() {
138 selectMenuPath("Component", "Size", "Width", "100%");
139 toggleColumnHidable(0);
140 toggleColumnHidable(1);
141 toggleColumnHidingToggleCaptionChange(0);
142 getSidebarOpenButton().click();
143 assertEquals("Column 0 caption 0", getColumnHidingToggle(0).getText());
144 getSidebarOpenButton().click();
154 assertColumnHeaderOrder(1, 2, 3, 11);
156 getSidebarOpenButton().click();
157 assertNull(getColumnHidingToggle(0));
158 getSidebarOpenButton().click();
161 assertColumnHeaderOrder(1, 2, 3, 11, 0);
163 getSidebarOpenButton().click();
164 assertEquals("Column 0 caption 0", getColumnHidingToggle(0).getText());
168 public void testColumnHidingToggleCaption_settingToggleCaption_updatesToggle() {
169 toggleColumnHidable(1);
170 getSidebarOpenButton().click();
171 assertEquals("column 1",
172 getGridElement().getHeaderCell(0, 1).getText().toLowerCase());
173 assertEquals("Column 1", getColumnHidingToggle(1).getText());
175 toggleColumnHidingToggleCaptionChange(1);
177 getSidebarOpenButton().click();
178 assertEquals("column 1",
179 getGridElement().getHeaderCell(0, 1).getText().toLowerCase());
180 assertEquals("Column 1 caption 0", getColumnHidingToggle(1).getText());
182 toggleColumnHidingToggleCaptionChange(1);
183 getSidebarOpenButton().click();
184 assertEquals("Column 1 caption 1", getColumnHidingToggle(1).getText());
188 public void testColumnHidingToggleCaption_settingWidgetToHeader_toggleCaptionStays() {
189 toggleColumnHidable(1);
190 getSidebarOpenButton().click();
191 assertEquals("column 1",
192 getGridElement().getHeaderCell(0, 1).getText().toLowerCase());
193 assertEquals("Column 1", getColumnHidingToggle(1).getText());
195 selectMenuPath("Component", "Columns", "Column 1", "Header Type",
198 getSidebarOpenButton().click();
199 assertEquals("Column 1", getColumnHidingToggle(1).getText());
203 public void testColumnHidingToggleCaption_settingColumnHeaderCaption_toggleCaptionIsEqual() {
204 toggleColumnHidable(1);
206 selectMenuPath("Component", "Columns", "Column 1",
207 "Change header caption");
209 getSidebarOpenButton().click();
210 assertEquals("column 1 header 0",
211 getGridElement().getHeaderCell(0, 1).getText().toLowerCase());
212 assertEquals("Column 1 header 0", getColumnHidingToggle(1).getText());
216 public void testColumnHidingToggleCaption_explicitlySet_toggleCaptionIsNotOverridden() {
217 toggleColumnHidable(1);
219 selectMenuPath("Component", "Columns", "Column 1",
220 "Change hiding toggle caption");
221 selectMenuPath("Component", "Columns", "Column 1",
222 "Change header caption");
224 getSidebarOpenButton().click();
225 assertEquals("column 1 header 0",
226 getGridElement().getHeaderCell(0, 1).getText().toLowerCase());
227 assertEquals("Column 1 caption 0", getColumnHidingToggle(1).getText());
230 private void toggleColumnHidingToggleCaptionChange(int index) {
231 selectMenuPath("Component", "Columns", "Column " + index,
232 "Change hiding toggle caption");
236 public void testFrozenColumnHiding_hiddenColumnMadeFrozen_frozenWhenMadeVisible() {
237 selectMenuPath("Component", "Size", "Width", "100%");
238 toggleColumnHidable(0);
239 toggleColumnHidable(1);
240 getSidebarOpenButton().click();
241 getColumnHidingToggle(0).click();
242 getColumnHidingToggle(1).click();
244 assertColumnHeaderOrder(2, 3, 4, 5);
247 verifyColumnNotFrozen(0);
248 verifyColumnNotFrozen(1);
250 getSidebarOpenButton().click();
251 getColumnHidingToggle(0).click();
252 assertColumnHeaderOrder(0, 2, 3, 4, 5);
253 verifyColumnFrozen(0);
254 verifyColumnNotFrozen(1);
256 getColumnHidingToggle(1).click();
257 assertColumnHeaderOrder(0, 1, 2, 3, 4, 5);
258 verifyColumnFrozen(0);
259 verifyColumnFrozen(1);
260 verifyColumnNotFrozen(2);
264 public void testFrozenColumnHiding_hiddenFrozenColumnUnfrozen_notFrozenWhenMadeVisible() {
265 selectMenuPath("Component", "Size", "Width", "100%");
266 toggleColumnHidable(0);
267 toggleColumnHidable(1);
269 verifyColumnFrozen(0);
270 verifyColumnFrozen(1);
271 verifyColumnNotFrozen(2);
272 verifyColumnNotFrozen(3);
274 getSidebarOpenButton().click();
275 getColumnHidingToggle(0).click();
276 getColumnHidingToggle(1).click();
277 assertColumnHeaderOrder(2, 3, 4, 5);
278 verifyColumnNotFrozen(0);
279 verifyColumnNotFrozen(1);
282 verifyColumnNotFrozen(0);
283 verifyColumnNotFrozen(1);
285 getSidebarOpenButton().click();
286 getColumnHidingToggle(0).click();
287 assertColumnHeaderOrder(0, 2, 3, 4, 5);
288 verifyColumnNotFrozen(0);
289 verifyColumnNotFrozen(1);
291 getColumnHidingToggle(1).click();
292 assertColumnHeaderOrder(0, 1, 2, 3, 4, 5);
293 verifyColumnNotFrozen(0);
294 verifyColumnNotFrozen(1);
295 verifyColumnNotFrozen(2);
298 private void verifyColumnFrozen(int index) {
299 assertTrue(getGridElement().getHeaderCell(0, index).isFrozen());
302 private void verifyColumnNotFrozen(int index) {
303 assertFalse(getGridElement().getHeaderCell(0, index).isFrozen());
306 private void toggleColumnHidable(int index) {
307 selectMenuPath("Component", "Columns", "Column " + index, "Hidable");
310 private void addRemoveColumn(int index) {
311 selectMenuPath("Component", "Columns", "Column " + index,