]> source.dussan.org Git - vaadin-framework.git/blob
f40b61058e34c53bf05ffdf318332b6a34f8e05a
[vaadin-framework.git] /
1 /*
2  * Copyright 2000-2016 Vaadin Ltd.
3  *
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
6  * the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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
14  * the License.
15  */
16 package com.vaadin.tests.components.grid.basicfeatures.server;
17
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;
23
24 import org.junit.Before;
25 import org.junit.Test;
26
27 import com.vaadin.testbench.parallel.TestCategory;
28 import com.vaadin.tests.components.grid.basicfeatures.GridBasicFeaturesTest;
29
30 @TestCategory("grid")
31 public class GridColumnVisibilityTest extends GridBasicFeaturesTest {
32
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" };
37
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";
44
45     @Before
46     public void setUp() {
47         openTestURL();
48     }
49
50     @Test
51     public void columnIsNotShownWhenHidden() {
52         assertEquals("column 0",
53                 getGridElement().getHeaderCell(0, 0).getText().toLowerCase());
54
55         selectMenuPath(TOGGLE_HIDE_COLUMN_0);
56         assertEquals("column 1",
57                 getGridElement().getHeaderCell(0, 0).getText().toLowerCase());
58     }
59
60     @Test
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());
66     }
67
68     @Test
69     public void registeringListener() {
70         assertFalse(logContainsText(COLUMN_0_BECAME_HIDDEN_MSG));
71         selectMenuPath(TOGGLE_LISTENER);
72         assertFalse(logContainsText(COLUMN_0_BECAME_HIDDEN_MSG));
73
74         selectMenuPath(TOGGLE_HIDE_COLUMN_0);
75         assertTrue(logContainsText(COLUMN_0_BECAME_HIDDEN_MSG));
76         assertTrue(logContainsText(USER_ORIGINATED_FALSE));
77
78         selectMenuPath(TOGGLE_HIDE_COLUMN_0);
79         assertTrue(logContainsText(COLUMN_0_BECAME_UNHIDDEN_MSG));
80         assertTrue(logContainsText(USER_ORIGINATED_FALSE));
81     }
82
83     @Test
84     public void deregisteringListener() {
85         selectMenuPath(TOGGLE_LISTENER);
86         selectMenuPath(TOGGLE_HIDE_COLUMN_0);
87
88         selectMenuPath(TOGGLE_LISTENER);
89         selectMenuPath(TOGGLE_HIDE_COLUMN_0);
90         assertFalse(logContainsText(COLUMN_0_BECAME_UNHIDDEN_MSG));
91     }
92
93     @Test
94     public void testColumnHiding_userOriginated_correctParams() {
95         selectMenuPath(TOGGLE_LISTENER);
96         toggleColumnHidable(0);
97         assertColumnHeaderOrder(0, 1, 2, 3);
98
99         getSidebarOpenButton().click();
100         getColumnHidingToggle(0).click();
101         getSidebarOpenButton().click();
102
103         assertColumnHeaderOrder(1, 2, 3);
104         assertTrue(logContainsText(COLUMN_0_BECAME_HIDDEN_MSG));
105         assertTrue(logContainsText(USER_ORIGINATED_TRUE));
106
107         getSidebarOpenButton().click();
108         getColumnHidingToggle(0).click();
109         getSidebarOpenButton().click();
110
111         assertColumnHeaderOrder(0, 1, 2, 3);
112         assertTrue(logContainsText(COLUMN_0_BECAME_UNHIDDEN_MSG));
113         assertTrue(logContainsText(USER_ORIGINATED_TRUE));
114
115         getSidebarOpenButton().click();
116         getColumnHidingToggle(0).click();
117         getSidebarOpenButton().click();
118
119         assertColumnHeaderOrder(1, 2, 3);
120         assertTrue(logContainsText(COLUMN_0_BECAME_HIDDEN_MSG));
121         assertTrue(logContainsText(USER_ORIGINATED_TRUE));
122     }
123
124     @Test
125     public void testColumnHiding_whenHidableColumnRemoved_toggleRemoved() {
126         toggleColumnHidable(0);
127         toggleColumnHidable(1);
128         getSidebarOpenButton().click();
129         assertNotNull(getColumnHidingToggle(0));
130
131         addRemoveColumn(0);
132
133         assertNull(getColumnHidingToggle(0));
134     }
135
136     @Test
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();
145
146         addRemoveColumn(0);
147         addRemoveColumn(4);
148         addRemoveColumn(5);
149         addRemoveColumn(6);
150         addRemoveColumn(7);
151         addRemoveColumn(8);
152         addRemoveColumn(9);
153         addRemoveColumn(10);
154         assertColumnHeaderOrder(1, 2, 3, 11);
155
156         getSidebarOpenButton().click();
157         assertNull(getColumnHidingToggle(0));
158         getSidebarOpenButton().click();
159
160         addRemoveColumn(0);
161         assertColumnHeaderOrder(1, 2, 3, 11, 0);
162
163         getSidebarOpenButton().click();
164         assertEquals("Column 0 caption 0", getColumnHidingToggle(0).getText());
165     }
166
167     @Test
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());
174
175         toggleColumnHidingToggleCaptionChange(1);
176
177         getSidebarOpenButton().click();
178         assertEquals("column 1",
179                 getGridElement().getHeaderCell(0, 1).getText().toLowerCase());
180         assertEquals("Column 1 caption 0", getColumnHidingToggle(1).getText());
181
182         toggleColumnHidingToggleCaptionChange(1);
183         getSidebarOpenButton().click();
184         assertEquals("Column 1 caption 1", getColumnHidingToggle(1).getText());
185     }
186
187     @Test
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());
194
195         selectMenuPath("Component", "Columns", "Column 1", "Header Type",
196                 "Widget Header");
197
198         getSidebarOpenButton().click();
199         assertEquals("Column 1", getColumnHidingToggle(1).getText());
200     }
201
202     @Test
203     public void testColumnHidingToggleCaption_settingColumnHeaderCaption_toggleCaptionIsEqual() {
204         toggleColumnHidable(1);
205
206         selectMenuPath("Component", "Columns", "Column 1",
207                 "Change header caption");
208
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());
213     }
214
215     @Test
216     public void testColumnHidingToggleCaption_explicitlySet_toggleCaptionIsNotOverridden() {
217         toggleColumnHidable(1);
218
219         selectMenuPath("Component", "Columns", "Column 1",
220                 "Change hiding toggle caption");
221         selectMenuPath("Component", "Columns", "Column 1",
222                 "Change header caption");
223
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());
228     }
229
230     private void toggleColumnHidingToggleCaptionChange(int index) {
231         selectMenuPath("Component", "Columns", "Column " + index,
232                 "Change hiding toggle caption");
233     }
234
235     @Test
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();
243
244         assertColumnHeaderOrder(2, 3, 4, 5);
245
246         setFrozenColumns(2);
247         verifyColumnNotFrozen(0);
248         verifyColumnNotFrozen(1);
249
250         getSidebarOpenButton().click();
251         getColumnHidingToggle(0).click();
252         assertColumnHeaderOrder(0, 2, 3, 4, 5);
253         verifyColumnFrozen(0);
254         verifyColumnNotFrozen(1);
255
256         getColumnHidingToggle(1).click();
257         assertColumnHeaderOrder(0, 1, 2, 3, 4, 5);
258         verifyColumnFrozen(0);
259         verifyColumnFrozen(1);
260         verifyColumnNotFrozen(2);
261     }
262
263     @Test
264     public void testFrozenColumnHiding_hiddenFrozenColumnUnfrozen_notFrozenWhenMadeVisible() {
265         selectMenuPath("Component", "Size", "Width", "100%");
266         toggleColumnHidable(0);
267         toggleColumnHidable(1);
268         setFrozenColumns(2);
269         verifyColumnFrozen(0);
270         verifyColumnFrozen(1);
271         verifyColumnNotFrozen(2);
272         verifyColumnNotFrozen(3);
273
274         getSidebarOpenButton().click();
275         getColumnHidingToggle(0).click();
276         getColumnHidingToggle(1).click();
277         assertColumnHeaderOrder(2, 3, 4, 5);
278         verifyColumnNotFrozen(0);
279         verifyColumnNotFrozen(1);
280
281         setFrozenColumns(0);
282         verifyColumnNotFrozen(0);
283         verifyColumnNotFrozen(1);
284
285         getSidebarOpenButton().click();
286         getColumnHidingToggle(0).click();
287         assertColumnHeaderOrder(0, 2, 3, 4, 5);
288         verifyColumnNotFrozen(0);
289         verifyColumnNotFrozen(1);
290
291         getColumnHidingToggle(1).click();
292         assertColumnHeaderOrder(0, 1, 2, 3, 4, 5);
293         verifyColumnNotFrozen(0);
294         verifyColumnNotFrozen(1);
295         verifyColumnNotFrozen(2);
296     }
297
298     private void verifyColumnFrozen(int index) {
299         assertTrue(getGridElement().getHeaderCell(0, index).isFrozen());
300     }
301
302     private void verifyColumnNotFrozen(int index) {
303         assertFalse(getGridElement().getHeaderCell(0, index).isFrozen());
304     }
305
306     private void toggleColumnHidable(int index) {
307         selectMenuPath("Component", "Columns", "Column " + index, "Hidable");
308     }
309
310     private void addRemoveColumn(int index) {
311         selectMenuPath("Component", "Columns", "Column " + index,
312                 "Add / Remove");
313     }
314 }