aboutsummaryrefslogtreecommitdiffstats
path: root/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboBoxResetValue.java
blob: 7bf1c658fc918d426bb9879dc614b948ff1faf7f (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
package com.vaadin.tests.components.combobox;

import com.vaadin.server.VaadinRequest;
import com.vaadin.tests.components.AbstractReindeerTestUI;
import com.vaadin.ui.Button;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.v7.ui.ComboBox;

public class ComboBoxResetValue extends AbstractReindeerTestUI {

    protected static final String EMPTY_VALUE = "Empty value";
    protected static final String WITH_SET_NULL_SELECTION_ITEM_ID = "nullSelectionAllowedWithSetNullSelectionItemId";
    protected static final String WITHOUT_NULL_SELECTION_ITEM_ID = "nullSelectionAllowedWithoutNullSelectionItemId";
    protected static final String NULL_SELECTION_NOT_ALLOWED = "nullSelectionNotAllowed";

    @Override
    protected void setup(VaadinRequest request) {
        final ComboBox cbNullSelectionAllowedWithSetNullSelectionItemId = getComboBoxWithNullSelectionAllowedWithSetNullSelectionItemId();
        final ComboBox cbNullSelectionAllowedWithoutNullSelectionItemId = getComboBoxWithNullSelectionAllowedWithoutNullSelectionItemId();
        final ComboBox cbNullSelectionNotAllowed = getComboBoxWithNullSelectionNotAllowed();

        Button b = new Button("Reset");
        b.addClickListener(event -> {
            cbNullSelectionAllowedWithSetNullSelectionItemId.setValue(null);
            cbNullSelectionAllowedWithoutNullSelectionItemId.setValue(null);
            cbNullSelectionNotAllowed.setValue(null);
        });
        addComponents(new HorizontalLayout(new VerticalLayout(
                cbNullSelectionAllowedWithSetNullSelectionItemId,
                cbNullSelectionAllowedWithoutNullSelectionItemId,
                cbNullSelectionNotAllowed), b));
    }

    protected ComboBox getComboBoxWithNullSelectionAllowedWithSetNullSelectionItemId() {
        ComboBox cb = new ComboBox();
        cb.setId(WITH_SET_NULL_SELECTION_ITEM_ID);
        cb.setImmediate(true);
        cb.setNullSelectionAllowed(true);

        cb.addItem(EMPTY_VALUE);
        cb.setNullSelectionItemId(EMPTY_VALUE);

        cb.addItem(1);
        cb.select(1);
        return cb;
    }

    protected ComboBox getComboBoxWithNullSelectionAllowedWithoutNullSelectionItemId() {
        ComboBox cb = new ComboBox();
        cb.setId(WITHOUT_NULL_SELECTION_ITEM_ID);
        cb.setImmediate(true);
        cb.setNullSelectionAllowed(true);

        cb.addItem(1);
        cb.select(1);
        return cb;
    }

    protected ComboBox getComboBoxWithNullSelectionNotAllowed() {
        ComboBox cb = new ComboBox();
        cb.setId(NULL_SELECTION_NOT_ALLOWED);
        cb.setImmediate(true);
        cb.setNullSelectionAllowed(false);

        cb.addItem(1);
        cb.select(1);
        return cb;
    }

    @Override
    protected Integer getTicketNumber() {
        return 13217;
    }

    @Override
    protected String getTestDescription() {
        return "Tests that reseting (setValue(null), select(null)) of combobox works correctly (removes/updates old selection, also correctly works with filtering)";
    }

}