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.

TreeGridBasicFeaturesTest.java 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. package com.vaadin.tests.components.treegrid;
  2. import java.util.Arrays;
  3. import java.util.Collection;
  4. import org.junit.Assert;
  5. import org.junit.Before;
  6. import org.junit.Ignore;
  7. import org.junit.Test;
  8. import org.junit.runner.RunWith;
  9. import org.junit.runners.Parameterized.Parameters;
  10. import org.openqa.selenium.Keys;
  11. import org.openqa.selenium.interactions.Actions;
  12. import com.vaadin.testbench.By;
  13. import com.vaadin.testbench.elements.TreeGridElement;
  14. import com.vaadin.tests.tb3.MultiBrowserTest;
  15. import com.vaadin.tests.tb3.ParameterizedTB3Runner;
  16. @RunWith(ParameterizedTB3Runner.class)
  17. public class TreeGridBasicFeaturesTest extends MultiBrowserTest {
  18. private TreeGridElement grid;
  19. public void setDataProvider(String dataProviderString) {
  20. selectMenuPath("Component", "Features", "Set data provider",
  21. dataProviderString);
  22. }
  23. @Parameters
  24. public static Collection<String> getDataProviders() {
  25. return Arrays.asList("LazyHierarchicalDataProvider",
  26. "InMemoryHierarchicalDataProvider");
  27. }
  28. @Before
  29. public void before() {
  30. openTestURL("theme=valo");
  31. grid = $(TreeGridElement.class).first();
  32. }
  33. @Test
  34. @Ignore // currently no implementation exists for toggling from the server
  35. // side
  36. public void toggle_collapse_server_side() {
  37. Assert.assertEquals(3, grid.getRowCount());
  38. assertCellTexts(0, 0, new String[] { "0 | 0", "0 | 1", "0 | 2" });
  39. selectMenuPath("Component", "Features", "Toggle expand", "0 | 0");
  40. Assert.assertEquals(6, grid.getRowCount());
  41. assertCellTexts(1, 0, new String[] { "1 | 0", "1 | 1", "1 | 2" });
  42. selectMenuPath("Component", "Features", "Toggle expand", "0 | 0");
  43. Assert.assertEquals(3, grid.getRowCount());
  44. assertCellTexts(0, 0, new String[] { "0 | 0", "0 | 1", "0 | 2" });
  45. // collapsing a leaf should have no effect
  46. selectMenuPath("Component", "Features", "Toggle expand", "1 | 0");
  47. Assert.assertEquals(3, grid.getRowCount());
  48. }
  49. @Test
  50. public void non_leaf_collapse_on_click() {
  51. Assert.assertEquals(3, grid.getRowCount());
  52. assertCellTexts(0, 0, new String[] { "0 | 0", "0 | 1", "0 | 2" });
  53. // Should expand "0 | 0"
  54. grid.getRow(0).getCell(0)
  55. .findElement(By.className("v-tree-grid-expander")).click();
  56. Assert.assertEquals(6, grid.getRowCount());
  57. assertCellTexts(1, 0, new String[] { "1 | 0", "1 | 1", "1 | 2" });
  58. // Should collapse "0 | 0"
  59. grid.getRow(0).getCell(0)
  60. .findElement(By.className("v-tree-grid-expander")).click();
  61. Assert.assertEquals(3, grid.getRowCount());
  62. assertCellTexts(0, 0, new String[] { "0 | 0", "0 | 1", "0 | 2" });
  63. }
  64. @Test
  65. @Ignore // FIXME: remove ignore annotation once #8758 is done
  66. public void keyboard_navigation() {
  67. grid.getRow(0).getCell(0).click();
  68. // Should expand "0 | 0"
  69. new Actions(getDriver()).keyDown(Keys.ALT).sendKeys(Keys.RIGHT)
  70. .keyUp(Keys.ALT).perform();
  71. Assert.assertEquals(6, grid.getRowCount());
  72. assertCellTexts(1, 0, new String[] { "1 | 0", "1 | 1", "1 | 2" });
  73. // Should collapse "0 | 0"
  74. new Actions(getDriver()).keyDown(Keys.ALT).sendKeys(Keys.LEFT)
  75. .keyUp(Keys.ALT).perform();
  76. Assert.assertEquals(3, grid.getRowCount());
  77. assertCellTexts(0, 0, new String[] { "0 | 0", "0 | 1", "0 | 2" });
  78. }
  79. @Test
  80. public void changing_hierarchy_column() {
  81. Assert.assertTrue(grid.getRow(0).getCell(0)
  82. .isElementPresent(By.className("v-tree-grid-expander")));
  83. Assert.assertFalse(grid.getRow(0).getCell(1)
  84. .isElementPresent(By.className("v-tree-grid-expander")));
  85. selectMenuPath("Component", "Features", "Set hierarchy column",
  86. "depth");
  87. Assert.assertFalse(grid.getRow(0).getCell(0)
  88. .isElementPresent(By.className("v-tree-grid-expander")));
  89. Assert.assertTrue(grid.getRow(0).getCell(1)
  90. .isElementPresent(By.className("v-tree-grid-expander")));
  91. selectMenuPath("Component", "Features", "Set hierarchy column",
  92. "string");
  93. Assert.assertTrue(grid.getRow(0).getCell(0)
  94. .isElementPresent(By.className("v-tree-grid-expander")));
  95. Assert.assertFalse(grid.getRow(0).getCell(1)
  96. .isElementPresent(By.className("v-tree-grid-expander")));
  97. }
  98. private void assertCellTexts(int startRowIndex, int cellIndex,
  99. String[] cellTexts) {
  100. int index = startRowIndex;
  101. for (String cellText : cellTexts) {
  102. Assert.assertEquals(cellText,
  103. grid.getRow(index).getCell(cellIndex).getText());
  104. index++;
  105. }
  106. }
  107. }