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.assertFalse;
20 import org.junit.Assert;
21 import org.junit.Test;
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;
29 public class GridCellStyleGeneratorTest extends GridBasicFeaturesTest {
31 public void testStyleNameGeneratorScrolling() throws Exception {
34 selectRowStyleNameGenerator(
35 GridBasicFeatures.ROW_STYLE_GENERATOR_ROW_NUMBERS_FOR_3_OF_4);
36 selectCellStyleNameGenerator(
37 GridBasicFeatures.CELL_STYLE_GENERATOR_SPECIAL);
39 GridRowElement row = getGridElement().getRow(2);
40 GridCellElement cell = getGridElement().getCell(3, 2);
42 Assert.assertTrue(hasCssClass(row, "row2"));
43 Assert.assertTrue(hasCssClass(cell, "Column_2"));
45 // Scroll down and verify that the old elements don't have the
48 // Carefully chosen offset to hit an index % 4 without cell style
49 row = getGridElement().getRow(352);
50 cell = getGridElement().getCell(353, 2);
52 Assert.assertFalse(hasCssClass(row, "row352"));
53 Assert.assertFalse(hasCssClass(cell, "Column_2"));
57 public void testDisableStyleNameGenerator() throws Exception {
60 selectRowStyleNameGenerator(
61 GridBasicFeatures.ROW_STYLE_GENERATOR_ROW_NUMBERS_FOR_3_OF_4);
62 selectCellStyleNameGenerator(
63 GridBasicFeatures.CELL_STYLE_GENERATOR_SPECIAL);
65 // Just verify that change was effective
66 GridRowElement row2 = getGridElement().getRow(2);
67 GridCellElement cell3_2 = getGridElement().getCell(3, 2);
69 Assert.assertTrue(hasCssClass(row2, "row2"));
70 Assert.assertTrue(hasCssClass(cell3_2, "Column_2"));
72 // Disable the generator and check again
73 selectRowStyleNameGenerator(GridBasicFeatures.ROW_STYLE_GENERATOR_NONE);
74 selectCellStyleNameGenerator(
75 GridBasicFeatures.CELL_STYLE_GENERATOR_NONE);
77 Assert.assertFalse(hasCssClass(row2, "row2"));
78 Assert.assertFalse(hasCssClass(cell3_2, "Column_2"));
82 public void testChangeStyleNameGenerator() throws Exception {
85 selectRowStyleNameGenerator(
86 GridBasicFeatures.ROW_STYLE_GENERATOR_ROW_NUMBERS_FOR_3_OF_4);
87 selectCellStyleNameGenerator(
88 GridBasicFeatures.CELL_STYLE_GENERATOR_SPECIAL);
90 // Just verify that change was effective
91 GridRowElement row2 = getGridElement().getRow(2);
92 GridCellElement cell3_2 = getGridElement().getCell(3, 2);
94 Assert.assertTrue(hasCssClass(row2, "row2"));
95 Assert.assertTrue(hasCssClass(cell3_2, "Column_2"));
97 // Change the generator and check again
98 selectRowStyleNameGenerator(GridBasicFeatures.ROW_STYLE_GENERATOR_NONE);
99 selectCellStyleNameGenerator(
100 GridBasicFeatures.CELL_STYLE_GENERATOR_PROPERTY_TO_STRING);
102 // Old styles removed?
103 Assert.assertFalse(hasCssClass(row2, "row2"));
104 Assert.assertFalse(hasCssClass(cell3_2, "Column_2"));
106 // New style present?
107 Assert.assertTrue(hasCssClass(cell3_2, "Column-2"));
111 public void testCellStyleGeneratorWithSelectionColumn() {
114 selectMenuPath("Component", "State", "Selection mode", "multi");
116 selectCellStyleNameGenerator(
117 GridBasicFeatures.CELL_STYLE_GENERATOR_SPECIAL);
119 assertFalse("Error notification was present",
120 isElementPresent(NotificationElement.class));
123 private void selectRowStyleNameGenerator(String name) {
124 selectMenuPath("Component", "State", "Row style generator", name);
127 private void selectCellStyleNameGenerator(String name) {
128 selectMenuPath("Component", "State", "Cell style generator", name);
132 public void testEmptyStringStyleGenerator() {
135 selectCellStyleNameGenerator(
136 GridBasicFeatures.CELL_STYLE_GENERATOR_EMPTY);
137 selectRowStyleNameGenerator(
138 GridBasicFeatures.ROW_STYLE_GENERATOR_EMPTY);
140 assertFalse("Error notification was present",
141 isElementPresent(NotificationElement.class));
145 public void testNullStringStyleGenerator() {
148 selectCellStyleNameGenerator(
149 GridBasicFeatures.CELL_STYLE_GENERATOR_NULL);
150 selectRowStyleNameGenerator(GridBasicFeatures.ROW_STYLE_GENERATOR_NULL);
152 assertFalse("Error notification was present",
153 isElementPresent(NotificationElement.class));