您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

GridEditRowTest.java 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. package com.vaadin.tests.components.grid;
  2. import static org.hamcrest.CoreMatchers.is;
  3. import static org.hamcrest.CoreMatchers.not;
  4. import static org.hamcrest.MatcherAssert.assertThat;
  5. import static org.hamcrest.Matchers.greaterThan;
  6. import org.junit.Test;
  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.GridEditorElement;
  11. import com.vaadin.testbench.parallel.TestCategory;
  12. import com.vaadin.tests.tb3.MultiBrowserTest;
  13. /**
  14. * Tests for ensuring that the furthest away visible rows don't get emptied when
  15. * editRow is called, and that the editor doesn't open beyond the lower border
  16. * of the Grid.
  17. *
  18. */
  19. @TestCategory("grid")
  20. public class GridEditRowTest extends MultiBrowserTest {
  21. private GridElement grid;
  22. private ButtonElement addButton;
  23. private ButtonElement editButton;
  24. @Override
  25. public void setup() throws Exception {
  26. super.setup();
  27. openTestURL();
  28. grid = $(GridElement.class).first();
  29. addButton = $(ButtonElement.class).caption("Add").first();
  30. editButton = $(ButtonElement.class).caption("Edit").first();
  31. }
  32. public void addRows(int count) {
  33. for (int i = 0; i < count; ++i) {
  34. addButton.click();
  35. }
  36. }
  37. public void editLastRow() {
  38. editButton.click();
  39. }
  40. private void assertRowContents(int rowIndex) {
  41. assertThat(grid.getCell(rowIndex, 0).getText(), is("name" + rowIndex));
  42. }
  43. private void assertEditorWithinGrid() {
  44. GridEditorElement editor = grid.getEditor();
  45. // allow 1px leeway
  46. assertThat(editor.getLocation().y + editor.getSize().height, not(
  47. greaterThan(grid.getLocation().y + grid.getSize().height + 1)));
  48. }
  49. @Test
  50. public void testEditWhenAllRowsVisible() {
  51. addRows(7);
  52. assertRowContents(0);
  53. editLastRow();
  54. assertRowContents(0);
  55. waitForElementVisible(By.className("v-grid-editor"));
  56. // wait for position corrections
  57. sleep(100);
  58. assertEditorWithinGrid();
  59. }
  60. @Test
  61. public void testEditWhenSomeRowsNotVisible() {
  62. addRows(11);
  63. assertRowContents(3);
  64. editLastRow();
  65. waitForElementVisible(By.className("v-grid-editor"));
  66. // wait for position corrections
  67. sleep(100);
  68. assertRowContents(3);
  69. assertEditorWithinGrid();
  70. }
  71. @Test
  72. public void testEditWhenSomeRowsOutsideOfCache() {
  73. addRows(100);
  74. assertRowContents(91);
  75. editLastRow();
  76. waitForElementVisible(By.className("v-grid-editor"));
  77. // wait for position corrections
  78. sleep(100);
  79. assertRowContents(91);
  80. assertEditorWithinGrid();
  81. }
  82. }