summaryrefslogtreecommitdiffstats
path: root/uitest
diff options
context:
space:
mode:
authorAnna Koskinen <Ansku@users.noreply.github.com>2020-01-28 12:34:22 +0200
committerGitHub <noreply@github.com>2020-01-28 12:34:22 +0200
commit75caa0488dee5b59f37d5691430c01de0b55c2db (patch)
treea58c3fb8fb1fa29a80d97ce982ac3acb6a78a0f5 /uitest
parent2aa2de52f0c532f4a6f400b16eb08c340fc80f02 (diff)
downloadvaadin-framework-75caa0488dee5b59f37d5691430c01de0b55c2db.tar.gz
vaadin-framework-75caa0488dee5b59f37d5691430c01de0b55c2db.zip
Don't reset date to current at DateField state (e.g. read-only) updates. (#11879)
- DateFields with month or year resolution should not get their date reset to current date if the field's state is updated (e.g. by changing read-only status or adding a range). Fixes: #11864, #11605
Diffstat (limited to 'uitest')
-rw-r--r--uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldMonthResolutionStatusChange.java49
-rw-r--r--uitest/src/test/java/com/vaadin/tests/components/datefield/DateFieldMonthResolutionStatusChangeTest.java38
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());
+ }
+
+}