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
168
169
170
|
package com.vaadin.tests.components.treegrid;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
import com.vaadin.testbench.By;
import com.vaadin.testbench.elements.TreeGridElement;
import com.vaadin.tests.tb3.MultiBrowserTest;
public class TreeGridHugeTreeNavigationTest extends MultiBrowserTest {
private TreeGridElement grid;
@Before
public void before() {
setDebug(true);
openTestURL();
grid = $(TreeGridElement.class).first();
}
@Test
public void keyboard_navigation() {
grid.getRow(0).getCell(0).click();
// Should navigate to "Granddad 1" and expand it
new Actions(getDriver()).sendKeys(Keys.DOWN, Keys.RIGHT).perform();
assertEquals(6, grid.getRowCount());
assertCellTexts(0, 0, "Granddad 0", "Granddad 1", "Dad 1/0", "Dad 1/1",
"Dad 1/2", "Granddad 2");
checkRowFocused(1);
// Should navigate to and expand "Dad 1/1"
new Actions(getDriver()).sendKeys(Keys.DOWN, Keys.DOWN, Keys.RIGHT)
.perform();
assertCellTexts(0, 0, "Granddad 0", "Granddad 1", "Dad 1/0", "Dad 1/1",
"Son 1/1/0", "Son 1/1/1", "Son 1/1/2", "Son 1/1/3");
checkRowFocused(3);
// Should navigate 100 items down
Keys downKeyArr[] = new Keys[100];
for (int i = 0; i < 100; i++) {
downKeyArr[i] = Keys.DOWN;
}
new Actions(getDriver()).sendKeys(downKeyArr).perform();
WebElement son1_1_99 = findFocusedRow();
assertEquals("Son 1/1/99 --", son1_1_99.getText());
// Should navigate to "Dad 1/1" back
new Actions(getDriver())
.sendKeys(Keys.HOME, Keys.DOWN, Keys.DOWN, Keys.DOWN).perform();
WebElement dad1_1 = findFocusedRow();
assertEquals("Dad 1/1 --", dad1_1.getText());
// Should collapse "Dad 1/1"
new Actions(getDriver()).sendKeys(Keys.LEFT).perform();
assertCellTexts(0, 0, "Granddad 0", "Granddad 1", "Dad 1/0", "Dad 1/1",
"Dad 1/2", "Granddad 2");
checkRowFocused(3);
// Should navigate to "Granddad 1"
new Actions(getDriver()).sendKeys(Keys.LEFT).perform();
assertCellTexts(0, 0, "Granddad 0", "Granddad 1", "Dad 1/0", "Dad 1/1",
"Dad 1/2", "Granddad 2");
checkRowFocused(1);
// Should collapse "Granddad 1"
new Actions(getDriver()).sendKeys(Keys.LEFT).perform();
assertCellTexts(0, 0, "Granddad 0", "Granddad 1", "Granddad 2");
checkRowFocused(1);
// Nothing should happen
new Actions(getDriver()).sendKeys(Keys.LEFT).perform();
assertCellTexts(0, 0, "Granddad 0", "Granddad 1", "Granddad 2");
checkRowFocused(1);
assertNoErrorNotifications();
}
@Test
public void no_exception_when_calling_expand_or_collapse_twice() {
// Currently the collapsed state is updated in a round trip to the
// server, thus it is possible to trigger an expand on the same row
// multiple times through the UI. This should not cause exceptions, but
// rather ignore the redundant calls.
grid.getRow(0).getCell(0).click();
new Actions(getDriver()).sendKeys(Keys.RIGHT, Keys.RIGHT).perform();
assertNoErrorNotifications();
new Actions(getDriver()).sendKeys(Keys.LEFT, Keys.LEFT).perform();
assertNoErrorNotifications();
}
@Test
public void uncollapsible_item() {
grid.getRow(0).getCell(0).click();
new Actions(getDriver()).sendKeys(Keys.DOWN, Keys.DOWN, Keys.RIGHT)
.perform();
grid.waitForVaadin();
// expand Dad 2/1
new Actions(getDriver()).sendKeys(Keys.DOWN, Keys.DOWN, Keys.RIGHT)
.perform();
grid.waitForVaadin();
assertNoErrorNotifications();
assertCellTexts(5, 0, "Son 2/1/0");
new Actions(getDriver()).sendKeys(Keys.LEFT).perform();
grid.waitForVaadin();
assertNoErrorNotifications();
assertCellTexts(5, 0, "Son 2/1/0");
}
@Test
public void can_toggle_collapse_on_row_that_is_no_longer_in_cache() {
grid.getRow(0).getCell(0).click();
// Expand 2 levels
new Actions(getDriver()).sendKeys(Keys.RIGHT).perform();
grid.waitForVaadin();
new Actions(getDriver()).sendKeys(Keys.DOWN, Keys.RIGHT).perform();
grid.waitForVaadin();
grid.scrollToRow(200);
grid.waitForVaadin();
// Jump into view
new Actions(getDriver()).sendKeys(Keys.LEFT).perform();
grid.waitForVaadin();
// Collapse
new Actions(getDriver()).sendKeys(Keys.LEFT).perform();
grid.waitForVaadin();
assertEquals(6, grid.getRowCount());
// Expand
new Actions(getDriver()).sendKeys(Keys.RIGHT, Keys.UP).perform();
grid.waitForVaadin();
grid.scrollToRow(200);
new Actions(getDriver()).sendKeys(Keys.RIGHT).perform();
grid.waitForVaadin();
assertEquals(306, grid.getRowCount());
}
private WebElement findFocusedRow() {
return grid.findElement(By.className("v-treegrid-row-focused"));
}
private void checkRowFocused(int index) {
if (index > 0) {
assertFalse(grid.getRow(index - 1)
.hasClassName("v-treegrid-row-focused"));
}
assertTrue(grid.getRow(index).hasClassName("v-treegrid-row-focused"));
assertFalse(
grid.getRow(index + 1).hasClassName("v-treegrid-row-focused"));
}
private void assertCellTexts(int startRowIndex, int cellIndex,
String... cellTexts) {
int index = startRowIndex;
for (String cellText : cellTexts) {
assertEquals(cellText,
grid.getRow(index).getCell(cellIndex).getText());
index++;
}
}
}
|