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

import java.util.ArrayList;
import java.util.List;

import com.vaadin.tests.components.ComponentTestCase;
import com.vaadin.ui.Component;
import com.vaadin.ui.MenuBar;
import com.vaadin.ui.MenuBar.MenuItem;

public class Menubars extends ComponentTestCase<MenuBar> {

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

    @Override
    protected void initializeComponents() {

        MenuBar m;
        m = createMenuBar("This is an undefined wide menubar with 3 items", 3);

        m.setWidth(null);
        addTestComponent(m);

        m = createMenuBar(
                "This is an undefined wide menubar with fixed 100px height (4 items)",
                4);
        m.setWidth(null);
        m.setHeight("100px");
        addTestComponent(m);

        m = createMenuBar("This is a 200px wide menubar with 10 items", 10);
        m.setWidth("200px");
        addTestComponent(m);

        m = createMenuBar("This is a 200px wide menubar with 2 items", 2);
        m.setWidth("200px");
        addTestComponent(m);

        m = createMenuBar("This is a 100% wide menubar with 3 items ", 3);
        m.setWidth("100%");
        addTestComponent(m);

        m = createMenuBar("This is a 100% wide menubar with 40 items ", 40);
        m.setWidth("100%");
        addTestComponent(m);

        m = createMenuBar(
                "This is a 100% wide menubar with fixed 65px height (5 items). ",
                5);
        m.setWidth("100%");
        m.setHeight("65px");

        addTestComponent(m);

    }

    private MenuBar createMenuBar(String text, int items) {
        MenuBar m = new MenuBar();
        m.setCaption(text);

        for (int i = 1; i <= items; i++) {
            MenuItem mi = m.addItem("Item " + i, null);
            for (int j = 1; j <= items; j++) {
                mi.addItem("Sub menu " + i + "/" + j, null);
            }
        }

        return m;
    }

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

    @Override
    protected List<Component> createActions() {
        List<Component> actions = new ArrayList<>();
        actions.add(createErrorIndicatorAction(false));
        actions.add(createEnabledAction(true));

        return actions;
    }

}