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.client;
18 import org.junit.Assert;
19 import org.junit.Test;
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;
26 public class GridCellStyleGeneratorTest extends GridBasicClientFeaturesTest {
29 public void testStyleNameGeneratorScrolling() throws Exception {
32 selectCellStyleNameGenerator(
33 GridBasicClientFeaturesWidget.CELL_STYLE_GENERATOR_COL_INDEX);
34 selectRowStyleNameGenerator(
35 GridBasicClientFeaturesWidget.ROW_STYLE_GENERATOR_ROW_INDEX);
37 GridRowElement row2 = getGridElement().getRow(2);
38 GridCellElement cell4_2 = getGridElement().getCell(4, 2);
40 Assert.assertTrue(hasCssClass(row2, "2"));
41 Assert.assertTrue(hasCssClass(cell4_2, "4_2"));
43 // Scroll down and verify that the old elements don't have the
46 getGridElement().getRow(350);
48 Assert.assertFalse(hasCssClass(row2, "2"));
49 Assert.assertFalse(hasCssClass(cell4_2, "4_2"));
53 public void testDisableStyleNameGenerator() throws Exception {
56 selectCellStyleNameGenerator(
57 GridBasicClientFeaturesWidget.CELL_STYLE_GENERATOR_COL_INDEX);
58 selectRowStyleNameGenerator(
59 GridBasicClientFeaturesWidget.ROW_STYLE_GENERATOR_ROW_INDEX);
61 // Just verify that change was effective
62 GridRowElement row2 = getGridElement().getRow(2);
63 GridCellElement cell4_2 = getGridElement().getCell(4, 2);
65 Assert.assertTrue(hasCssClass(row2, "2"));
66 Assert.assertTrue(hasCssClass(cell4_2, "4_2"));
68 // Disable the generator and check again
69 selectCellStyleNameGenerator(
70 GridBasicClientFeaturesWidget.CELL_STYLE_GENERATOR_NONE);
71 selectRowStyleNameGenerator(
72 GridBasicClientFeaturesWidget.ROW_STYLE_GENERATOR_NONE);
74 Assert.assertFalse(hasCssClass(row2, "2"));
75 Assert.assertFalse(hasCssClass(cell4_2, "4_2"));
79 public void testChangeStyleNameGenerator() throws Exception {
82 selectCellStyleNameGenerator(
83 GridBasicClientFeaturesWidget.CELL_STYLE_GENERATOR_COL_INDEX);
84 selectRowStyleNameGenerator(
85 GridBasicClientFeaturesWidget.ROW_STYLE_GENERATOR_ROW_INDEX);
87 // Just verify that change was effective
88 GridRowElement row2 = getGridElement().getRow(2);
89 GridCellElement cell4_2 = getGridElement().getCell(4, 2);
91 Assert.assertTrue(hasCssClass(row2, "2"));
92 Assert.assertTrue(hasCssClass(cell4_2, "4_2"));
94 // Change the generator and check again
95 selectRowStyleNameGenerator(
96 GridBasicClientFeaturesWidget.ROW_STYLE_GENERATOR_NONE);
97 selectCellStyleNameGenerator(
98 GridBasicClientFeaturesWidget.CELL_STYLE_GENERATOR_SIMPLE);
100 // Old styles removed?
101 Assert.assertFalse(hasCssClass(row2, "2"));
102 Assert.assertFalse(hasCssClass(cell4_2, "4_2"));
104 // New style present?
105 Assert.assertTrue(hasCssClass(cell4_2, "two"));
109 public void testStyleNameGeneratorChangePrimary() throws Exception {
112 selectCellStyleNameGenerator(
113 GridBasicClientFeaturesWidget.CELL_STYLE_GENERATOR_COL_INDEX);
114 selectRowStyleNameGenerator(
115 GridBasicClientFeaturesWidget.ROW_STYLE_GENERATOR_ROW_INDEX);
117 // Just verify that change was effective
118 GridRowElement row2 = getGridElement().getRow(2);
119 GridCellElement cell4_2 = getGridElement().getCell(4, 2);
121 Assert.assertTrue(hasCssClass(row2, "2"));
122 Assert.assertTrue(hasCssClass(cell4_2, "4_2"));
124 // Change primary stylename
125 selectMenuPath("Component", "State", "Primary Stylename",
128 // Styles still present
129 Assert.assertTrue(hasCssClass(row2, "2"));
130 Assert.assertTrue(hasCssClass(cell4_2, "4_2"));
132 // New styles present?
133 Assert.assertFalse(hasCssClass(row2, "v-escalator-row-2"));
135 hasCssClass(cell4_2, "v-escalator-cell-content-4_2"));
138 private void selectCellStyleNameGenerator(String name) {
139 selectMenuPath("Component", "State", "Cell style generator", name);
142 private void selectRowStyleNameGenerator(String name) {
143 selectMenuPath("Component", "State", "Row style generator", name);