]> source.dussan.org Git - vaadin-framework.git/commitdiff
Take overlays into account in getConnectorForElement. (#11980)
authorAnna Koskinen <Ansku@users.noreply.github.com>
Tue, 5 May 2020 07:46:38 +0000 (10:46 +0300)
committerGitHub <noreply@github.com>
Tue, 5 May 2020 07:46:38 +0000 (10:46 +0300)
* Take overlays into account in getConnectorForElement.

Fixes #11212

client/src/main/java/com/vaadin/client/Util.java
uitest/src/main/java/com/vaadin/tests/tooltip/NestedOverlayTooltip.java [new file with mode: 0644]
uitest/src/test/java/com/vaadin/tests/tooltip/NestedOverlayTooltipTest.java [new file with mode: 0644]

index 02c21179bf5dac3731b6f87b5fc8787b2b69b124..02c545f563259cda61e13b82ecc5aa51b9da0c6c 100644 (file)
@@ -579,15 +579,10 @@ public class Util {
             }
 
             if (connector != null) {
-                // check that inside the rootElement
-                while (browseElement != null && browseElement != rootElement) {
-                    browseElement = browseElement.getParentElement();
-                }
-                if (browseElement != rootElement) {
-                    return null;
-                } else {
+                if (isConnectedToParent(browseElement, rootElement)) {
                     return connector;
                 }
+                return null;
             }
 
             browseElement = browseElement.getParentElement();
@@ -606,6 +601,28 @@ public class Util {
         }
     }
 
+    private static boolean isConnectedToParent(Element element,
+            Element rootElement) {
+        Element browseElement = element;
+        // check if inside the rootElement
+        while (browseElement != null && browseElement != rootElement) {
+            browseElement = browseElement.getParentElement();
+        }
+        if (browseElement == rootElement) {
+            return true;
+        }
+        // Not inside the root, possibly inside a VOverlay such as
+        // VWindow instead.
+        @SuppressWarnings("deprecation")
+        VOverlay overlay = WidgetUtil.findWidget(element, VOverlay.class,
+                false);
+        if (overlay != null && overlay.getOwner() != null) {
+            browseElement = overlay.getOwner().getElement();
+            return isConnectedToParent(browseElement, rootElement);
+        }
+        return false;
+    }
+
     /**
      * Will (attempt) to focus the given DOM Element.
      *
diff --git a/uitest/src/main/java/com/vaadin/tests/tooltip/NestedOverlayTooltip.java b/uitest/src/main/java/com/vaadin/tests/tooltip/NestedOverlayTooltip.java
new file mode 100644 (file)
index 0000000..9dd23e8
--- /dev/null
@@ -0,0 +1,120 @@
+package com.vaadin.tests.tooltip;
+
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.AbstractTestUI;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.MenuBar;
+import com.vaadin.ui.MenuBar.MenuItem;
+import com.vaadin.ui.PopupView;
+import com.vaadin.ui.VerticalLayout;
+import com.vaadin.ui.Window;
+
+public class NestedOverlayTooltip extends AbstractTestUI {
+
+    @Override
+    protected void setup(VaadinRequest request) {
+        Button openWindowButton = createOpenWindowButton();
+        PopupView openPopUpViewLink = createOpenPopUpViewButton();
+
+        MenuBar menuBar = new MenuBar();
+        MenuItem menuItem = menuBar.addItem("First item");
+        MenuItem firstDropdownItem = menuItem.addItem("Dropdown item");
+        firstDropdownItem.setDescription("Dropdown Item tooltip");
+
+        addComponents(openWindowButton, openPopUpViewLink, menuBar);
+    }
+
+    private Button createOpenWindowButton() {
+        Button openWindowButton = new Button("Open window");
+        openWindowButton.setDescription("Button tooltip");
+        openWindowButton.addClickListener(event -> {
+            Window window = new Window();
+            window.center();
+            window.setWidth("500px");
+            window.setHeight("500px");
+
+            Button openInnerWindowButton = new Button("Open inner window");
+            openInnerWindowButton.setDescription("Button tooltip");
+            openInnerWindowButton.addClickListener(innerEvent -> {
+                Window innerWindow = new Window();
+                innerWindow.center();
+                innerWindow.setWidth("400px");
+                innerWindow.setHeight("400px");
+
+                Button dummyButton = new Button(
+                        "This button doesn't do a thing");
+                dummyButton.setDescription("DummyButton tooltip");
+
+                MenuBar innerWindowMenuBar = new MenuBar();
+                innerWindowMenuBar.setDescription("MenuBar tooltip");
+                MenuItem menuItem = innerWindowMenuBar
+                        .addItem("First item in inner window");
+                MenuItem firstDropdownItem = menuItem
+                        .addItem("Inner window dropdown item");
+                firstDropdownItem
+                        .setDescription("Inner window dropdown item tooltip");
+
+                innerWindow.setContent(
+                        new VerticalLayout(dummyButton, innerWindowMenuBar));
+                addWindow(innerWindow);
+            });
+
+            MenuBar windowMenuBar = new MenuBar();
+            windowMenuBar.setDescription("MenuBar tooltip");
+            MenuItem menuItem = windowMenuBar.addItem("First item in window");
+            MenuItem firstDropdownItem = menuItem
+                    .addItem("Window dropdown item");
+            firstDropdownItem.setDescription("Window dropdown item tooltip");
+
+            window.setContent(
+                    new VerticalLayout(openInnerWindowButton, windowMenuBar));
+            addWindow(window);
+        });
+        return openWindowButton;
+    }
+
+    private PopupView createOpenPopUpViewButton() {
+        PopupView dummyView = new PopupView("Open empty popupView",
+                new VerticalLayout());
+        dummyView.setDescription("This dummy popupView has no content");
+
+        MenuBar innerPopupMenuBar = new MenuBar();
+        innerPopupMenuBar.setDescription("MenuBar tooltip");
+        MenuItem innerPopupMenuItem = innerPopupMenuBar
+                .addItem("First item in inner popupView");
+        MenuItem firstDropdownInnerPopupItem = innerPopupMenuItem
+                .addItem("Inner popupView dropdown item");
+        firstDropdownInnerPopupItem
+                .setDescription("Inner popupView dropdown item tooltip");
+
+        PopupView innerView = new PopupView("Open inner popupView",
+                new VerticalLayout(dummyView, innerPopupMenuBar));
+        innerView.setDescription("This inner popupView has content");
+
+        MenuBar popupMenuBar = new MenuBar();
+        popupMenuBar.setDescription("MenuBar tooltip");
+        MenuItem popupMenuItem = popupMenuBar
+                .addItem("First item in popupView");
+        MenuItem firstDropdownPopupItem = popupMenuItem
+                .addItem("PopupView dropdown item");
+        firstDropdownPopupItem
+                .setDescription("PopupView dropdown item tooltip");
+
+        PopupView popupView = new PopupView("Open popupView",
+                new VerticalLayout(innerView, innerView, popupMenuBar));
+        popupView.setDescription("This popupView has content");
+        return popupView;
+    }
+
+    @Override
+    protected String getTestDescription() {
+        return "MenuItem's tooltip should be visible even when "
+                + "the MenuBar is located within a Window, PopupView, "
+                + "or some other component that extends VOverlay";
+    }
+
+    @Override
+    protected Integer getTicketNumber() {
+        return 11212;
+    }
+}
diff --git a/uitest/src/test/java/com/vaadin/tests/tooltip/NestedOverlayTooltipTest.java b/uitest/src/test/java/com/vaadin/tests/tooltip/NestedOverlayTooltipTest.java
new file mode 100644 (file)
index 0000000..c8c5bc1
--- /dev/null
@@ -0,0 +1,73 @@
+package com.vaadin.tests.tooltip;
+
+import org.junit.Test;
+import org.openqa.selenium.WebElement;
+
+import com.vaadin.testbench.By;
+import com.vaadin.testbench.elements.ButtonElement;
+import com.vaadin.testbench.elements.PopupViewElement;
+import com.vaadin.testbench.elements.UIElement;
+import com.vaadin.testbench.elements.WindowElement;
+import com.vaadin.tests.tb3.TooltipTest;
+
+public class NestedOverlayTooltipTest extends TooltipTest {
+
+    @Override
+    public void setup() throws Exception {
+        super.setup();
+        openTestURL();
+    }
+
+    private void openDropDownAndTestTooltip(WebElement base, String firstItem,
+            String tooltip) throws Exception {
+        WebElement menuBar = base.findElement(By.className("v-menubar"));
+        menuBar.findElement(By.vaadin("#" + firstItem)).click();
+        WebElement popup = findElement(By.className("v-menubar-popup"));
+        WebElement item = popup.findElement(By.className("v-menubar-menuitem"));
+        checkTooltip(item, tooltip);
+    }
+
+    @Test
+    public void testMenuItemTooltip() throws Exception {
+        UIElement ui = $(UIElement.class).first();
+        openDropDownAndTestTooltip(ui, "First item", "Dropdown Item tooltip");
+    }
+
+    @Test
+    public void testMenuItemTooltipWithinWindow() throws Exception {
+        $(ButtonElement.class).first().click();
+        WindowElement window = $(WindowElement.class).first();
+        openDropDownAndTestTooltip(window, "First item in window",
+                "Window dropdown item tooltip");
+    }
+
+    @Test
+    public void testMenuItemTooltipWithinNestedWindow() throws Exception {
+        $(ButtonElement.class).first().click();
+        WindowElement window = $(WindowElement.class).first();
+        window.$(ButtonElement.class).first().click();
+        WindowElement subWindow = $(WindowElement.class).get(1);
+        openDropDownAndTestTooltip(subWindow, "First item in inner window",
+                "Inner window dropdown item tooltip");
+    }
+
+    @Test
+    public void testMenuItemTooltipWithinPopupView() throws Exception {
+        $(PopupViewElement.class).first().click();
+        WebElement popup = findElement(By.className("v-popupview-popup"));
+        openDropDownAndTestTooltip(popup, "First item in popupView",
+                "PopupView dropdown item tooltip");
+    }
+
+    @Test
+    public void testMenuItemTooltipWithinNestedPopupView() throws Exception {
+        $(PopupViewElement.class).first().click();
+        WebElement popup = findElement(By.className("v-popupview-popup"));
+        popup.findElement(By.className("v-popupview")).click();
+        WebElement innerPopup = findElements(By.className("v-popupview-popup"))
+                .get(1);
+        openDropDownAndTestTooltip(innerPopup, "First item in inner popupView",
+                "Inner popupView dropdown item tooltip");
+    }
+
+}