diff options
author | Denis <denis@vaadin.com> | 2017-01-19 10:01:03 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-01-19 10:01:03 +0200 |
commit | f42b9657b818da483b839d3b43b4cf55552ef034 (patch) | |
tree | dd65e611eb326469b4dbeb84eefc2c69b57f3e5f /uitest | |
parent | dafc8310259a2e79bb203c7f786c9aba5354937b (diff) | |
download | vaadin-framework-f42b9657b818da483b839d3b43b4cf55552ef034.tar.gz vaadin-framework-f42b9657b818da483b839d3b43b4cf55552ef034.zip |
Introduce DateTimeFile and InlineDateTimeField. (#8218)
* Introduce DateTimeFile and InlineDateTimeField.
Fixes #8132
* Correct and provide declarative tests.
* Provide a date converter and UI tests.
Diffstat (limited to 'uitest')
33 files changed, 1677 insertions, 24 deletions
diff --git a/uitest/src/main/java/com/vaadin/tests/components/datefield/AbstractDateFieldTest.java b/uitest/src/main/java/com/vaadin/tests/components/datefield/AbstractDateFieldTest.java index 369abcc80f..8ae2d48afd 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/datefield/AbstractDateFieldTest.java +++ b/uitest/src/main/java/com/vaadin/tests/components/datefield/AbstractDateFieldTest.java @@ -7,19 +7,12 @@ import java.util.LinkedHashMap; import java.util.Locale; import com.vaadin.shared.ui.datefield.DateResolution; -import com.vaadin.tests.components.TestDateField; import com.vaadin.tests.components.abstractfield.AbstractFieldTest; import com.vaadin.ui.AbstractLocalDateField; -public class AbstractDateFieldTest<T extends AbstractLocalDateField> +public abstract class AbstractDateFieldTest<T extends AbstractLocalDateField> extends AbstractFieldTest<T, LocalDate> { - @SuppressWarnings("unchecked") - @Override - protected Class<T> getTestClass() { - return (Class<T>) TestDateField.class; - } - private Command<T, LocalDate> setValue = new Command<T, LocalDate>() { @Override diff --git a/uitest/src/main/java/com/vaadin/tests/components/datefield/AbstractDateTimeFieldTest.java b/uitest/src/main/java/com/vaadin/tests/components/datefield/AbstractDateTimeFieldTest.java new file mode 100644 index 0000000000..522fa118ed --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/components/datefield/AbstractDateTimeFieldTest.java @@ -0,0 +1,130 @@ +package com.vaadin.tests.components.datefield; + +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.time.LocalDateTime; +import java.util.LinkedHashMap; +import java.util.Locale; + +import com.vaadin.shared.ui.datefield.DateTimeResolution; +import com.vaadin.tests.components.abstractfield.AbstractFieldTest; +import com.vaadin.ui.AbstractLocalDateTimeField; + +public abstract class AbstractDateTimeFieldTest<T extends AbstractLocalDateTimeField> + extends AbstractFieldTest<T, LocalDateTime> { + + private Command<T, LocalDateTime> setValue = new Command<T, LocalDateTime>() { + + @Override + public void execute(T c, LocalDateTime value, Object data) { + c.setValue(value); + } + }; + + @Override + protected void createActions() { + super.createActions(); + createResolutionSelectAction(CATEGORY_FEATURES); + createBooleanAction("Lenient", CATEGORY_FEATURES, false, + lenientCommand); + createBooleanAction("Show week numbers", CATEGORY_FEATURES, false, + weekNumberCommand); + createDateFormatSelectAction(CATEGORY_FEATURES); + createSetValueAction(CATEGORY_FEATURES); + + } + + private void createSetValueAction(String category) { + LinkedHashMap<String, LocalDateTime> options = new LinkedHashMap<>(); + options.put("(null)", null); + options.put("(current time)", LocalDateTime.now()); + options.put("2010-12-12", LocalDateTime.of(2010, 12, 12, 6, 34, 23)); + createMultiClickAction("Set value", category, options, setValue, null); + } + + private void createDateFormatSelectAction(String category) { + LinkedHashMap<String, String> options = new LinkedHashMap<>(); + + options.put("-", null); + options.put("d M yyyy", "d M yyyy"); + options.put("d MM yyyy", "d MM yyyy"); + options.put("d MMM yyyy", "d MMM yyyy"); + options.put("d MMMM yyyy", "d MMMM yyyy"); + options.put("dd M yyyy", "dd M yyyy"); + options.put("ddd M yyyy", "ddd M yyyy"); + options.put("d M y", "d M y"); + options.put("d M yy", "d M yy"); + options.put("d M yyy", "d M yyy"); + options.put("d M yyyy", "d M yyyy"); + options.put("d M 'custom text' yyyy", "d M 'custom text' yyyy"); + options.put("'day:'d', month:'M', year: 'yyyy", + "'day:'d', month:'M', year: 'yyyy"); + options.put(getDatePattern(new Locale("fi", "FI"), DateFormat.LONG), + getDatePattern(new Locale("fi", "FI"), DateFormat.LONG)); + options.put(getDatePattern(new Locale("fi", "FI"), DateFormat.MEDIUM), + getDatePattern(new Locale("fi", "FI"), DateFormat.MEDIUM)); + options.put(getDatePattern(new Locale("fi", "FI"), DateFormat.SHORT), + getDatePattern(new Locale("fi", "FI"), DateFormat.SHORT)); + + createSelectAction("Date format", category, options, "-", + dateFormatCommand); + + } + + private String getDatePattern(Locale locale, int dateStyle) { + DateFormat dateFormat = DateFormat.getDateInstance(dateStyle, locale); + + if (dateFormat instanceof SimpleDateFormat) { + String pattern = ((SimpleDateFormat) dateFormat).toPattern(); + return pattern; + } + return null; + + } + + private void createResolutionSelectAction(String category) { + LinkedHashMap<String, DateTimeResolution> options = new LinkedHashMap<>(); + options.put("Year", DateTimeResolution.YEAR); + options.put("Month", DateTimeResolution.MONTH); + options.put("Day", DateTimeResolution.DAY); + options.put("Hour", DateTimeResolution.HOUR); + options.put("Min", DateTimeResolution.MINUTE); + options.put("Sec", DateTimeResolution.SECOND); + + createSelectAction("Resolution", category, options, "Year", + resolutionCommand); + } + + private Command<T, DateTimeResolution> resolutionCommand = new Command<T, DateTimeResolution>() { + + @Override + public void execute(T c, DateTimeResolution value, Object data) { + c.setResolution(value); + + } + }; + private Command<T, Boolean> lenientCommand = new Command<T, Boolean>() { + + @Override + public void execute(T c, Boolean value, Object data) { + c.setLenient(false); + + } + }; + private Command<T, Boolean> weekNumberCommand = new Command<T, Boolean>() { + + @Override + public void execute(T c, Boolean value, Object data) { + c.setShowISOWeekNumbers(value); + + } + }; + private Command<T, String> dateFormatCommand = new Command<T, String>() { + + @Override + public void execute(T c, String value, Object data) { + c.setDateFormat(value); + } + }; + +} diff --git a/uitest/src/main/java/com/vaadin/tests/components/datefield/AriaDateTimeDisabled.java b/uitest/src/main/java/com/vaadin/tests/components/datefield/AriaDateTimeDisabled.java new file mode 100644 index 0000000000..9c5b030d87 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/components/datefield/AriaDateTimeDisabled.java @@ -0,0 +1,49 @@ +/* + * Copyright 2000-2016 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.tests.components.datefield; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractReindeerTestUI; +import com.vaadin.ui.DateTimeField; +import com.vaadin.ui.VerticalLayout; + +public class AriaDateTimeDisabled extends AbstractReindeerTestUI { + + @Override + protected void setup(VaadinRequest request) { + VerticalLayout content = new VerticalLayout(); + content.setMargin(true); + content.setSpacing(true); + + final DateTimeField disabledDateField = new DateTimeField( + "Disabled DateField"); + disabledDateField.setEnabled(false); + + setContent(content); + content.addComponent(disabledDateField); + content.addComponent(new DateTimeField("Enabled DateField")); + } + + @Override + protected String getTestDescription() { + return "Test for aria-disabled attribute on DateField."; + } + + @Override + protected Integer getTicketNumber() { + return 13463; + } +} diff --git a/uitest/src/main/java/com/vaadin/tests/components/datefield/CustomDateTimeFormat.java b/uitest/src/main/java/com/vaadin/tests/components/datefield/CustomDateTimeFormat.java new file mode 100644 index 0000000000..90c11b6244 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/components/datefield/CustomDateTimeFormat.java @@ -0,0 +1,59 @@ +/* + * Copyright 2000-2016 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.tests.components.datefield; + +import java.time.LocalDateTime; +import java.util.Locale; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.shared.ui.datefield.DateTimeResolution; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.DateTimeField; + +/** + * @author Vaadin Ltd + * + */ +public class CustomDateTimeFormat extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + setLocale(new Locale("fi", "FI")); + + DateTimeField field = new DateTimeField(); + field.setResolution(DateTimeResolution.SECOND); + field.setWidth("300px"); + + String pattern = "d. MMMM'ta 'yyyy 'klo 'H.mm.ss"; + field.setDateFormat(pattern); + + field.setValue(LocalDateTime.of(2010, 1, 1, 12, 23, 45)); + + addComponent(field); + + } + + @Override + protected String getTestDescription() { + return "Month name should be visible in text box if format pattern includes it"; + } + + @Override + protected Integer getTicketNumber() { + return 3490; + } + +} diff --git a/uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldDayResolutionOffset.java b/uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldDayResolutionOffset.java index e38dd6895c..2107b9ff61 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldDayResolutionOffset.java +++ b/uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldDayResolutionOffset.java @@ -1,18 +1,17 @@ package com.vaadin.tests.components.datefield; -import java.time.LocalDate; +import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import com.vaadin.server.VaadinRequest; -import com.vaadin.shared.ui.datefield.DateResolution; +import com.vaadin.shared.ui.datefield.DateTimeResolution; import com.vaadin.tests.components.AbstractReindeerTestUI; -import com.vaadin.tests.components.TestDateField; -import com.vaadin.ui.AbstractDateField; +import com.vaadin.ui.DateTimeField; import com.vaadin.ui.Label; public class DateFieldDayResolutionOffset extends AbstractReindeerTestUI { - private final String initialDateString = "09/01/2014"; + private final String initialDateString = "09/01/2014 00:00:00"; @Override protected void setup(VaadinRequest request) { @@ -20,8 +19,7 @@ public class DateFieldDayResolutionOffset extends AbstractReindeerTestUI { dateValue.setId("dateValue"); final DateTimeFormatter dateformat = getDateFormat(); - final AbstractDateField<LocalDate, DateResolution> dateField = getDateField( - dateformat); + final DateTimeField dateField = getDateField(dateformat); addComponent(dateValue); addComponent(dateField); @@ -30,19 +28,18 @@ public class DateFieldDayResolutionOffset extends AbstractReindeerTestUI { .setValue(dateformat.format(dateField.getValue()))); } - private AbstractDateField<LocalDate, DateResolution> getDateField( - DateTimeFormatter dateformat) { - final AbstractDateField<LocalDate, DateResolution> dateField = new TestDateField(); - LocalDate initialDate = dateformat.parse(initialDateString, - LocalDate::from); - dateField.setResolution(DateResolution.DAY); + private DateTimeField getDateField(DateTimeFormatter dateformat) { + final DateTimeField dateField = new DateTimeField(); + LocalDateTime initialDate = dateformat.parse(initialDateString, + LocalDateTime::from); + dateField.setResolution(DateTimeResolution.DAY); dateField.setValue(initialDate); return dateField; } private DateTimeFormatter getDateFormat() { final DateTimeFormatter dateformat = DateTimeFormatter - .ofPattern("MM/dd/yyyy"); + .ofPattern("MM/dd/yyyy HH:mm:ss"); return dateformat; } diff --git a/uitest/src/main/java/com/vaadin/tests/components/datefield/DateTimeFieldChangeResolution.java b/uitest/src/main/java/com/vaadin/tests/components/datefield/DateTimeFieldChangeResolution.java new file mode 100644 index 0000000000..2bf161daf4 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/components/datefield/DateTimeFieldChangeResolution.java @@ -0,0 +1,63 @@ +/* + * Copyright 2000-2016 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.tests.components.datefield; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.shared.ui.datefield.DateTimeResolution; +import com.vaadin.tests.components.AbstractReindeerTestUI; +import com.vaadin.ui.Button; +import com.vaadin.ui.DateTimeField; +import com.vaadin.ui.HorizontalLayout; +import com.vaadin.ui.Label; + +public class DateTimeFieldChangeResolution extends AbstractReindeerTestUI { + + public static final String DATEFIELD_ID = "datefield"; + // The ID of a button is BUTTON_BASE_ID + resolution, e.g. button-month + public static final String BUTTON_BASE_ID = "button-"; + + @Override + protected void setup(VaadinRequest request) { + final DateTimeField dateField = new DateTimeField("Enter date"); + dateField.setResolution(DateTimeResolution.YEAR); + dateField.setId(DATEFIELD_ID); + addComponent(dateField); + + Label label = new Label("Select resolution"); + addComponent(label); + HorizontalLayout hlayout = new HorizontalLayout(); + addComponent(hlayout); + for (final DateTimeResolution value : DateTimeResolution.values()) { + String resolutionString = value.toString().toLowerCase(); + Button button = new Button(resolutionString); + button.addClickListener(event -> dateField.setResolution(value)); + button.setId(BUTTON_BASE_ID + resolutionString); + hlayout.addComponent(button); + } + + } + + @Override + protected String getTestDescription() { + return "The calendar should always have the correct resolution and the text field should be empty before selecting a date."; + } + + @Override + protected Integer getTicketNumber() { + return 14174; + } + +} 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 new file mode 100644 index 0000000000..1481439748 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/components/datefield/DateTimeFieldElementUI.java @@ -0,0 +1,24 @@ +package com.vaadin.tests.components.datefield; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractReindeerTestUI; +import com.vaadin.ui.DateTimeField; +import com.vaadin.ui.InlineDateTimeField; + +public class DateTimeFieldElementUI extends AbstractReindeerTestUI { + @Override + protected void setup(VaadinRequest request) { + addComponent(new DateTimeField()); + addComponent(new InlineDateTimeField()); + } + + @Override + protected Integer getTicketNumber() { + return 17090; + } + + @Override + protected String getTestDescription() { + return "DateTimeField should be accessible using TB4 DateTimeFieldElement."; + } +} diff --git a/uitest/src/main/java/com/vaadin/tests/components/datefield/DateTimeFieldFastForward.java b/uitest/src/main/java/com/vaadin/tests/components/datefield/DateTimeFieldFastForward.java new file mode 100644 index 0000000000..5bb2905f14 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/components/datefield/DateTimeFieldFastForward.java @@ -0,0 +1,39 @@ +/* + * Copyright 2000-2016 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.tests.components.datefield; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractReindeerTestUI; +import com.vaadin.ui.InlineDateTimeField; + +public class DateTimeFieldFastForward extends AbstractReindeerTestUI { + + @Override + protected void setup(VaadinRequest request) { + addComponent(new InlineDateTimeField()); + } + + @Override + protected String getTestDescription() { + return "Tests that right-click doesn't interfere with fast-forwarding (holding down left mouse button)."; + } + + @Override + protected Integer getTicketNumber() { + return 8012; + } + +} diff --git a/uitest/src/main/java/com/vaadin/tests/components/datefield/DateTimeFieldIsValid.java b/uitest/src/main/java/com/vaadin/tests/components/datefield/DateTimeFieldIsValid.java new file mode 100644 index 0000000000..7213cb229b --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/components/datefield/DateTimeFieldIsValid.java @@ -0,0 +1,53 @@ +package com.vaadin.tests.components.datefield; + +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUIWithLog; +import com.vaadin.ui.DateTimeField; + +public class DateTimeFieldIsValid extends AbstractTestUIWithLog { + + @Override + protected String getTestDescription() { + return "A dateField with invalid text should return false in isValid both when " + + "handling ValueChange event and after value is changed."; + } + + @Override + protected Integer getTicketNumber() { + return 14487; + } + + private String pattern = "dd/MM/yy H.mm"; + private DateTimeFormatter format = DateTimeFormatter.ofPattern(pattern); + + @Override + protected void setup(VaadinRequest request) { + final DateTimeField dateField = new DateTimeField("Insert Date: "); + dateField.setDateFormat(pattern); + + dateField.addValueChangeListener(event -> log("valueChange: value: " + + format(dateField.getValue()) + ", is valid: " + + (dateField.getErrorMessage() == null))); + addComponent(dateField); + addButton("check dateField", + event -> log("buttonClick: value: " + + format(dateField.getValue()) + ", is valid: " + + (dateField.getErrorMessage() == null))); + } + + /** + * @since + * @param value + * @return + */ + protected String format(LocalDateTime value) { + if (value != null) { + return format.format(value); + } else { + return null; + } + } +} diff --git a/uitest/src/main/java/com/vaadin/tests/components/datefield/DateTimeFieldKeyboardInput.java b/uitest/src/main/java/com/vaadin/tests/components/datefield/DateTimeFieldKeyboardInput.java new file mode 100644 index 0000000000..91de230b88 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/components/datefield/DateTimeFieldKeyboardInput.java @@ -0,0 +1,47 @@ +/* + * Copyright 2000-2016 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.tests.components.datefield; + +import java.time.LocalDateTime; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractReindeerTestUI; +import com.vaadin.ui.DateTimeField; +import com.vaadin.ui.Label; + +public class DateTimeFieldKeyboardInput extends AbstractReindeerTestUI { + + @Override + protected void setup(VaadinRequest request) { + final DateTimeField dateField = new DateTimeField("Select date", + LocalDateTime.of(2014, 1, 15, 7, 2)); + dateField.setDateFormat("dd.MM.yyyy HH:mm"); + addComponent(dateField); + dateField.addValueChangeListener( + event -> addComponent(new Label("Date has been changed."))); + } + + @Override + public Integer getTicketNumber() { + return 16677; + } + + @Override + public String getTestDescription() { + return "When a new date is entered in the text field using the keyboard, pressing the return key after typing the date, " + + "a label with the text 'Date has been changed' should appear."; + } +}
\ No newline at end of file diff --git a/uitest/src/main/java/com/vaadin/tests/components/datefield/DateTimeFieldReadOnly.java b/uitest/src/main/java/com/vaadin/tests/components/datefield/DateTimeFieldReadOnly.java new file mode 100644 index 0000000000..3b739579f1 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/components/datefield/DateTimeFieldReadOnly.java @@ -0,0 +1,45 @@ +package com.vaadin.tests.components.datefield; + +import java.time.LocalDateTime; +import java.util.Locale; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractReindeerTestUI; +import com.vaadin.ui.Button; +import com.vaadin.ui.DateTimeField; + +public class DateTimeFieldReadOnly extends AbstractReindeerTestUI { + + @Override + protected String getTestDescription() { + return "A read-only DateField should not show the popup button and not be editable."; + } + + @Override + protected Integer getTicketNumber() { + return 3163; + } + + @Override + protected void setup(VaadinRequest request) { + final DateTimeField timeField = new DateTimeField( + "A read-only datefield"); + timeField.setCaption(null); + timeField.setIcon(null); + timeField.setWidth("15em"); + timeField.addStyleName("timeField"); + timeField.setLocale(new Locale("fi")); + + // Set date so that testing always has same time + timeField.setValue(LocalDateTime.of(2009, 6, 12, 7, 34)); + timeField.setReadOnly(true); + + addComponent(timeField); + + Button b = new Button("Switch read-only"); + b.addClickListener( + event -> timeField.setReadOnly(!timeField.isReadOnly())); + + addComponent(b); + } +} diff --git a/uitest/src/main/java/com/vaadin/tests/components/datefield/DateTimeFieldTest.java b/uitest/src/main/java/com/vaadin/tests/components/datefield/DateTimeFieldTest.java new file mode 100644 index 0000000000..814cf03e53 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/components/datefield/DateTimeFieldTest.java @@ -0,0 +1,64 @@ +/* + * Copyright 2000-2016 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.tests.components.datefield; + +import java.util.LinkedHashMap; + +import com.vaadin.ui.DateTimeField; + +/** + * @author Vaadin Ltd + * + */ +public class DateTimeFieldTest + extends AbstractDateTimeFieldTest<DateTimeField> { + + @Override + protected Class<DateTimeField> getTestClass() { + return DateTimeField.class; + } + + @Override + protected void createActions() { + super.createActions(); + + createInputPromptSelectAction(CATEGORY_FEATURES); + createTextEnabledAction(CATEGORY_FEATURES); + } + + private void createInputPromptSelectAction(String category) { + LinkedHashMap<String, String> options = new LinkedHashMap<>(); + options.put("<none>", null); + options.put("Please enter date", "Please enter date"); + options.put("åäöÅÄÖ", "åäöÅÄÖ"); + + createSelectAction("Input prompt", category, options, "<none>", + new Command<DateTimeField, String>() { + + @Override + public void execute(DateTimeField c, String value, + Object data) { + c.setPlaceholder(value); + + } + }); + } + + private void createTextEnabledAction(String category) { + this.createBooleanAction("Text field enabled", category, true, + (field, value, data) -> field.setTextFieldEnabled(value)); + } +} diff --git a/uitest/src/main/java/com/vaadin/tests/components/datefield/DisabledInlineDateTimeField.java b/uitest/src/main/java/com/vaadin/tests/components/datefield/DisabledInlineDateTimeField.java new file mode 100644 index 0000000000..839da97bb4 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/components/datefield/DisabledInlineDateTimeField.java @@ -0,0 +1,50 @@ +/* + * Copyright 2000-2016 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.tests.components.datefield; + +import java.time.LocalDateTime; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractReindeerTestUI; +import com.vaadin.ui.InlineDateTimeField; + +public class DisabledInlineDateTimeField extends AbstractReindeerTestUI { + + @Override + protected void setup(VaadinRequest request) { + InlineDateTimeField df = new InlineDateTimeField("Disabled"); + LocalDateTime date = LocalDateTime.of(2014, 6, 5, 11, 34); + df.setValue(date); + df.setEnabled(false); + addComponent(df); + + df = new InlineDateTimeField("Read-only"); + df.setValue(date); + df.setReadOnly(true); + addComponent(df); + } + + @Override + protected String getTestDescription() { + return "Testing disabled and read-only modes of InlineDateField."; + } + + @Override + protected Integer getTicketNumber() { + return 10262; + } + +} diff --git a/uitest/src/main/java/com/vaadin/tests/components/datefield/InlineDateTimeFieldTest.java b/uitest/src/main/java/com/vaadin/tests/components/datefield/InlineDateTimeFieldTest.java new file mode 100644 index 0000000000..5beedfcff4 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/components/datefield/InlineDateTimeFieldTest.java @@ -0,0 +1,32 @@ +/* + * Copyright 2000-2016 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.tests.components.datefield; + +import com.vaadin.ui.InlineDateTimeField; + +/** + * @author Vaadin Ltd + * + */ +public class InlineDateTimeFieldTest + extends AbstractDateTimeFieldTest<InlineDateTimeField> { + + @Override + protected Class<InlineDateTimeField> getTestClass() { + return InlineDateTimeField.class; + } + +} diff --git a/uitest/src/main/java/com/vaadin/tests/components/datefield/PopupDateTimeFieldStates.java b/uitest/src/main/java/com/vaadin/tests/components/datefield/PopupDateTimeFieldStates.java new file mode 100644 index 0000000000..60c46d2f74 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/components/datefield/PopupDateTimeFieldStates.java @@ -0,0 +1,68 @@ +/* + * Copyright 2000-2016 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.tests.components.datefield; + +import java.time.LocalDateTime; +import java.util.Locale; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.DateTimeField; +import com.vaadin.ui.GridLayout; + +/** + * @author Vaadin Ltd + * + */ +public class PopupDateTimeFieldStates extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + setLocale(Locale.ENGLISH); + final GridLayout gridLayout = new GridLayout(2, 2); + gridLayout.setSpacing(true); + + gridLayout.addComponent(createPopupDateTimeField(true, true)); + gridLayout.addComponent(createPopupDateTimeField(true, false)); + gridLayout.addComponent(createPopupDateTimeField(false, true)); + gridLayout.addComponent(createPopupDateTimeField(false, false)); + + getLayout().addComponent(gridLayout); + } + + @Override + protected String getTestDescription() { + return "Test that PopupDateTimeField is rendered consistently across browsers"; + } + + @Override + protected Integer getTicketNumber() { + return 14565; + } + + private static DateTimeField createPopupDateTimeField(final boolean enabled, + final boolean textFieldEnabled) { + final DateTimeField popupDatefield = new DateTimeField(); + + popupDatefield.setValue(LocalDateTime.of(2014, 9, 3, 10, 34)); + popupDatefield.setCaption("Enabled: " + enabled + + ", Text field enabled: " + textFieldEnabled); + popupDatefield.setEnabled(enabled); + popupDatefield.setTextFieldEnabled(textFieldEnabled); + return popupDatefield; + } + +} diff --git a/uitest/src/main/java/com/vaadin/tests/components/datefield/PopupTimeClosingWithEsc.java b/uitest/src/main/java/com/vaadin/tests/components/datefield/PopupTimeClosingWithEsc.java new file mode 100644 index 0000000000..2b16397435 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/components/datefield/PopupTimeClosingWithEsc.java @@ -0,0 +1,62 @@ +/* + * Copyright 2000-2016 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.tests.components.datefield; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.shared.ui.datefield.DateTimeResolution; +import com.vaadin.tests.components.AbstractReindeerTestUI; +import com.vaadin.ui.DateTimeField; +import com.vaadin.ui.VerticalLayout; + +public class PopupTimeClosingWithEsc extends AbstractReindeerTestUI { + + @Override + protected void setup(VaadinRequest request) { + DateTimeField secondResolution = new DateTimeField("Second"); + secondResolution.setId("second"); + secondResolution.setResolution(DateTimeResolution.SECOND); + + DateTimeField minuteResolution = new DateTimeField("Minute"); + minuteResolution.setId("minute"); + minuteResolution.setResolution(DateTimeResolution.MINUTE); + + DateTimeField hourResolution = new DateTimeField("Hour"); + hourResolution.setId("hour"); + hourResolution.setResolution(DateTimeResolution.HOUR); + + DateTimeField month = new DateTimeField("Month"); + month.setId("month"); + month.setResolution(DateTimeResolution.MONTH); + + VerticalLayout layout = new VerticalLayout(); + layout.setMargin(true); + layout.setSpacing(true); + layout.addComponents(secondResolution, minuteResolution, hourResolution, + month); + setContent(layout); + } + + @Override + protected String getTestDescription() { + return "Testing that the DateField popup can be closed with ESC key."; + } + + @Override + protected Integer getTicketNumber() { + return 12317; + } + +} diff --git a/uitest/src/main/java/com/vaadin/tests/components/datefield/TimePopupSelection.java b/uitest/src/main/java/com/vaadin/tests/components/datefield/TimePopupSelection.java new file mode 100644 index 0000000000..ab63506649 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/components/datefield/TimePopupSelection.java @@ -0,0 +1,50 @@ +/* + * Copyright 2000-2016 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.tests.components.datefield; + +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.util.Locale; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.shared.ui.datefield.DateTimeResolution; +import com.vaadin.tests.components.AbstractTestUIWithLog; +import com.vaadin.ui.DateTimeField; + +/** + * @author Vaadin Ltd + * + */ +public class TimePopupSelection extends AbstractTestUIWithLog { + + private static final DateTimeFormatter FORMATTER = DateTimeFormatter + .ofPattern("dd/MM/yyyy HH:mm:ss"); + + @Override + protected void setup(VaadinRequest request) { + setLocale(Locale.ENGLISH); + DateTimeField field = new DateTimeField(); + field.setResolution(DateTimeResolution.SECOND); + + field.setValue(LocalDateTime.of(2017, 1, 13, 1, 0)); + + field.addValueChangeListener( + event -> log(FORMATTER.format(event.getValue()))); + + addComponent(field); + } + +} diff --git a/uitest/src/test/java/com/vaadin/tests/components/datefield/AriaDateTimeDisabledTest.java b/uitest/src/test/java/com/vaadin/tests/components/datefield/AriaDateTimeDisabledTest.java new file mode 100644 index 0000000000..b5e420e45b --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/components/datefield/AriaDateTimeDisabledTest.java @@ -0,0 +1,44 @@ +/* + * Copyright 2000-2016 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.tests.components.datefield; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +import com.vaadin.testbench.By; +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class AriaDateTimeDisabledTest extends MultiBrowserTest { + + @Test + public void verifyAriaDisabledAttributes() { + openTestURL(); + + // Expect aria-disabled="false" on the enabled DateField. + String ariaDisabled = driver + .findElement(By + .vaadin("/VVerticalLayout[0]/VPopupTimeCalendar[1]#popupButton")) + .getAttribute("aria-disabled"); + assertEquals("false", ariaDisabled); + + // Expect aria-disabled="true" on the disabled DateField. + ariaDisabled = driver.findElement(By.cssSelector(".v-disabled button")) + .getAttribute("aria-disabled"); + assertEquals("true", ariaDisabled); + } + +} diff --git a/uitest/src/test/java/com/vaadin/tests/components/datefield/CustomDateTimeFormatTest.java b/uitest/src/test/java/com/vaadin/tests/components/datefield/CustomDateTimeFormatTest.java new file mode 100644 index 0000000000..3016ef6cc8 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/components/datefield/CustomDateTimeFormatTest.java @@ -0,0 +1,39 @@ +/* + * Copyright 2000-2016 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.tests.components.datefield; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +import com.vaadin.testbench.By; +import com.vaadin.tests.tb3.MultiBrowserTest; + +/** + * @author Vaadin Ltd + * + */ +public class CustomDateTimeFormatTest extends MultiBrowserTest { + + @Test + public void checkCustomDateFormat() { + openTestURL(); + + String text = findElement(By.tagName("input")).getAttribute("value"); + assertEquals("1. tammikuuta 2010 klo 12.23.45", text); + } + +} diff --git a/uitest/src/test/java/com/vaadin/tests/components/datefield/DateFieldDayResolutionOffsetTest.java b/uitest/src/test/java/com/vaadin/tests/components/datefield/DateFieldDayResolutionOffsetTest.java index 9817ec4394..26f94be717 100644 --- a/uitest/src/test/java/com/vaadin/tests/components/datefield/DateFieldDayResolutionOffsetTest.java +++ b/uitest/src/test/java/com/vaadin/tests/components/datefield/DateFieldDayResolutionOffsetTest.java @@ -21,7 +21,7 @@ public class DateFieldDayResolutionOffsetTest extends MultiBrowserTest { select2ndOfSeptember(); LabelElement dateValue = $(LabelElement.class).id("dateValue"); - assertThat(dateValue.getText(), is("09/02/2014")); + assertThat(dateValue.getText(), is("09/02/2014 00:00:00")); } private void select2ndOfSeptember() { diff --git a/uitest/src/test/java/com/vaadin/tests/components/datefield/DateTimeFieldChangeResolutionTest.java b/uitest/src/test/java/com/vaadin/tests/components/datefield/DateTimeFieldChangeResolutionTest.java new file mode 100644 index 0000000000..cd0b6212c7 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/components/datefield/DateTimeFieldChangeResolutionTest.java @@ -0,0 +1,199 @@ +/* + * Copyright 2000-2016 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.tests.components.datefield; + +import static com.vaadin.tests.components.datefield.DateFieldChangeResolution.BUTTON_BASE_ID; +import static com.vaadin.tests.components.datefield.DateFieldChangeResolution.DATEFIELD_ID; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; +import org.openqa.selenium.Keys; +import org.openqa.selenium.WebElement; + +import com.vaadin.shared.ui.datefield.DateTimeResolution; +import com.vaadin.testbench.By; +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class DateTimeFieldChangeResolutionTest extends MultiBrowserTest { + + private WebElement dateFieldButton, textField; + private WebElement resolutionSecond, resolutionMinute, resolutionHour, + resolutionDay, resolutionMonth, resolutionYear; + + @Test + public void changeResolutionBetweenYearAndMonth() throws Exception { + initialize(); + click(resolutionMonth); + checkHeaderAndBody(DateTimeResolution.MONTH, true); + click(resolutionYear); + checkHeaderAndBody(DateTimeResolution.YEAR, true); + } + + @Test + public void changeResolutionBetweenYearAndSecond() throws Exception { + initialize(); + click(resolutionSecond); + checkHeaderAndBody(DateTimeResolution.SECOND, true); + click(resolutionYear); + checkHeaderAndBody(DateTimeResolution.YEAR, true); + } + + @Test + public void changeResolutionToDayThenMonth() throws Exception { + initialize(); + checkHeaderAndBody(DateTimeResolution.YEAR, true); // check the initial + // state + click(resolutionDay); + checkHeaderAndBody(DateTimeResolution.DAY, true); + click(resolutionMonth); + checkHeaderAndBody(DateTimeResolution.MONTH, true); + } + + @Test + public void setDateAndChangeResolution() throws Exception { + initialize(); + // Set the date to previous month. + click(resolutionMonth); + openPopupDateField(); + click(driver.findElement(By.className("v-button-prevmonth"))); + closePopupDateField(); + assertFalse( + "The text field of the calendar should not be empty after selecting a date", + textField.getAttribute("value").isEmpty()); + // Change resolutions and check that the selected date is not lost and + // that the calendar has the correct resolution. + click(resolutionHour); + checkHeaderAndBody(DateTimeResolution.HOUR, false); + click(resolutionYear); + checkHeaderAndBody(DateTimeResolution.YEAR, false); + click(resolutionMinute); + checkHeaderAndBody(DateTimeResolution.MINUTE, false); + } + + private void initialize() { + openTestURL(); + WebElement dateField = driver.findElement(By.id(DATEFIELD_ID)); + dateFieldButton = dateField + .findElement(By.className("v-datefield-button")); + textField = dateField + .findElement(By.className("v-datefield-textfield")); + resolutionSecond = driver.findElement(By.id(BUTTON_BASE_ID + "second")); + resolutionMinute = driver.findElement(By.id(BUTTON_BASE_ID + "minute")); + resolutionHour = driver.findElement(By.id(BUTTON_BASE_ID + "hour")); + resolutionDay = driver.findElement(By.id(BUTTON_BASE_ID + "day")); + resolutionMonth = driver.findElement(By.id(BUTTON_BASE_ID + "month")); + resolutionYear = driver.findElement(By.id(BUTTON_BASE_ID + "year")); + } + + private void checkHeaderAndBody(DateTimeResolution resolution, + boolean textFieldIsEmpty) throws Exception { + // Popup date field has all kinds of strange timers on the + // client side + sleep(100); + // Open the popup calendar, perform checks and close the popup. + openPopupDateField(); + if (resolution.compareTo(DateTimeResolution.MONTH) <= 0) { + checkMonthHeader(); + } else { + checkYearHeader(); + } + if (resolution.compareTo(DateTimeResolution.DAY) <= 0) { + assertTrue( + "A calendar with the chosen resolution should have a body", + calendarHasBody()); + } else { + assertFalse( + "A calendar with the chosen resolution should not have a body", + calendarHasBody()); + } + if (textFieldIsEmpty) { + assertTrue("The text field of the calendar should be empty", + textField.getAttribute("value").isEmpty()); + } else { + assertFalse("The text field of the calendar should not be empty", + textField.getAttribute("value").isEmpty()); + } + closePopupDateField(); + } + + private void checkMonthHeader() { + checkHeaderForYear(); + checkHeaderForMonth(true); + } + + private void checkYearHeader() { + checkHeaderForYear(); + checkHeaderForMonth(false); + } + + private boolean calendarHasBody() { + return isElementPresent(By.className("v-datefield-calendarpanel-body")); + } + + private void checkHeaderForMonth(boolean buttonsExpected) { + // If buttonsExpected is true, check that there are buttons for changing + // the month. Otherwise check that there are no such buttons. + if (buttonsExpected) { + assertTrue( + "The calendar should have a button for switching to the previous month", + isElementPresent(By.cssSelector( + ".v-datefield-calendarpanel-header .v-datefield-calendarpanel-prevmonth .v-button-prevmonth"))); + assertTrue( + "The calendar should have a button for switching to the next month", + isElementPresent(By.cssSelector( + ".v-datefield-calendarpanel-header .v-datefield-calendarpanel-nextmonth .v-button-nextmonth"))); + } else { + assertFalse( + "The calendar should not have a button for switching to the previous month", + isElementPresent(By.cssSelector( + ".v-datefield-calendarpanel-header .v-datefield-calendarpanel-prevmonth .v-button-prevmonth"))); + assertFalse( + "The calendar should not have a button for switching to the next month", + isElementPresent(By.cssSelector( + ".v-datefield-calendarpanel-header .v-datefield-calendarpanel-nextmonth .v-button-nextmonth"))); + } + } + + private void checkHeaderForYear() { + assertTrue( + "The calendar should have a button for switching to the previous year", + isElementPresent(By.cssSelector( + ".v-datefield-calendarpanel-header .v-datefield-calendarpanel-prevyear .v-button-prevyear"))); + assertTrue("The calendar header should show the selected year", + isElementPresent(By.cssSelector( + ".v-datefield-calendarpanel-header .v-datefield-calendarpanel-month"))); + assertTrue( + "The calendar should have a button for switching to the next year", + isElementPresent(By.cssSelector( + ".v-datefield-calendarpanel-header .v-datefield-calendarpanel-nextyear .v-button-nextyear"))); + + } + + private void click(WebElement element) { + testBenchElement(element).click(5, 5); + } + + private void openPopupDateField() { + click(dateFieldButton); + } + + private void closePopupDateField() { + WebElement element = driver + .findElement(By.cssSelector(".v-datefield-calendarpanel")); + element.sendKeys(Keys.ESCAPE); + } +}
\ No newline at end of file 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 new file mode 100644 index 0000000000..4b2b2719c4 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/components/datefield/DateTimeFieldElementTest.java @@ -0,0 +1,26 @@ +package com.vaadin.tests.components.datefield; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.core.Is.is; + +import org.junit.Test; + +import com.vaadin.testbench.customelements.DateTimeFieldElement; +import com.vaadin.testbench.customelements.InlineDateTimeFieldElement; +import com.vaadin.tests.tb3.SingleBrowserTest; + +public class DateTimeFieldElementTest extends SingleBrowserTest { + + @Test + public void dateFieldElementIsLocated() { + openTestURL(); + + assertThat($(DateTimeFieldElement.class).all().size(), is(1)); + assertThat($(InlineDateTimeFieldElement.class).all().size(), is(1)); + } + + @Override + protected Class<?> getUIClass() { + return DateTimeFieldElementUI.class; + } +}
\ No newline at end of file diff --git a/uitest/src/test/java/com/vaadin/tests/components/datefield/DateTimeFieldFastForwardTest.java b/uitest/src/test/java/com/vaadin/tests/components/datefield/DateTimeFieldFastForwardTest.java new file mode 100644 index 0000000000..f42afe1779 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/components/datefield/DateTimeFieldFastForwardTest.java @@ -0,0 +1,72 @@ +/* + * Copyright 2000-2016 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.tests.components.datefield; + +import static org.junit.Assert.assertEquals; + +import org.junit.Assert; +import org.junit.Test; +import org.openqa.selenium.By; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.interactions.Actions; + +import com.vaadin.testbench.elements.VerticalLayoutElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class DateTimeFieldFastForwardTest extends MultiBrowserTest { + + @Test + public void testFastForwardOnRightMouseClick() throws Exception { + openTestURL(); + String firstMonth = getSelectedMonth(); + WebElement nextMonthButton = driver + .findElement(By.className("v-button-nextmonth")); + + // Click and hold left mouse button to start fast forwarding. + new Actions(driver).clickAndHold(nextMonthButton).perform(); + sleep(1000); + + // Right click and release the left button. + + new Actions(driver).contextClick(nextMonthButton) + .release(nextMonthButton).perform(); + + // Now the fast forwarding should be ended, get the expected month. + String expectedMonth = getSelectedMonth(); + + // Make browser context menu disappear, since it will crash IE + $(VerticalLayoutElement.class).first().click(); + + Assert.assertFalse("Month did not change during fast forward", + firstMonth.equals(expectedMonth)); + + // Wait for a while. + Thread.sleep(1000); + + // Verify that we didn't fast forward any further after the left button + // was released. + String actualMonth = getSelectedMonth(); + assertEquals(expectedMonth, actualMonth); + } + + private String getSelectedMonth() { + return driver + .findElement( + By.className("v-inline-datefield-calendarpanel-month")) + .getText(); + } + +} diff --git a/uitest/src/test/java/com/vaadin/tests/components/datefield/DateTimeFieldIsValidTest.java b/uitest/src/test/java/com/vaadin/tests/components/datefield/DateTimeFieldIsValidTest.java new file mode 100644 index 0000000000..986db81c93 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/components/datefield/DateTimeFieldIsValidTest.java @@ -0,0 +1,66 @@ +/* + * Copyright 2000-2016 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.tests.components.datefield; + +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.customelements.AbstractDateFieldElement; +import com.vaadin.testbench.elements.ButtonElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +/** + * @author Vaadin Ltd + */ +public class DateTimeFieldIsValidTest extends MultiBrowserTest { + + @Test + public void testInvalidText() throws Exception { + openTestURL(); + + waitForElementVisible(By.id("Log")); + waitForElementVisible(By.className("v-datefield")); + WebElement dateTextbox = $(AbstractDateFieldElement.class).first() + .findElement(By.className("v-textfield")); + ButtonElement button = $(ButtonElement.class).first(); + + dateTextbox.sendKeys("01/01/01 1.12", Keys.TAB); + assertLogText("1. valueChange: value: 01/01/01 1.12, is valid: true"); + button.click(); + assertLogText("2. buttonClick: value: 01/01/01 1.12, is valid: true"); + + dateTextbox.sendKeys("lala", Keys.TAB); + assertLogText("3. valueChange: value: null, is valid: false"); + button.click(); + assertLogText("4. buttonClick: value: null, is valid: false"); + + dateTextbox.clear(); + dateTextbox.sendKeys("02/02/02 2.34", Keys.TAB); + assertLogText("5. valueChange: value: 02/02/02 2.34, is valid: true"); + button.click(); + assertLogText("6. buttonClick: value: 02/02/02 2.34, is valid: true"); + } + + private void assertLogText(String expected) throws Exception { + String text = findElement(By.vaadin("PID_SLog_row_0")).getText(); + Assert.assertTrue("Expected '" + expected + "' found '" + text + "'", + text.equals(expected)); + } + +} diff --git a/uitest/src/test/java/com/vaadin/tests/components/datefield/DateTimeFieldKeyboardInputTest.java b/uitest/src/test/java/com/vaadin/tests/components/datefield/DateTimeFieldKeyboardInputTest.java new file mode 100644 index 0000000000..715e3e67f7 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/components/datefield/DateTimeFieldKeyboardInputTest.java @@ -0,0 +1,43 @@ +/* + * Copyright 2000-2016 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.tests.components.datefield; + +import static org.junit.Assert.assertTrue; + +import org.junit.Test; +import org.openqa.selenium.By; +import org.openqa.selenium.Keys; +import org.openqa.selenium.WebElement; + +import com.vaadin.testbench.customelements.DateTimeFieldElement; +import com.vaadin.testbench.elements.LabelElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class DateTimeFieldKeyboardInputTest extends MultiBrowserTest { + + @Test + public void testValueChangeEvent() { + openTestURL(); + WebElement dateFieldText = $(DateTimeFieldElement.class).first() + .findElement(By.tagName("input")); + dateFieldText.clear(); + int numLabelsBeforeUpdate = $(LabelElement.class).all().size(); + dateFieldText.sendKeys("20.10.2013 7:2", Keys.RETURN); + int numLabelsAfterUpdate = $(LabelElement.class).all().size(); + assertTrue("Changing the date failed.", + numLabelsAfterUpdate == numLabelsBeforeUpdate + 1); + } +}
\ No newline at end of file diff --git a/uitest/src/test/java/com/vaadin/tests/components/datefield/DateTimeFieldReadOnlyTest.java b/uitest/src/test/java/com/vaadin/tests/components/datefield/DateTimeFieldReadOnlyTest.java new file mode 100644 index 0000000000..a4e79ac95a --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/components/datefield/DateTimeFieldReadOnlyTest.java @@ -0,0 +1,46 @@ +package com.vaadin.tests.components.datefield; + +import java.io.IOException; + +import org.junit.Test; +import org.openqa.selenium.Keys; + +import com.vaadin.testbench.By; +import com.vaadin.testbench.customelements.AbstractDateFieldElement; +import com.vaadin.testbench.elements.ButtonElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class DateTimeFieldReadOnlyTest extends MultiBrowserTest { + + @Test + public void readOnlyDateFieldPopupShouldNotOpen() + throws IOException, InterruptedException { + openTestURL(); + + compareScreen("initial-date"); + toggleReadOnly(); + + openPopup(); + compareScreen("readwrite-popup-date"); + + closePopup(); + toggleReadOnly(); + compareScreen("readonly-date"); + } + + private void closePopup() { + findElement(By.className("v-datefield-calendarpanel")) + .sendKeys(Keys.RETURN); + } + + private void openPopup() { + // waiting for openPopup() in TB4 beta1: + // http://dev.vaadin.com/ticket/13766 + $(AbstractDateFieldElement.class).first() + .findElement(By.tagName("button")).click(); + } + + private void toggleReadOnly() { + $(ButtonElement.class).caption("Switch read-only").first().click(); + } +} diff --git a/uitest/src/test/java/com/vaadin/tests/components/datefield/AbstractDateFieldTestTest.java b/uitest/src/test/java/com/vaadin/tests/components/datefield/DateTimeFieldTestTest.java index caaf84b8f7..e835ac5158 100644 --- a/uitest/src/test/java/com/vaadin/tests/components/datefield/AbstractDateFieldTestTest.java +++ b/uitest/src/test/java/com/vaadin/tests/components/datefield/DateTimeFieldTestTest.java @@ -25,7 +25,11 @@ import org.openqa.selenium.interactions.Actions; import com.vaadin.testbench.elements.NotificationElement; import com.vaadin.tests.tb3.MultiBrowserTest; -public class AbstractDateFieldTestTest extends MultiBrowserTest { +/** + * @author Vaadin Ltd + * + */ +public class DateTimeFieldTestTest extends MultiBrowserTest { @Test public void testMakingRequired() throws InterruptedException { diff --git a/uitest/src/test/java/com/vaadin/tests/components/datefield/DisabledInlineDateTimeFieldTest.java b/uitest/src/test/java/com/vaadin/tests/components/datefield/DisabledInlineDateTimeFieldTest.java new file mode 100644 index 0000000000..621666c924 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/components/datefield/DisabledInlineDateTimeFieldTest.java @@ -0,0 +1,79 @@ +/* + * Copyright 2000-2016 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.tests.components.datefield; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; + +import org.junit.Test; +import org.openqa.selenium.By; +import org.openqa.selenium.WebElement; + +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class DisabledInlineDateTimeFieldTest extends MultiBrowserTest { + + @Test + public void testDisabled() { + openTestURL(); + testNextMonthControls(".v-disabled"); + testDaySelection(".v-disabled"); + } + + @Test + public void testReadOnly() { + openTestURL(); + testNextMonthControls(".v-readonly"); + testDaySelection(".v-readonly"); + } + + private void testNextMonthControls(String cssClass) { + // Get the currently selected month. + String expectedMonth = getSelectedMonth(cssClass); + + // Attempt to click the next month button. + driver.findElement(By.cssSelector(cssClass + " .v-button-nextmonth")) + .click(); + + // Assert that we did not navigate to next month. + String actualMonth = getSelectedMonth(cssClass); + assertEquals(expectedMonth, actualMonth); + } + + private void testDaySelection(String cssClass) { + // We know that the first day element is not selected, because of the + // fixed date in the test. + WebElement nonSelectedDay = driver.findElement(By.cssSelector( + cssClass + " .v-inline-datefield-calendarpanel-day")); + + // Assert it is not selected before click. + assertFalse(nonSelectedDay.getAttribute("class").contains("selected")); + + // Click on the non-selected day. + nonSelectedDay.click(); + + // Assert that clicking did not select the day. + assertFalse(nonSelectedDay.getAttribute("class").contains("selected")); + } + + private String getSelectedMonth(String selectorPrefix) { + return driver + .findElement(By.cssSelector(selectorPrefix + + " .v-inline-datefield-calendarpanel-month")) + .getText(); + } + +} diff --git a/uitest/src/test/java/com/vaadin/tests/components/datefield/InlineDateTimeFieldTestTest.java b/uitest/src/test/java/com/vaadin/tests/components/datefield/InlineDateTimeFieldTestTest.java new file mode 100644 index 0000000000..1ddd9ca6b0 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/components/datefield/InlineDateTimeFieldTestTest.java @@ -0,0 +1,37 @@ +/* + * Copyright 2000-2016 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.tests.components.datefield; + +import org.junit.Test; + +import com.google.gwt.editor.client.Editor.Ignore; + +/** + * Reuse tests from super DateTimeFieldTestTest class. + * + * @author Vaadin Ltd + * + */ +public class InlineDateTimeFieldTestTest extends DateTimeFieldTestTest { + + @Override + @Test + @Ignore + public void testValueAfterOpeningPopupInRequiredField() + throws InterruptedException { + // no popup for inline date field + } +} diff --git a/uitest/src/test/java/com/vaadin/tests/components/datefield/PopupDateFieldStatesTest.java b/uitest/src/test/java/com/vaadin/tests/components/datefield/PopupDateFieldStatesTest.java index 5f82bab831..7d642faf70 100644 --- a/uitest/src/test/java/com/vaadin/tests/components/datefield/PopupDateFieldStatesTest.java +++ b/uitest/src/test/java/com/vaadin/tests/components/datefield/PopupDateFieldStatesTest.java @@ -1,8 +1,11 @@ package com.vaadin.tests.components.datefield; import java.io.IOException; +import java.util.regex.Pattern; import org.junit.Test; +import org.openqa.selenium.By; +import org.openqa.selenium.WebElement; import com.vaadin.tests.tb3.MultiBrowserTest; @@ -13,6 +16,15 @@ public class PopupDateFieldStatesTest extends MultiBrowserTest { throws IOException, InterruptedException { openTestURL(); + // wait until loading indicator becomes invisible + WebElement loadingIndicator = findElement( + By.className("v-loading-indicator")); + Pattern pattern = Pattern.compile("display: *none;"); + waitUntil(driver -> { + return pattern.matcher(loadingIndicator.getAttribute("style")) + .find(); + }); + compareScreen("dateFieldStates"); } diff --git a/uitest/src/test/java/com/vaadin/tests/components/datefield/PopupDateTimeFieldStatesTest.java b/uitest/src/test/java/com/vaadin/tests/components/datefield/PopupDateTimeFieldStatesTest.java new file mode 100644 index 0000000000..bd97b6342b --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/components/datefield/PopupDateTimeFieldStatesTest.java @@ -0,0 +1,31 @@ +package com.vaadin.tests.components.datefield; + +import java.io.IOException; +import java.util.regex.Pattern; + +import org.junit.Test; +import org.openqa.selenium.By; +import org.openqa.selenium.WebElement; + +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class PopupDateTimeFieldStatesTest extends MultiBrowserTest { + + @Test + public void readOnlyDateFieldPopupShouldNotOpen() + throws IOException, InterruptedException { + openTestURL(); + + // wait until loading indicator becomes invisible + WebElement loadingIndicator = findElement( + By.className("v-loading-indicator")); + Pattern pattern = Pattern.compile("display: *none;"); + waitUntil(driver -> { + return pattern.matcher(loadingIndicator.getAttribute("style")) + .find(); + }); + + compareScreen("dateFieldStates"); + } + +} diff --git a/uitest/src/test/java/com/vaadin/tests/components/datefield/PopupTimeClosingWithEscTest.java b/uitest/src/test/java/com/vaadin/tests/components/datefield/PopupTimeClosingWithEscTest.java new file mode 100644 index 0000000000..6bb7a67e1c --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/components/datefield/PopupTimeClosingWithEscTest.java @@ -0,0 +1,63 @@ +/* + * Copyright 2000-2016 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.tests.components.datefield; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; +import org.openqa.selenium.By; +import org.openqa.selenium.Keys; + +import com.vaadin.testbench.annotations.RunLocally; +import com.vaadin.testbench.parallel.Browser; +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class PopupTimeClosingWithEscTest extends MultiBrowserTest { + + @Test + public void testPopupClosing() { + openTestURL(); + + testPopupClosing("second"); + testPopupClosing("minute"); + testPopupClosing("hour"); + testPopupClosing("month"); + } + + private void testPopupClosing(String dateFieldId) { + openPopup(dateFieldId); + assertTrue(isPopupVisible()); + sendEscToCalendarPanel(); + assertFalse(isPopupVisible()); + } + + private void openPopup(String dateFieldId) { + driver.findElement( + vaadinLocator("PID_S" + dateFieldId + "#popupButton")).click(); + } + + private boolean isPopupVisible() { + return !(driver.findElements(By.cssSelector(".v-datefield-popup")) + .isEmpty()); + } + + private void sendEscToCalendarPanel() { + driver.findElement(By.cssSelector(".v-datefield-calendarpanel")) + .sendKeys(Keys.ESCAPE); + } + +} diff --git a/uitest/src/test/java/com/vaadin/tests/components/datefield/TimePopupSelectionTest.java b/uitest/src/test/java/com/vaadin/tests/components/datefield/TimePopupSelectionTest.java new file mode 100644 index 0000000000..a6226de976 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/components/datefield/TimePopupSelectionTest.java @@ -0,0 +1,67 @@ +/* + * Copyright 2000-2016 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.tests.components.datefield; + +import java.util.List; + +import org.junit.Assert; +import org.junit.Test; +import org.openqa.selenium.Keys; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.ui.Select; + +import com.vaadin.testbench.By; +import com.vaadin.testbench.customelements.DateTimeFieldElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +/** + * @author Vaadin Ltd + * + */ +public class TimePopupSelectionTest extends MultiBrowserTest { + + @Test + public void selectDateAndTimeFromPopup() { + openTestURL(); + + DateTimeFieldElement field = $(DateTimeFieldElement.class).first(); + Assert.assertEquals("1/13/17 01:00:00 AM", field.getValue()); + + field.openPopup(); + + List<WebElement> timeSelects = findElement( + By.className("v-datefield-calendarpanel-time")) + .findElements(By.tagName("select")); + + new Select(timeSelects.get(0)).selectByValue("09"); + Assert.assertEquals("1/13/17 09:00:00 AM", field.getValue()); + + new Select(timeSelects.get(1)).selectByValue("35"); + Assert.assertEquals("1/13/17 09:35:00 AM", field.getValue()); + + new Select(timeSelects.get(2)).selectByValue("41"); + Assert.assertEquals("1/13/17 09:35:41 AM", field.getValue()); + + closePopup(); + + waitUntil(driver -> getLogRow(0).equals("1. 13/01/2017 09:35:41")); + } + + private void closePopup() { + findElement(By.className("v-datefield-calendarpanel")) + .sendKeys(Keys.ENTER); + } +} |