aboutsummaryrefslogtreecommitdiffstats
path: root/uitest/src/main/java/com/vaadin/tests/components/datefield/DateFields.java
blob: 86bee4af69608a73b6aa49fb24ff18da5dfa551d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package com.vaadin.tests.components.datefield;

import java.time.LocalDate;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;

import com.vaadin.annotations.Widgetset;
import com.vaadin.shared.ui.datefield.DateResolution;
import com.vaadin.tests.components.ComponentTestCase;
import com.vaadin.ui.Component;
import com.vaadin.ui.DateField;

@SuppressWarnings("serial")
@Widgetset("com.vaadin.DefaultWidgetSet")
public class DateFields extends ComponentTestCase<DateField> {

    private static final Locale[] LOCALES = { Locale.US, Locale.TAIWAN,
            new Locale("fi", "FI") };

    @Override
    protected Class<DateField> getTestClass() {
        return DateField.class;
    }

    @Override
    protected void initializeComponents() {

        for (Locale locale : LOCALES) {
            DateField pd = createPopupDateField("Undefined width", "-1",
                    locale);
            pd.setId("Locale-" + locale + "-undefined-wide");
            addTestComponent(pd);
            pd = createPopupDateField("500px width", "500px", locale);
            pd.setId("Locale-" + locale + "-500px-wide");
            addTestComponent(pd);
            pd = createPopupDateField("Initially empty", "", locale);
            pd.setValue(null);
            pd.setId("Locale-" + locale + "-initially-empty");
            addTestComponent(pd);
        }

    }

    private DateField createPopupDateField(String caption, String width,
            Locale locale) {
        DateField pd = new DateField(caption + "(" + locale + ")");
        pd.setWidth(width);
        pd.setValue(LocalDate.of(1970, 05, 23));
        pd.setLocale(locale);
        pd.setResolution(DateResolution.YEAR);

        return pd;
    }

    @Override
    protected String getTestDescription() {
        return "A generic test for PopupDateFields in different configurations";
    }

    @Override
    protected List<Component> createActions() {
        List<Component> actions = super.createActions();
        actions.add(createResolutionSelectAction());
        actions.add(createInputPromptSelectAction());
        return actions;
    }

    private Component createResolutionSelectAction() {
        LinkedHashMap<String, DateResolution> options = new LinkedHashMap<>();
        options.put("Year", DateResolution.YEAR);
        options.put("Month", DateResolution.MONTH);
        options.put("Day", DateResolution.DAY);
        return createSelectAction("Resolution", options, "Year",
                (field, value, data) -> field.setResolution(value));
    }

    private Component createInputPromptSelectAction() {
        LinkedHashMap<String, String> options = new LinkedHashMap<>();
        options.put("<none>", null);
        options.put("Please enter date", "Please enter date");
        options.put("åäöÅÄÖ", "åäöÅÄÖ");

        return createSelectAction("Input prompt", options, "<none>",
                new Command<DateField, String>() {

                    @Override
                    public void execute(DateField c, String value,
                            Object data) {
                        c.setPlaceholder(value);

                    }
                });
    }

}