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.escalator;
18 import static org.junit.Assert.assertEquals;
19 import static org.junit.Assert.assertNotEquals;
20 import static org.junit.Assert.assertNotNull;
21 import static org.junit.Assert.assertNull;
22 import static org.junit.Assert.assertTrue;
24 import org.junit.Test;
25 import org.openqa.selenium.By;
27 import com.vaadin.tests.components.grid.basicfeatures.EscalatorBasicClientFeaturesTest;
29 public class EscalatorRowColumnTest extends EscalatorBasicClientFeaturesTest {
32 * The scroll position of the Escalator when scrolled all the way down, to
33 * reveal the 100:th row.
35 private static final int BOTTOM_SCROLL_POSITION = 1857;
38 public void testInit() {
40 assertNotNull(getEscalator());
41 assertNull(getHeaderRow(0));
42 assertNull(getBodyRow(0));
43 assertNull(getFooterRow(0));
45 assertLogContains("Columns: 0");
46 assertLogContains("Header rows: 0");
47 assertLogContains("Body rows: 0");
48 assertLogContains("Footer rows: 0");
52 public void testInsertAColumn() {
55 selectMenuPath(COLUMNS_AND_ROWS, COLUMNS, ADD_ONE_COLUMN_TO_BEGINNING);
56 assertNull(getHeaderRow(0));
57 assertNull(getBodyRow(0));
58 assertNull(getFooterRow(0));
59 assertLogContains("Columns: 1");
63 public void testInsertAHeaderRow() {
66 selectMenuPath(COLUMNS_AND_ROWS, HEADER_ROWS, ADD_ONE_ROW_TO_BEGINNING);
67 assertNull(getHeaderCell(0, 0));
68 assertNull(getBodyCell(0, 0));
69 assertNull(getFooterCell(0, 0));
70 assertLogContains("Header rows: 1");
74 public void testInsertABodyRow() {
77 selectMenuPath(COLUMNS_AND_ROWS, BODY_ROWS, ADD_ONE_ROW_TO_BEGINNING);
78 assertNull(getHeaderCell(0, 0));
79 assertNull(getBodyCell(0, 0));
80 assertNull(getFooterCell(0, 0));
81 assertLogContains("Body rows: 1");
85 public void testInsertAFooterRow() {
88 selectMenuPath(COLUMNS_AND_ROWS, FOOTER_ROWS, ADD_ONE_ROW_TO_BEGINNING);
89 assertNull(getHeaderCell(0, 0));
90 assertNull(getBodyCell(0, 0));
91 assertNull(getFooterCell(0, 0));
92 assertLogContains("Footer rows: 1");
96 public void testInsertAColumnAndAHeaderRow() {
99 selectMenuPath(COLUMNS_AND_ROWS, COLUMNS, ADD_ONE_COLUMN_TO_BEGINNING);
100 selectMenuPath(COLUMNS_AND_ROWS, HEADER_ROWS, ADD_ONE_ROW_TO_BEGINNING);
101 assertNotNull(getHeaderCell(0, 0));
102 assertNull(getBodyCell(0, 0));
103 assertNull(getFooterCell(0, 0));
104 assertLogContains("Columns: 1");
105 assertLogContains("Header rows: 1");
109 public void testInsertAColumnAndABodyRow() {
112 selectMenuPath(COLUMNS_AND_ROWS, COLUMNS, ADD_ONE_COLUMN_TO_BEGINNING);
113 selectMenuPath(COLUMNS_AND_ROWS, BODY_ROWS, ADD_ONE_ROW_TO_BEGINNING);
114 assertNull(getHeaderCell(0, 0));
115 assertNotNull(getBodyCell(0, 0));
116 assertNull(getFooterCell(0, 0));
117 assertLogContains("Columns: 1");
118 assertLogContains("Body rows: 1");
122 public void testInsertAColumnAndAFooterRow() {
125 selectMenuPath(COLUMNS_AND_ROWS, COLUMNS, ADD_ONE_COLUMN_TO_BEGINNING);
126 selectMenuPath(COLUMNS_AND_ROWS, FOOTER_ROWS, ADD_ONE_ROW_TO_BEGINNING);
127 assertNull(getHeaderCell(0, 0));
128 assertNull(getBodyCell(0, 0));
129 assertNotNull(getFooterCell(0, 0));
130 assertLogContains("Columns: 1");
131 assertLogContains("Footer rows: 1");
135 public void testInsertAHeaderRowAndAColumn() {
138 selectMenuPath(COLUMNS_AND_ROWS, HEADER_ROWS, ADD_ONE_ROW_TO_BEGINNING);
139 selectMenuPath(COLUMNS_AND_ROWS, COLUMNS, ADD_ONE_COLUMN_TO_BEGINNING);
140 assertNotNull(getHeaderCell(0, 0));
141 assertNull(getBodyCell(0, 0));
142 assertNull(getFooterCell(0, 0));
143 assertLogContains("Columns: 1");
144 assertLogContains("Header rows: 1");
148 public void testInsertABodyRowAndAColumn() {
151 selectMenuPath(COLUMNS_AND_ROWS, BODY_ROWS, ADD_ONE_ROW_TO_BEGINNING);
152 selectMenuPath(COLUMNS_AND_ROWS, COLUMNS, ADD_ONE_COLUMN_TO_BEGINNING);
153 assertNull(getHeaderCell(0, 0));
154 assertNotNull(getBodyCell(0, 0));
155 assertNull(getFooterCell(0, 0));
156 assertLogContains("Columns: 1");
157 assertLogContains("Body rows: 1");
161 public void testInsertAFooterRowAndAColumn() {
164 selectMenuPath(COLUMNS_AND_ROWS, FOOTER_ROWS, ADD_ONE_ROW_TO_BEGINNING);
165 selectMenuPath(COLUMNS_AND_ROWS, COLUMNS, ADD_ONE_COLUMN_TO_BEGINNING);
166 assertNull(getHeaderCell(0, 0));
167 assertNull(getBodyCell(0, 0));
168 assertNotNull(getFooterCell(0, 0));
169 assertLogContains("Columns: 1");
170 assertLogContains("Footer rows: 1");
174 public void testFillColRow() {
177 selectMenuPath(GENERAL, POPULATE_COLUMN_ROW);
178 scrollVerticallyTo(2000); // more like 1857, but this should be enough.
180 // if not found, an exception is thrown here
181 assertTrue("Wanted cell was not visible",
182 isElementPresent(By.xpath("//td[text()='Cell: 9,99']")));
186 public void testFillRowCol() {
189 selectMenuPath(GENERAL, POPULATE_ROW_COLUMN);
190 scrollVerticallyTo(2000); // more like 1857, but this should be enough.
192 // if not found, an exception is thrown here
193 assertTrue("Wanted cell was not visible",
194 isElementPresent(By.xpath("//td[text()='Cell: 9,99']")));
198 public void testClearColRow() {
201 selectMenuPath(GENERAL, POPULATE_COLUMN_ROW);
202 selectMenuPath(GENERAL, CLEAR_COLUMN_ROW);
204 assertNull(getBodyCell(0, 0));
208 public void testClearRowCol() {
211 selectMenuPath(GENERAL, POPULATE_COLUMN_ROW);
212 selectMenuPath(GENERAL, CLEAR_ROW_COLUMN);
214 assertNull(getBodyCell(0, 0));
218 public void testResizeColToFit() {
220 selectMenuPath(GENERAL, POPULATE_COLUMN_ROW);
222 selectMenuPath(COLUMNS_AND_ROWS, COLUMNS, RESIZE_FIRST_COLUMN_TO_100PX);
223 int originalWidth = getBodyCell(0, 0).getSize().getWidth();
225 assertEquals(100, originalWidth);
227 selectMenuPath(COLUMNS_AND_ROWS, COLUMNS,
228 RESIZE_FIRST_COLUMN_TO_MAX_WIDTH);
229 int newWidth = getBodyCell(0, 0).getSize().getWidth();
230 assertNotEquals("Column width should've changed", originalWidth,
235 public void testRemoveMoreThanPagefulAtBottomWhileScrolledToBottom()
238 selectMenuPath(GENERAL, POPULATE_COLUMN_ROW);
240 scrollVerticallyTo(BOTTOM_SCROLL_POSITION);
241 selectMenuPath(COLUMNS_AND_ROWS, BODY_ROWS, REMOVE_50_ROWS_FROM_BOTTOM);
242 assertEquals("Row 49: 0,49", getBodyCell(-1, 0).getText());
244 scrollVerticallyTo(0);
246 // let the DOM organize itself
249 // if something goes wrong, it'll explode before this.
250 assertEquals("Row 0: 0,0", getBodyCell(0, 0).getText());
254 public void testRemoveMoreThanPagefulAtBottomWhileScrolledAlmostToBottom()
257 selectMenuPath(GENERAL, POPULATE_COLUMN_ROW);
259 // bottom minus 15 rows.
260 scrollVerticallyTo(BOTTOM_SCROLL_POSITION - 15 * 20);
261 selectMenuPath(COLUMNS_AND_ROWS, BODY_ROWS, REMOVE_50_ROWS_FROM_BOTTOM);
262 assertEquals("Row 49: 0,49", getBodyCell(-1, 0).getText());
264 scrollVerticallyTo(0);
266 // let the DOM organize itself
269 // if something goes wrong, it'll explode before this.
270 assertEquals("Row 0: 0,0", getBodyCell(0, 0).getText());
274 public void testRemoveMoreThanPagefulNearBottomWhileScrolledToBottom()
277 selectMenuPath(GENERAL, POPULATE_COLUMN_ROW);
279 scrollVerticallyTo(BOTTOM_SCROLL_POSITION);
280 selectMenuPath(COLUMNS_AND_ROWS, BODY_ROWS,
281 REMOVE_50_ROWS_FROM_ALMOST_BOTTOM);
282 assertEquals("Row 49: 0,99", getBodyCell(-1, 0).getText());
284 scrollVerticallyTo(0);
286 // let the DOM organize itself
289 // if something goes wrong, it'll explode before this.
290 assertEquals("Row 0: 0,0", getBodyCell(0, 0).getText());
294 public void testRemoveMoreThanPagefulNearBottomWhileScrolledAlmostToBottom()
297 selectMenuPath(GENERAL, POPULATE_COLUMN_ROW);
299 // bottom minus 15 rows.
300 scrollVerticallyTo(BOTTOM_SCROLL_POSITION - 15 * 20);
301 selectMenuPath(COLUMNS_AND_ROWS, BODY_ROWS,
302 REMOVE_50_ROWS_FROM_ALMOST_BOTTOM);
304 // let the DOM organize itself
306 assertEquals("Row 49: 0,99", getBodyCell(-1, 0).getText());
308 scrollVerticallyTo(0);
310 // let the DOM organize itself
313 // if something goes wrong, it'll explode before this.
314 assertEquals("Row 0: 0,0", getBodyCell(0, 0).getText());