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
|
package com.vaadin.v7.tests.components.grid;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.number.IsCloseTo.closeTo;
import static org.junit.Assert.fail;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import org.junit.Test;
import org.openqa.selenium.By;
import com.vaadin.testbench.elements.GridElement;
import com.vaadin.testbench.elements.OptionGroupElement;
import com.vaadin.testbench.parallel.TestCategory;
import com.vaadin.tests.tb3.MultiBrowserTest;
/**
* Tests that Grid gets correct height based on height mode, and resizes
* properly with details row if height is undefined.
*
* @author Vaadin Ltd
*/
@TestCategory("grid")
public class GridHeightTest extends MultiBrowserTest {
@Override
public void setup() throws Exception {
super.setup();
openTestURL();
waitForElementPresent(By.className("v-grid"));
}
@Test
public void testGridHeightAndResizingUndefined()
throws InterruptedException {
assertNoErrors(testGridHeightAndResizing(GridHeight.UNDEFINED));
}
@Test
public void testGridHeightAndResizingRow() throws InterruptedException {
assertNoErrors(testGridHeightAndResizing(GridHeight.ROW3));
}
@Test
public void testGridHeightAndResizingFull() throws InterruptedException {
assertNoErrors(testGridHeightAndResizing(GridHeight.FULL));
}
private Map<AssertionError, Object[]> testGridHeightAndResizing(
Object gridHeight) throws InterruptedException {
Map<AssertionError, Object[]> errors = new HashMap<>();
String caption;
if (GridHeight.ROW3.equals(gridHeight)) {
caption = gridHeight + " rows";
} else {
caption = (String) gridHeight;
}
$(OptionGroupElement.class).id("gridHeightSelector")
.selectByText(caption);
for (String gridWidth : GridHeight.gridWidths) {
$(OptionGroupElement.class).id("gridWidthSelector")
.selectByText(gridWidth);
for (String detailsRowHeight : GridHeight.detailsRowHeights) {
$(OptionGroupElement.class).id("detailsHeightSelector")
.selectByText(detailsRowHeight);
sleep(500);
GridElement grid = $(GridElement.class).first();
int initialHeight = grid.getSize().getHeight();
try {
// check default height
assertGridHeight(getExpectedInitialHeight(gridHeight),
initialHeight);
} catch (AssertionError e) {
errors.put(e, new Object[] { gridHeight, gridWidth,
detailsRowHeight, "initial" });
}
grid.getRow(2).click(5, 5);
waitForElementPresent(By.id("lbl1"));
int openHeight = grid.getSize().getHeight();
try {
// check height with details row opened
assertGridHeight(getExpectedOpenedHeight(gridHeight,
detailsRowHeight), openHeight);
} catch (AssertionError e) {
errors.put(e, new Object[] { gridHeight, gridWidth,
detailsRowHeight, "opened" });
}
// Firefox fails to close the details row if the clicks happen
// too close to each other
sleep(500);
grid.getRow(2).click(5, 5);
waitForElementNotPresent(By.id("lbl1"));
int afterHeight = grid.getSize().getHeight();
try {
// check height with details row closed again
assertThat("Unexpected Grid Height", afterHeight,
is(initialHeight));
} catch (AssertionError e) {
errors.put(e, new Object[] { gridHeight, gridWidth,
detailsRowHeight, "closed" });
}
}
}
return errors;
}
private void assertNoErrors(Map<AssertionError, Object[]> errors) {
if (!errors.isEmpty()) {
StringBuilder sb = new StringBuilder("Exceptions: ");
for (Entry<AssertionError, Object[]> entry : errors.entrySet()) {
sb.append("\n");
for (Object value : entry.getValue()) {
sb.append(value);
sb.append(" - ");
}
sb.append(entry.getKey().getMessage());
}
fail(sb.toString());
}
}
private int getExpectedInitialHeight(Object gridHeight) {
int result = 0;
if (GridHeight.UNDEFINED.equals(gridHeight)
|| GridHeight.ROW3.equals(gridHeight)) {
result = 81;
} else if (GridHeight.FULL.equals(gridHeight)) {
// pre-existing issue
result = 400;
}
return result;
}
private int getExpectedOpenedHeight(Object gridHeight,
Object detailsRowHeight) {
int result = 0;
if (GridHeight.UNDEFINED.equals(gridHeight)) {
if (GridHeight.PX100.equals(detailsRowHeight)) {
result = 182;
} else if (GridHeight.FULL.equals(detailsRowHeight)) {
result = 131;
} else if (GridHeight.UNDEFINED.equals(detailsRowHeight)) {
result = 136;
}
} else if (GridHeight.ROW3.equals(gridHeight)
|| GridHeight.FULL.equals(gridHeight)) {
result = getExpectedInitialHeight(gridHeight);
}
return result;
}
private void assertGridHeight(int expected, int actual) {
assertThat("Unexpected Grid Height", (double) actual,
closeTo(expected, 1));
}
}
|