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.

GridEditRowTest.java 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /*
  2. * Copyright 2000-2016 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.tests.components.grid;
  17. import static org.hamcrest.CoreMatchers.is;
  18. import static org.hamcrest.CoreMatchers.not;
  19. import static org.hamcrest.MatcherAssert.assertThat;
  20. import static org.hamcrest.Matchers.greaterThan;
  21. import org.junit.Test;
  22. import com.vaadin.testbench.By;
  23. import com.vaadin.testbench.elements.ButtonElement;
  24. import com.vaadin.testbench.elements.GridElement;
  25. import com.vaadin.testbench.elements.GridElement.GridEditorElement;
  26. import com.vaadin.testbench.parallel.TestCategory;
  27. import com.vaadin.tests.tb3.MultiBrowserTest;
  28. /**
  29. * Tests for ensuring that the furthest away visible rows don't get emptied when
  30. * editRow is called, and that the editor doesn't open beyond the lower border
  31. * of the Grid.
  32. *
  33. */
  34. @TestCategory("grid")
  35. public class GridEditRowTest extends MultiBrowserTest {
  36. private GridElement grid;
  37. private ButtonElement addButton;
  38. private ButtonElement editButton;
  39. @Override
  40. public void setup() throws Exception {
  41. super.setup();
  42. openTestURL();
  43. grid = $(GridElement.class).first();
  44. addButton = $(ButtonElement.class).caption("Add").first();
  45. editButton = $(ButtonElement.class).caption("Edit").first();
  46. }
  47. public void addRows(int count) {
  48. for (int i = 0; i < count; ++i) {
  49. addButton.click();
  50. }
  51. }
  52. public void editLastRow() {
  53. editButton.click();
  54. }
  55. private void assertRowContents(int rowIndex) {
  56. assertThat(grid.getCell(rowIndex, 0).getText(), is("name" + rowIndex));
  57. }
  58. private void assertEditorWithinGrid() {
  59. GridEditorElement editor = grid.getEditor();
  60. assertThat(editor.getLocation().y + editor.getSize().height,
  61. not(greaterThan(grid.getLocation().y + grid.getSize().height)));
  62. }
  63. @Test
  64. public void testEditWhenAllRowsVisible() {
  65. addRows(7);
  66. assertRowContents(0);
  67. editLastRow();
  68. assertRowContents(0);
  69. waitForElementVisible(By.className("v-grid-editor"));
  70. assertEditorWithinGrid();
  71. }
  72. @Test
  73. public void testEditWhenSomeRowsNotVisible() {
  74. addRows(11);
  75. assertRowContents(3);
  76. editLastRow();
  77. waitForElementVisible(By.className("v-grid-editor"));
  78. assertRowContents(3);
  79. assertEditorWithinGrid();
  80. }
  81. @Test
  82. public void testEditWhenSomeRowsOutsideOfCache() {
  83. addRows(100);
  84. assertRowContents(91);
  85. editLastRow();
  86. waitForElementVisible(By.className("v-grid-editor"));
  87. assertRowContents(91);
  88. assertEditorWithinGrid();
  89. }
  90. }