summaryrefslogtreecommitdiffstats
path: root/uitest
diff options
context:
space:
mode:
authorArtur <artur@vaadin.com>2017-06-12 16:44:05 +0300
committerIlia Motornyi <elmot@vaadin.com>2017-06-12 16:44:05 +0300
commit2f5e484a12f25d10ac6034d8ee9176b553b96c2d (patch)
treea12ee185335d2dbc9530a3300ec0915cd056c176 /uitest
parentc5cdca0c6290b96cf9499d29b4b5380466b33082 (diff)
downloadvaadin-framework-2f5e484a12f25d10ac6034d8ee9176b553b96c2d.tar.gz
vaadin-framework-2f5e484a12f25d10ac6034d8ee9176b553b96c2d.zip
Add methods for setting the date as an ISO value for date fields
Diffstat (limited to 'uitest')
-rw-r--r--uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldElementUI.java46
-rw-r--r--uitest/src/main/java/com/vaadin/tests/components/datefield/DateTimeFieldElementUI.java44
-rw-r--r--uitest/src/test/java/com/vaadin/tests/components/datefield/DateFieldElementTest.java46
-rw-r--r--uitest/src/test/java/com/vaadin/tests/components/datefield/DateTimeFieldElementTest.java47
4 files changed, 169 insertions, 14 deletions
diff --git a/uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldElementUI.java b/uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldElementUI.java
index f7f1495cf1..bd1fda5201 100644
--- a/uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldElementUI.java
+++ b/uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldElementUI.java
@@ -1,15 +1,51 @@
package com.vaadin.tests.components.datefield;
+import java.time.LocalDate;
+import java.util.Locale;
+
+import com.vaadin.annotations.Widgetset;
import com.vaadin.server.VaadinRequest;
-import com.vaadin.tests.components.AbstractReindeerTestUI;
-import com.vaadin.tests.components.TestDateField;
+import com.vaadin.tests.components.AbstractReindeerTestUIWithLog;
import com.vaadin.ui.DateField;
+import com.vaadin.ui.InlineDateField;
+
+@Widgetset("com.vaadin.DefaultWidgetSet")
+public class DateFieldElementUI extends AbstractReindeerTestUIWithLog {
+ public static final LocalDate TEST_DATE_TIME = DateTimeFieldElementUI.TEST_DATE_TIME
+ .toLocalDate();
+ public static final LocalDate ANOTHER_TEST_DATE_TIME = DateTimeFieldElementUI.ANOTHER_TEST_DATE_TIME
+ .toLocalDate();
-public class DateFieldElementUI extends AbstractReindeerTestUI {
@Override
protected void setup(VaadinRequest request) {
- addComponent(new DateField());
- addComponent(new TestDateField());
+ log.setNumberLogRows(false);
+ DateField df = new DateField();
+ df.addValueChangeListener(event -> {
+ log("Default date field value set to " + event.getValue());
+ });
+ addComponent(df);
+ InlineDateField inlineDateField = new InlineDateField();
+ inlineDateField.addValueChangeListener(event -> {
+ log("Default inline date field value set to " + event.getValue());
+ });
+ addComponent(inlineDateField);
+
+ DateField finnishDatefield = new DateField("Finnish");
+ finnishDatefield.setId("fi");
+ finnishDatefield.setLocale(new Locale("fi", "FI"));
+ finnishDatefield.setValue(TEST_DATE_TIME);
+ finnishDatefield.addValueChangeListener(event -> {
+ log("Finnish date field value set to " + event.getValue());
+ });
+ addComponent(finnishDatefield);
+ DateField usDatefield = new DateField("US");
+ usDatefield.setId("us");
+ usDatefield.setLocale(Locale.US);
+ usDatefield.setValue(TEST_DATE_TIME);
+ usDatefield.addValueChangeListener(event -> {
+ log("US date field value set to " + event.getValue());
+ });
+ addComponent(usDatefield);
}
@Override
diff --git a/uitest/src/main/java/com/vaadin/tests/components/datefield/DateTimeFieldElementUI.java b/uitest/src/main/java/com/vaadin/tests/components/datefield/DateTimeFieldElementUI.java
index 1481439748..1bd5ddd1f6 100644
--- a/uitest/src/main/java/com/vaadin/tests/components/datefield/DateTimeFieldElementUI.java
+++ b/uitest/src/main/java/com/vaadin/tests/components/datefield/DateTimeFieldElementUI.java
@@ -1,15 +1,51 @@
package com.vaadin.tests.components.datefield;
+import java.time.LocalDateTime;
+import java.util.Locale;
+
+import com.vaadin.annotations.Widgetset;
import com.vaadin.server.VaadinRequest;
-import com.vaadin.tests.components.AbstractReindeerTestUI;
+import com.vaadin.tests.components.AbstractReindeerTestUIWithLog;
import com.vaadin.ui.DateTimeField;
import com.vaadin.ui.InlineDateTimeField;
-public class DateTimeFieldElementUI extends AbstractReindeerTestUI {
+@Widgetset("com.vaadin.DefaultWidgetSet")
+public class DateTimeFieldElementUI extends AbstractReindeerTestUIWithLog {
+ public static final LocalDateTime TEST_DATE_TIME = LocalDateTime.of(2017,
+ 12, 13, 17, 58);
+ public static final LocalDateTime ANOTHER_TEST_DATE_TIME = LocalDateTime
+ .of(2016, 11, 12, 16, 57);
+
@Override
protected void setup(VaadinRequest request) {
- addComponent(new DateTimeField());
- addComponent(new InlineDateTimeField());
+ log.setNumberLogRows(false);
+ DateTimeField df = new DateTimeField();
+ df.addValueChangeListener(event -> {
+ log("Default date field value set to " + event.getValue());
+ });
+ addComponent(df);
+ InlineDateTimeField inlineDateTimeField = new InlineDateTimeField();
+ inlineDateTimeField.addValueChangeListener(event -> {
+ log("Default inline date field value set to " + event.getValue());
+ });
+ addComponent(inlineDateTimeField);
+
+ DateTimeField finnishDateTimeField = new DateTimeField("Finnish");
+ finnishDateTimeField.setId("fi");
+ finnishDateTimeField.setLocale(new Locale("fi", "FI"));
+ finnishDateTimeField.setValue(TEST_DATE_TIME);
+ finnishDateTimeField.addValueChangeListener(event -> {
+ log("Finnish date field value set to " + event.getValue());
+ });
+ addComponent(finnishDateTimeField);
+ DateTimeField usDateTimeField = new DateTimeField("US");
+ usDateTimeField.setId("us");
+ usDateTimeField.setLocale(Locale.US);
+ usDateTimeField.setValue(TEST_DATE_TIME);
+ usDateTimeField.addValueChangeListener(event -> {
+ log("US date field value set to " + event.getValue());
+ });
+ addComponent(usDateTimeField);
}
@Override
diff --git a/uitest/src/test/java/com/vaadin/tests/components/datefield/DateFieldElementTest.java b/uitest/src/test/java/com/vaadin/tests/components/datefield/DateFieldElementTest.java
index bbfd15e733..29a05187bc 100644
--- a/uitest/src/test/java/com/vaadin/tests/components/datefield/DateFieldElementTest.java
+++ b/uitest/src/test/java/com/vaadin/tests/components/datefield/DateFieldElementTest.java
@@ -3,10 +3,13 @@ package com.vaadin.tests.components.datefield;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
+import java.time.LocalDate;
+
+import org.junit.Assert;
import org.junit.Test;
-import com.vaadin.testbench.elements.AbstractDateFieldElement;
import com.vaadin.testbench.elements.DateFieldElement;
+import com.vaadin.testbench.elements.InlineDateFieldElement;
import com.vaadin.tests.tb3.SingleBrowserTest;
public class DateFieldElementTest extends SingleBrowserTest {
@@ -15,8 +18,45 @@ public class DateFieldElementTest extends SingleBrowserTest {
public void dateFieldElementIsLocated() {
openTestURL();
- assertThat($(DateFieldElement.class).all().size(), is(2));
- assertThat($(AbstractDateFieldElement.class).all().size(), is(2));
+ assertThat($(DateFieldElement.class).all().size(), is(3));
+ assertThat($(InlineDateFieldElement.class).all().size(), is(1));
+ }
+
+ @Test
+ public void setGetValue() {
+ openTestURL();
+
+ // No date set
+ DateFieldElement defaultInitiallyEmpty = $(DateFieldElement.class)
+ .first();
+ Assert.assertNull(defaultInitiallyEmpty.getDate());
+ defaultInitiallyEmpty.setDate(DateFieldElementUI.TEST_DATE_TIME);
+ Assert.assertEquals(DateFieldElementUI.TEST_DATE_TIME,
+ defaultInitiallyEmpty.getDate());
+ assertServerValue("Default date field",
+ DateFieldElementUI.TEST_DATE_TIME);
+
+ DateFieldElement fi = $(DateFieldElement.class).id("fi");
+ Assert.assertEquals(DateFieldElementUI.TEST_DATE_TIME, fi.getDate());
+ fi.setDate(DateFieldElementUI.ANOTHER_TEST_DATE_TIME);
+ Assert.assertEquals(DateFieldElementUI.ANOTHER_TEST_DATE_TIME,
+ fi.getDate());
+ assertServerValue("Finnish date field",
+ DateFieldElementUI.ANOTHER_TEST_DATE_TIME);
+
+ DateFieldElement us = $(DateFieldElement.class).id("us");
+ Assert.assertEquals(DateFieldElementUI.TEST_DATE_TIME, us.getDate());
+ us.setDate(DateFieldElementUI.ANOTHER_TEST_DATE_TIME);
+ Assert.assertEquals(DateFieldElementUI.ANOTHER_TEST_DATE_TIME,
+ us.getDate());
+ assertServerValue("US date field",
+ DateFieldElementUI.ANOTHER_TEST_DATE_TIME);
+ }
+
+ private void assertServerValue(String id, LocalDate testDateTime) {
+ Assert.assertEquals(id + " value set to " + testDateTime.toString(),
+ getLogRow(0));
+
}
@Override
diff --git a/uitest/src/test/java/com/vaadin/tests/components/datefield/DateTimeFieldElementTest.java b/uitest/src/test/java/com/vaadin/tests/components/datefield/DateTimeFieldElementTest.java
index 51694f24cd..2138fb5df0 100644
--- a/uitest/src/test/java/com/vaadin/tests/components/datefield/DateTimeFieldElementTest.java
+++ b/uitest/src/test/java/com/vaadin/tests/components/datefield/DateTimeFieldElementTest.java
@@ -3,6 +3,9 @@ package com.vaadin.tests.components.datefield;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
+import java.time.LocalDateTime;
+
+import org.junit.Assert;
import org.junit.Test;
import com.vaadin.testbench.elements.DateTimeFieldElement;
@@ -12,13 +15,53 @@ import com.vaadin.tests.tb3.SingleBrowserTest;
public class DateTimeFieldElementTest extends SingleBrowserTest {
@Test
- public void dateFieldElementIsLocated() {
+ public void DateTimeFieldElementIsLocated() {
openTestURL();
- assertThat($(DateTimeFieldElement.class).all().size(), is(1));
+ assertThat($(DateTimeFieldElement.class).all().size(), is(3));
assertThat($(InlineDateTimeFieldElement.class).all().size(), is(1));
}
+ @Test
+ public void setGetValue() {
+ openTestURL();
+
+ // No date set
+ DateTimeFieldElement defaultInitiallyEmpty = $(
+ DateTimeFieldElement.class).first();
+ Assert.assertNull(defaultInitiallyEmpty.getDateTime());
+ defaultInitiallyEmpty
+ .setDateTime(DateTimeFieldElementUI.TEST_DATE_TIME);
+ Assert.assertEquals(DateTimeFieldElementUI.TEST_DATE_TIME,
+ defaultInitiallyEmpty.getDateTime());
+ assertServerValue("Default date field",
+ DateTimeFieldElementUI.TEST_DATE_TIME);
+
+ DateTimeFieldElement fi = $(DateTimeFieldElement.class).id("fi");
+ Assert.assertEquals(DateTimeFieldElementUI.TEST_DATE_TIME,
+ fi.getDateTime());
+ fi.setDateTime(DateTimeFieldElementUI.ANOTHER_TEST_DATE_TIME);
+ Assert.assertEquals(DateTimeFieldElementUI.ANOTHER_TEST_DATE_TIME,
+ fi.getDateTime());
+ assertServerValue("Finnish date field",
+ DateTimeFieldElementUI.ANOTHER_TEST_DATE_TIME);
+
+ DateTimeFieldElement us = $(DateTimeFieldElement.class).id("us");
+ Assert.assertEquals(DateTimeFieldElementUI.TEST_DATE_TIME,
+ us.getDateTime());
+ us.setDateTime(DateTimeFieldElementUI.ANOTHER_TEST_DATE_TIME);
+ Assert.assertEquals(DateTimeFieldElementUI.ANOTHER_TEST_DATE_TIME,
+ us.getDateTime());
+ assertServerValue("US date field",
+ DateTimeFieldElementUI.ANOTHER_TEST_DATE_TIME);
+ }
+
+ private void assertServerValue(String id, LocalDateTime testDateTime) {
+ Assert.assertEquals(id + " value set to " + testDateTime.toString(),
+ getLogRow(0));
+
+ }
+
@Override
protected Class<?> getUIClass() {
return DateTimeFieldElementUI.class;