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.

TreeGridCollapseDisabledTest.java 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. package com.vaadin.tests.components.treegrid;
  2. import org.junit.Assert;
  3. import org.junit.Before;
  4. import org.junit.Test;
  5. import com.vaadin.testbench.elements.TreeGridElement;
  6. import com.vaadin.tests.tb3.SingleBrowserTest;
  7. public class TreeGridCollapseDisabledTest extends SingleBrowserTest {
  8. private TreeGridElement grid;
  9. @Override
  10. protected Class<?> getUIClass() {
  11. return TreeGridBasicFeatures.class;
  12. }
  13. @Before
  14. public void before() {
  15. openTestURL();
  16. grid = $(TreeGridElement.class).first();
  17. }
  18. @Test
  19. public void collapse_disabled_for_all() {
  20. selectMenuPath("Component", "Features", "Collapse allowed",
  21. "all disabled");
  22. // Assert first and second row can be expanded, but not collapsed
  23. assertExpandRow(0);
  24. assertCollapseRowDisabled(0);
  25. assertExpandRow(1);
  26. assertCollapseRowDisabled(1);
  27. }
  28. @Test
  29. public void collapse_disabled_for_depth0() {
  30. selectMenuPath("Component", "Features", "Collapse allowed",
  31. "depth 0 disabled");
  32. // Assert first row expands
  33. assertExpandRow(0);
  34. // Assert second row expands and collapses
  35. assertExpandRow(1);
  36. assertCollapseRow(1);
  37. // Assert first row does not collapse
  38. assertCollapseRowDisabled(0);
  39. }
  40. @Test
  41. public void collapse_disabled_for_depth1() {
  42. selectMenuPath("Component", "Features", "Collapse allowed",
  43. "depth 1 disabled");
  44. // Assert first row expands
  45. assertExpandRow(0);
  46. // Assert second row expands but does not collapse
  47. assertExpandRow(1);
  48. assertCollapseRowDisabled(1);
  49. // Assert first row still collapses
  50. assertCollapseRow(0);
  51. }
  52. @Test
  53. public void collapse_disabled_mode_change_with_expanded_rows() {
  54. // Assert first row expands
  55. assertExpandRow(0);
  56. // Assert second row expands and collapses
  57. assertExpandRow(1);
  58. assertCollapseRow(1);
  59. selectMenuPath("Component", "Features", "Collapse allowed",
  60. "depth 1 disabled");
  61. Assert.assertTrue("First row should still be expanded",
  62. grid.isRowExpanded(0, 0));
  63. // Assert second row expands but does not collapse
  64. assertExpandRow(1);
  65. assertCollapseRowDisabled(1);
  66. // Assert first row still collapses
  67. assertCollapseRow(0);
  68. }
  69. private void assertExpandRow(int row) {
  70. Assert.assertFalse(grid.isRowExpanded(row, 0));
  71. grid.expandWithClick(row);
  72. Assert.assertTrue(grid.isRowExpanded(row, 0));
  73. }
  74. private void assertCollapseRow(int row) {
  75. Assert.assertTrue("Row not expanded", grid.isRowExpanded(row, 0));
  76. grid.collapseWithClick(row);
  77. Assert.assertFalse("Row did not collapse", grid.isRowExpanded(row, 0));
  78. }
  79. private void assertCollapseRowDisabled(int row) {
  80. Assert.assertTrue("Row not expanded", grid.isRowExpanded(row, 0));
  81. grid.collapseWithClick(row);
  82. Assert.assertTrue("Row should not collapse",
  83. grid.isRowExpanded(row, 0));
  84. }
  85. }