Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vursen committed May 29, 2024
1 parent c1e4e69 commit bfcbf42
Show file tree
Hide file tree
Showing 3 changed files with 155 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -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);
}

}
Original file line number Diff line number Diff line change
@@ -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"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ public void setDateAriaLabel(String dateLabel) {
/**
* Gets the aria-label suffix for the date picker.
* <p>
* 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.
*
Expand Down Expand Up @@ -472,7 +472,7 @@ public void setTimeAriaLabel(String timeLabel) {
/**
* Gets the aria-label suffix for the time picker.
* <p>
* 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.
*
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit bfcbf42

Please sign in to comment.