diff options
author | Olli Tietäväinen <ollit@vaadin.com> | 2017-08-10 15:57:27 +0300 |
---|---|---|
committer | Henri Sara <henri.sara@gmail.com> | 2017-08-10 15:57:27 +0300 |
commit | 66e68f1ef25804dabfb4b0e4cdd7d59c66522927 (patch) | |
tree | 47190488a16fc39a87305878516a58cf00d1dcc7 /uitest | |
parent | 24473c8deac75d9ac229252a81b534ba0e62b31c (diff) | |
download | vaadin-framework-66e68f1ef25804dabfb4b0e4cdd7d59c66522927.tar.gz vaadin-framework-66e68f1ef25804dabfb4b0e4cdd7d59c66522927.zip |
Enable setting non-selected default value for DateField (#9745)
Requested feature: allow setting DateField to a certain starting point without selecting a value.
Diffstat (limited to 'uitest')
2 files changed, 80 insertions, 0 deletions
diff --git a/uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldWithDefaultValue.java b/uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldWithDefaultValue.java new file mode 100755 index 0000000000..e422fc991e --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldWithDefaultValue.java @@ -0,0 +1,34 @@ +package com.vaadin.tests.components.datefield; + +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; + +import com.vaadin.annotations.Widgetset; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.DateField; + +@Widgetset("com.vaadin.DefaultWidgetSet") +public class DateFieldWithDefaultValue extends AbstractTestUI { + + static final String DATEFIELD_HAS_DEFAULT = "hasdefault"; + + static final String DATEFIELD_REGULAR = "regular"; + + @Override + protected void setup(VaadinRequest request) { + DateField dfWithDefault = new DateField( + "Date field with default value 2010-10-01"); + dfWithDefault.setId(DATEFIELD_HAS_DEFAULT); + LocalDate defaultValue = LocalDate.parse("2010-10-01", + DateTimeFormatter.ISO_DATE); + dfWithDefault.setDefaultValue(defaultValue); + addComponent(dfWithDefault); + + DateField regularDF = new DateField("Regular datefield"); + regularDF.setId(DATEFIELD_REGULAR); + addComponent(regularDF); + + } + +} diff --git a/uitest/src/test/java/com/vaadin/tests/components/datefield/DateFieldWithDefaultValueTest.java b/uitest/src/test/java/com/vaadin/tests/components/datefield/DateFieldWithDefaultValueTest.java new file mode 100755 index 0000000000..964b6bbecb --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/components/datefield/DateFieldWithDefaultValueTest.java @@ -0,0 +1,46 @@ +package com.vaadin.tests.components.datefield; + +import static com.vaadin.tests.components.datefield.DateFieldWithDefaultValue.DATEFIELD_HAS_DEFAULT; +import static com.vaadin.tests.components.datefield.DateFieldWithDefaultValue.DATEFIELD_REGULAR; + +import org.junit.Test; +import org.openqa.selenium.By; +import org.openqa.selenium.WebElement; + +import com.vaadin.testbench.elements.DateFieldElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class DateFieldWithDefaultValueTest extends MultiBrowserTest { + + @Test + public void testDateFieldDefaultValue() { + openTestURL(); + String datePickerId = DATEFIELD_HAS_DEFAULT; + getDateFieldElement(datePickerId).openPopup(); + WebElement monthSpanElement = getMonthSpanFromVisibleCalendarPanel(); + // Can't check for "October 2010", since IE11 translates October -> + // lokakuu + assert (monthSpanElement.getText().contains("2010")); + } + + @Test + public void testDateFieldWithNoDefault() { + openTestURL(); + String datePickerId = DATEFIELD_REGULAR; + getDateFieldElement(datePickerId).openPopup(); + WebElement monthSpanElement = getMonthSpanFromVisibleCalendarPanel(); + assert (!monthSpanElement.getText().contains("2010")); + } + + private WebElement getMonthSpanFromVisibleCalendarPanel() { + return getDriver() + .findElements( + By.cssSelector(".v-datefield-calendarpanel-month")) + .get(0); + } + + private DateFieldElement getDateFieldElement(String id) { + return $(DateFieldElement.class).id(id); + } + +} |