aboutsummaryrefslogtreecommitdiffstats
path: root/uitest/src/test/java/com/vaadin/tests/components/combobox/ComboBoxEmptyItemsKeyboardNavigationTest.java
blob: 45f614a164401d5a6d6550fa3971536c30813784 (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.combobox;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.collection.IsEmptyCollection.empty;

import java.util.List;

import org.junit.Test;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebElement;

import com.vaadin.testbench.By;
import com.vaadin.testbench.elements.ComboBoxElement;
import com.vaadin.tests.tb3.SingleBrowserTest;

public class ComboBoxEmptyItemsKeyboardNavigationTest
        extends SingleBrowserTest {

    @Test
    public void navigatingUpOnAnEmptyMenuDoesntThrowErrors() {
        setDebug(true);
        openTestURL();

        ComboBoxElement combobox = $(ComboBoxElement.class).first();
        combobox.sendKeys("a", Keys.ARROW_UP);

        List<WebElement> errors = findElements(By.className("SEVERE"));

        assertThat(errors, empty());
    }

    @Test
    public void selectingUsingEnterInAnEmptyMenu() {
        setDebug(true);
        openTestURL();

        ComboBoxElement combobox = $(ComboBoxElement.class).first();
        combobox.sendKeys("a", Keys.ENTER);

        List<WebElement> errors = findElements(By.className("SEVERE"));

        assertThat(errors, empty());

        assertPopupClosed(combobox);
    }

    @Test
    public void selectingUsingTabInAnEmptyMenu() {
        setDebug(true);
        openTestURL();

        ComboBoxElement combobox = $(ComboBoxElement.class).first();
        // The joy of testing, one tab should be enough but is not (it is
        // locally), two tabs does the trick for PhantomJS on the cluster...
        combobox.sendKeys("abc", Keys.TAB, Keys.TAB);

        List<WebElement> errors = findElements(By.className("SEVERE"));

        assertThat(errors, empty());
        assertPopupClosed(combobox);
    }

    private void assertPopupClosed(ComboBoxElement combobox) {
        org.openqa.selenium.By bySuggestionPopup = By.vaadin("#popup");

        assertThat("ComboBox popup should not be open",
                combobox.findElements(bySuggestionPopup).isEmpty());

    }
}