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.

DateTimeFieldReadOnlyTest.java 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. package com.vaadin.tests.components.datefield;
  2. import static org.junit.Assert.assertEquals;
  3. import static org.junit.Assert.assertFalse;
  4. import static org.junit.Assert.assertTrue;
  5. import java.io.IOException;
  6. import org.junit.Test;
  7. import org.openqa.selenium.ElementNotInteractableException;
  8. import org.openqa.selenium.WebElement;
  9. import com.vaadin.testbench.By;
  10. import com.vaadin.testbench.elements.ButtonElement;
  11. import com.vaadin.testbench.elements.DateTimeFieldElement;
  12. import com.vaadin.tests.tb3.MultiBrowserTest;
  13. public class DateTimeFieldReadOnlyTest extends MultiBrowserTest {
  14. @Test
  15. public void readOnlyDateFieldPopupShouldNotOpen()
  16. throws IOException, InterruptedException {
  17. openTestURL();
  18. DateTimeFieldElement df = $(DateTimeFieldElement.class).first();
  19. WebElement dfButton = df
  20. .findElement(By.className("v-datefield-button"));
  21. // ensure initial read-only state works and pop-up cannot be opened
  22. assertTrue(df.hasClassName("v-readonly"));
  23. assertEquals("none", dfButton.getCssValue("display"));
  24. assertTrue(findElements(By.className("v-datefield-calendarpanel"))
  25. .isEmpty());
  26. assertFalse(openPopup(df));
  27. assertTrue(findElements(By.className("v-datefield-calendarpanel"))
  28. .isEmpty());
  29. // ensure read-only state can be removed and the component is still
  30. // functional
  31. toggleReadOnly();
  32. assertFalse(df.hasClassName("v-readonly"));
  33. assertEquals("inline-block", dfButton.getCssValue("display"));
  34. assertTrue(openPopup(df));
  35. assertEquals(1,
  36. findElements(By.className("v-datefield-calendarpanel")).size());
  37. // ensure read-only state can be re-applied, pop-up is closed and cannot
  38. // be re-opened
  39. toggleReadOnly();
  40. assertTrue(df.hasClassName("v-readonly"));
  41. assertEquals("none", dfButton.getCssValue("display"));
  42. assertTrue(findElements(By.className("v-datefield-calendarpanel"))
  43. .isEmpty());
  44. assertFalse(openPopup(df));
  45. assertTrue(findElements(By.className("v-datefield-calendarpanel"))
  46. .isEmpty());
  47. }
  48. private boolean openPopup(DateTimeFieldElement df) {
  49. // ensure the hidden button cannot be interacted with
  50. try {
  51. df.openPopup();
  52. return true;
  53. } catch (ElementNotInteractableException e) {
  54. return false;
  55. }
  56. }
  57. private void toggleReadOnly() {
  58. $(ButtonElement.class).caption("Switch read-only").first().click();
  59. }
  60. }