diff --git a/vaadin-date-time-picker-flow-parent/vaadin-date-time-picker-flow-integration-tests/src/main/java/com/vaadin/flow/component/datetimepicker/DateTimePickerI18nPage.java b/vaadin-date-time-picker-flow-parent/vaadin-date-time-picker-flow-integration-tests/src/main/java/com/vaadin/flow/component/datetimepicker/DateTimePickerI18nPage.java new file mode 100644 index 00000000000..880085d275d --- /dev/null +++ b/vaadin-date-time-picker-flow-parent/vaadin-date-time-picker-flow-integration-tests/src/main/java/com/vaadin/flow/component/datetimepicker/DateTimePickerI18nPage.java @@ -0,0 +1,58 @@ +/* + * Copyright 2000-2024 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.flow.component.datetimepicker; + +import com.vaadin.flow.component.html.Div; +import com.vaadin.flow.component.html.NativeButton; +import com.vaadin.flow.router.Route; + +@Route("vaadin-date-time-picker/i18n") +public class DateTimePickerI18nPage extends Div { + + public DateTimePickerI18nPage() { + DateTimePicker dateTimePicker = new DateTimePicker(); + + DateTimePicker.DateTimePickerI18n i18n = new DateTimePicker.DateTimePickerI18n(); + i18n.setDateLabel("date"); + i18n.setTimeLabel("time"); + + NativeButton setI18n = new NativeButton("Set i18n", + event -> dateTimePicker.setI18n(i18n)); + setI18n.setId("set-i18n"); + + NativeButton setDateAriaLabel = new NativeButton("Set date aria label", + event -> dateTimePicker.setDateAriaLabel("Custom date")); + setDateAriaLabel.setId("set-date-aria-label"); + + NativeButton removeDateAriaLabel = new NativeButton( + "Remove date aria label", + event -> dateTimePicker.setDateAriaLabel(null)); + removeDateAriaLabel.setId("remove-date-aria-label"); + + NativeButton setTimeAriaLabel = new NativeButton("Set time aria label", + event -> dateTimePicker.setTimeAriaLabel("Custom time")); + setTimeAriaLabel.setId("set-time-aria-label"); + + NativeButton removeTimeAriaLabel = new NativeButton( + "Remove time aria label", + event -> dateTimePicker.setTimeAriaLabel(null)); + removeTimeAriaLabel.setId("remove-time-aria-label"); + + add(dateTimePicker, setI18n, setDateAriaLabel, removeDateAriaLabel, + setTimeAriaLabel, removeTimeAriaLabel); + } + +} diff --git a/vaadin-date-time-picker-flow-parent/vaadin-date-time-picker-flow-integration-tests/src/test/java/com/vaadin/flow/component/datetimepicker/DateTimePickerI18nIT.java b/vaadin-date-time-picker-flow-parent/vaadin-date-time-picker-flow-integration-tests/src/test/java/com/vaadin/flow/component/datetimepicker/DateTimePickerI18nIT.java new file mode 100644 index 00000000000..ab89e802d73 --- /dev/null +++ b/vaadin-date-time-picker-flow-parent/vaadin-date-time-picker-flow-integration-tests/src/test/java/com/vaadin/flow/component/datetimepicker/DateTimePickerI18nIT.java @@ -0,0 +1,93 @@ +/* + * Copyright 2000-2024 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.flow.component.datetimepicker; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import com.vaadin.flow.component.datetimepicker.testbench.DateTimePickerElement; +import com.vaadin.tests.AbstractComponentIT; +import com.vaadin.flow.testutil.TestPath; + +@TestPath("vaadin-date-time-picker/i18n") +public class DateTimePickerI18nIT extends AbstractComponentIT { + + private DateTimePickerElement dateTimePicker; + + @Before + public void init() { + open(); + dateTimePicker = $(DateTimePickerElement.class).first(); + } + + @Test + public void setAndRemoveDateAriaLabel_assertI18nProperty() { + $("button").id("set-date-aria-label").click(); + Assert.assertEquals("Custom date", + dateTimePicker.getPropertyString("i18n", "dateLabel")); + + $("button").id("remove-date-aria-label").click(); + Assert.assertNull( + dateTimePicker.getPropertyString("i18n", "dateLabel")); + } + + @Test + public void setAndRemoveTimeAriaLabel_assertI18nProperty() { + $("button").id("set-time-aria-label").click(); + Assert.assertEquals("Custom time", + dateTimePicker.getPropertyString("i18n", "timeLabel")); + + $("button").id("remove-time-aria-label").click(); + Assert.assertNull( + dateTimePicker.getPropertyString("i18n", "timeLabel")); + } + + @Test + public void setI18n_assertI18nProperty() { + $("button").id("set-i18n").click(); + Assert.assertEquals("date", + dateTimePicker.getPropertyString("i18n", "dateLabel")); + Assert.assertEquals("time", + dateTimePicker.getPropertyString("i18n", "timeLabel")); + } + + @Test + public void setI18n_setAndRemoveDateAriaLabel_assertI18nProperty() { + $("button").id("set-i18n").click(); + + $("button").id("set-date-aria-label").click(); + Assert.assertEquals("Custom date", + dateTimePicker.getPropertyString("i18n", "dateLabel")); + + $("button").id("remove-date-aria-label").click(); + Assert.assertEquals("date", + dateTimePicker.getPropertyString("i18n", "dateLabel")); + } + + @Test + public void setI18n_setAndRemoveTimeAriaLabel_assertI18nProperty() { + $("button").id("set-i18n").click(); + + $("button").id("set-time-aria-label").click(); + Assert.assertEquals("Custom time", + dateTimePicker.getPropertyString("i18n", "timeLabel")); + + $("button").id("remove-time-aria-label").click(); + Assert.assertEquals("time", + dateTimePicker.getPropertyString("i18n", "timeLabel")); + } +} diff --git a/vaadin-date-time-picker-flow-parent/vaadin-date-time-picker-flow/src/main/java/com/vaadin/flow/component/datetimepicker/DateTimePicker.java b/vaadin-date-time-picker-flow-parent/vaadin-date-time-picker-flow/src/main/java/com/vaadin/flow/component/datetimepicker/DateTimePicker.java index dcda2ab5ef7..fb01715cec4 100644 --- a/vaadin-date-time-picker-flow-parent/vaadin-date-time-picker-flow/src/main/java/com/vaadin/flow/component/datetimepicker/DateTimePicker.java +++ b/vaadin-date-time-picker-flow-parent/vaadin-date-time-picker-flow/src/main/java/com/vaadin/flow/component/datetimepicker/DateTimePicker.java @@ -440,7 +440,7 @@ public void setDateAriaLabel(String dateLabel) { /** * Gets the aria-label suffix for the date picker. *

- * Note, this method will return the last value passed to + * Note: this method will return the last value passed to * {@link #setDateAriaLabel(String)}, not the value currently set on the * `aria-label` attribute of the date picker input element. * @@ -472,7 +472,7 @@ public void setTimeAriaLabel(String timeLabel) { /** * Gets the aria-label suffix for the time picker. *

- * Note, this method will return the last value passed to + * Note: this method will return the last value passed to * {@link #setTimeAriaLabel(String)}, not the value currently set on the * `aria-label` attribute of the time picker input element. * @@ -897,11 +897,11 @@ private void updateI18n() { JsonObject i18nJson = (JsonObject) JsonSerializer.toJson(i18nObject); if (dateAriaLabel != null) { - i18nJson.put("dateAriaLabel", dateAriaLabel); + i18nJson.put("dateLabel", dateAriaLabel); } if (timeAriaLabel != null) { - i18nJson.put("timeAriaLabel", timeAriaLabel); + i18nJson.put("timeLabel", timeAriaLabel); } getElement().setPropertyJson("i18n", i18nJson);