aboutsummaryrefslogtreecommitdiffstats
path: root/uitest/src/test/java/com/vaadin/tests/components/combobox/ComboboxMenuBarAutoopenTest.java
blob: 4d4d8fb175e7bc87843a45d72a2f766ea705b152 (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
package com.vaadin.tests.components.combobox;

import static org.junit.Assert.assertFalse;

import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;

import com.vaadin.testbench.elements.ComboBoxElement;
import com.vaadin.testbench.elements.MenuBarElement;
import com.vaadin.tests.tb3.MultiBrowserTest;
import com.vaadin.ui.Notification.Type;

/**
 * Test that checks whether Combobox popup is closed on click to autoopen
 * menubar and its item.
 *
 * @author Vaadin Ltd
 */
public class ComboboxMenuBarAutoopenTest extends MultiBrowserTest {

    @Test
    public void closeComboboxPopupOnClickToMenuBar() {
        openTestURL();

        openPopup();
        MenuBarElement menuBar = selectMenuBar();
        menuBar.click();
        assertFalse("Combobox popup items are visible",
                isElementPresent(By.className("gwt-MenuItem")));
    }

    @Test
    public void closeComboboxPopupOnClickToMenuBarItem() {
        openTestURL();

        openPopup();

        // hover over menubar to open
        WebElement menuBarItem = findElement(
                By.className("v-menubar-menuitem-caption"));
        moveToElement(menuBarItem);

        // click submenu item
        findElements(By.className("v-menubar-menuitem-caption")).get(1).click();
        assertElementPresent(By.className(
                "v-Notification-" + Type.HUMANIZED_MESSAGE.getStyle()));

        assertFalse("Combobox popup items are visible",
                isElementPresent(By.className("gwt-MenuItem")));
    }

    private void openPopup() {
        ComboBoxElement combobox = $(ComboBoxElement.class).first();
        combobox.openPopup();

        moveToElement(findElement(By.className("gwt-MenuItem")));
    }

    private MenuBarElement selectMenuBar() {
        MenuBarElement menuBar = $(MenuBarElement.class).first();
        menuBar.focus();

        moveToElement(menuBar);

        return menuBar;
    }

    private void moveToElement(WebElement target) {
        Actions actions = new Actions(driver);
        actions.moveToElement(target).build().perform();
    }
}