2 * Copyright 2000-2016 Vaadin Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 * use this file except in compliance with the License. You may obtain a copy of
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 * License for the specific language governing permissions and limitations under
16 package com.vaadin.tests.components.grid.basicfeatures.server;
18 import static org.junit.Assert.assertEquals;
19 import static org.junit.Assert.assertFalse;
20 import static org.junit.Assert.assertNotNull;
21 import static org.junit.Assert.assertTrue;
22 import static org.junit.Assert.fail;
24 import org.junit.Before;
25 import org.junit.Test;
26 import org.openqa.selenium.NoSuchElementException;
28 import com.vaadin.testbench.By;
29 import com.vaadin.testbench.TestBenchElement;
30 import com.vaadin.testbench.elements.NotificationElement;
31 import com.vaadin.tests.components.grid.basicfeatures.GridBasicFeaturesTest;
33 public class GridDetailsServerTest extends GridBasicFeaturesTest {
35 * The reason to why last item details wasn't selected is that since it will
36 * exist only after the viewport has been scrolled into view, we wouldn't be
37 * able to scroll that particular details row into view, making tests
38 * awkward with two scroll commands back to back.
40 private static final int ALMOST_LAST_INDEX = 995;
41 private static final String[] OPEN_ALMOST_LAST_ITEM_DETAILS = new String[] {
42 "Component", "Details", "Open " + ALMOST_LAST_INDEX };
43 private static final String[] OPEN_FIRST_ITEM_DETAILS = new String[] {
44 "Component", "Details", "Open firstItemId" };
45 private static final String[] TOGGLE_FIRST_ITEM_DETAILS = new String[] {
46 "Component", "Details", "Toggle firstItemId" };
47 private static final String[] DETAILS_GENERATOR_NULL = new String[] {
48 "Component", "Details", "Generators", "NULL" };
49 private static final String[] DETAILS_GENERATOR_WATCHING = new String[] {
50 "Component", "Details", "Generators", "\"Watching\"" };
51 private static final String[] DETAILS_GENERATOR_PERSISTING = new String[] {
52 "Component", "Details", "Generators", "Persisting" };
53 private static final String[] CHANGE_HIERARCHY = new String[] { "Component",
54 "Details", "Generators", "- Change Component" };
61 @Test(expected = NoSuchElementException.class)
62 public void openWithNoGenerator() {
64 getGridElement().getDetails(0);
65 fail("Expected NoSuchElementException");
66 } catch (NoSuchElementException ignore) {
69 selectMenuPath(OPEN_FIRST_ITEM_DETAILS);
70 getGridElement().getDetails(0);
74 public void openVisiblePopulatedDetails() {
75 selectMenuPath(DETAILS_GENERATOR_WATCHING);
76 selectMenuPath(OPEN_FIRST_ITEM_DETAILS);
77 assertNotNull("details should've populated", getGridElement()
78 .getDetails(0).findElement(By.className("v-widget")));
81 @Test(expected = NoSuchElementException.class)
82 public void closeVisiblePopulatedDetails() {
83 selectMenuPath(DETAILS_GENERATOR_WATCHING);
84 selectMenuPath(OPEN_FIRST_ITEM_DETAILS);
85 selectMenuPath(OPEN_FIRST_ITEM_DETAILS);
86 getGridElement().getDetails(0);
90 public void openDetailsOutsideOfActiveRange() throws InterruptedException {
91 getGridElement().scroll(10000);
92 selectMenuPath(DETAILS_GENERATOR_WATCHING);
93 selectMenuPath(OPEN_FIRST_ITEM_DETAILS);
94 getGridElement().scroll(0);
96 assertNotNull("details should've been opened",
97 getGridElement().getDetails(0));
100 @Test(expected = NoSuchElementException.class)
101 public void closeDetailsOutsideOfActiveRange() {
102 selectMenuPath(OPEN_FIRST_ITEM_DETAILS);
103 getGridElement().scroll(10000);
104 selectMenuPath(OPEN_FIRST_ITEM_DETAILS);
105 getGridElement().scroll(0);
106 getGridElement().getDetails(0);
110 public void componentIsVisibleClientSide() {
111 selectMenuPath(DETAILS_GENERATOR_WATCHING);
112 selectMenuPath(OPEN_FIRST_ITEM_DETAILS);
114 TestBenchElement details = getGridElement().getDetails(0);
115 assertNotNull("No widget detected inside details",
116 details.findElement(By.className("v-widget")));
120 public void openingDetailsTwice() {
121 selectMenuPath(DETAILS_GENERATOR_WATCHING);
122 selectMenuPath(OPEN_FIRST_ITEM_DETAILS); // open
123 selectMenuPath(OPEN_FIRST_ITEM_DETAILS); // close
124 selectMenuPath(OPEN_FIRST_ITEM_DETAILS); // open
126 TestBenchElement details = getGridElement().getDetails(0);
127 assertNotNull("No widget detected inside details",
128 details.findElement(By.className("v-widget")));
131 @Test(expected = NoSuchElementException.class)
132 public void scrollingDoesNotCreateAFloodOfDetailsRows() {
133 selectMenuPath(DETAILS_GENERATOR_WATCHING);
135 // scroll somewhere to hit uncached rows
136 getGridElement().scrollToRow(101);
139 getGridElement().getDetails(100);
143 public void openingDetailsOutOfView() {
144 getGridElement().scrollToRow(500);
146 selectMenuPath(DETAILS_GENERATOR_WATCHING);
147 selectMenuPath(OPEN_FIRST_ITEM_DETAILS);
149 getGridElement().scrollToRow(0);
151 // if this fails, it'll fail before the assertNotNull
152 assertNotNull("unexpected null details row",
153 getGridElement().getDetails(0));
157 public void togglingAVisibleDetailsRowWithOneRoundtrip() {
158 selectMenuPath(DETAILS_GENERATOR_WATCHING);
159 selectMenuPath(OPEN_FIRST_ITEM_DETAILS); // open
161 assertTrue("Unexpected generator content",
162 getGridElement().getDetails(0).getText().endsWith("(0)"));
163 selectMenuPath(TOGGLE_FIRST_ITEM_DETAILS);
164 assertTrue("New component was not displayed in the client",
165 getGridElement().getDetails(0).getText().endsWith("(1)"));
169 public void almostLastItemIdIsRendered() {
170 selectMenuPath(DETAILS_GENERATOR_WATCHING);
171 selectMenuPath(OPEN_ALMOST_LAST_ITEM_DETAILS);
172 scrollGridVerticallyTo(100000);
174 TestBenchElement details = getGridElement()
175 .getDetails(ALMOST_LAST_INDEX);
176 assertNotNull(details);
177 assertTrue("Unexpected details content",
178 details.getText().endsWith(ALMOST_LAST_INDEX + " (0)"));
182 public void persistingChangesWorkInDetails() {
183 selectMenuPath(DETAILS_GENERATOR_PERSISTING);
184 selectMenuPath(OPEN_FIRST_ITEM_DETAILS);
185 assertEquals("One", getGridElement().getDetails(0).getText());
186 selectMenuPath(CHANGE_HIERARCHY);
187 assertEquals("Two", getGridElement().getDetails(0).getText());
191 public void persistingChangesWorkInDetailsWhileOutOfView() {
192 selectMenuPath(DETAILS_GENERATOR_PERSISTING);
193 selectMenuPath(OPEN_FIRST_ITEM_DETAILS);
194 assertEquals("One", getGridElement().getDetails(0).getText());
195 scrollGridVerticallyTo(10000);
196 selectMenuPath(CHANGE_HIERARCHY);
197 scrollGridVerticallyTo(0);
198 assertEquals("Two", getGridElement().getDetails(0).getText());
202 public void persistingChangesWorkInDetailsWhenNotAttached() {
203 selectMenuPath(DETAILS_GENERATOR_PERSISTING);
204 selectMenuPath(OPEN_FIRST_ITEM_DETAILS);
205 assertEquals("One", getGridElement().getDetails(0).getText());
207 selectMenuPath(OPEN_FIRST_ITEM_DETAILS);
208 assertFalse("Details should be detached",
209 getGridElement().isElementPresent(By.vaadin("#details[0]")));
211 selectMenuPath(CHANGE_HIERARCHY);
212 selectMenuPath(OPEN_FIRST_ITEM_DETAILS);
214 assertEquals("Two", getGridElement().getDetails(0).getText());
218 public void swappingDetailsGenerators_noDetailsShown() {
219 selectMenuPath(DETAILS_GENERATOR_WATCHING);
220 selectMenuPath(DETAILS_GENERATOR_NULL);
221 assertFalse("Got some errors", $(NotificationElement.class).exists());
225 public void swappingDetailsGenerators_shownDetails() {
226 selectMenuPath(DETAILS_GENERATOR_PERSISTING);
227 selectMenuPath(OPEN_FIRST_ITEM_DETAILS);
228 assertTrue("Details should contain 'One' at first",
229 getGridElement().getDetails(0).getText().contains("One"));
231 selectMenuPath(DETAILS_GENERATOR_WATCHING);
233 "Details should contain 'Watching' after swapping generator",
234 getGridElement().getDetails(0).getText().contains("Watching"));
238 public void swappingDetailsGenerators_whileDetailsScrolledOut_showNever() {
239 scrollGridVerticallyTo(1000);
240 selectMenuPath(OPEN_FIRST_ITEM_DETAILS);
241 selectMenuPath(DETAILS_GENERATOR_WATCHING);
242 assertFalse("Got some errors", $(NotificationElement.class).exists());
246 public void swappingDetailsGenerators_whileDetailsScrolledOut_showAfter() {
247 scrollGridVerticallyTo(1000);
248 selectMenuPath(DETAILS_GENERATOR_PERSISTING);
249 selectMenuPath(OPEN_FIRST_ITEM_DETAILS);
250 selectMenuPath(DETAILS_GENERATOR_WATCHING);
251 scrollGridVerticallyTo(0);
253 assertFalse("Got some errors", $(NotificationElement.class).exists());
254 assertNotNull("Could not find a details",
255 getGridElement().getDetails(0));
259 public void swappingDetailsGenerators_whileDetailsScrolledOut_showBefore() {
260 selectMenuPath(DETAILS_GENERATOR_PERSISTING);
261 selectMenuPath(OPEN_FIRST_ITEM_DETAILS);
262 selectMenuPath(DETAILS_GENERATOR_WATCHING);
263 scrollGridVerticallyTo(1000);
265 assertFalse("Got some errors", $(NotificationElement.class).exists());
266 assertNotNull("Could not find a details",
267 getGridElement().getDetails(0));
271 public void swappingDetailsGenerators_whileDetailsScrolledOut_showBeforeAndAfter() {
272 selectMenuPath(DETAILS_GENERATOR_PERSISTING);
273 selectMenuPath(OPEN_FIRST_ITEM_DETAILS);
274 selectMenuPath(DETAILS_GENERATOR_WATCHING);
275 scrollGridVerticallyTo(1000);
276 scrollGridVerticallyTo(0);
278 assertFalse("Got some errors", $(NotificationElement.class).exists());
279 assertNotNull("Could not find a details",
280 getGridElement().getDetails(0));
284 public void noAssertErrorsOnEmptyDetailsAndScrollDown() {
285 selectMenuPath(OPEN_FIRST_ITEM_DETAILS);
286 scrollGridVerticallyTo(500);
287 assertFalse(logContainsText("AssertionError"));
291 public void noAssertErrorsOnPopulatedDetailsAndScrollDown() {
292 selectMenuPath(DETAILS_GENERATOR_WATCHING);
293 selectMenuPath(OPEN_FIRST_ITEM_DETAILS);
294 scrollGridVerticallyTo(500);
295 assertFalse(logContainsText("AssertionError"));