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.

DateFieldMonthResolutionClickTest.java 3.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. package com.vaadin.tests.components.datefield;
  2. import com.vaadin.testbench.elements.DateFieldElement;
  3. import com.vaadin.tests.tb3.MultiBrowserTest;
  4. import org.junit.Before;
  5. import org.junit.Test;
  6. import org.openqa.selenium.By;
  7. import java.time.ZoneId;
  8. import java.time.ZonedDateTime;
  9. import static org.junit.Assert.assertTrue;
  10. public class DateFieldMonthResolutionClickTest extends MultiBrowserTest {
  11. @Before
  12. public void setUp() throws Exception {
  13. super.setup();
  14. openTestURL();
  15. }
  16. @Test
  17. public void testClickChangeValueYear() {
  18. DateFieldElement yearResolutionDF = $(DateFieldElement.class)
  19. .id("yearResolutionDF");
  20. yearResolutionDF.openPopup();
  21. assertTrue("Initially there should be no value",
  22. yearResolutionDF.getValue() == null
  23. || yearResolutionDF.getValue().isEmpty());
  24. findElement(By.className("v-datefield-calendarpanel-month")).click();
  25. waitForElementNotPresent(By.className("v-datefield-popup"));
  26. assertTrue("The selected year should be the current one",
  27. getZonedDateTimeAtECT().getYear() == Integer
  28. .valueOf(yearResolutionDF.getValue()));
  29. }
  30. @Test
  31. public void testClickChangeValueMonth() {
  32. DateFieldElement monthResolutionDF = $(DateFieldElement.class)
  33. .id("monthResolutionDF");
  34. monthResolutionDF.openPopup();
  35. assertTrue(
  36. String.format("Initially there should be no value, but was %s",
  37. monthResolutionDF.getValue()),
  38. monthResolutionDF.getValue() == null
  39. || monthResolutionDF.getValue().isEmpty());
  40. findElement(By.className("v-datefield-calendarpanel-month")).click();
  41. waitForElementNotPresent(By.className("v-datefield-popup"));
  42. String dateValue = new StringBuilder()
  43. .append(getZonedDateTimeAtECT().getMonth().getValue())
  44. .append("/").append(getZonedDateTimeAtECT().getYear())
  45. .toString();
  46. assertTrue("The selected year should be the current one",
  47. dateValue.equals(monthResolutionDF.getValue()));
  48. }
  49. @Test
  50. public void testResolutionDayHeaderNotClickable() {
  51. DateFieldElement dayResolutionDF = $(DateFieldElement.class)
  52. .id("resolutionDayDF");
  53. dayResolutionDF.openPopup();
  54. waitForElementPresent(By.className("v-datefield-popup"));
  55. findElement(By.className("v-datefield-calendarpanel-month")).click();
  56. // Click should have no effect
  57. assertElementPresent(By.className("v-datefield-popup"));
  58. }
  59. @Test
  60. public void setResoultionToYearAndClick() {
  61. // Switch the resolution to verify clicking is now enabled
  62. findElement(By.id("buttonChangeResolution")).click();
  63. waitForElementPresent(By.id("resolutionDayDF"));
  64. $(DateFieldElement.class).id("resolutionDayDF").openPopup();
  65. waitForElementPresent(By.className("v-datefield-popup"));
  66. findElement(By.className("v-datefield-calendarpanel-month")).click();
  67. waitForElementNotPresent(By.className("v-datefield-popup"));
  68. // Set Back to month
  69. findElement(By.id("buttonChangeResolution")).click();
  70. }
  71. private ZonedDateTime getZonedDateTimeAtECT() {
  72. return ZonedDateTime.now(ZoneId.of("Europe/Paris"));
  73. }
  74. }