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.

GridRendererSwitchTest.java 5.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. package com.vaadin.tests.components.grid;
  2. import static org.junit.Assert.assertEquals;
  3. import static org.junit.Assert.assertFalse;
  4. import static org.junit.Assert.assertTrue;
  5. import org.junit.Test;
  6. import com.vaadin.testbench.By;
  7. import com.vaadin.testbench.elements.ButtonElement;
  8. import com.vaadin.testbench.elements.GridElement;
  9. import com.vaadin.testbench.elements.NotificationElement;
  10. import com.vaadin.testbench.parallel.TestCategory;
  11. import com.vaadin.tests.tb3.SingleBrowserTest;
  12. @TestCategory("xvfb-test")
  13. public class GridRendererSwitchTest extends SingleBrowserTest {
  14. @Test
  15. public void testSwitchRenderer() {
  16. setDebug(true);
  17. openTestURL();
  18. GridElement grid = $(GridElement.class).first();
  19. assertEquals("Unexpected content in first grid cell", "Foo 0",
  20. grid.getCell(0, 0).getAttribute("innerHTML"));
  21. ButtonElement button = $(ButtonElement.class).first();
  22. button.click();
  23. assertFalse("No button in cell", grid.getCell(0, 0)
  24. .findElements(By.tagName("button")).isEmpty());
  25. grid.getCell(0, 0).findElement(By.tagName("button")).click();
  26. assertTrue("Notification not shown",
  27. isElementPresent(NotificationElement.class));
  28. button.click();
  29. assertEquals("Cell should be back to text content.", "Foo 0",
  30. grid.getCell(0, 0).getAttribute("innerHTML"));
  31. assertNoErrorNotifications();
  32. }
  33. @Test
  34. public void testSwitchRendererReorderColumns() {
  35. setDebug(true);
  36. openTestURL();
  37. GridElement grid = $(GridElement.class).first();
  38. assertEquals("Unexpected content in first grid cell", "Foo 0",
  39. grid.getCell(0, 0).getAttribute("innerHTML"));
  40. ButtonElement button = $(ButtonElement.class).caption("Switch").first();
  41. button.click();
  42. ButtonElement reverse = $(ButtonElement.class).caption("Reverse")
  43. .first();
  44. reverse.click();
  45. assertEquals("Unexpected content in first grid cell after reorder",
  46. "Bar 0", grid.getCell(0, 0).getAttribute("innerHTML"));
  47. assertFalse("No button in cell after reversing order", grid
  48. .getCell(0, 1).findElements(By.tagName("button")).isEmpty());
  49. grid.getCell(0, 1).findElement(By.tagName("button")).click();
  50. assertTrue("Notification not shown",
  51. isElementPresent(NotificationElement.class));
  52. reverse.click();
  53. assertFalse("No button in cell after restoring original order", grid
  54. .getCell(0, 0).findElements(By.tagName("button")).isEmpty());
  55. assertNoErrorNotifications();
  56. }
  57. @Test
  58. public void testReorderColumnsSwitchRenderer() {
  59. setDebug(true);
  60. openTestURL();
  61. GridElement grid = $(GridElement.class).first();
  62. assertEquals("Unexpected content in first grid cell", "Foo 0",
  63. grid.getCell(0, 0).getAttribute("innerHTML"));
  64. ButtonElement reverse = $(ButtonElement.class).caption("Reverse")
  65. .first();
  66. reverse.click();
  67. assertEquals("Unexpected content in first grid cell after reorder",
  68. "Bar 0", grid.getCell(0, 0).getAttribute("innerHTML"));
  69. ButtonElement button = $(ButtonElement.class).caption("Switch").first();
  70. button.click();
  71. assertFalse(
  72. "No button in cell after reversing order and changing renderer",
  73. grid.getCell(0, 1).findElements(By.tagName("button"))
  74. .isEmpty());
  75. grid.getCell(0, 1).findElement(By.tagName("button")).click();
  76. assertTrue("Notification not shown",
  77. isElementPresent(NotificationElement.class));
  78. button.click();
  79. assertEquals("Cell should be back to text content.", "Foo 0",
  80. grid.getCell(0, 1).getAttribute("innerHTML"));
  81. assertNoErrorNotifications();
  82. }
  83. @Test
  84. public void testReorderColumnsHideAndSwitch() {
  85. setDebug(true);
  86. openTestURL();
  87. GridElement grid = $(GridElement.class).first();
  88. assertEquals("Unexpected content in first grid cell", "Foo 0",
  89. grid.getCell(0, 0).getAttribute("innerHTML"));
  90. ButtonElement reverse = $(ButtonElement.class).caption("Reverse")
  91. .first();
  92. reverse.click();
  93. assertEquals("Unexpected content in first grid cell after reorder",
  94. "Bar 0", grid.getCell(0, 0).getAttribute("innerHTML"));
  95. grid.toggleColumnHidden("Bar");
  96. ButtonElement button = $(ButtonElement.class).caption("Switch").first();
  97. button.click();
  98. assertNoErrorNotifications();
  99. assertFalse(
  100. "No button in cell after reversing order and changing renderer",
  101. grid.getCell(0, 0).findElements(By.tagName("button"))
  102. .isEmpty());
  103. grid.getCell(0, 0).findElement(By.tagName("button")).click();
  104. assertTrue("Notification not shown",
  105. isElementPresent(NotificationElement.class));
  106. }
  107. @Test
  108. public void testSwitchRendererOfHiddenColumn() {
  109. setDebug(true);
  110. openTestURL();
  111. GridElement grid = $(GridElement.class).first();
  112. assertEquals("Unexpected content in first grid cell", "Foo 0",
  113. grid.getCell(0, 0).getAttribute("innerHTML"));
  114. grid.toggleColumnHidden("Foo");
  115. assertEquals("Unexpected content in first grid cell after hide",
  116. "Bar 0", grid.getCell(0, 0).getAttribute("innerHTML"));
  117. ButtonElement button = $(ButtonElement.class).caption("Switch").first();
  118. button.click();
  119. assertNoErrorNotifications();
  120. assertEquals(
  121. "Unexpected content in first grid cell after hidden renderer change",
  122. "Bar 0", grid.getCell(0, 0).getAttribute("innerHTML"));
  123. }
  124. }