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.

DisabledInlineDateFieldTest.java 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. package com.vaadin.tests.components.datefield;
  2. import static org.junit.Assert.assertEquals;
  3. import static org.junit.Assert.assertFalse;
  4. import org.junit.Test;
  5. import org.openqa.selenium.By;
  6. import org.openqa.selenium.WebElement;
  7. import com.vaadin.tests.tb3.MultiBrowserTest;
  8. public class DisabledInlineDateFieldTest extends MultiBrowserTest {
  9. @Test
  10. public void testDisabled() {
  11. openTestURL();
  12. testNextMonthControls(".v-disabled");
  13. testDaySelection(".v-disabled");
  14. }
  15. @Test
  16. public void testReadOnly() {
  17. openTestURL();
  18. testNextMonthControls(".v-readonly");
  19. testDaySelection(".v-readonly");
  20. }
  21. private void testNextMonthControls(String cssClass) {
  22. // Get the currently selected month.
  23. String expectedMonth = getSelectedMonth(cssClass);
  24. // Attempt to click the next month button.
  25. driver.findElement(By.cssSelector(cssClass + " .v-button-nextmonth"))
  26. .click();
  27. // Assert that we did not navigate to next month.
  28. String actualMonth = getSelectedMonth(cssClass);
  29. assertEquals(expectedMonth, actualMonth);
  30. }
  31. private void testDaySelection(String cssClass) {
  32. // We know that the first day element is not selected, because of the
  33. // fixed date in the test.
  34. WebElement nonSelectedDay = driver.findElement(By.cssSelector(
  35. cssClass + " .v-inline-datefield-calendarpanel-day"));
  36. // Assert it is not selected before click.
  37. assertFalse(nonSelectedDay.getAttribute("class").contains("selected"));
  38. // Click on the non-selected day.
  39. nonSelectedDay.click();
  40. // Assert that clicking did not select the day.
  41. assertFalse(nonSelectedDay.getAttribute("class").contains("selected"));
  42. }
  43. private String getSelectedMonth(String selectorPrefix) {
  44. return driver
  45. .findElement(By.cssSelector(selectorPrefix
  46. + " .v-inline-datefield-calendarpanel-month"))
  47. .getText();
  48. }
  49. }