diff --git a/vertx-vaadin-tests/test-root-context/src/main/java/com/vaadin/flow/uitest/ui/BrowserWindowResizeView.java b/vertx-vaadin-tests/test-root-context/src/main/java/com/vaadin/flow/uitest/ui/BrowserWindowResizeView.java index 650b7019..42267fe0 100644 --- a/vertx-vaadin-tests/test-root-context/src/main/java/com/vaadin/flow/uitest/ui/BrowserWindowResizeView.java +++ b/vertx-vaadin-tests/test-root-context/src/main/java/com/vaadin/flow/uitest/ui/BrowserWindowResizeView.java @@ -23,6 +23,7 @@ package com.vaadin.flow.uitest.ui; import com.vaadin.flow.component.html.Div; +import com.vaadin.flow.component.html.NativeButton; import com.vaadin.flow.router.Route; import com.vaadin.flow.uitest.vertx.ViewTestLayout; @@ -35,8 +36,17 @@ protected void onShow() { windowSize.setId("size-info"); - getPage().addBrowserWindowResizeListener(event -> windowSize.setText(String.valueOf(event.getWidth()))); + getPage().addBrowserWindowResizeListener(event -> windowSize.setText( + "%sx%s".formatted(event.getWidth(), event.getHeight()))); add(windowSize); + + var modalBtn = new NativeButton("Open modal (should keep working"); + modalBtn.setId("modal"); + modalBtn.addClickListener(e -> { + add(new Div("Now modal, but resize events should still flow in")); + getUI().get().addModal(new Div()); + }); + add(modalBtn); } } diff --git a/vertx-vaadin-tests/test-root-context/src/test/java/com/vaadin/flow/uitest/ui/BrowserWindowResizeIT.java b/vertx-vaadin-tests/test-root-context/src/test/java/com/vaadin/flow/uitest/ui/BrowserWindowResizeIT.java index 38bc8732..3936d3d2 100644 --- a/vertx-vaadin-tests/test-root-context/src/test/java/com/vaadin/flow/uitest/ui/BrowserWindowResizeIT.java +++ b/vertx-vaadin-tests/test-root-context/src/test/java/com/vaadin/flow/uitest/ui/BrowserWindowResizeIT.java @@ -32,20 +32,53 @@ public class BrowserWindowResizeIT extends ChromeBrowserTest { @Test - public void listenResizeEvent() { + public void listenResizeEvent() throws InterruptedException { open(); + Dimension currentSize = getDriver().manage().window().getSize(); int newWidth = currentSize.getWidth() - 10; - getDriver().manage().window().setSize(new Dimension(newWidth, currentSize.getHeight())); + int newHeight = currentSize.getHeight() - 10; + getDriver().manage().window() + .setSize(new Dimension(newWidth, newHeight)); + + // debounced by default with 300 + Thread.sleep(500); WebElement info = findElement(By.id("size-info")); - Assert.assertEquals(String.valueOf(newWidth), info.getText()); + Assert.assertEquals(String.valueOf(newWidth), + info.getText().split("x")[0]); + // Selenium sets the window size, the tested API reports viewport + // size... + int actualHeight = Integer.parseInt(info.getText().split("x")[1]); newWidth -= 30; - getDriver().manage().window().setSize(new Dimension(newWidth, currentSize.getHeight())); + newHeight -= 20; + actualHeight -= 20; + getDriver().manage().window() + .setSize(new Dimension(newWidth, newHeight)); + + Thread.sleep(500); + + Assert.assertEquals(String.valueOf(newWidth), + info.getText().split("x")[0]); + Assert.assertEquals(String.valueOf(actualHeight), + info.getText().split("x")[1]); + + // check the same comes in still if modal component set + findElement(By.id("modal")).click(); + newWidth += 30; + newHeight += 20; + actualHeight += 20; + getDriver().manage().window() + .setSize(new Dimension(newWidth, newHeight)); + + Thread.sleep(500); - Assert.assertEquals(String.valueOf(newWidth), info.getText()); + Assert.assertEquals(String.valueOf(newWidth), + info.getText().split("x")[0]); + Assert.assertEquals(String.valueOf(actualHeight), + info.getText().split("x")[1]); } }