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

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