aboutsummaryrefslogtreecommitdiffstats
path: root/uitest/src/test/java/com/vaadin/tests/components/nativeselect/NativeSelectCaptionGenerationTest.java
blob: a66dc87a064523ec24ac8070027a2df5c104a09c (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
package com.vaadin.tests.components.nativeselect;

import static org.junit.Assert.assertEquals;

import java.util.List;

import org.junit.Test;

import com.vaadin.testbench.TestBenchElement;
import com.vaadin.testbench.elements.ButtonElement;
import com.vaadin.testbench.elements.NativeSelectElement;
import com.vaadin.tests.tb3.SingleBrowserTest;

public class NativeSelectCaptionGenerationTest extends SingleBrowserTest {

    private static final String[] value = { "Foo", "Bar", "Baz", "Spam",
            "Eggs" };

    @Test
    public void testDefaultDeclarativeCaptions() {
        openTestURL();
        List<TestBenchElement> options = $(NativeSelectElement.class).first()
                .getOptions();
        for (int i = 0; i < options.size(); ++i) {
            assertEquals("Captions don't match.", value[i],
                    options.get(i).getText());
        }
    }

    @Test
    public void testToStringCaptions() {
        openTestURL();
        $(ButtonElement.class).caption("toString").first().click();
        List<TestBenchElement> options = $(NativeSelectElement.class).first()
                .getOptions();
        for (int i = 0; i < options.size(); ++i) {
            assertEquals("Captions don't match.", "Option " + (i + 1),
                    options.get(i).getText());
        }
    }

    @Test
    public void testNumberOnlyCaptions() {
        openTestURL();
        $(ButtonElement.class).caption("Only number").first().click();
        List<TestBenchElement> options = $(NativeSelectElement.class).first()
                .getOptions();
        for (int i = 0; i < options.size(); ++i) {
            assertEquals("Captions don't match.", "" + (i + 1),
                    options.get(i).getText());
        }
    }

    @Test
    public void testChangeGeneratorToStringAndBackToDeclarative() {
        openTestURL();
        $(ButtonElement.class).caption("toString").first().click();
        $(ButtonElement.class).caption("Declarative").first().click();
        List<TestBenchElement> options = $(NativeSelectElement.class).first()
                .getOptions();
        for (int i = 0; i < options.size(); ++i) {
            assertEquals("Captions don't match.", value[i],
                    options.get(i).getText());
        }
    }
}