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.

GridEditorUITest.java 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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.containsString;
  18. import static org.hamcrest.CoreMatchers.not;
  19. import static org.hamcrest.MatcherAssert.assertThat;
  20. import static org.junit.Assert.assertFalse;
  21. import static org.junit.Assert.assertTrue;
  22. import org.junit.Test;
  23. import org.openqa.selenium.Keys;
  24. import org.openqa.selenium.interactions.Actions;
  25. import com.vaadin.testbench.By;
  26. import com.vaadin.testbench.elements.GridElement;
  27. import com.vaadin.testbench.elements.GridElement.GridCellElement;
  28. import com.vaadin.testbench.elements.NotificationElement;
  29. import com.vaadin.testbench.elements.PasswordFieldElement;
  30. import com.vaadin.testbench.parallel.TestCategory;
  31. import com.vaadin.tests.tb3.MultiBrowserTest;
  32. @TestCategory("grid")
  33. public class GridEditorUITest extends MultiBrowserTest {
  34. @Override
  35. public void setup() throws Exception {
  36. super.setup();
  37. setDebug(true);
  38. openTestURL();
  39. }
  40. private void openEditor(int rowIndex) {
  41. GridElement grid = $(LegacyGridElement.class).first();
  42. GridCellElement cell = grid.getCell(rowIndex, 1);
  43. new Actions(driver).moveToElement(cell).doubleClick().build().perform();
  44. }
  45. private void saveEditor() {
  46. findElement(By.cssSelector(".v-grid-editor-save")).click();
  47. }
  48. private GridCellElement getHeaderCell(int rowIndex, int colIndex) {
  49. GridElement grid = $(LegacyGridElement.class).first();
  50. GridCellElement headerCell = grid.getHeaderCell(rowIndex, colIndex);
  51. return headerCell;
  52. }
  53. @Test
  54. public void testEditor() {
  55. assertFalse("Sanity check",
  56. isElementPresent(PasswordFieldElement.class));
  57. openEditor(5);
  58. new Actions(getDriver()).sendKeys(Keys.ESCAPE).perform();
  59. openEditor(10);
  60. assertTrue("Editor should be opened with a password field",
  61. isElementPresent(PasswordFieldElement.class));
  62. assertFalse("Notification was present",
  63. isElementPresent(NotificationElement.class));
  64. }
  65. @Test
  66. public void savingResetsSortingIndicator() {
  67. GridCellElement headerCell = getHeaderCell(0, 0);
  68. headerCell.click();
  69. openEditor(1);
  70. saveEditor();
  71. assertThat(headerCell.getAttribute("class"),
  72. not(containsString("sort-")));
  73. }
  74. }