diff options
author | Anna Koskinen <Ansku@users.noreply.github.com> | 2020-01-15 17:07:14 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-01-15 17:07:14 +0200 |
commit | 2bf0b02220ea96ee959b766a32bf1a79ae968317 (patch) | |
tree | 96ac048aaf9af90eaf0021706e1403c2f324e1f0 /uitest | |
parent | a799444d832a82c3ad1467a6a60735aab015c87f (diff) | |
download | vaadin-framework-2bf0b02220ea96ee959b766a32bf1a79ae968317.tar.gz vaadin-framework-2bf0b02220ea96ee959b766a32bf1a79ae968317.zip |
Ensure value change happens before shortcuts in compatibility components (#11871)
Fixes #10854
Diffstat (limited to 'uitest')
2 files changed, 86 insertions, 0 deletions
diff --git a/uitest/src/main/java/com/vaadin/tests/components/datefield/CompatibilityDateFieldShortcut.java b/uitest/src/main/java/com/vaadin/tests/components/datefield/CompatibilityDateFieldShortcut.java new file mode 100644 index 0000000000..0881ced2fc --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/components/datefield/CompatibilityDateFieldShortcut.java @@ -0,0 +1,47 @@ +package com.vaadin.tests.components.datefield; + +import java.text.SimpleDateFormat; +import java.util.Date; + +import com.vaadin.event.ShortcutAction.KeyCode; +import com.vaadin.event.ShortcutListener; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.Notification; +import com.vaadin.v7.ui.DateField; + +@SuppressWarnings("deprecation") +public class CompatibilityDateFieldShortcut extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + String dateFormat = "dd/MM/yyyy"; + + DateField dateField = new DateField(); + dateField.setValue(new Date(2018 - 1900, 0, 11)); + dateField.setDateFormat(dateFormat); + + dateField.addShortcutListener( + new ShortcutListener("Enter", KeyCode.ENTER, null) { + @Override + public void handleAction(Object sender, Object target) { + SimpleDateFormat df = new SimpleDateFormat(dateFormat); + Notification.show(df.format(dateField.getValue())); + } + }); + + addComponent(dateField); + } + + @Override + protected String getTestDescription() { + return "Modify the date manually (without using the popup element) and" + + " then press Enter. The notification should show the modified" + + " value instead of the old value."; + } + + @Override + protected Integer getTicketNumber() { + return 10854; + } +} diff --git a/uitest/src/test/java/com/vaadin/tests/components/datefield/CompatibilityDateFieldShortcutTest.java b/uitest/src/test/java/com/vaadin/tests/components/datefield/CompatibilityDateFieldShortcutTest.java new file mode 100644 index 0000000000..8ed2da2b77 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/components/datefield/CompatibilityDateFieldShortcutTest.java @@ -0,0 +1,39 @@ +package com.vaadin.tests.components.datefield; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.openqa.selenium.By; +import org.openqa.selenium.Keys; +import org.openqa.selenium.WebElement; + +import com.vaadin.testbench.elements.DateFieldElement; +import com.vaadin.testbench.elements.NotificationElement; +import com.vaadin.tests.tb3.SingleBrowserTest; + +public class CompatibilityDateFieldShortcutTest extends SingleBrowserTest { + + private static final String DATEFIELD_VALUE_ORIGINAL = "11/01/2018"; + private static final String DATEFIELD_VALUE_MODIFIED = "21/01/2018"; + + @Test + public void modifyValueAndPressEnter() { + openTestURL(); + + DateFieldElement dateField = $(DateFieldElement.class).first(); + WebElement dateFieldText = dateField.findElement(By.tagName("input")); + + assertEquals("DateField value should be \"" + DATEFIELD_VALUE_ORIGINAL + + "\"", DATEFIELD_VALUE_ORIGINAL, dateField.getValue()); + + dateFieldText.click(); + dateFieldText.sendKeys(Keys.HOME, Keys.DELETE, "2"); + dateFieldText.sendKeys(Keys.ENTER); + + assertEquals("DateField value should be \"" + DATEFIELD_VALUE_MODIFIED + + "\"", DATEFIELD_VALUE_MODIFIED, dateField.getValue()); + + assertEquals(DATEFIELD_VALUE_MODIFIED, + $(NotificationElement.class).first().getCaption()); + } +} |