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.

TreeTablePartialUpdatesTest.java 8.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. package com.vaadin.tests.components.treetable;
  2. import static org.junit.Assert.assertEquals;
  3. import static org.junit.Assert.assertFalse;
  4. import java.io.IOException;
  5. import java.util.List;
  6. import org.junit.Test;
  7. import org.openqa.selenium.WebElement;
  8. import org.openqa.selenium.support.ui.ExpectedConditions;
  9. import com.vaadin.testbench.By;
  10. import com.vaadin.testbench.commands.TestBenchElementCommands;
  11. import com.vaadin.testbench.elements.TreeTableElement;
  12. import com.vaadin.testbench.parallel.BrowserUtil;
  13. import com.vaadin.tests.tb3.MultiBrowserTest;
  14. /**
  15. * Tests partial updates of a TreeTable.
  16. *
  17. * @author Vaadin Ltd
  18. */
  19. public class TreeTablePartialUpdatesTest extends MultiBrowserTest {
  20. @Test
  21. public void testLongScroll() throws IOException, InterruptedException {
  22. openTestURL();
  23. TreeTableElement treeTable = $(TreeTableElement.class).first();
  24. List<WebElement> rows = treeTable
  25. .findElement(By.className("v-table-body"))
  26. .findElements(By.tagName("tr"));
  27. assertEquals("unexpected row count", 4, rows.size());
  28. // expand the first root element
  29. treeTable.getCell(0, 0)
  30. .findElement(By.className("v-treetable-treespacer")).click();
  31. treeTable = $(TreeTableElement.class).first();
  32. // wait for the scrollposition element to disappear
  33. waitUntilNot(ExpectedConditions.visibilityOfElementLocated(
  34. By.className("v-table-scrollposition")));
  35. rows = treeTable.findElement(By.className("v-table-body"))
  36. .findElements(By.tagName("tr"));
  37. assertEquals("unexpected cached row count", 46, rows.size());
  38. // TODO: replace these with just treeTable.scroll(int) when #13826 has
  39. // been fixed
  40. TestBenchElementCommands scrollable = testBenchElement(
  41. treeTable.findElement(By.className("v-scrollable")));
  42. // scroll far enough down to drop the first row from the cache
  43. // but not far enough to reach the last row
  44. if (BrowserUtil.isChrome(getDesiredCapabilities())) {
  45. // Chrome 56 requires different scroll position
  46. scrollable.scroll(846);
  47. } else {
  48. scrollable.scroll(1692);
  49. }
  50. // wait for the scrollposition element to disappear
  51. waitUntilNot(ExpectedConditions.visibilityOfElementLocated(
  52. By.className("v-table-scrollposition")));
  53. assertEquals("elements found where there should be none", 0,
  54. treeTable.findElements(By.vaadin("#row[0]/col[0]")).size());
  55. assertEquals("elements found where there should be none", 0,
  56. treeTable.findElements(By.vaadin("#row[203]/col[0]")).size());
  57. // scroll 6000 to make sure to actually hit bottom
  58. scrollable.scroll(6000);
  59. // wait for the scrollposition element to disappear
  60. waitUntilNot(ExpectedConditions.visibilityOfElementLocated(
  61. By.className("v-table-scrollposition")));
  62. // check the contents
  63. treeTable = $(TreeTableElement.class).first();
  64. rows = treeTable.findElement(By.className("v-table-body"))
  65. .findElements(By.tagName("tr"));
  66. assertEquals("unexpected cached row count", 45, rows.size());
  67. assertEquals("unexpected cell contents (final row expected)", "END",
  68. treeTable.getCell(203, 0).getText());
  69. assertEquals("unexpected cell contents (first visible row expected)",
  70. "188", treeTable.getCell(189, 0).getText());
  71. assertEquals("unexpected cell contents (first cached row expected)",
  72. "158", treeTable.getCell(159, 0).getText());
  73. assertEquals("elements found where there should be none", 0,
  74. treeTable.findElements(By.vaadin("#row[158]/col[0]")).size());
  75. assertEquals("elements found where there should be none", 0,
  76. treeTable.findElements(By.vaadin("#row[204]/col[0]")).size());
  77. // check the actual visibility
  78. compareScreen("bottom");
  79. }
  80. @Test
  81. public void testNegativeArraySize()
  82. throws IOException, InterruptedException {
  83. openTestURL();
  84. TreeTableElement treeTable = $(TreeTableElement.class).first();
  85. List<WebElement> rows = treeTable
  86. .findElement(By.className("v-table-body"))
  87. .findElements(By.tagName("tr"));
  88. assertEquals("unexpected row count", 4, rows.size());
  89. // expand the first root element
  90. treeTable.getCell(0, 0)
  91. .findElement(By.className("v-treetable-treespacer")).click();
  92. // wait for the scrollposition element to disappear
  93. waitUntilNot(ExpectedConditions.visibilityOfElementLocated(
  94. By.className("v-table-scrollposition")));
  95. treeTable = $(TreeTableElement.class).first();
  96. rows = treeTable.findElement(By.className("v-table-body"))
  97. .findElements(By.tagName("tr"));
  98. assertEquals("unexpected cached row count", 46, rows.size());
  99. // TODO: replace these with just treeTable.scroll(int) when #13826 has
  100. // been fixed
  101. TestBenchElementCommands scrollable = testBenchElement(
  102. treeTable.findElement(By.className("v-scrollable")));
  103. // scroll far enough down to reach the second root item again
  104. scrollable.scroll(3969);
  105. // wait for the scrollposition element to disappear
  106. waitUntilNot(ExpectedConditions.visibilityOfElementLocated(
  107. By.className("v-table-scrollposition")));
  108. assertEquals("elements found where there should be none", 0,
  109. treeTable.findElements(By.vaadin("#row[0]/col[0]")).size());
  110. assertEquals("unexpected cell contents", "root2",
  111. treeTable.getCell(201, 0).getText());
  112. assertEquals("unexpected cell contents", "END",
  113. treeTable.getCell(203, 0).getText());
  114. // expand the second root element
  115. treeTable.getCell(201, 0)
  116. .findElement(By.className("v-treetable-treespacer")).click();
  117. // wait for the scrollposition element to disappear
  118. waitUntilNot(ExpectedConditions.visibilityOfElementLocated(
  119. By.className("v-table-scrollposition")));
  120. // ensure the last cached row isn't the final row
  121. treeTable = $(TreeTableElement.class).first();
  122. rows = treeTable.findElement(By.className("v-table-body"))
  123. .findElements(By.tagName("tr"));
  124. String elementText = rows.get(rows.size() - 1)
  125. .findElement(By.className("v-table-cell-wrapper")).getText();
  126. assertFalse("final row found when it should be beyond cache",
  127. elementText.contains("END"));
  128. // collapse the second root element
  129. treeTable.getCell(201, 0)
  130. .findElement(By.className("v-treetable-treespacer")).click();
  131. // wait for the scrollposition element to disappear
  132. waitUntilNot(ExpectedConditions.visibilityOfElementLocated(
  133. By.className("v-table-scrollposition")));
  134. // check the contents
  135. treeTable = $(TreeTableElement.class).first();
  136. rows = treeTable.findElement(By.className("v-table-body"))
  137. .findElements(By.tagName("tr"));
  138. assertEquals("unexpected cached row count", 45, rows.size());
  139. assertEquals("unexpected cell contents (final row expected)", "END",
  140. treeTable.getCell(203, 0).getText());
  141. assertEquals("unexpected cell contents (first visible row expected)",
  142. "188", treeTable.getCell(189, 0).getText());
  143. assertEquals("unexpected cell contents (first cached row expected)",
  144. "158", treeTable.getCell(159, 0).getText());
  145. assertEquals("elements found where there should be none", 0,
  146. treeTable.findElements(By.vaadin("#row[158]/col[0]")).size());
  147. assertEquals("elements found where there should be none", 0,
  148. treeTable.findElements(By.vaadin("#row[204]/col[0]")).size());
  149. // check the actual visibility
  150. compareScreen("bottom");
  151. }
  152. }