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.

GridInTabSheetTest.java 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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 org.openqa.selenium.Keys;
  7. import com.vaadin.testbench.By;
  8. import com.vaadin.testbench.elements.ButtonElement;
  9. import com.vaadin.testbench.elements.GridElement;
  10. import com.vaadin.testbench.elements.GridElement.GridCellElement;
  11. import com.vaadin.testbench.elements.NotificationElement;
  12. import com.vaadin.testbench.elements.TabSheetElement;
  13. import com.vaadin.testbench.parallel.BrowserUtil;
  14. import com.vaadin.testbench.parallel.TestCategory;
  15. import com.vaadin.tests.tb3.MultiBrowserTest;
  16. @TestCategory("grid")
  17. public class GridInTabSheetTest extends MultiBrowserTest {
  18. @Test
  19. public void testRemoveAllRowsAndAddThreeNewOnes() {
  20. setDebug(true);
  21. openTestURL();
  22. for (int i = 0; i < 3; ++i) {
  23. removeGridRow();
  24. }
  25. for (int i = 0; i < 3; ++i) {
  26. addGridRow();
  27. assertEquals("" + (100 + i),
  28. getGridElement().getCell(i, 1).getText());
  29. }
  30. assertNoNotification();
  31. }
  32. private void assertNoNotification() {
  33. assertFalse("There was an unexpected error notification",
  34. isElementPresent(NotificationElement.class));
  35. }
  36. @Test
  37. public void testAddManyRowsWhenGridIsHidden() {
  38. setDebug(true);
  39. openTestURL();
  40. TabSheetElement tabsheet = $(TabSheetElement.class).first();
  41. tabsheet.openTab("Label");
  42. for (int i = 0; i < 50; ++i) {
  43. addGridRow();
  44. }
  45. tabsheet.openTab("Grid");
  46. assertNoNotification();
  47. }
  48. @Test
  49. public void testAddCellStyleGeneratorWhenGridIsHidden() {
  50. setDebug(true);
  51. openTestURL();
  52. TabSheetElement tabsheet = $(TabSheetElement.class).first();
  53. tabsheet.openTab("Label");
  54. addCellStyleGenerator();
  55. tabsheet.openTab("Grid");
  56. assertNoNotification();
  57. }
  58. @Test
  59. public void testNoDataRequestFromClientWhenSwitchingTab() {
  60. setDebug(true);
  61. openTestURL();
  62. TabSheetElement tabsheet = $(TabSheetElement.class).first();
  63. tabsheet.openTab("Label");
  64. tabsheet.openTab("Grid");
  65. getLogs().forEach(logText -> assertTrue(
  66. "There should be no logged requests, was: " + logText,
  67. logText.trim().isEmpty()));
  68. assertNoNotification();
  69. }
  70. @Test
  71. public void testEditorOpenWhenSwitchingTab() {
  72. setDebug(true);
  73. openTestURL();
  74. GridElement grid = $(GridElement.class).first();
  75. editRow(grid, 0);
  76. assertEquals("Editor should be open", "0",
  77. grid.getEditor().getField(1).getAttribute("value"));
  78. TabSheetElement tabsheet = $(TabSheetElement.class).first();
  79. tabsheet.openTab("Label");
  80. tabsheet.openTab("Grid");
  81. grid = $(GridElement.class).first();
  82. assertFalse("Editor should be closed.",
  83. grid.isElementPresent(By.vaadin("#editor")));
  84. editRow(grid, 1);
  85. assertEquals("Editor should open after tab switch", "1",
  86. grid.getEditor().getField(1).getAttribute("value"));
  87. // Close the current editor and reopen on a different row
  88. grid.sendKeys(Keys.ESCAPE);
  89. editRow(grid, 0);
  90. assertEquals("Editor should move", "0",
  91. grid.getEditor().getField(1).getAttribute("value"));
  92. assertNoErrorNotifications();
  93. }
  94. protected void editRow(GridElement grid, int row) {
  95. GridCellElement cell = grid.getCell(row, 1);
  96. if (BrowserUtil.isFirefox(getDesiredCapabilities())) {
  97. cell.click();
  98. grid.sendKeys(Keys.RETURN);
  99. } else {
  100. cell.doubleClick();
  101. }
  102. }
  103. private void removeGridRow() {
  104. $(ButtonElement.class).caption("Remove row from Grid").first().click();
  105. }
  106. private void addGridRow() {
  107. $(ButtonElement.class).caption("Add row to Grid").first().click();
  108. }
  109. private void addCellStyleGenerator() {
  110. $(ButtonElement.class).caption("Add CellStyleGenerator").first()
  111. .click();
  112. }
  113. private GridElement getGridElement() {
  114. return $(GridElement.class).first();
  115. }
  116. }