Browse Source

Always close expanded top level menu item on click (#14568).

Change-Id: I04b0b64fd9054b7284efa59a8c56d8a64616ca7b
tags/7.7.0.alpha3
Denis Anisimov 9 years ago
parent
commit
5d6f189e32

+ 2
- 0
client/src/main/java/com/vaadin/client/ui/VMenuBar.java View File

@@ -590,8 +590,10 @@ public class VMenuBar extends SimpleFocusablePanel implements
popup.setOwner(this);
} else {
VMenuBar parent = parentMenu;
popup.addAutoHidePartner(parent.getSelected().getElement());
while (parent.getParentMenu() != null) {
parent = parent.getParentMenu();
popup.addAutoHidePartner(parent.getSelected().getElement());
}
popup.setOwner(parent);
}

+ 63
- 0
uitest/src/main/java/com/vaadin/tests/components/menubar/MenuBarClickOpenedMenu.java View File

@@ -0,0 +1,63 @@
/*
* Copyright 2000-2014 Vaadin Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.vaadin.tests.components.menubar;

import com.vaadin.server.VaadinRequest;
import com.vaadin.tests.components.AbstractTestUI;
import com.vaadin.ui.MenuBar;
import com.vaadin.ui.MenuBar.Command;
import com.vaadin.ui.MenuBar.MenuItem;

/**
* Test UI for top click on expanded top level menu and sub-menus.
*
* @author Vaadin Ltd
*/
public class MenuBarClickOpenedMenu extends AbstractTestUI {

@Override
protected void setup(VaadinRequest request) {
MenuBar menuBar = new MenuBar();
menuBar.addStyleName("top-level");
MenuItem file = menuBar.addItem("File", null);
file.setStyleName("first-level");
MenuItem open = file.addItem("Open", null);
open.setStyleName("second-level");
MenuItem as = open.addItem("as", null);
as.setStyleName("third-level");
MenuItem leaf = as.addItem("Text", new MenuBarCommand());
leaf.setStyleName("leaf");
addComponent(menuBar);
}

@Override
protected String getTestDescription() {
return "Top level menu item should always close menu on click. "
+ "Submenu should not close if it's already opened";
}

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

private class MenuBarCommand implements Command {
@Override
public void menuSelected(MenuItem selectedItem) {
}
}

}

+ 89
- 0
uitest/src/test/java/com/vaadin/tests/components/menubar/MenuBarClickOpenedMenuTest.java View File

@@ -0,0 +1,89 @@
/*
* Copyright 2000-2014 Vaadin Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.vaadin.tests.components.menubar;

import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.ui.ExpectedCondition;

import com.vaadin.testbench.By;
import com.vaadin.tests.tb3.MultiBrowserTest;

/**
* Test for top level menu item which should close its sub-menus each time when
* it's clicked. Also it checks sub-menu item which should not close its
* sub-menus if they are opened on click.
*
* @author Vaadin Ltd
*/
public class MenuBarClickOpenedMenuTest extends MultiBrowserTest {

@Before
@Override
public void setup() throws Exception {
super.setup();
openTestURL();
expand("v-menubar-menuitem-first-level");
expand("v-menubar-menuitem-second-level");
expand("v-menubar-menuitem-third-level");
checkPresence("v-menubar-menuitem-leaf", true);
}

@Test
public void testTopLevelMenuClickClosesSubMenus() {
click("v-menubar-menuitem-first-level");
checkSubMenus(false);
}

@Test
public void testSubMenuClickDoesNotCloseSubMenus() {
click("v-menubar-menuitem-second-level");
checkSubMenus(true);
}

private void expand(String menuItemClassName) {
checkPresence(menuItemClassName, true);
click(menuItemClassName);
}

private void click(String menuItemClassName) {
findElement(By.className(menuItemClassName)).click();
}

private void checkSubMenus(boolean present) {
checkPresence("v-menubar-menuitem-second-level", present);
checkPresence("v-menubar-menuitem-third-level", present);
checkPresence("v-menubar-menuitem-leaf", present);
}

private void checkPresence(final String menuItemClassName,
final boolean present) {
waitUntil(new ExpectedCondition<Boolean>() {
@Override
public Boolean apply(WebDriver input) {
return isElementPresent(By.className(menuItemClassName)) == present;
}

@Override
public String toString() {
// Timed out after 10 seconds waiting for ...
return menuItemClassName + " to " + (present ? "" : "not ")
+ "be present";
}
});
}
}

Loading…
Cancel
Save