1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
|
package com.vaadin.tests.components.table;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import com.vaadin.testbench.TestBenchElement;
import com.vaadin.testbench.elements.TableElement;
import com.vaadin.tests.tb3.MultiBrowserTest;
@SuppressWarnings("deprecation")
public class TableGeneratedRowsTest extends MultiBrowserTest {
@Override
protected Class<?> getUIClass() {
return Tables.class;
}
@Test
public void changeRowGenerator() {
openTestURL();
TableElement table = $(TableElement.class).first();
/* No row generator */
TestBenchElement cell = table.getCell(4, 0);
int tableWidth = table.getSize().getWidth();
int cellWidth = cell.getSize().getWidth();
int buffer = 40; // for paddings, borders, scrollbars, and bit extra
int bufferedTableWidth = tableWidth - buffer;
String text = cell.getText();
assertFalse("Unexpected cell contents without applying row generator: "
+ text, text != null && text.startsWith("FOOBARBAZ"));
assertLessThan(
"Cell shouldn't be spanned without applying row generator: "
+ cellWidth + " isn't less than " + (tableWidth / 10),
cellWidth, tableWidth / 10);
/* Spanned row generator */
selectMenuPath("Component", "Features", "Row generator",
"Every fifth row, spanned");
cell = table.getCell(4, 0);
cellWidth = cell.getSize().getWidth();
text = cell.getText();
assertTrue(
"Unexpected cell contents for spanned generated row: " + text,
text != null && text.startsWith("FOOBARBAZ"));
assertLessThanOrEqual(
"Spanned cell isn't wide enough for spanned generated row: "
+ cellWidth + " isn't more than " + bufferedTableWidth,
bufferedTableWidth, cellWidth);
/* Non-spanned row generator */
selectMenuPath("Component", "Features", "Row generator",
"Every tenth row, no spanning");
cell = table.getCell(4, 0);
cellWidth = cell.getSize().getWidth();
text = cell.getText();
assertFalse(
"Unexpected cell contents after replacing spanned row generator: "
+ text,
text != null && text.startsWith("FOOBARBAZ"));
assertLessThan(
"Cell shouldn't be spanned anymore after replacing spanned row generator: "
+ cellWidth + " isn't less than " + (tableWidth / 10),
cellWidth, tableWidth / 10);
cell = table.getCell(9, 0);
cellWidth = cell.getSize().getWidth();
text = cell.getText();
assertTrue("Unexpected cell contents for non-spanned generated row: "
+ text, text != null && text.startsWith("FOO0"));
assertLessThan(
"Unexpected cell width for non-spanned generated row: "
+ cellWidth + " isn't less than " + (tableWidth / 10),
cellWidth, tableWidth / 10);
/* Spanned and html formatted row generator */
selectMenuPath("Component", "Features", "Row generator",
"Every eight row, spanned, html formatted");
cell = table.getCell(9, 0);
cellWidth = cell.getSize().getWidth();
text = cell.getText();
assertFalse(
"Unexpected cell contents after replacing non-spanned row generator: "
+ text,
text != null && text.startsWith("FOO0"));
assertLessThan(
"Unexpected cell width after replacing non-spanned row generator: "
+ cellWidth + " isn't less than " + (tableWidth / 10),
cellWidth, tableWidth / 10);
cell = table.getCell(7, 0);
cellWidth = cell.getSize().getWidth();
text = cell.getText();
assertTrue("Unexpected contents for spanned and html formatted cell: "
+ text, text != null && text.startsWith("FOO BAR BAZ"));
assertLessThanOrEqual(
"Spanned and html formatted cell isn't wide enough: "
+ cellWidth + " isn't more than " + bufferedTableWidth,
bufferedTableWidth, cellWidth);
WebElement bazSpan = cell.findElement(By.tagName("span"));
if (bazSpan == null) {
fail("Unexpected styling: no span found");
} else {
String bazStyle = bazSpan.getAttribute("style");
assertTrue("Unexpected styling: " + bazStyle,
bazStyle != null && bazStyle.contains("color: red"));
}
/* Spanned row generator for all rows */
selectMenuPath("Component", "Features", "Row generator",
"Every row, spanned");
for (int i = 0; i < 10; ++i) {
cell = table.getCell(i, 0);
cellWidth = cell.getSize().getWidth();
text = cell.getText();
assertTrue(
"Unexpected cell contents with every row spanned: " + text,
text != null && text.startsWith("SPANNED"));
assertLessThanOrEqual(
"Spanned cell isn't wide enough with every row spanned: "
+ cellWidth + " isn't more than "
+ bufferedTableWidth,
bufferedTableWidth, cellWidth);
}
/* No row generator */
selectMenuPath("Component", "Features", "Row generator", "None");
for (int i = 0; i < 10; ++i) {
cell = table.getCell(i, 0);
cellWidth = cell.getSize().getWidth();
text = cell.getText();
assertFalse(
"Unexpected cell contents without row generator: " + text,
text != null && text.startsWith("SPANNED"));
assertLessThan(
"Unexpected cell width without row generator: " + cellWidth
+ " isn't less than " + (tableWidth / 10),
cellWidth, tableWidth / 10);
}
}
}
|