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.

TreeGridBigDetailsManagerTest.java 30KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870
  1. package com.vaadin.tests.components.treegrid;
  2. import static org.hamcrest.Matchers.greaterThanOrEqualTo;
  3. import static org.hamcrest.Matchers.not;
  4. import static org.hamcrest.number.IsCloseTo.closeTo;
  5. import static org.junit.Assert.assertEquals;
  6. import static org.junit.Assert.assertNotEquals;
  7. import static org.junit.Assert.assertNotNull;
  8. import static org.junit.Assert.assertThat;
  9. import java.util.List;
  10. import org.junit.Before;
  11. import org.junit.Test;
  12. import org.openqa.selenium.StaleElementReferenceException;
  13. import org.openqa.selenium.WebDriver;
  14. import org.openqa.selenium.WebElement;
  15. import org.openqa.selenium.support.ui.ExpectedCondition;
  16. import org.openqa.selenium.support.ui.ExpectedConditions;
  17. import com.vaadin.testbench.By;
  18. import com.vaadin.testbench.TestBenchElement;
  19. import com.vaadin.testbench.elements.ButtonElement;
  20. import com.vaadin.testbench.elements.TreeGridElement;
  21. import com.vaadin.tests.tb3.MultiBrowserTest;
  22. public class TreeGridBigDetailsManagerTest extends MultiBrowserTest {
  23. private static final String CLASSNAME_ERROR = "v-Notification-error";
  24. private static final String CLASSNAME_LABEL = "v-label";
  25. private static final String CLASSNAME_LEAF = "v-treegrid-row-depth-1";
  26. private static final String CLASSNAME_SPACER = "v-treegrid-spacer";
  27. private static final String CLASSNAME_TREEGRID = "v-treegrid";
  28. private static final String EXPAND_ALL = "expandAll";
  29. private static final String COLLAPSE_ALL = "collapseAll";
  30. private static final String SHOW_DETAILS = "showDetails";
  31. private static final String HIDE_DETAILS = "hideDetails";
  32. private static final String ADD_GRID = "addGrid";
  33. private static final String SCROLL_TO_55 = "scrollTo55";
  34. private static final String SCROLL_TO_3055 = "scrollTo3055";
  35. private static final String SCROLL_TO_END = "scrollToEnd";
  36. private static final String SCROLL_TO_START = "scrollToStart";
  37. private static final String TOGGLE_15 = "toggle15";
  38. private static final String TOGGLE_3000 = "toggle3000";
  39. private TreeGridElement treeGrid;
  40. private int expectedSpacerHeight = 0;
  41. private int expectedRowHeight = 0;
  42. private ExpectedCondition<Boolean> expectedConditionDetails(final int root,
  43. final Integer branch, final Integer leaf) {
  44. return new ExpectedCondition<Boolean>() {
  45. @Override
  46. public Boolean apply(WebDriver arg0) {
  47. return getSpacer(root, branch, leaf) != null;
  48. }
  49. @Override
  50. public String toString() {
  51. // waiting for...
  52. if (leaf != null) {
  53. return String.format(
  54. "Leaf %s/%s/%s details row contents to be found",
  55. root, branch, leaf);
  56. }
  57. return String.format(
  58. "Branch %s/%s details row contents to be found", root,
  59. branch);
  60. }
  61. };
  62. }
  63. private WebElement getSpacer(final int root, final Integer branch,
  64. final Integer leaf) {
  65. String text;
  66. if (leaf == null) {
  67. if (branch == null) {
  68. text = "details for Root %s";
  69. } else {
  70. text = "details for Branch %s/%s";
  71. }
  72. } else {
  73. text = "details for Leaf %s/%s/%s";
  74. }
  75. try {
  76. List<WebElement> spacers = treeGrid
  77. .findElements(By.className(CLASSNAME_SPACER));
  78. for (WebElement spacer : spacers) {
  79. List<WebElement> labels = spacer
  80. .findElements(By.className(CLASSNAME_LABEL));
  81. for (WebElement label : labels) {
  82. if (String.format(text, root, branch, leaf)
  83. .equals(label.getText())) {
  84. return spacer;
  85. }
  86. }
  87. }
  88. } catch (StaleElementReferenceException e) {
  89. treeGrid = $(TreeGridElement.class).first();
  90. }
  91. return null;
  92. }
  93. private WebElement getRow(int index) {
  94. return treeGrid.getBody().findElements(By.className("v-treegrid-row"))
  95. .get(index);
  96. }
  97. private void ensureExpectedSpacerHeightSet() {
  98. if (expectedSpacerHeight == 0) {
  99. expectedSpacerHeight = treeGrid
  100. .findElement(By.className(CLASSNAME_SPACER)).getSize()
  101. .getHeight();
  102. assertThat((double) expectedSpacerHeight, closeTo(27d, 2d));
  103. }
  104. }
  105. private void assertSpacerCount(int expectedSpacerCount) {
  106. assertEquals("Unexpected amount of spacers.", expectedSpacerCount,
  107. treeGrid.findElements(By.className(CLASSNAME_SPACER)).size());
  108. }
  109. /**
  110. * Asserts that every spacer has the same height.
  111. */
  112. private void assertSpacerHeights() {
  113. List<WebElement> spacers = treeGrid
  114. .findElements(By.className(CLASSNAME_SPACER));
  115. for (WebElement spacer : spacers) {
  116. assertEquals("Unexpected spacer height.", expectedSpacerHeight,
  117. spacer.getSize().getHeight());
  118. }
  119. }
  120. /**
  121. * Asserts that every spacer is at least a row height from the previous one.
  122. * Doesn't check that the spacers are in correct order or rendered properly.
  123. */
  124. private void assertSpacerPositions() {
  125. List<WebElement> spacers = treeGrid
  126. .findElements(By.className(CLASSNAME_SPACER));
  127. WebElement previousSpacer = null;
  128. for (WebElement spacer : spacers) {
  129. if (previousSpacer == null) {
  130. previousSpacer = spacer;
  131. continue;
  132. }
  133. // -1 should be enough, but increased tolerance to -3 for FireFox
  134. // and IE11 since a few pixels' discrepancy isn't relevant for this
  135. // fix
  136. assertThat("Unexpected spacer position.", spacer.getLocation().y,
  137. greaterThanOrEqualTo(previousSpacer.getLocation().y
  138. + expectedSpacerHeight + expectedRowHeight - 3));
  139. previousSpacer = spacer;
  140. }
  141. }
  142. private void assertNoErrors() {
  143. assertEquals("Error notification detected.", 0,
  144. treeGrid.findElements(By.className(CLASSNAME_ERROR)).size());
  145. }
  146. private void addGrid() {
  147. $(ButtonElement.class).id(ADD_GRID).click();
  148. waitForElementPresent(By.className(CLASSNAME_TREEGRID));
  149. treeGrid = $(TreeGridElement.class).first();
  150. expectedRowHeight = treeGrid.getRow(0).getSize().getHeight();
  151. }
  152. @Before
  153. public void before() {
  154. openTestURL();
  155. }
  156. @Test
  157. public void expandAllOpenAllInitialDetails_toggleOneTwice_hideAll() {
  158. $(ButtonElement.class).id(EXPAND_ALL).click();
  159. $(ButtonElement.class).id(SHOW_DETAILS).click();
  160. addGrid();
  161. waitUntil(expectedConditionDetails(0, 0, 0));
  162. ensureExpectedSpacerHeightSet();
  163. int spacerCount = treeGrid.findElements(By.className(CLASSNAME_SPACER))
  164. .size();
  165. assertSpacerPositions();
  166. treeGrid.collapseWithClick(0);
  167. // collapsing one shouldn't affect spacer count, just update the cache
  168. waitUntil(ExpectedConditions.not(expectedConditionDetails(0, 0, 0)));
  169. assertSpacerHeights();
  170. assertSpacerPositions();
  171. assertSpacerCount(spacerCount);
  172. treeGrid.expandWithClick(0);
  173. // expanding back shouldn't affect spacer count, just update the cache
  174. waitUntil(expectedConditionDetails(0, 0, 0));
  175. assertSpacerHeights();
  176. assertSpacerPositions();
  177. assertSpacerCount(spacerCount);
  178. // test that repeating the toggle still doesn't change anything
  179. treeGrid.collapseWithClick(0);
  180. waitUntil(ExpectedConditions.not(expectedConditionDetails(0, 0, 0)));
  181. assertSpacerHeights();
  182. assertSpacerPositions();
  183. assertSpacerCount(spacerCount);
  184. treeGrid.expandWithClick(0);
  185. waitUntil(expectedConditionDetails(0, 0, 0));
  186. assertSpacerHeights();
  187. assertSpacerPositions();
  188. assertSpacerCount(spacerCount);
  189. // test that hiding all still won't break things
  190. $(ButtonElement.class).id(HIDE_DETAILS).click();
  191. waitForElementNotPresent(By.className(CLASSNAME_SPACER));
  192. assertNoErrors();
  193. }
  194. @Test
  195. public void expandAllOpenAllInitialDetails_toggleAll() {
  196. $(ButtonElement.class).id(EXPAND_ALL).click();
  197. $(ButtonElement.class).id(SHOW_DETAILS).click();
  198. addGrid();
  199. waitUntil(expectedConditionDetails(0, 0, 0));
  200. ensureExpectedSpacerHeightSet();
  201. int spacerCount = treeGrid.findElements(By.className(CLASSNAME_SPACER))
  202. .size();
  203. assertSpacerPositions();
  204. $(ButtonElement.class).id(COLLAPSE_ALL).click();
  205. // There should still be a full cache's worth of details rows open,
  206. // just not the same rows than before collapsing all.
  207. waitForElementNotPresent(By.className(CLASSNAME_LEAF));
  208. assertSpacerCount(spacerCount);
  209. assertSpacerHeights();
  210. assertSpacerPositions();
  211. // FIXME: TreeGrid fails to update cache correctly when you expand all
  212. // and triggers client-side exceptions for rows that fall outside of the
  213. // cache because they try to extend the cache with a range that isn't
  214. // connected to the cached range
  215. if (true) {// remove this block after fixed
  216. return;
  217. }
  218. $(ButtonElement.class).id(EXPAND_ALL).click();
  219. // State should have returned to what it was before collapsing.
  220. waitUntil(expectedConditionDetails(0, 0, 0), 15);
  221. assertSpacerCount(spacerCount);
  222. assertSpacerHeights();
  223. assertSpacerPositions();
  224. assertNoErrors();
  225. }
  226. @Test
  227. public void expandAllOpenNoInitialDetails_showSeveral_toggleOneByOne() {
  228. $(ButtonElement.class).id(EXPAND_ALL).click();
  229. addGrid();
  230. // open details for several rows, leave one out from the hierarchy that
  231. // is to be collapsed
  232. treeGrid.getCell(0, 0).click();
  233. treeGrid.getCell(1, 0).click();
  234. treeGrid.getCell(2, 0).click();
  235. // no click for cell (3, 0)
  236. treeGrid.getCell(4, 0).click();
  237. treeGrid.getCell(5, 0).click();
  238. treeGrid.getCell(6, 0).click();
  239. treeGrid.getCell(7, 0).click();
  240. treeGrid.getCell(8, 0).click();
  241. int spacerCount = 8;
  242. waitUntil(expectedConditionDetails(0, 0, 0));
  243. assertSpacerCount(spacerCount);
  244. ensureExpectedSpacerHeightSet();
  245. assertSpacerPositions();
  246. // toggle the root with open details rows
  247. treeGrid.collapseWithClick(0);
  248. waitUntil(ExpectedConditions.not(expectedConditionDetails(0, 0, 0)));
  249. assertSpacerCount(1);
  250. assertSpacerHeights();
  251. treeGrid.expandWithClick(0);
  252. waitUntil(expectedConditionDetails(0, 0, 0));
  253. assertSpacerCount(spacerCount);
  254. assertSpacerHeights();
  255. assertSpacerPositions();
  256. // toggle one of the branches with open details rows
  257. treeGrid.collapseWithClick(5);
  258. waitUntil(ExpectedConditions.not(expectedConditionDetails(0, 1, 0)));
  259. assertSpacerCount(spacerCount - 3);
  260. assertSpacerHeights();
  261. assertSpacerPositions();
  262. treeGrid.expandWithClick(5);
  263. waitUntil(expectedConditionDetails(0, 1, 0));
  264. assertSpacerCount(spacerCount);
  265. assertSpacerHeights();
  266. assertSpacerPositions();
  267. assertNoErrors();
  268. }
  269. @Test
  270. public void expandAllOpenAllInitialDetails_hideOne() {
  271. $(ButtonElement.class).id(EXPAND_ALL).click();
  272. $(ButtonElement.class).id(SHOW_DETAILS).click();
  273. addGrid();
  274. // check the position of a row
  275. int oldY = treeGrid.getCell(2, 0).getLocation().getY();
  276. // hide the spacer from previous row
  277. treeGrid.getCell(1, 0).click();
  278. // ensure the investigated row moved
  279. assertNotEquals(oldY, treeGrid.getCell(2, 0).getLocation().getY());
  280. }
  281. @Test
  282. public void expandAllOpenAllInitialDetailsScrolled_toggleOne_hideAll() {
  283. $(ButtonElement.class).id(EXPAND_ALL).click();
  284. $(ButtonElement.class).id(SHOW_DETAILS).click();
  285. addGrid();
  286. $(ButtonElement.class).id(SCROLL_TO_55).click();
  287. waitUntil(expectedConditionDetails(1, 2, 0));
  288. ensureExpectedSpacerHeightSet();
  289. int spacerCount = treeGrid.findElements(By.className(CLASSNAME_SPACER))
  290. .size();
  291. assertSpacerPositions();
  292. treeGrid.collapseWithClick(50);
  293. // collapsing one shouldn't affect spacer count, just update the cache
  294. waitUntil(ExpectedConditions.not(expectedConditionDetails(1, 2, 0)));
  295. assertSpacerHeights();
  296. assertSpacerPositions();
  297. assertSpacerCount(spacerCount);
  298. treeGrid.expandWithClick(50);
  299. // expanding back shouldn't affect spacer count, just update the cache
  300. waitUntil(expectedConditionDetails(1, 2, 0));
  301. assertSpacerHeights();
  302. assertSpacerPositions();
  303. assertSpacerCount(spacerCount);
  304. // test that repeating the toggle still doesn't change anything
  305. treeGrid.collapseWithClick(50);
  306. waitUntil(ExpectedConditions.not(expectedConditionDetails(1, 2, 0)));
  307. assertSpacerHeights();
  308. assertSpacerPositions();
  309. assertSpacerCount(spacerCount);
  310. treeGrid.expandWithClick(50);
  311. waitUntil(expectedConditionDetails(1, 2, 0));
  312. assertSpacerHeights();
  313. assertSpacerPositions();
  314. assertSpacerCount(spacerCount);
  315. // test that hiding all still won't break things
  316. $(ButtonElement.class).id(HIDE_DETAILS).click();
  317. waitForElementNotPresent(By.className(CLASSNAME_SPACER));
  318. assertNoErrors();
  319. }
  320. @Test
  321. public void expandAllOpenAllInitialDetailsScrolled_toggleAll() {
  322. $(ButtonElement.class).id(EXPAND_ALL).click();
  323. $(ButtonElement.class).id(SHOW_DETAILS).click();
  324. addGrid();
  325. $(ButtonElement.class).id(SCROLL_TO_55).click();
  326. waitUntil(expectedConditionDetails(1, 3, 0));
  327. ensureExpectedSpacerHeightSet();
  328. int spacerCount = treeGrid.findElements(By.className(CLASSNAME_SPACER))
  329. .size();
  330. assertSpacerPositions();
  331. $(ButtonElement.class).id(COLLAPSE_ALL).click();
  332. waitForElementNotPresent(By.className(CLASSNAME_LEAF));
  333. // There should still be a full cache's worth of details rows open,
  334. // just not the same rows than before collapsing all.
  335. assertSpacerCount(spacerCount);
  336. assertSpacerHeights();
  337. assertSpacerPositions();
  338. // FIXME: collapsing and expanding too many rows after scrolling still
  339. // fails to reset to the same state
  340. if (true) { // remove this block after fixed
  341. return;
  342. }
  343. $(ButtonElement.class).id(EXPAND_ALL).click();
  344. // State should have returned to what it was before collapsing.
  345. waitUntil(expectedConditionDetails(1, 3, 0));
  346. assertSpacerCount(spacerCount);
  347. assertSpacerHeights();
  348. assertSpacerPositions();
  349. assertNoErrors();
  350. }
  351. @Test
  352. public void expandAllOpenNoInitialDetailsScrolled_showSeveral_toggleOneByOne() {
  353. $(ButtonElement.class).id(EXPAND_ALL).click();
  354. addGrid();
  355. $(ButtonElement.class).id(SCROLL_TO_55).click();
  356. assertSpacerCount(0);
  357. // open details for several rows, leave one out from the hierarchy that
  358. // is to be collapsed
  359. treeGrid.getCell(50, 0).click(); // Branch 1/2
  360. treeGrid.getCell(51, 0).click(); // Leaf 1/2/0
  361. treeGrid.getCell(52, 0).click(); // Leaf 1/2/1
  362. // no click for cell (53, 0) // Leaf 1/2/2
  363. treeGrid.getCell(54, 0).click(); // Branch 1/3
  364. treeGrid.getCell(55, 0).click(); // Leaf 1/3/0
  365. treeGrid.getCell(56, 0).click(); // Leaf 1/3/1
  366. treeGrid.getCell(57, 0).click(); // Leaf 1/3/2
  367. treeGrid.getCell(58, 0).click(); // Branch 1/4
  368. int spacerCount = 8;
  369. waitUntil(expectedConditionDetails(1, 2, 0));
  370. assertSpacerCount(spacerCount);
  371. ensureExpectedSpacerHeightSet();
  372. assertSpacerPositions();
  373. // toggle the branch with partially open details rows
  374. treeGrid.collapseWithClick(50);
  375. waitUntil(ExpectedConditions.not(expectedConditionDetails(1, 2, 0)));
  376. assertSpacerCount(spacerCount - 2);
  377. assertSpacerHeights();
  378. assertSpacerPositions();
  379. treeGrid.expandWithClick(50);
  380. waitUntil(expectedConditionDetails(1, 2, 0));
  381. assertSpacerCount(spacerCount);
  382. assertSpacerHeights();
  383. assertSpacerPositions();
  384. // toggle the branch with fully open details rows
  385. treeGrid.collapseWithClick(54);
  386. waitUntil(ExpectedConditions.not(expectedConditionDetails(1, 3, 0)));
  387. assertSpacerCount(spacerCount - 3);
  388. assertSpacerHeights();
  389. assertSpacerPositions();
  390. treeGrid.expandWithClick(54);
  391. waitUntil(expectedConditionDetails(1, 3, 0));
  392. assertSpacerCount(spacerCount);
  393. assertSpacerHeights();
  394. assertSpacerPositions();
  395. // repeat both toggles to ensure still no errors
  396. treeGrid.collapseWithClick(50);
  397. waitUntil(ExpectedConditions.not(expectedConditionDetails(1, 2, 0)));
  398. assertSpacerCount(spacerCount - 2);
  399. assertSpacerHeights();
  400. assertSpacerPositions();
  401. treeGrid.expandWithClick(50);
  402. waitUntil(expectedConditionDetails(1, 2, 0));
  403. assertSpacerCount(spacerCount);
  404. assertSpacerHeights();
  405. assertSpacerPositions();
  406. treeGrid.collapseWithClick(54);
  407. waitUntil(ExpectedConditions.not(expectedConditionDetails(1, 3, 0)));
  408. assertSpacerCount(spacerCount - 3);
  409. assertSpacerHeights();
  410. assertSpacerPositions();
  411. treeGrid.expandWithClick(54);
  412. waitUntil(expectedConditionDetails(1, 3, 0));
  413. assertSpacerCount(spacerCount);
  414. assertSpacerHeights();
  415. assertSpacerPositions();
  416. assertNoErrors();
  417. }
  418. @Test
  419. public void expandAllOpenAllInitialDetailsScrolled_hideOne() {
  420. $(ButtonElement.class).id(EXPAND_ALL).click();
  421. $(ButtonElement.class).id(SHOW_DETAILS).click();
  422. addGrid();
  423. $(ButtonElement.class).id(SCROLL_TO_55).click();
  424. // check the position of a row
  425. int oldY = treeGrid.getCell(52, 0).getLocation().getY();
  426. // hide the spacer from previous row
  427. treeGrid.getCell(51, 0).click();
  428. // ensure the investigated row moved
  429. assertNotEquals(oldY, treeGrid.getCell(52, 0).getLocation().getY());
  430. }
  431. @Test
  432. public void expandAllOpenAllInitialDetailsScrolledFar_toggleOne_hideAll() {
  433. $(ButtonElement.class).id(EXPAND_ALL).click();
  434. $(ButtonElement.class).id(SHOW_DETAILS).click();
  435. addGrid();
  436. $(ButtonElement.class).id(SCROLL_TO_3055).click();
  437. waitUntil(expectedConditionDetails(74, 4, 0));
  438. ensureExpectedSpacerHeightSet();
  439. int spacerCount = treeGrid.findElements(By.className(CLASSNAME_SPACER))
  440. .size();
  441. assertSpacerPositions();
  442. treeGrid.collapseWithClick(3051);
  443. // collapsing one shouldn't affect spacer count, just update the cache
  444. waitUntil(ExpectedConditions.not(expectedConditionDetails(1, 2, 0)));
  445. assertSpacerHeights();
  446. assertSpacerPositions();
  447. assertSpacerCount(spacerCount);
  448. treeGrid.expandWithClick(3051);
  449. // expanding back shouldn't affect spacer count, just update the cache
  450. waitUntil(expectedConditionDetails(74, 4, 0));
  451. assertSpacerHeights();
  452. assertSpacerPositions();
  453. assertSpacerCount(spacerCount);
  454. // test that repeating the toggle still doesn't change anything
  455. treeGrid.collapseWithClick(3051);
  456. waitUntil(ExpectedConditions.not(expectedConditionDetails(74, 4, 0)));
  457. assertSpacerHeights();
  458. assertSpacerPositions();
  459. assertSpacerCount(spacerCount);
  460. treeGrid.expandWithClick(3051);
  461. waitUntil(expectedConditionDetails(74, 4, 0));
  462. assertSpacerHeights();
  463. assertSpacerPositions();
  464. assertSpacerCount(spacerCount);
  465. // test that hiding all still won't break things
  466. $(ButtonElement.class).id(HIDE_DETAILS).click();
  467. waitForElementNotPresent(By.className(CLASSNAME_SPACER));
  468. assertNoErrors();
  469. }
  470. @Test
  471. public void expandAllOpenAllInitialDetailsScrolledFar_toggleAll() {
  472. $(ButtonElement.class).id(EXPAND_ALL).click();
  473. $(ButtonElement.class).id(SHOW_DETAILS).click();
  474. addGrid();
  475. $(ButtonElement.class).id(SCROLL_TO_3055).click();
  476. waitUntil(expectedConditionDetails(74, 4, 0));
  477. ensureExpectedSpacerHeightSet();
  478. int spacerCount = treeGrid.findElements(By.className(CLASSNAME_SPACER))
  479. .size();
  480. assertSpacerPositions();
  481. $(ButtonElement.class).id(COLLAPSE_ALL).click();
  482. waitForElementNotPresent(By.className(CLASSNAME_LEAF));
  483. // There should still be a full cache's worth of details rows open,
  484. // just not the same rows than before collapsing all.
  485. assertSpacerCount(spacerCount);
  486. assertSpacerHeights();
  487. assertSpacerPositions();
  488. // FIXME: collapsing and expanding too many rows after scrolling still
  489. // fails to reset to the same state
  490. if (true) { // remove this block after fixed
  491. return;
  492. }
  493. $(ButtonElement.class).id(EXPAND_ALL).click();
  494. // State should have returned to what it was before collapsing.
  495. waitUntil(expectedConditionDetails(74, 4, 0));
  496. assertSpacerCount(spacerCount);
  497. assertSpacerHeights();
  498. assertSpacerPositions();
  499. assertNoErrors();
  500. }
  501. @Test
  502. public void expandAllOpenNoInitialDetailsScrolledFar_showSeveral_toggleOneByOne() {
  503. $(ButtonElement.class).id(EXPAND_ALL).click();
  504. addGrid();
  505. $(ButtonElement.class).id(SCROLL_TO_3055).click();
  506. assertSpacerCount(0);
  507. // open details for several rows, leave one out from the hierarchy that
  508. // is to be collapsed
  509. treeGrid.getCell(3051, 0).click(); // Branch 74/4
  510. treeGrid.getCell(3052, 0).click(); // Leaf 74/4/0
  511. treeGrid.getCell(3053, 0).click(); // Leaf 74/4/1
  512. // no click for cell (3054, 0) // Leaf 74/4/2
  513. treeGrid.getCell(3055, 0).click(); // Branch 74/5
  514. treeGrid.getCell(3056, 0).click(); // Leaf 74/5/0
  515. treeGrid.getCell(3057, 0).click(); // Leaf 74/5/1
  516. treeGrid.getCell(3058, 0).click(); // Leaf 74/5/2
  517. treeGrid.getCell(3059, 0).click(); // Branch 74/6
  518. int spacerCount = 8;
  519. waitUntil(expectedConditionDetails(74, 4, 0));
  520. assertSpacerCount(spacerCount);
  521. ensureExpectedSpacerHeightSet();
  522. assertSpacerPositions();
  523. // toggle the branch with partially open details rows
  524. treeGrid.collapseWithClick(3051);
  525. waitUntil(ExpectedConditions.not(expectedConditionDetails(74, 4, 0)));
  526. assertSpacerCount(spacerCount - 2);
  527. assertSpacerHeights();
  528. assertSpacerPositions();
  529. treeGrid.expandWithClick(3051);
  530. waitUntil(expectedConditionDetails(74, 4, 0));
  531. assertSpacerCount(spacerCount);
  532. assertSpacerHeights();
  533. assertSpacerPositions();
  534. // toggle the branch with fully open details rows
  535. treeGrid.collapseWithClick(3055);
  536. waitUntil(ExpectedConditions.not(expectedConditionDetails(74, 5, 0)));
  537. assertSpacerCount(spacerCount - 3);
  538. assertSpacerHeights();
  539. assertSpacerPositions();
  540. treeGrid.expandWithClick(3055);
  541. waitUntil(expectedConditionDetails(74, 5, 0));
  542. assertSpacerCount(spacerCount);
  543. assertSpacerHeights();
  544. assertSpacerPositions();
  545. // repeat both toggles to ensure still no errors
  546. treeGrid.collapseWithClick(3051);
  547. waitUntil(ExpectedConditions.not(expectedConditionDetails(74, 4, 0)));
  548. assertSpacerCount(spacerCount - 2);
  549. assertSpacerHeights();
  550. assertSpacerPositions();
  551. treeGrid.expandWithClick(3051);
  552. waitUntil(expectedConditionDetails(74, 4, 0));
  553. assertSpacerCount(spacerCount);
  554. assertSpacerHeights();
  555. assertSpacerPositions();
  556. treeGrid.collapseWithClick(3055);
  557. waitUntil(ExpectedConditions.not(expectedConditionDetails(74, 5, 0)));
  558. assertSpacerCount(spacerCount - 3);
  559. assertSpacerHeights();
  560. assertSpacerPositions();
  561. treeGrid.expandWithClick(3055);
  562. waitUntil(expectedConditionDetails(74, 5, 0));
  563. assertSpacerCount(spacerCount);
  564. assertSpacerHeights();
  565. assertSpacerPositions();
  566. assertNoErrors();
  567. }
  568. @Test
  569. public void expandAllOpenAllInitialDetailsScrolledFar_hideOne() {
  570. $(ButtonElement.class).id(EXPAND_ALL).click();
  571. $(ButtonElement.class).id(SHOW_DETAILS).click();
  572. addGrid();
  573. $(ButtonElement.class).id(SCROLL_TO_3055).click();
  574. // check the position of a row
  575. int oldY = treeGrid.getCell(3052, 0).getLocation().getY();
  576. // hide the spacer from previous row
  577. treeGrid.getCell(3051, 0).click();
  578. // ensure the investigated row moved
  579. assertNotEquals(oldY, treeGrid.getCell(52, 0).getLocation().getY());
  580. }
  581. @Test
  582. public void expandAllOpenAllInitialDetails_checkScrollPositions() {
  583. $(ButtonElement.class).id(EXPAND_ALL).click();
  584. $(ButtonElement.class).id(SHOW_DETAILS).click();
  585. addGrid();
  586. TestBenchElement tableWrapper = treeGrid.getTableWrapper();
  587. $(ButtonElement.class).id(SCROLL_TO_55).click();
  588. waitUntil(expectedConditionDetails(1, 3, 0));
  589. WebElement detailsRow = getSpacer(1, 3, 0);
  590. assertNotNull("Spacer for row 55 not found", detailsRow);
  591. int wrapperY = tableWrapper.getLocation().getY();
  592. int wrapperHeight = tableWrapper.getSize().getHeight();
  593. int detailsY = detailsRow.getLocation().getY();
  594. int detailsHeight = detailsRow.getSize().getHeight();
  595. assertThat("Scroll to 55 didn't scroll as expected",
  596. (double) detailsY + detailsHeight,
  597. closeTo(wrapperY + wrapperHeight, 1d));
  598. $(ButtonElement.class).id(SCROLL_TO_3055).click();
  599. waitUntil(expectedConditionDetails(74, 5, null));
  600. detailsRow = getSpacer(74, 5, null);
  601. assertNotNull("Spacer for row 3055 not found", detailsRow);
  602. detailsY = detailsRow.getLocation().getY();
  603. detailsHeight = detailsRow.getSize().getHeight();
  604. assertThat("Scroll to 3055 didn't scroll as expected",
  605. (double) detailsY + detailsHeight,
  606. closeTo(wrapperY + wrapperHeight, 1d));
  607. $(ButtonElement.class).id(SCROLL_TO_END).click();
  608. waitUntil(expectedConditionDetails(99, 9, 2));
  609. detailsRow = getSpacer(99, 9, 2);
  610. assertNotNull("Spacer for last row not found", detailsRow);
  611. detailsY = detailsRow.getLocation().getY();
  612. detailsHeight = detailsRow.getSize().getHeight();
  613. // the layout jumps sometimes, check again
  614. wrapperY = tableWrapper.getLocation().getY();
  615. wrapperHeight = tableWrapper.getSize().getHeight();
  616. assertThat("Scroll to end didn't scroll as expected",
  617. (double) detailsY + detailsHeight,
  618. closeTo(wrapperY + wrapperHeight, 1d));
  619. $(ButtonElement.class).id(SCROLL_TO_START).click();
  620. waitUntil(expectedConditionDetails(0, 0, 0));
  621. WebElement firstRow = getRow(0);
  622. TestBenchElement header = treeGrid.getHeader();
  623. assertThat("Scroll to start didn't scroll as expected",
  624. (double) firstRow.getLocation().getY(),
  625. closeTo(wrapperY + header.getSize().getHeight(), 1d));
  626. }
  627. @Test
  628. public void expandAllOpenNoInitialDetails_testToggleScrolling() {
  629. $(ButtonElement.class).id(EXPAND_ALL).click();
  630. addGrid();
  631. TestBenchElement tableWrapper = treeGrid.getTableWrapper();
  632. int wrapperY = tableWrapper.getLocation().getY();
  633. WebElement firstRow = getRow(0);
  634. int firstRowY = firstRow.getLocation().getY();
  635. TestBenchElement header = treeGrid.getHeader();
  636. int headerHeight = header.getSize().getHeight();
  637. assertThat("Unexpected initial scroll position", (double) firstRowY,
  638. closeTo(wrapperY + headerHeight, 1d));
  639. $(ButtonElement.class).id(TOGGLE_15).click();
  640. firstRowY = firstRow.getLocation().getY();
  641. assertThat(
  642. "Toggling row 15's details open should have caused scrolling",
  643. (double) firstRowY, not(closeTo(wrapperY + headerHeight, 1d)));
  644. $(ButtonElement.class).id(SCROLL_TO_START).click();
  645. firstRowY = firstRow.getLocation().getY();
  646. assertThat("Scrolling to start failed", (double) firstRowY,
  647. closeTo(wrapperY + headerHeight, 1d));
  648. $(ButtonElement.class).id(TOGGLE_15).click();
  649. firstRowY = firstRow.getLocation().getY();
  650. assertThat(
  651. "Toggling row 15's details closed should not have caused scrolling",
  652. (double) firstRowY, closeTo(wrapperY + headerHeight, 1d));
  653. $(ButtonElement.class).id(TOGGLE_3000).click();
  654. firstRowY = firstRow.getLocation().getY();
  655. assertThat(
  656. "Toggling row 3000's details open should not have caused scrolling",
  657. (double) firstRowY, closeTo(wrapperY + headerHeight, 1d));
  658. $(ButtonElement.class).id(SCROLL_TO_55).click();
  659. WebElement row = getRow(0);
  660. assertNotEquals("First row should be out of visual range", firstRowY,
  661. row);
  662. $(ButtonElement.class).id(TOGGLE_15).click();
  663. assertEquals(
  664. "Toggling row 15's details open should not have caused scrolling "
  665. + "when row 15 is outside of visual range",
  666. row, getRow(0));
  667. }
  668. }