aboutsummaryrefslogtreecommitdiffstats
path: root/uitest/src/main/java/com/vaadin/tests/components/select/NullSelectionItemId.java
blob: 102ffe4426e4662b62e7234db64033dbefb9baa7 (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
package com.vaadin.tests.components.select;

import com.vaadin.tests.components.TestBase;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Button.ClickListener;
import com.vaadin.v7.ui.Select;

public class NullSelectionItemId extends TestBase implements ClickListener {

    private static final String NULL_ITEM_ID = "Null item id";

    private Select mySelect;

    @Override
    protected void setup() {

        mySelect = new Select("My Select");

        // add items
        mySelect.addItem(NULL_ITEM_ID);
        mySelect.addItem("Another item");

        // allow null and set the null item id
        mySelect.setNullSelectionAllowed(true);
        mySelect.setNullSelectionItemId(NULL_ITEM_ID);

        // select the null item
        mySelect.select(NULL_ITEM_ID);

        Button button = new Button("Show selected value", this);

        addComponent(mySelect);
        addComponent(button);

        button = new Button(
                "Select null with select(NULL_ITEM_ID) (should make value null)",
                event -> mySelect.select(NULL_ITEM_ID));

        addComponent(button);

        button = new Button(
                "Select null with setValue(null) (should make value null)",
                event -> mySelect.setValue(null));

        addComponent(button);

    }

    @Override
    public void buttonClick(ClickEvent event) {
        getMainWindow().showNotification(
                "mySelect.getValue() returns: " + mySelect.getValue());
    }

    @Override
    protected String getDescription() {
        return "Steps to reproduce:<br />"
                + "<ol><li>Click the button -> value is the item id \"Null item id\" (should be null).</li>"
                + "<li>Select the \"Another item\".</li>"
                + "<li>Select back the first item.</li>"
                + "<li>Click the button -> the value is null (as it should)</li></ol>";
    }

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

}