]> source.dussan.org Git - vaadin-framework.git/commitdiff
Fix a regression in VMenuBar.getSubpartElement (#14879).
authorMika Murtojarvi <mika@vaadin.com>
Mon, 27 Oct 2014 15:44:16 +0000 (17:44 +0200)
committerVaadin Code Review <review@vaadin.com>
Thu, 30 Oct 2014 13:44:46 +0000 (13:44 +0000)
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

client/src/com/vaadin/client/ui/VMenuBar.java
uitest/src/com/vaadin/tests/components/menubar/MenuBarsWithNesting.java [new file with mode: 0644]
uitest/src/com/vaadin/tests/components/menubar/MenuBarsWithNestingTest.java [new file with mode: 0644]

index 99489407173b629f657961c82783f3013aac4781..5102e6faeadddbc0b1ade18efcde1155a9282734 100644 (file)
@@ -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 (file)
index 0000000..16a0896
--- /dev/null
@@ -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 (file)
index 0000000..4c3383c
--- /dev/null
@@ -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