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.

GridDetailsServerTest.java 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  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.server;
  17. import static org.junit.Assert.assertEquals;
  18. import static org.junit.Assert.assertFalse;
  19. import static org.junit.Assert.assertNotNull;
  20. import static org.junit.Assert.assertTrue;
  21. import static org.junit.Assert.fail;
  22. import org.junit.Before;
  23. import org.junit.Ignore;
  24. import org.junit.Test;
  25. import org.openqa.selenium.By;
  26. import org.openqa.selenium.NoSuchElementException;
  27. import com.vaadin.testbench.TestBenchElement;
  28. import com.vaadin.testbench.elements.NotificationElement;
  29. import com.vaadin.tests.components.grid.basicfeatures.GridBasicFeaturesTest;
  30. public class GridDetailsServerTest extends GridBasicFeaturesTest {
  31. /**
  32. * The reason to why last item details wasn't selected is that since it will
  33. * exist only after the viewport has been scrolled into view, we wouldn't be
  34. * able to scroll that particular details row into view, making tests
  35. * awkward with two scroll commands back to back.
  36. */
  37. private static final int ALMOST_LAST_INDEX = 995;
  38. private static final String[] OPEN_ALMOST_LAST_ITEM_DETAILS = new String[] {
  39. "Component", "Details", "Open " + ALMOST_LAST_INDEX };
  40. private static final String[] OPEN_FIRST_ITEM_DETAILS = new String[] {
  41. "Component", "Details", "Open firstItemId" };
  42. private static final String[] TOGGLE_FIRST_ITEM_DETAILS = new String[] {
  43. "Component", "Details", "Toggle firstItemId" };
  44. private static final String[] DETAILS_GENERATOR_NULL = new String[] {
  45. "Component", "Details", "Generators", "NULL" };
  46. private static final String[] DETAILS_GENERATOR_WATCHING = new String[] {
  47. "Component", "Details", "Generators", "\"Watching\"" };
  48. private static final String[] DETAILS_GENERATOR_HIERARCHICAL = new String[] {
  49. "Component", "Details", "Generators", "Hierarchical" };
  50. private static final String[] CHANGE_HIERARCHY = new String[] {
  51. "Component", "Details", "Generators", "- Change Component" };
  52. @Before
  53. public void setUp() {
  54. openTestURL();
  55. }
  56. @Test
  57. public void openVisibleDetails() {
  58. try {
  59. getGridElement().getDetails(0);
  60. fail("Expected NoSuchElementException");
  61. } catch (NoSuchElementException ignore) {
  62. // expected
  63. }
  64. selectMenuPath(OPEN_FIRST_ITEM_DETAILS);
  65. assertNotNull("details should've opened", getGridElement()
  66. .getDetails(0));
  67. }
  68. @Test(expected = NoSuchElementException.class)
  69. public void closeVisibleDetails() {
  70. selectMenuPath(OPEN_FIRST_ITEM_DETAILS);
  71. selectMenuPath(OPEN_FIRST_ITEM_DETAILS);
  72. getGridElement().getDetails(0);
  73. }
  74. @Test
  75. public void openDetailsOutsideOfActiveRange() throws InterruptedException {
  76. getGridElement().scroll(10000);
  77. selectMenuPath(OPEN_FIRST_ITEM_DETAILS);
  78. getGridElement().scroll(0);
  79. Thread.sleep(50);
  80. assertNotNull("details should've been opened", getGridElement()
  81. .getDetails(0));
  82. }
  83. @Test(expected = NoSuchElementException.class)
  84. public void closeDetailsOutsideOfActiveRange() {
  85. selectMenuPath(OPEN_FIRST_ITEM_DETAILS);
  86. getGridElement().scroll(10000);
  87. selectMenuPath(OPEN_FIRST_ITEM_DETAILS);
  88. getGridElement().scroll(0);
  89. getGridElement().getDetails(0);
  90. }
  91. @Test
  92. public void componentIsVisibleClientSide() {
  93. selectMenuPath(DETAILS_GENERATOR_WATCHING);
  94. selectMenuPath(OPEN_FIRST_ITEM_DETAILS);
  95. TestBenchElement details = getGridElement().getDetails(0);
  96. assertNotNull("No widget detected inside details",
  97. details.findElement(By.className("v-widget")));
  98. }
  99. @Test
  100. public void openingDetailsTwice() {
  101. selectMenuPath(DETAILS_GENERATOR_WATCHING);
  102. selectMenuPath(OPEN_FIRST_ITEM_DETAILS); // open
  103. selectMenuPath(OPEN_FIRST_ITEM_DETAILS); // close
  104. selectMenuPath(OPEN_FIRST_ITEM_DETAILS); // open
  105. TestBenchElement details = getGridElement().getDetails(0);
  106. assertNotNull("No widget detected inside details",
  107. details.findElement(By.className("v-widget")));
  108. }
  109. @Test(expected = NoSuchElementException.class)
  110. public void scrollingDoesNotCreateAFloodOfDetailsRows() {
  111. selectMenuPath(DETAILS_GENERATOR_WATCHING);
  112. // scroll somewhere to hit uncached rows
  113. getGridElement().scrollToRow(101);
  114. // this should throw
  115. getGridElement().getDetails(100);
  116. }
  117. @Test
  118. public void openingDetailsOutOfView() {
  119. getGridElement().scrollToRow(500);
  120. selectMenuPath(DETAILS_GENERATOR_WATCHING);
  121. selectMenuPath(OPEN_FIRST_ITEM_DETAILS);
  122. getGridElement().scrollToRow(0);
  123. // if this fails, it'll fail before the assertNotNull
  124. assertNotNull("unexpected null details row", getGridElement()
  125. .getDetails(0));
  126. }
  127. @Test
  128. public void togglingAVisibleDetailsRowWithOneRoundtrip() {
  129. selectMenuPath(DETAILS_GENERATOR_WATCHING);
  130. selectMenuPath(OPEN_FIRST_ITEM_DETAILS); // open
  131. assertTrue("Unexpected generator content",
  132. getGridElement().getDetails(0).getText().endsWith("(0)"));
  133. selectMenuPath(TOGGLE_FIRST_ITEM_DETAILS);
  134. assertTrue("New component was not displayed in the client",
  135. getGridElement().getDetails(0).getText().endsWith("(1)"));
  136. }
  137. @Test
  138. public void almosLastItemIdIsRendered() {
  139. selectMenuPath(DETAILS_GENERATOR_WATCHING);
  140. selectMenuPath(OPEN_ALMOST_LAST_ITEM_DETAILS);
  141. scrollGridVerticallyTo(100000);
  142. TestBenchElement details = getGridElement().getDetails(
  143. ALMOST_LAST_INDEX);
  144. assertNotNull(details);
  145. assertTrue("Unexpected details content",
  146. details.getText().endsWith(ALMOST_LAST_INDEX + " (0)"));
  147. }
  148. @Test
  149. public void hierarchyChangesWorkInDetails() {
  150. selectMenuPath(DETAILS_GENERATOR_HIERARCHICAL);
  151. selectMenuPath(OPEN_FIRST_ITEM_DETAILS);
  152. assertEquals("One", getGridElement().getDetails(0).getText());
  153. selectMenuPath(CHANGE_HIERARCHY);
  154. assertEquals("Two", getGridElement().getDetails(0).getText());
  155. }
  156. @Ignore("This use case is not currently supported by Grid. If the detail "
  157. + "is out of view, the component is detached from the UI and a "
  158. + "new instance is generated when scrolled back. Support will "
  159. + "maybe be incorporated at a later time")
  160. @Test
  161. public void hierarchyChangesWorkInDetailsWhileOutOfView() {
  162. selectMenuPath(DETAILS_GENERATOR_HIERARCHICAL);
  163. selectMenuPath(OPEN_FIRST_ITEM_DETAILS);
  164. scrollGridVerticallyTo(10000);
  165. selectMenuPath(CHANGE_HIERARCHY);
  166. scrollGridVerticallyTo(0);
  167. assertEquals("Two", getGridElement().getDetails(0).getText());
  168. }
  169. @Test
  170. public void swappingDetailsGenerators_noDetailsShown() {
  171. selectMenuPath(DETAILS_GENERATOR_WATCHING);
  172. selectMenuPath(DETAILS_GENERATOR_NULL);
  173. assertFalse("Got some errors", $(NotificationElement.class).exists());
  174. }
  175. @Test
  176. public void swappingDetailsGenerators_shownDetails() {
  177. selectMenuPath(OPEN_FIRST_ITEM_DETAILS);
  178. assertTrue("Details should be empty at the start", getGridElement()
  179. .getDetails(0).getText().isEmpty());
  180. selectMenuPath(DETAILS_GENERATOR_WATCHING);
  181. assertFalse("Details should not be empty after swapping generator",
  182. getGridElement().getDetails(0).getText().isEmpty());
  183. }
  184. @Test
  185. public void swappingDetailsGenerators_whileDetailsScrolledOut_showNever() {
  186. scrollGridVerticallyTo(1000);
  187. selectMenuPath(OPEN_FIRST_ITEM_DETAILS);
  188. selectMenuPath(DETAILS_GENERATOR_WATCHING);
  189. assertFalse("Got some errors", $(NotificationElement.class).exists());
  190. }
  191. @Test
  192. public void swappingDetailsGenerators_whileDetailsScrolledOut_showAfter() {
  193. scrollGridVerticallyTo(1000);
  194. selectMenuPath(OPEN_FIRST_ITEM_DETAILS);
  195. selectMenuPath(DETAILS_GENERATOR_WATCHING);
  196. scrollGridVerticallyTo(0);
  197. assertFalse("Got some errors", $(NotificationElement.class).exists());
  198. assertNotNull("Could not find a details", getGridElement()
  199. .getDetails(0));
  200. }
  201. @Test
  202. public void swappingDetailsGenerators_whileDetailsScrolledOut_showBefore() {
  203. selectMenuPath(OPEN_FIRST_ITEM_DETAILS);
  204. selectMenuPath(DETAILS_GENERATOR_WATCHING);
  205. scrollGridVerticallyTo(1000);
  206. assertFalse("Got some errors", $(NotificationElement.class).exists());
  207. assertNotNull("Could not find a details", getGridElement()
  208. .getDetails(0));
  209. }
  210. @Test
  211. public void swappingDetailsGenerators_whileDetailsScrolledOut_showBeforeAndAfter() {
  212. selectMenuPath(OPEN_FIRST_ITEM_DETAILS);
  213. selectMenuPath(DETAILS_GENERATOR_WATCHING);
  214. scrollGridVerticallyTo(1000);
  215. scrollGridVerticallyTo(0);
  216. assertFalse("Got some errors", $(NotificationElement.class).exists());
  217. assertNotNull("Could not find a details", getGridElement()
  218. .getDetails(0));
  219. }
  220. @Test
  221. public void nullDetailComponentToggling() {
  222. selectMenuPath(OPEN_FIRST_ITEM_DETAILS);
  223. selectMenuPath(DETAILS_GENERATOR_WATCHING);
  224. selectMenuPath(DETAILS_GENERATOR_NULL);
  225. assertTrue("Details should be empty with null component",
  226. getGridElement().getDetails(0).getText().isEmpty());
  227. selectMenuPath(DETAILS_GENERATOR_WATCHING);
  228. assertFalse("Details should be not empty with details component",
  229. getGridElement().getDetails(0).getText().isEmpty());
  230. }
  231. }