You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

EscalatorRowColumnTest.java 9.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. /*
  2. * Copyright 2000-2014 Vaadin Ltd.
  3. *
  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
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  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
  14. * the License.
  15. */
  16. package com.vaadin.tests.components.grid.basicfeatures;
  17. import static org.junit.Assert.assertEquals;
  18. import static org.junit.Assert.assertNotEquals;
  19. import static org.junit.Assert.assertNotNull;
  20. import static org.junit.Assert.assertNull;
  21. import org.junit.Test;
  22. import org.openqa.selenium.By;
  23. public class EscalatorRowColumnTest extends EscalatorBasicClientFeaturesTest {
  24. /**
  25. * The scroll position of the Escalator when scrolled all the way down, to
  26. * reveal the 100:th row.
  27. */
  28. private static final int BOTTOM_SCROLL_POSITION = 1857;
  29. @Test
  30. public void testInit() {
  31. openTestURL();
  32. assertNotNull(getEscalator());
  33. assertNull(getHeaderRow(0));
  34. assertNull(getBodyRow(0));
  35. assertNull(getFooterRow(0));
  36. assertLogContains("Columns: 0");
  37. assertLogContains("Header rows: 0");
  38. assertLogContains("Body rows: 0");
  39. assertLogContains("Footer rows: 0");
  40. }
  41. @Test
  42. public void testInsertAColumn() {
  43. openTestURL();
  44. selectMenuPath(COLUMNS_AND_ROWS, COLUMNS, ADD_ONE_COLUMN_TO_BEGINNING);
  45. assertNull(getHeaderRow(0));
  46. assertNull(getBodyRow(0));
  47. assertNull(getFooterRow(0));
  48. assertLogContains("Columns: 1");
  49. }
  50. @Test
  51. public void testInsertAHeaderRow() {
  52. openTestURL();
  53. selectMenuPath(COLUMNS_AND_ROWS, HEADER_ROWS, ADD_ONE_ROW_TO_BEGINNING);
  54. assertNull(getHeaderCell(0, 0));
  55. assertNull(getBodyCell(0, 0));
  56. assertNull(getFooterCell(0, 0));
  57. assertLogContains("Header rows: 1");
  58. }
  59. @Test
  60. public void testInsertABodyRow() {
  61. openTestURL();
  62. selectMenuPath(COLUMNS_AND_ROWS, BODY_ROWS, ADD_ONE_ROW_TO_BEGINNING);
  63. assertNull(getHeaderCell(0, 0));
  64. assertNull(getBodyCell(0, 0));
  65. assertNull(getFooterCell(0, 0));
  66. assertLogContains("Body rows: 1");
  67. }
  68. @Test
  69. public void testInsertAFooterRow() {
  70. openTestURL();
  71. selectMenuPath(COLUMNS_AND_ROWS, FOOTER_ROWS, ADD_ONE_ROW_TO_BEGINNING);
  72. assertNull(getHeaderCell(0, 0));
  73. assertNull(getBodyCell(0, 0));
  74. assertNull(getFooterCell(0, 0));
  75. assertLogContains("Footer rows: 1");
  76. }
  77. @Test
  78. public void testInsertAColumnAndAHeaderRow() {
  79. openTestURL();
  80. selectMenuPath(COLUMNS_AND_ROWS, COLUMNS, ADD_ONE_COLUMN_TO_BEGINNING);
  81. selectMenuPath(COLUMNS_AND_ROWS, HEADER_ROWS, ADD_ONE_ROW_TO_BEGINNING);
  82. assertNotNull(getHeaderCell(0, 0));
  83. assertNull(getBodyCell(0, 0));
  84. assertNull(getFooterCell(0, 0));
  85. assertLogContains("Columns: 1");
  86. assertLogContains("Header rows: 1");
  87. }
  88. @Test
  89. public void testInsertAColumnAndABodyRow() {
  90. openTestURL();
  91. selectMenuPath(COLUMNS_AND_ROWS, COLUMNS, ADD_ONE_COLUMN_TO_BEGINNING);
  92. selectMenuPath(COLUMNS_AND_ROWS, BODY_ROWS, ADD_ONE_ROW_TO_BEGINNING);
  93. assertNull(getHeaderCell(0, 0));
  94. assertNotNull(getBodyCell(0, 0));
  95. assertNull(getFooterCell(0, 0));
  96. assertLogContains("Columns: 1");
  97. assertLogContains("Body rows: 1");
  98. }
  99. @Test
  100. public void testInsertAColumnAndAFooterRow() {
  101. openTestURL();
  102. selectMenuPath(COLUMNS_AND_ROWS, COLUMNS, ADD_ONE_COLUMN_TO_BEGINNING);
  103. selectMenuPath(COLUMNS_AND_ROWS, FOOTER_ROWS, ADD_ONE_ROW_TO_BEGINNING);
  104. assertNull(getHeaderCell(0, 0));
  105. assertNull(getBodyCell(0, 0));
  106. assertNotNull(getFooterCell(0, 0));
  107. assertLogContains("Columns: 1");
  108. assertLogContains("Footer rows: 1");
  109. }
  110. @Test
  111. public void testInsertAHeaderRowAndAColumn() {
  112. openTestURL();
  113. selectMenuPath(COLUMNS_AND_ROWS, HEADER_ROWS, ADD_ONE_ROW_TO_BEGINNING);
  114. selectMenuPath(COLUMNS_AND_ROWS, COLUMNS, ADD_ONE_COLUMN_TO_BEGINNING);
  115. assertNotNull(getHeaderCell(0, 0));
  116. assertNull(getBodyCell(0, 0));
  117. assertNull(getFooterCell(0, 0));
  118. assertLogContains("Columns: 1");
  119. assertLogContains("Header rows: 1");
  120. }
  121. @Test
  122. public void testInsertABodyRowAndAColumn() {
  123. openTestURL();
  124. selectMenuPath(COLUMNS_AND_ROWS, BODY_ROWS, ADD_ONE_ROW_TO_BEGINNING);
  125. selectMenuPath(COLUMNS_AND_ROWS, COLUMNS, ADD_ONE_COLUMN_TO_BEGINNING);
  126. assertNull(getHeaderCell(0, 0));
  127. assertNotNull(getBodyCell(0, 0));
  128. assertNull(getFooterCell(0, 0));
  129. assertLogContains("Columns: 1");
  130. assertLogContains("Body rows: 1");
  131. }
  132. @Test
  133. public void testInsertAFooterRowAndAColumn() {
  134. openTestURL();
  135. selectMenuPath(COLUMNS_AND_ROWS, FOOTER_ROWS, ADD_ONE_ROW_TO_BEGINNING);
  136. selectMenuPath(COLUMNS_AND_ROWS, COLUMNS, ADD_ONE_COLUMN_TO_BEGINNING);
  137. assertNull(getHeaderCell(0, 0));
  138. assertNull(getBodyCell(0, 0));
  139. assertNotNull(getFooterCell(0, 0));
  140. assertLogContains("Columns: 1");
  141. assertLogContains("Footer rows: 1");
  142. }
  143. @Test
  144. public void testFillColRow() {
  145. openTestURL();
  146. selectMenuPath(GENERAL, POPULATE_COLUMN_ROW);
  147. scrollVerticallyTo(2000); // more like 1857, but this should be enough.
  148. // if not found, an exception is thrown here
  149. findElement(By.xpath("//td[text()='Cell: 9,99']"));
  150. }
  151. @Test
  152. public void testFillRowCol() {
  153. openTestURL();
  154. selectMenuPath(GENERAL, POPULATE_ROW_COLUMN);
  155. scrollVerticallyTo(2000); // more like 1857, but this should be enough.
  156. // if not found, an exception is thrown here
  157. findElement(By.xpath("//td[text()='Cell: 9,99']"));
  158. }
  159. @Test
  160. public void testClearColRow() {
  161. openTestURL();
  162. selectMenuPath(GENERAL, POPULATE_COLUMN_ROW);
  163. selectMenuPath(GENERAL, CLEAR_COLUMN_ROW);
  164. assertNull(getBodyCell(0, 0));
  165. }
  166. @Test
  167. public void testClearRowCol() {
  168. openTestURL();
  169. selectMenuPath(GENERAL, POPULATE_COLUMN_ROW);
  170. selectMenuPath(GENERAL, CLEAR_ROW_COLUMN);
  171. assertNull(getBodyCell(0, 0));
  172. }
  173. @Test
  174. public void testResizeColToFit() {
  175. openTestURL();
  176. selectMenuPath(GENERAL, POPULATE_COLUMN_ROW);
  177. int originalWidth = getBodyCell(0, 0).getSize().getWidth();
  178. selectMenuPath(COLUMNS_AND_ROWS, COLUMNS,
  179. RESIZE_FIRST_COLUMN_TO_MAX_WIDTH);
  180. int newWidth = getBodyCell(0, 0).getSize().getWidth();
  181. assertNotEquals("Column width should've changed", originalWidth,
  182. newWidth);
  183. }
  184. @Test
  185. public void testRemoveMoreThanPagefulAtBottomWhileScrolledToBottom()
  186. throws Exception {
  187. openTestURL();
  188. selectMenuPath(GENERAL, POPULATE_COLUMN_ROW);
  189. scrollVerticallyTo(BOTTOM_SCROLL_POSITION);
  190. selectMenuPath(COLUMNS_AND_ROWS, BODY_ROWS, REMOVE_50_ROWS_FROM_BOTTOM);
  191. assertEquals("Row 49: 0,49", getBodyCell(-1, 0).getText());
  192. scrollVerticallyTo(0);
  193. // let the DOM organize itself
  194. Thread.sleep(500);
  195. // if something goes wrong, it'll explode before this.
  196. assertEquals("Row 0: 0,0", getBodyCell(0, 0).getText());
  197. }
  198. @Test
  199. public void testRemoveMoreThanPagefulAtBottomWhileScrolledAlmostToBottom()
  200. throws Exception {
  201. openTestURL();
  202. selectMenuPath(GENERAL, POPULATE_COLUMN_ROW);
  203. // bottom minus 15 rows.
  204. scrollVerticallyTo(BOTTOM_SCROLL_POSITION - 15 * 20);
  205. selectMenuPath(COLUMNS_AND_ROWS, BODY_ROWS, REMOVE_50_ROWS_FROM_BOTTOM);
  206. assertEquals("Row 49: 0,49", getBodyCell(-1, 0).getText());
  207. scrollVerticallyTo(0);
  208. // let the DOM organize itself
  209. Thread.sleep(500);
  210. // if something goes wrong, it'll explode before this.
  211. assertEquals("Row 0: 0,0", getBodyCell(0, 0).getText());
  212. }
  213. @Test
  214. public void testRemoveMoreThanPagefulNearBottomWhileScrolledToBottom()
  215. throws Exception {
  216. openTestURL();
  217. selectMenuPath(GENERAL, POPULATE_COLUMN_ROW);
  218. scrollVerticallyTo(BOTTOM_SCROLL_POSITION);
  219. selectMenuPath(COLUMNS_AND_ROWS, BODY_ROWS,
  220. REMOVE_50_ROWS_FROM_ALMOST_BOTTOM);
  221. assertEquals("Row 49: 0,99", getBodyCell(-1, 0).getText());
  222. scrollVerticallyTo(0);
  223. // let the DOM organize itself
  224. Thread.sleep(500);
  225. // if something goes wrong, it'll explode before this.
  226. assertEquals("Row 0: 0,0", getBodyCell(0, 0).getText());
  227. }
  228. @Test
  229. public void testRemoveMoreThanPagefulNearBottomWhileScrolledAlmostToBottom()
  230. throws Exception {
  231. openTestURL();
  232. selectMenuPath(GENERAL, POPULATE_COLUMN_ROW);
  233. // bottom minus 15 rows.
  234. scrollVerticallyTo(BOTTOM_SCROLL_POSITION - 15 * 20);
  235. selectMenuPath(COLUMNS_AND_ROWS, BODY_ROWS,
  236. REMOVE_50_ROWS_FROM_ALMOST_BOTTOM);
  237. // let the DOM organize itself
  238. Thread.sleep(500);
  239. assertEquals("Row 49: 0,99", getBodyCell(-1, 0).getText());
  240. scrollVerticallyTo(0);
  241. // let the DOM organize itself
  242. Thread.sleep(500);
  243. // if something goes wrong, it'll explode before this.
  244. assertEquals("Row 0: 0,0", getBodyCell(0, 0).getText());
  245. }
  246. }