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 10KB

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