]> source.dussan.org Git - vaadin-framework.git/blob
dcb4740eda08cd9b4c0438bbe21d89d1101e9bae
[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.client;
17
18 import org.junit.Assert;
19 import org.junit.Test;
20
21 import com.vaadin.testbench.elements.GridElement.GridCellElement;
22 import com.vaadin.testbench.elements.GridElement.GridRowElement;
23 import com.vaadin.tests.components.grid.basicfeatures.GridBasicClientFeaturesTest;
24 import com.vaadin.tests.widgetset.client.grid.GridBasicClientFeaturesWidget;
25
26 public class GridCellStyleGeneratorTest extends GridBasicClientFeaturesTest {
27
28     @Test
29     public void testStyleNameGeneratorScrolling() throws Exception {
30         openTestURL();
31
32         selectCellStyleNameGenerator(
33                 GridBasicClientFeaturesWidget.CELL_STYLE_GENERATOR_COL_INDEX);
34         selectRowStyleNameGenerator(
35                 GridBasicClientFeaturesWidget.ROW_STYLE_GENERATOR_ROW_INDEX);
36
37         GridRowElement row2 = getGridElement().getRow(2);
38         GridCellElement cell4_2 = getGridElement().getCell(4, 2);
39
40         Assert.assertTrue(hasCssClass(row2, "2"));
41         Assert.assertTrue(hasCssClass(cell4_2, "4_2"));
42
43         // Scroll down and verify that the old elements don't have the
44         // stylename any more
45
46         getGridElement().getRow(350);
47
48         Assert.assertFalse(hasCssClass(row2, "2"));
49         Assert.assertFalse(hasCssClass(cell4_2, "4_2"));
50     }
51
52     @Test
53     public void testDisableStyleNameGenerator() throws Exception {
54         openTestURL();
55
56         selectCellStyleNameGenerator(
57                 GridBasicClientFeaturesWidget.CELL_STYLE_GENERATOR_COL_INDEX);
58         selectRowStyleNameGenerator(
59                 GridBasicClientFeaturesWidget.ROW_STYLE_GENERATOR_ROW_INDEX);
60
61         // Just verify that change was effective
62         GridRowElement row2 = getGridElement().getRow(2);
63         GridCellElement cell4_2 = getGridElement().getCell(4, 2);
64
65         Assert.assertTrue(hasCssClass(row2, "2"));
66         Assert.assertTrue(hasCssClass(cell4_2, "4_2"));
67
68         // Disable the generator and check again
69         selectCellStyleNameGenerator(
70                 GridBasicClientFeaturesWidget.CELL_STYLE_GENERATOR_NONE);
71         selectRowStyleNameGenerator(
72                 GridBasicClientFeaturesWidget.ROW_STYLE_GENERATOR_NONE);
73
74         Assert.assertFalse(hasCssClass(row2, "2"));
75         Assert.assertFalse(hasCssClass(cell4_2, "4_2"));
76     }
77
78     @Test
79     public void testChangeStyleNameGenerator() throws Exception {
80         openTestURL();
81
82         selectCellStyleNameGenerator(
83                 GridBasicClientFeaturesWidget.CELL_STYLE_GENERATOR_COL_INDEX);
84         selectRowStyleNameGenerator(
85                 GridBasicClientFeaturesWidget.ROW_STYLE_GENERATOR_ROW_INDEX);
86
87         // Just verify that change was effective
88         GridRowElement row2 = getGridElement().getRow(2);
89         GridCellElement cell4_2 = getGridElement().getCell(4, 2);
90
91         Assert.assertTrue(hasCssClass(row2, "2"));
92         Assert.assertTrue(hasCssClass(cell4_2, "4_2"));
93
94         // Change the generator and check again
95         selectRowStyleNameGenerator(
96                 GridBasicClientFeaturesWidget.ROW_STYLE_GENERATOR_NONE);
97         selectCellStyleNameGenerator(
98                 GridBasicClientFeaturesWidget.CELL_STYLE_GENERATOR_SIMPLE);
99
100         // Old styles removed?
101         Assert.assertFalse(hasCssClass(row2, "2"));
102         Assert.assertFalse(hasCssClass(cell4_2, "4_2"));
103
104         // New style present?
105         Assert.assertTrue(hasCssClass(cell4_2, "two"));
106     }
107
108     @Test
109     public void testStyleNameGeneratorChangePrimary() throws Exception {
110         openTestURL();
111
112         selectCellStyleNameGenerator(
113                 GridBasicClientFeaturesWidget.CELL_STYLE_GENERATOR_COL_INDEX);
114         selectRowStyleNameGenerator(
115                 GridBasicClientFeaturesWidget.ROW_STYLE_GENERATOR_ROW_INDEX);
116
117         // Just verify that change was effective
118         GridRowElement row2 = getGridElement().getRow(2);
119         GridCellElement cell4_2 = getGridElement().getCell(4, 2);
120
121         Assert.assertTrue(hasCssClass(row2, "2"));
122         Assert.assertTrue(hasCssClass(cell4_2, "4_2"));
123
124         // Change primary stylename
125         selectMenuPath("Component", "State", "Primary Stylename",
126                 "v-escalator");
127
128         // Styles still present
129         Assert.assertTrue(hasCssClass(row2, "2"));
130         Assert.assertTrue(hasCssClass(cell4_2, "4_2"));
131
132         // New styles present?
133         Assert.assertFalse(hasCssClass(row2, "v-escalator-row-2"));
134         Assert.assertFalse(
135                 hasCssClass(cell4_2, "v-escalator-cell-content-4_2"));
136     }
137
138     private void selectCellStyleNameGenerator(String name) {
139         selectMenuPath("Component", "State", "Cell style generator", name);
140     }
141
142     private void selectRowStyleNameGenerator(String name) {
143         selectMenuPath("Component", "State", "Row style generator", name);
144     }
145 }