diff options
author | Mika Murtojarvi <mika@vaadin.com> | 2014-10-27 17:44:16 +0200 |
---|---|---|
committer | Markus Koivisto <markus@vaadin.com> | 2014-11-03 09:46:44 +0200 |
commit | 953881a0420f43cbf1c9dd0c2edf854a70969275 (patch) | |
tree | 2d7dd3bfe7e34cb90fef34a61fc1c20265e9ccf1 | |
parent | 2f9fe0b5079510e0981f70071ca23449b66b244f (diff) | |
download | vaadin-framework-953881a0420f43cbf1c9dd0c2edf854a70969275.tar.gz vaadin-framework-953881a0420f43cbf1c9dd0c2edf854a70969275.zip |
Fix a regression in VMenuBar.getSubpartElement (#14879).
A change done in an earlier patch set
(https://dev.vaadin.com/review/#/c/5283/) caused a test failure with
Internet Explorer 8.
Change-Id: I8159135ab7ec4b73682e90daf393b879bf587930
3 files changed, 209 insertions, 1 deletions
diff --git a/client/src/com/vaadin/client/ui/VMenuBar.java b/client/src/com/vaadin/client/ui/VMenuBar.java index 9948940717..5102e6faea 100644 --- a/client/src/com/vaadin/client/ui/VMenuBar.java +++ b/client/src/com/vaadin/client/ui/VMenuBar.java @@ -1583,7 +1583,7 @@ public class VMenuBar extends SimpleFocusablePanel implements /*-{ var n = element.childNodes.length; if(n > 0){ - return element.childNodes[n - 1].textContent; + return element.childNodes[n - 1].nodeValue; } else{ return ""; diff --git a/uitest/src/com/vaadin/tests/components/menubar/MenuBarsWithNesting.java b/uitest/src/com/vaadin/tests/components/menubar/MenuBarsWithNesting.java new file mode 100644 index 0000000000..16a0896aa2 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/menubar/MenuBarsWithNesting.java @@ -0,0 +1,125 @@ +/* + * 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.FontAwesome; +import com.vaadin.server.Resource; +import com.vaadin.server.ThemeResource; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.Label; +import com.vaadin.ui.MenuBar; +import com.vaadin.ui.MenuBar.MenuItem; + +/** + * A UI for testing VMenuBar.getSubPartElement(String). The UI contains two + * MenuBars, one without icons and one containing items with and without icons. + * Some of the icons are textual (using FontAwesome) and should behave like + * items with image icons: the icon should not be considered to be a part of the + * item's caption. + * + * @since + * @author Vaadin + */ +@SuppressWarnings("serial") +public class MenuBarsWithNesting extends AbstractTestUI { + + // The label displays the last selection. + private final Label label = new Label("Initial content"); + + // The captions and icons used in the second MenuBar. + public final static String[] itemNames = { "Icon item", "Arrow down", + "Arrow up", "Warning" }; + private final static Resource[] itemIcons = { + new ThemeResource("window/img/restore.png"), + FontAwesome.ARROW_DOWN, FontAwesome.ARROW_UP, FontAwesome.WARNING }; + + // The last menu item is nested with the following submenu items. + public final static String[] nestedItemnames = { "No icon", "Font icon", + "Image icon" }; + private final static Resource[] nestedItemIcons = { null, FontAwesome.LINK, + new ThemeResource("window/img/restore.png") }; + + private MenuBar.Command selectionCommand; + + @Override + protected void setup(VaadinRequest request) { + selectionCommand = new MenuBar.Command() { + @Override + public void menuSelected(MenuItem selectedItem) { + label.setValue(selectedItem.getText()); + } + }; + addComponent(createFirstMenuBar()); + addComponent(createSecondMenuBar()); + addComponent(label); + } + + /* + * Returns a menu bar with three levels of nesting but no icons. + */ + private MenuBar createFirstMenuBar() { + MenuBar menuBar = new MenuBar(); + MenuItem file = menuBar.addItem("File", null); + file.addItem("Open", selectionCommand); + file.addItem("Save", selectionCommand); + file.addItem("Save As..", selectionCommand); + file.addSeparator(); + MenuItem export = file.addItem("Export..", null); + export.addItem("As PDF...", selectionCommand); + export.addItem("As Doc...", selectionCommand); + file.addSeparator(); + file.addItem("Exit", selectionCommand); + + MenuItem edit = menuBar.addItem("Edit", null); + edit.addItem("Copy", selectionCommand); + edit.addItem("Cut", selectionCommand); + edit.addItem("Paste", selectionCommand); + + menuBar.addItem("Help", selectionCommand); + return menuBar; + } + + /* + * Returns a menu bar containing items with icons. The last menu item is + * nested and its submenu contains items with and without icons. + */ + private MenuBar createSecondMenuBar() { + MenuBar menuBar = new MenuBar(); + int n = itemNames.length; + for (int i = 0; i < n - 1; i++) { + menuBar.addItem(itemNames[i], itemIcons[i], selectionCommand); + } + MenuItem last = menuBar.addItem(itemNames[n - 1], itemIcons[n - 1], + null); + for (int i = 0; i < nestedItemnames.length; i++) { + last.addItem(nestedItemnames[i], nestedItemIcons[i], + selectionCommand); + } + return menuBar; + } + + @Override + protected String getTestDescription() { + return "This UI is used for testing subpart functionality of MenuBar. The " + + "functionality is used in TestBench tests."; + } + + @Override + protected Integer getTicketNumber() { + return 14879; + } +}
\ No newline at end of file diff --git a/uitest/src/com/vaadin/tests/components/menubar/MenuBarsWithNestingTest.java b/uitest/src/com/vaadin/tests/components/menubar/MenuBarsWithNestingTest.java new file mode 100644 index 0000000000..4c3383c5d6 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/menubar/MenuBarsWithNestingTest.java @@ -0,0 +1,83 @@ +/* + * 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 static com.vaadin.tests.components.menubar.MenuBarsWithNesting.itemNames; +import static com.vaadin.tests.components.menubar.MenuBarsWithNesting.nestedItemnames; + +import org.junit.Before; +import org.junit.Test; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.ui.ExpectedConditions; + +import com.vaadin.testbench.By; +import com.vaadin.testbench.elements.LabelElement; +import com.vaadin.testbench.elements.MenuBarElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +/** + * This class tests the method VMenuBar.getSubPartElement(String) by using + * Vaadin locators for finding the items of a MenuBar. + * + * @since + * @author Vaadin Ltd + */ +public class MenuBarsWithNestingTest extends MultiBrowserTest { + private MenuBarElement firstMenuBar, secondMenuBar; + private LabelElement label; + + @Before + public void init() { + openTestURL(); + firstMenuBar = $(MenuBarElement.class).first(); + secondMenuBar = $(MenuBarElement.class).get(1); + label = $(LabelElement.class).get(1); + } + + @Test + public void testMenuWithoutIcons() { + WebElement fileMenu = firstMenuBar.findElement(By.vaadin("#File")); + fileMenu.click(); + WebElement exportMenu = fileMenu.findElement(By.vaadin("#Export..")); + exportMenu.click(); + waitUntil(ExpectedConditions.visibilityOfElementLocated(By + .xpath(".//*[text() = 'As PDF...']"))); + } + + @Test + public void testMenuWithIcons() throws InterruptedException { + // There is a separate test for the last item of the second menu. + for (int i = 0; i < itemNames.length - 1; i++) { + String itemName = itemNames[i]; + secondMenuBar.findElement(By.vaadin("#" + itemName)).click(); + waitUntil(ExpectedConditions.textToBePresentInElement( + label.getWrappedElement(), itemName)); + } + } + + @Test + public void testNestedMenuWithIcons() throws InterruptedException { + String selection = itemNames[itemNames.length - 1]; + for (String itemName : nestedItemnames) { + WebElement lastMenuItem = secondMenuBar.findElement(By.vaadin("#" + + selection)); + lastMenuItem.click(); + lastMenuItem.findElement(By.vaadin("#" + itemName)).click(); + waitUntil(ExpectedConditions.textToBePresentInElement( + label.getWrappedElement(), itemName)); + } + } +}
\ No newline at end of file |