diff options
Diffstat (limited to 'uitest')
2 files changed, 87 insertions, 0 deletions
diff --git a/uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldMonthResolutionStatusChange.java b/uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldMonthResolutionStatusChange.java new file mode 100644 index 0000000000..55b2823a1d --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldMonthResolutionStatusChange.java @@ -0,0 +1,49 @@ +package com.vaadin.tests.components.datefield; + +import java.time.LocalDate; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.shared.ui.datefield.DateResolution; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.Button; +import com.vaadin.ui.DateField; + +public class DateFieldMonthResolutionStatusChange extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + DateField dateField = new DateField(); + dateField.setResolution(DateResolution.MONTH); + dateField.setValue(LocalDate.of(2019, 1, 1)); + dateField.setReadOnly(true); + + Button dateReadOnlySwitch = new Button("Toggle read-only"); + dateReadOnlySwitch.setId("readOnly"); + dateReadOnlySwitch.addClickListener(event -> { + dateField.setReadOnly(!dateField.isReadOnly()); + }); + + Button addRangeButton = new Button("Add range"); + addRangeButton.setId("addRange"); + addRangeButton.addClickListener(event -> { + dateField.setRangeStart(LocalDate.of(2018, 1, 1)); + dateField.setRangeEnd(LocalDate.of(2020, 1, 1)); + }); + + addComponent(dateField); + addComponent(dateReadOnlySwitch); + addComponent(addRangeButton); + } + + @Override + protected String getTestDescription() { + return "Changing any field status (e.g. read-only or range) before " + + "the DateField popup has been opened should not change " + + "the date to current."; + } + + @Override + protected Integer getTicketNumber() { + return 11864; + } +} diff --git a/uitest/src/test/java/com/vaadin/tests/components/datefield/DateFieldMonthResolutionStatusChangeTest.java b/uitest/src/test/java/com/vaadin/tests/components/datefield/DateFieldMonthResolutionStatusChangeTest.java new file mode 100644 index 0000000000..58a926546c --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/components/datefield/DateFieldMonthResolutionStatusChangeTest.java @@ -0,0 +1,38 @@ +package com.vaadin.tests.components.datefield; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +import com.vaadin.testbench.elements.ButtonElement; +import com.vaadin.testbench.elements.DateFieldElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class DateFieldMonthResolutionStatusChangeTest + extends MultiBrowserTest { + + @Test + public void testChangeReadOnly() { + openTestURL(); + DateFieldElement df = $(DateFieldElement.class).first(); + assertEquals("Unexpected initial date.", "1/19", df.getValue()); + + // switch read-only state + $(ButtonElement.class).id("readOnly").click(); + + assertEquals("Unexpected date change.", "1/19", df.getValue()); + } + + @Test + public void testAddRange() { + openTestURL(); + DateFieldElement df = $(DateFieldElement.class).first(); + assertEquals("Unexpected initial date.", "1/19", df.getValue()); + + // add range + $(ButtonElement.class).id("addRange").click(); + + assertEquals("Unexpected date change.", "1/19", df.getValue()); + } + +} |