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.client;
18 import static org.junit.Assert.assertEquals;
19 import static org.junit.Assert.assertFalse;
20 import static org.junit.Assert.assertNotEquals;
21 import static org.junit.Assert.assertNotNull;
22 import static org.junit.Assert.assertNull;
23 import static org.junit.Assert.assertTrue;
24 import static org.junit.Assert.fail;
26 import java.util.List;
28 import org.junit.Before;
29 import org.junit.Test;
30 import org.openqa.selenium.NoSuchElementException;
31 import org.openqa.selenium.WebElement;
33 import com.vaadin.shared.ui.grid.Range;
34 import com.vaadin.testbench.By;
35 import com.vaadin.testbench.ElementQuery;
36 import com.vaadin.testbench.TestBenchElement;
37 import com.vaadin.testbench.customelements.FixedNotificationElement;
38 import com.vaadin.tests.components.grid.basicfeatures.GridBasicClientFeaturesTest;
39 import com.vaadin.v7.shared.ui.grid.ScrollDestination;
41 public class GridDetailsClientTest extends GridBasicClientFeaturesTest {
43 private static final String[] SET_GENERATOR = new String[] { "Component",
44 "Row details", "Set generator" };
45 private static final String[] SET_FAULTY_GENERATOR = new String[] {
46 "Component", "Row details", "Set faulty generator" };
47 private static final String[] SET_EMPTY_GENERATOR = new String[] {
48 "Component", "Row details", "Set empty generator" };
56 @Test(expected = NoSuchElementException.class)
57 public void noDetailsByDefault() {
58 assertNull("details for row 1 should not exist at the start",
59 getGridElement().getDetails(1));
62 @Test(expected = NoSuchElementException.class)
63 public void nullRendererDoesNotShowDetailsPlaceholder() {
65 getGridElement().getDetails(1);
69 public void applyRendererThenOpenDetails() {
70 selectMenuPath(SET_GENERATOR);
73 TestBenchElement details = getGridElement().getDetails(1);
74 assertTrue("Unexpected details content",
75 details.getText().startsWith("Row: 1."));
78 @Test(expected = NoSuchElementException.class)
79 public void openDetailsThenAppyRendererShouldNotShowDetails() {
81 selectMenuPath(SET_GENERATOR);
83 getGridElement().getDetails(1);
87 public void openHiddenDetailsThenScrollToIt() {
89 getGridElement().getDetails(100);
90 fail("details row for 100 was apparently found, while it shouldn't have been.");
91 } catch (NoSuchElementException e) {
95 selectMenuPath(SET_GENERATOR);
96 toggleDetailsFor(100);
98 // scroll a bit beyond so we see below.
99 getGridElement().scrollToRow(101);
101 TestBenchElement details = getGridElement().getDetails(100);
102 assertTrue("Unexpected details content",
103 details.getText().startsWith("Row: 100."));
107 public void errorUpdaterShowsErrorNotification() {
108 assertFalse("No notifications should've been at the start",
109 $(FixedNotificationElement.class).exists());
111 selectMenuPath(SET_FAULTY_GENERATOR);
114 ElementQuery<FixedNotificationElement> notification = $(
115 FixedNotificationElement.class);
116 assertTrue("Was expecting an error notification here",
117 notification.exists());
118 notification.first().close();
120 assertEquals("The error details element should be empty", "",
121 getGridElement().getDetails(1).getText());
124 @Test(expected = NoSuchElementException.class)
125 public void detailsClosedWhenResettingGenerator() {
127 selectMenuPath(SET_GENERATOR);
130 selectMenuPath(SET_FAULTY_GENERATOR);
131 getGridElement().getDetails(1);
135 public void settingNewGeneratorStillWorksAfterError() {
136 selectMenuPath(SET_FAULTY_GENERATOR);
138 $(FixedNotificationElement.class).first().close();
141 selectMenuPath(SET_GENERATOR);
144 assertNotEquals("New details should've been generated even after error",
145 "", getGridElement().getDetails(1).getText());
149 public void updaterRendersExpectedWidgets() {
150 selectMenuPath(SET_GENERATOR);
153 TestBenchElement detailsElement = getGridElement().getDetails(1);
154 assertNotNull(detailsElement.findElement(By.className("gwt-Label")));
155 assertNotNull(detailsElement.findElement(By.className("gwt-Button")));
159 public void widgetsInUpdaterWorkAsExpected() {
160 selectMenuPath(SET_GENERATOR);
163 TestBenchElement detailsElement = getGridElement().getDetails(1);
164 WebElement button = detailsElement
165 .findElement(By.className("gwt-Button"));
168 WebElement label = detailsElement
169 .findElement(By.className("gwt-Label"));
170 assertEquals("clicked", label.getText());
174 public void emptyGenerator() {
175 selectMenuPath(SET_EMPTY_GENERATOR);
178 assertEquals("empty generator did not produce an empty details row", "",
179 getGridElement().getDetails(1).getText());
182 @Test(expected = NoSuchElementException.class)
183 public void removeDetailsRow() {
184 selectMenuPath(SET_GENERATOR);
188 getGridElement().getDetails(1);
192 public void rowElementClassNames() {
193 selectMenuPath(SET_GENERATOR);
197 List<WebElement> elements = getGridElement()
198 .findElements(By.className("v-grid-spacer"));
199 assertEquals("v-grid-spacer", elements.get(0).getAttribute("class"));
200 assertEquals("v-grid-spacer stripe",
201 elements.get(1).getAttribute("class"));
205 public void scrollDownToRowWithDetails() {
206 selectMenuPath(SET_GENERATOR);
207 toggleDetailsFor(100);
208 scrollToRow(100, ScrollDestination.ANY);
210 Range validScrollRange = Range.between(1691, 1706);
211 assertTrue(validScrollRange.contains(getGridVerticalScrollPos()));
215 public void scrollUpToRowWithDetails() {
216 selectMenuPath(SET_GENERATOR);
217 toggleDetailsFor(100);
218 scrollGridVerticallyTo(999999);
219 scrollToRow(100, ScrollDestination.ANY);
221 Range validScrollRange = Range.between(1981, 2001);
222 assertTrue(validScrollRange.contains(getGridVerticalScrollPos()));
226 public void cannotScrollBeforeTop() {
227 selectMenuPath(SET_GENERATOR);
229 scrollToRow(0, ScrollDestination.END);
230 assertEquals(0, getGridVerticalScrollPos());
234 public void cannotScrollAfterBottom() {
235 selectMenuPath(SET_GENERATOR);
236 toggleDetailsFor(999);
237 scrollToRow(999, ScrollDestination.START);
239 Range expectedRange = Range.withLength(19671, 20);
240 assertTrue(expectedRange.contains(getGridVerticalScrollPos()));
243 private void scrollToRow(int rowIndex, ScrollDestination destination) {
244 selectMenuPath(new String[] { "Component", "State", "Scroll to...",
245 "Row " + rowIndex + "...", "Destination " + destination });
248 private void toggleDetailsFor(int rowIndex) {
249 selectMenuPath(new String[] { "Component", "Row details",
250 "Toggle details for...", "Row " + rowIndex });