aboutsummaryrefslogtreecommitdiffstats
path: root/uitest/src/main/java/com/vaadin/tests/components/tabsheet/TabSelectionRevertedByServer.java
blob: 42f20819e9565a932ef4cbfd15b412f67618838f (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
package com.vaadin.tests.components.tabsheet;

import com.vaadin.server.VaadinRequest;
import com.vaadin.tests.components.AbstractReindeerTestUI;
import com.vaadin.ui.Component;
import com.vaadin.ui.Label;
import com.vaadin.ui.Notification;
import com.vaadin.ui.TabSheet;

/**
 * TabSheet test in case user selects a tab and on the selection listener the
 * selected tab is changed to another one.
 *
 * This test used to cause nonfunctional TabSheet if the current tab was 1, user
 * selects 5, then the selection listener will revert the selected tab to 1.
 *
 * @author Vaadin Ltd
 */
public class TabSelectionRevertedByServer extends AbstractReindeerTestUI {

    @Override
    protected void setup(VaadinRequest request) {

        final TabSheet tabsheet = new TabSheet();
        tabsheet.setWidth("400px");

        Component lastLabel = null;

        for (int i = 1; i <= 5; i++) {
            String caption = "Tab " + i;
            Label label = new Label(caption);
            tabsheet.addTab(label, caption);

            lastLabel = label;
        }

        tabsheet.setSelectedTab(0);

        final Component lastTab = lastLabel;

        tabsheet.addSelectedTabChangeListener(event -> {
            if (tabsheet.getSelectedTab().equals(lastTab)) {

                // Set focus back to first tab in tabsheet
                tabsheet.setSelectedTab(0);
                Notification.show("Focus set back to tab at position 0");
            }
        });

        addComponent(tabsheet);

        addButton("Select Last Tab", event -> tabsheet.setSelectedTab(lastTab));
    }

    @Override
    protected String getTestDescription() {
        return "Clicking on Tab 5 will revert to Tab 1. The action is handled on the server side and will set the selected tab to 1 if Tab 5 is selected.";
    }

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

}