summaryrefslogtreecommitdiffstats
path: root/uitest
diff options
context:
space:
mode:
authorTatu Lund <tatu@vaadin.com>2021-02-19 11:11:49 +0200
committerGitHub <noreply@github.com>2021-02-19 11:11:49 +0200
commit551177326f6ae8c4ddd7d5b3ab3bb3311304cc0a (patch)
tree9f370578832547243f8f516b7f2b30ce79fb1194 /uitest
parent45ed0c173aedb8c0b7194ed0b8eb656d24ddac9d (diff)
downloadvaadin-framework-551177326f6ae8c4ddd7d5b3ab3bb3311304cc0a.tar.gz
vaadin-framework-551177326f6ae8c4ddd7d5b3ab3bb3311304cc0a.zip
Add API to prevent invalid input when integrated range validator is used (#12168)
Do not fire DateField's value change event if the new date is not within the range. Fixes: #12163
Diffstat (limited to 'uitest')
-rw-r--r--uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldPreventInvalidInput.java32
-rw-r--r--uitest/src/test/java/com/vaadin/tests/components/datefield/DateFieldPreventInvalidInputTest.java40
2 files changed, 72 insertions, 0 deletions
diff --git a/uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldPreventInvalidInput.java b/uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldPreventInvalidInput.java
new file mode 100644
index 0000000000..257feefb6b
--- /dev/null
+++ b/uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldPreventInvalidInput.java
@@ -0,0 +1,32 @@
+package com.vaadin.tests.components.datefield;
+
+import java.time.LocalDate;
+
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.AbstractTestUI;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.DateField;
+import com.vaadin.ui.Label;
+
+public class DateFieldPreventInvalidInput extends AbstractTestUI {
+
+ @Override
+ protected void setup(VaadinRequest request) {
+ DateField dateField = new DateField();
+ dateField.setRangeStart(LocalDate.ofYearDay(2019, 1));
+ dateField.setRangeEnd(LocalDate.ofYearDay(2019, 365));
+ dateField.setPreventInvalidInput(true);
+ Button button = new Button("", event -> {
+ dateField.clear();
+ dateField.setPreventInvalidInput(false);
+ });
+ Label value = new Label();
+ value.setValue("no-value");
+ value.setId("value");
+ dateField.addValueChangeListener(event -> {
+ value.setValue(dateField.getValue().toString());
+ });
+ addComponents(dateField,value,button);
+ }
+
+}
diff --git a/uitest/src/test/java/com/vaadin/tests/components/datefield/DateFieldPreventInvalidInputTest.java b/uitest/src/test/java/com/vaadin/tests/components/datefield/DateFieldPreventInvalidInputTest.java
new file mode 100644
index 0000000000..9b3d1c1ef8
--- /dev/null
+++ b/uitest/src/test/java/com/vaadin/tests/components/datefield/DateFieldPreventInvalidInputTest.java
@@ -0,0 +1,40 @@
+package com.vaadin.tests.components.datefield;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.openqa.selenium.Keys;
+import org.openqa.selenium.WebElement;
+
+import com.vaadin.testbench.By;
+import com.vaadin.testbench.elements.ButtonElement;
+import com.vaadin.testbench.elements.DateFieldElement;
+import com.vaadin.testbench.elements.LabelElement;
+import com.vaadin.tests.tb3.SingleBrowserTest;
+
+public class DateFieldPreventInvalidInputTest extends SingleBrowserTest {
+
+ @Test
+ public void modifyValueAndPressTab() {
+ openTestURL();
+ DateFieldElement dateField = $(DateFieldElement.class).first();
+
+ WebElement dateTextbox = dateField
+ .findElement(By.className("v-textfield"));
+ ButtonElement button = $(ButtonElement.class).first();
+ LabelElement label = $(LabelElement.class).id("value");
+
+ // DateField is set not accept invalid input, this date is not in range
+ dateTextbox.click();
+ dateTextbox.sendKeys("01/01/21", Keys.TAB);
+ assertEquals("no-value", label.getText());
+
+ // Set DateField accept invalid input
+ button.click();
+
+ dateTextbox.click();
+ dateTextbox.sendKeys("01/01/21", Keys.TAB);
+ Assert.assertNotEquals("no-value", label.getText());
+ }
+}