-
Notifications
You must be signed in to change notification settings - Fork 728
/
GridDetailsServerTest.java
306 lines (260 loc) · 11.4 KB
/
GridDetailsServerTest.java
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
/*
* Copyright 2000-2014 Vaadin Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.vaadin.tests.components.grid.basicfeatures.server;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.NoSuchElementException;
import com.vaadin.testbench.By;
import com.vaadin.testbench.TestBenchElement;
import com.vaadin.testbench.elements.NotificationElement;
import com.vaadin.tests.components.grid.basicfeatures.GridBasicFeaturesTest;
public class GridDetailsServerTest extends GridBasicFeaturesTest {
/**
* The reason to why last item details wasn't selected is that since it will
* exist only after the viewport has been scrolled into view, we wouldn't be
* able to scroll that particular details row into view, making tests
* awkward with two scroll commands back to back.
*/
private static final int ALMOST_LAST_INDEX = 995;
private static final String[] OPEN_ALMOST_LAST_ITEM_DETAILS = new String[] {
"Component", "Details", "Open " + ALMOST_LAST_INDEX };
private static final String[] OPEN_FIRST_ITEM_DETAILS = new String[] {
"Component", "Details", "Open firstItemId" };
private static final String[] TOGGLE_FIRST_ITEM_DETAILS = new String[] {
"Component", "Details", "Toggle firstItemId" };
private static final String[] DETAILS_GENERATOR_NULL = new String[] {
"Component", "Details", "Generators", "NULL" };
private static final String[] DETAILS_GENERATOR_WATCHING = new String[] {
"Component", "Details", "Generators", "\"Watching\"" };
private static final String[] DETAILS_GENERATOR_PERSISTING = new String[] {
"Component", "Details", "Generators", "Persisting" };
private static final String[] CHANGE_HIERARCHY = new String[] {
"Component", "Details", "Generators", "- Change Component" };
@Before
public void setUp() {
openTestURL();
}
@Test(expected = NoSuchElementException.class)
public void openVisibleDetails() {
try {
getGridElement().getDetails(0);
fail("Expected NoSuchElementException");
} catch (NoSuchElementException ignore) {
// expected
}
selectMenuPath(OPEN_FIRST_ITEM_DETAILS);
getGridElement().getDetails(0);
}
@Test(expected = NoSuchElementException.class)
public void closeVisibleDetails() {
selectMenuPath(OPEN_FIRST_ITEM_DETAILS);
selectMenuPath(OPEN_FIRST_ITEM_DETAILS);
getGridElement().getDetails(0);
}
@Test
public void openVisiblePopulatedDetails() {
selectMenuPath(DETAILS_GENERATOR_WATCHING);
selectMenuPath(OPEN_FIRST_ITEM_DETAILS);
assertNotNull("details should've populated", getGridElement()
.getDetails(0).findElement(By.className("v-widget")));
}
@Test(expected = NoSuchElementException.class)
public void closeVisiblePopulatedDetails() {
selectMenuPath(DETAILS_GENERATOR_WATCHING);
selectMenuPath(OPEN_FIRST_ITEM_DETAILS);
selectMenuPath(OPEN_FIRST_ITEM_DETAILS);
getGridElement().getDetails(0);
}
@Test
public void openDetailsOutsideOfActiveRange() throws InterruptedException {
getGridElement().scroll(10000);
selectMenuPath(DETAILS_GENERATOR_WATCHING);
selectMenuPath(OPEN_FIRST_ITEM_DETAILS);
getGridElement().scroll(0);
Thread.sleep(50);
assertNotNull("details should've been opened", getGridElement()
.getDetails(0));
}
@Test(expected = NoSuchElementException.class)
public void closeDetailsOutsideOfActiveRange() {
selectMenuPath(OPEN_FIRST_ITEM_DETAILS);
getGridElement().scroll(10000);
selectMenuPath(OPEN_FIRST_ITEM_DETAILS);
getGridElement().scroll(0);
getGridElement().getDetails(0);
}
@Test
public void componentIsVisibleClientSide() {
selectMenuPath(DETAILS_GENERATOR_WATCHING);
selectMenuPath(OPEN_FIRST_ITEM_DETAILS);
TestBenchElement details = getGridElement().getDetails(0);
assertNotNull("No widget detected inside details",
details.findElement(By.className("v-widget")));
}
@Test
public void openingDetailsTwice() {
selectMenuPath(DETAILS_GENERATOR_WATCHING);
selectMenuPath(OPEN_FIRST_ITEM_DETAILS); // open
selectMenuPath(OPEN_FIRST_ITEM_DETAILS); // close
selectMenuPath(OPEN_FIRST_ITEM_DETAILS); // open
TestBenchElement details = getGridElement().getDetails(0);
assertNotNull("No widget detected inside details",
details.findElement(By.className("v-widget")));
}
@Test(expected = NoSuchElementException.class)
public void scrollingDoesNotCreateAFloodOfDetailsRows() {
selectMenuPath(DETAILS_GENERATOR_WATCHING);
// scroll somewhere to hit uncached rows
getGridElement().scrollToRow(101);
// this should throw
getGridElement().getDetails(100);
}
@Test
public void openingDetailsOutOfView() {
getGridElement().scrollToRow(500);
selectMenuPath(DETAILS_GENERATOR_WATCHING);
selectMenuPath(OPEN_FIRST_ITEM_DETAILS);
getGridElement().scrollToRow(0);
// if this fails, it'll fail before the assertNotNull
assertNotNull("unexpected null details row", getGridElement()
.getDetails(0));
}
@Test
public void togglingAVisibleDetailsRowWithOneRoundtrip() {
selectMenuPath(DETAILS_GENERATOR_WATCHING);
selectMenuPath(OPEN_FIRST_ITEM_DETAILS); // open
assertTrue("Unexpected generator content",
getGridElement().getDetails(0).getText().endsWith("(0)"));
selectMenuPath(TOGGLE_FIRST_ITEM_DETAILS);
assertTrue("New component was not displayed in the client",
getGridElement().getDetails(0).getText().endsWith("(1)"));
}
@Test
public void almostLastItemIdIsRendered() {
selectMenuPath(DETAILS_GENERATOR_WATCHING);
selectMenuPath(OPEN_ALMOST_LAST_ITEM_DETAILS);
scrollGridVerticallyTo(100000);
TestBenchElement details = getGridElement().getDetails(
ALMOST_LAST_INDEX);
assertNotNull(details);
assertTrue("Unexpected details content",
details.getText().endsWith(ALMOST_LAST_INDEX + " (0)"));
}
@Test
public void persistingChangesWorkInDetails() {
selectMenuPath(DETAILS_GENERATOR_PERSISTING);
selectMenuPath(OPEN_FIRST_ITEM_DETAILS);
assertEquals("One", getGridElement().getDetails(0).getText());
selectMenuPath(CHANGE_HIERARCHY);
assertEquals("Two", getGridElement().getDetails(0).getText());
}
@Test
public void persistingChangesWorkInDetailsWhileOutOfView() {
selectMenuPath(DETAILS_GENERATOR_PERSISTING);
selectMenuPath(OPEN_FIRST_ITEM_DETAILS);
assertEquals("One", getGridElement().getDetails(0).getText());
scrollGridVerticallyTo(10000);
selectMenuPath(CHANGE_HIERARCHY);
scrollGridVerticallyTo(0);
assertEquals("Two", getGridElement().getDetails(0).getText());
}
@Test
public void persistingChangesWorkInDetailsWhenNotAttached() {
selectMenuPath(DETAILS_GENERATOR_PERSISTING);
selectMenuPath(OPEN_FIRST_ITEM_DETAILS);
assertEquals("One", getGridElement().getDetails(0).getText());
selectMenuPath(OPEN_FIRST_ITEM_DETAILS);
assertFalse("Details should be detached", getGridElement()
.isElementPresent(By.vaadin("#details[0]")));
selectMenuPath(CHANGE_HIERARCHY);
selectMenuPath(OPEN_FIRST_ITEM_DETAILS);
assertEquals("Two", getGridElement().getDetails(0).getText());
}
@Test
public void swappingDetailsGenerators_noDetailsShown() {
selectMenuPath(DETAILS_GENERATOR_WATCHING);
selectMenuPath(DETAILS_GENERATOR_NULL);
assertFalse("Got some errors", $(NotificationElement.class).exists());
}
@Test
public void swappingDetailsGenerators_shownDetails() {
selectMenuPath(DETAILS_GENERATOR_PERSISTING);
selectMenuPath(OPEN_FIRST_ITEM_DETAILS);
assertTrue("Details should contain 'One' at first", getGridElement()
.getDetails(0).getText().contains("One"));
selectMenuPath(DETAILS_GENERATOR_WATCHING);
assertFalse(
"Details should contain 'Watching' after swapping generator",
getGridElement().getDetails(0).getText().contains("Watching"));
}
@Test
public void swappingDetailsGenerators_whileDetailsScrolledOut_showNever() {
scrollGridVerticallyTo(1000);
selectMenuPath(OPEN_FIRST_ITEM_DETAILS);
selectMenuPath(DETAILS_GENERATOR_WATCHING);
assertFalse("Got some errors", $(NotificationElement.class).exists());
}
@Test
public void swappingDetailsGenerators_whileDetailsScrolledOut_showAfter() {
scrollGridVerticallyTo(1000);
selectMenuPath(DETAILS_GENERATOR_PERSISTING);
selectMenuPath(OPEN_FIRST_ITEM_DETAILS);
selectMenuPath(DETAILS_GENERATOR_WATCHING);
scrollGridVerticallyTo(0);
assertFalse("Got some errors", $(NotificationElement.class).exists());
assertNotNull("Could not find a details", getGridElement()
.getDetails(0));
}
@Test
public void swappingDetailsGenerators_whileDetailsScrolledOut_showBefore() {
selectMenuPath(DETAILS_GENERATOR_PERSISTING);
selectMenuPath(OPEN_FIRST_ITEM_DETAILS);
selectMenuPath(DETAILS_GENERATOR_WATCHING);
scrollGridVerticallyTo(1000);
assertFalse("Got some errors", $(NotificationElement.class).exists());
assertNotNull("Could not find a details", getGridElement()
.getDetails(0));
}
@Test
public void swappingDetailsGenerators_whileDetailsScrolledOut_showBeforeAndAfter() {
selectMenuPath(DETAILS_GENERATOR_PERSISTING);
selectMenuPath(OPEN_FIRST_ITEM_DETAILS);
selectMenuPath(DETAILS_GENERATOR_WATCHING);
scrollGridVerticallyTo(1000);
scrollGridVerticallyTo(0);
assertFalse("Got some errors", $(NotificationElement.class).exists());
assertNotNull("Could not find a details", getGridElement()
.getDetails(0));
}
@Test
public void noAssertErrorsOnEmptyDetailsAndScrollDown() {
selectMenuPath(OPEN_FIRST_ITEM_DETAILS);
scrollGridVerticallyTo(500);
assertFalse(logContainsText("AssertionError"));
}
@Test
public void noAssertErrorsOnPopulatedDetailsAndScrollDown() {
selectMenuPath(DETAILS_GENERATOR_WATCHING);
selectMenuPath(OPEN_FIRST_ITEM_DETAILS);
scrollGridVerticallyTo(500);
assertFalse(logContainsText("AssertionError"));
}
}