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
|
package com.vaadin.tests.components.grid;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
import com.vaadin.testbench.By;
import com.vaadin.testbench.elements.ButtonElement;
import com.vaadin.testbench.elements.GridElement;
import com.vaadin.testbench.elements.GridElement.GridCellElement;
import com.vaadin.testbench.elements.TextFieldElement;
import com.vaadin.tests.tb3.SingleBrowserTest;
public class GridHeaderFooterComponentsTest extends SingleBrowserTest {
@Before
public void setUp() {
setDebug(true);
openTestURL();
}
@Test
public void hideAndShowComponentsInHeader() {
GridElement grid = $(GridElement.class).first();
int filterRow = 2;
assertNull(getHeaderElement(grid, filterRow, 1));
assertNotNull(getHeaderElement(grid, filterRow, 2));
assertNotNull(getHeaderElement(grid, filterRow, 3));
// Show (1,2)
grid.getHeaderCell(1, 1).$(ButtonElement.class).first().click();
TextFieldElement textfield = getHeaderElement(grid, filterRow, 1);
assertNotNull(textfield);
assertEquals("Filter: string", textfield.getValue());
textfield.setValue("foo");
assertEquals("1. value change for field in string to foo",
getLogRow(0));
assertNoErrorNotifications();
}
private TextFieldElement getHeaderElement(GridElement grid, int row,
int col) {
GridCellElement cell = grid.getHeaderCell(row, col);
List<TextFieldElement> all = cell.$(TextFieldElement.class).all();
if (all.isEmpty()) {
return null;
} else if (all.size() == 1) {
return all.get(0);
} else {
throw new RuntimeException(
"Multiple elements found in the header cell at " + row + ","
+ col);
}
}
@Test
public void hideAndShowComponentsInFooter() {
GridElement grid = $(GridElement.class).first();
int filterRow = 0;
assertNull(getFooterElement(grid, filterRow, 1));
assertNotNull(getFooterElement(grid, filterRow, 2));
assertNotNull(getFooterElement(grid, filterRow, 3));
// Show (1,2)
grid.getFooterCell(1, 1).$(ButtonElement.class).first().click();
TextFieldElement textfield = getFooterElement(grid, filterRow, 1);
assertNotNull(textfield);
assertEquals("Filter: string", textfield.getValue());
textfield.setValue("foo");
assertEquals("1. value change for field in string to foo",
getLogRow(0));
assertNoErrorNotifications();
}
private TextFieldElement getFooterElement(GridElement grid, int row,
int col) {
GridCellElement cell = grid.getFooterCell(row, col);
List<TextFieldElement> all = cell.$(TextFieldElement.class).all();
if (all.isEmpty()) {
return null;
} else if (all.size() == 1) {
return all.get(0);
} else {
throw new RuntimeException(
"Multiple elements found in the footer cell at " + row + ","
+ col);
}
}
@Test
public void testRemoveAllHeadersAndFooters() {
openTestURL();
for (int i = 2; i >= 0; --i) {
// Remove Header
$(GridElement.class).first().getHeaderCell(i, 0)
.$(ButtonElement.class).first().click();
assertFalse("Header " + i + " should not be present.",
$(GridElement.class).first()
.isElementPresent(By.vaadin("#header[" + i + "]")));
// Remove Footer
$(GridElement.class).first().getFooterCell(i, 0)
.$(ButtonElement.class).first().click();
assertFalse("Footer " + i + " should not be present.",
$(GridElement.class).first()
.isElementPresent(By.vaadin("#footer[" + i + "]")));
}
assertNoErrorNotifications();
}
}
|