]> source.dussan.org Git - vaadin-framework.git/blob
09431b2f6fde599ed6847fb82251b9bd2a1033e5
[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.assertFalse;
19
20 import org.junit.Assert;
21 import org.junit.Test;
22
23 import com.vaadin.testbench.elements.GridElement.GridCellElement;
24 import com.vaadin.testbench.elements.GridElement.GridRowElement;
25 import com.vaadin.testbench.elements.NotificationElement;
26 import com.vaadin.tests.components.grid.basicfeatures.GridBasicFeatures;
27 import com.vaadin.tests.components.grid.basicfeatures.GridBasicFeaturesTest;
28
29 public class GridCellStyleGeneratorTest extends GridBasicFeaturesTest {
30     @Test
31     public void testStyleNameGeneratorScrolling() throws Exception {
32         openTestURL();
33
34         selectRowStyleNameGenerator(
35                 GridBasicFeatures.ROW_STYLE_GENERATOR_ROW_NUMBERS_FOR_3_OF_4);
36         selectCellStyleNameGenerator(
37                 GridBasicFeatures.CELL_STYLE_GENERATOR_SPECIAL);
38
39         GridRowElement row = getGridElement().getRow(2);
40         GridCellElement cell = getGridElement().getCell(3, 2);
41
42         Assert.assertTrue(hasCssClass(row, "row2"));
43         Assert.assertTrue(hasCssClass(cell, "Column_2"));
44
45         // Scroll down and verify that the old elements don't have the
46         // stylename any more
47
48         // Carefully chosen offset to hit an index % 4 without cell style
49         row = getGridElement().getRow(352);
50         cell = getGridElement().getCell(353, 2);
51
52         Assert.assertFalse(hasCssClass(row, "row352"));
53         Assert.assertFalse(hasCssClass(cell, "Column_2"));
54     }
55
56     @Test
57     public void testDisableStyleNameGenerator() throws Exception {
58         openTestURL();
59
60         selectRowStyleNameGenerator(
61                 GridBasicFeatures.ROW_STYLE_GENERATOR_ROW_NUMBERS_FOR_3_OF_4);
62         selectCellStyleNameGenerator(
63                 GridBasicFeatures.CELL_STYLE_GENERATOR_SPECIAL);
64
65         // Just verify that change was effective
66         GridRowElement row2 = getGridElement().getRow(2);
67         GridCellElement cell3_2 = getGridElement().getCell(3, 2);
68
69         Assert.assertTrue(hasCssClass(row2, "row2"));
70         Assert.assertTrue(hasCssClass(cell3_2, "Column_2"));
71
72         // Disable the generator and check again
73         selectRowStyleNameGenerator(GridBasicFeatures.ROW_STYLE_GENERATOR_NONE);
74         selectCellStyleNameGenerator(
75                 GridBasicFeatures.CELL_STYLE_GENERATOR_NONE);
76
77         Assert.assertFalse(hasCssClass(row2, "row2"));
78         Assert.assertFalse(hasCssClass(cell3_2, "Column_2"));
79     }
80
81     @Test
82     public void testChangeStyleNameGenerator() throws Exception {
83         openTestURL();
84
85         selectRowStyleNameGenerator(
86                 GridBasicFeatures.ROW_STYLE_GENERATOR_ROW_NUMBERS_FOR_3_OF_4);
87         selectCellStyleNameGenerator(
88                 GridBasicFeatures.CELL_STYLE_GENERATOR_SPECIAL);
89
90         // Just verify that change was effective
91         GridRowElement row2 = getGridElement().getRow(2);
92         GridCellElement cell3_2 = getGridElement().getCell(3, 2);
93
94         Assert.assertTrue(hasCssClass(row2, "row2"));
95         Assert.assertTrue(hasCssClass(cell3_2, "Column_2"));
96
97         // Change the generator and check again
98         selectRowStyleNameGenerator(GridBasicFeatures.ROW_STYLE_GENERATOR_NONE);
99         selectCellStyleNameGenerator(
100                 GridBasicFeatures.CELL_STYLE_GENERATOR_PROPERTY_TO_STRING);
101
102         // Old styles removed?
103         Assert.assertFalse(hasCssClass(row2, "row2"));
104         Assert.assertFalse(hasCssClass(cell3_2, "Column_2"));
105
106         // New style present?
107         Assert.assertTrue(hasCssClass(cell3_2, "Column-2"));
108     }
109
110     @Test
111     public void testCellStyleGeneratorWithSelectionColumn() {
112         setDebug(true);
113         openTestURL();
114         selectMenuPath("Component", "State", "Selection mode", "multi");
115
116         selectCellStyleNameGenerator(
117                 GridBasicFeatures.CELL_STYLE_GENERATOR_SPECIAL);
118
119         assertFalse("Error notification was present",
120                 isElementPresent(NotificationElement.class));
121     }
122
123     private void selectRowStyleNameGenerator(String name) {
124         selectMenuPath("Component", "State", "Row style generator", name);
125     }
126
127     private void selectCellStyleNameGenerator(String name) {
128         selectMenuPath("Component", "State", "Cell style generator", name);
129     }
130
131     @Test
132     public void testEmptyStringStyleGenerator() {
133         setDebug(true);
134         openTestURL();
135         selectCellStyleNameGenerator(
136                 GridBasicFeatures.CELL_STYLE_GENERATOR_EMPTY);
137         selectRowStyleNameGenerator(
138                 GridBasicFeatures.ROW_STYLE_GENERATOR_EMPTY);
139
140         assertFalse("Error notification was present",
141                 isElementPresent(NotificationElement.class));
142     }
143
144     @Test
145     public void testNullStringStyleGenerator() {
146         setDebug(true);
147         openTestURL();
148         selectCellStyleNameGenerator(
149                 GridBasicFeatures.CELL_STYLE_GENERATOR_NULL);
150         selectRowStyleNameGenerator(GridBasicFeatures.ROW_STYLE_GENERATOR_NULL);
151
152         assertFalse("Error notification was present",
153                 isElementPresent(NotificationElement.class));
154     }
155 }