]> source.dussan.org Git - vaadin-framework.git/commitdiff
Ensure Composite's contents gets re-measured on resize. (#12154) (#12162)
authorAnna Koskinen <Ansku@users.noreply.github.com>
Wed, 2 Dec 2020 11:02:57 +0000 (13:02 +0200)
committerGitHub <noreply@github.com>
Wed, 2 Dec 2020 11:02:57 +0000 (13:02 +0200)
Fixes: #12153
client/src/main/java/com/vaadin/client/ui/composite/CompositeConnector.java
uitest/reference-screenshots/chrome/BaseThemeTest-testTheme_ANY_Chrome__labels_1.png [new file with mode: 0644]
uitest/reference-screenshots/chrome/RunoThemeTest-testTheme_ANY_Chrome__labels_1.png [new file with mode: 0644]
uitest/src/main/java/com/vaadin/tests/components/composite/CompositeVerticalLayoutGridResize.java [new file with mode: 0644]
uitest/src/main/java/com/vaadin/tests/components/composite/CompositeVerticalLayoutSplitPanelResize.java [new file with mode: 0644]
uitest/src/test/java/com/vaadin/tests/components/composite/CompositeVerticalLayoutGridResizeTest.java [new file with mode: 0644]
uitest/src/test/java/com/vaadin/tests/components/composite/CompositeVerticalLayoutSplitPanelResizeTest.java [new file with mode: 0644]

index 3093eaff4a63ea84ded2423d6010d19025d0effd..221a64db6c0cb2f44c0d440a1fe838b3d0ad5c88 100644 (file)
@@ -114,6 +114,8 @@ public class CompositeConnector extends AbstractHasComponentsConnector
         } else if (childConnector instanceof DirectionalManagedLayout) {
             ((DirectionalManagedLayout) childConnector).layoutHorizontally();
             ((DirectionalManagedLayout) childConnector).layoutVertically();
+        } else {
+            getLayoutManager().setNeedsMeasureRecursively(childConnector);
         }
     }
 
diff --git a/uitest/reference-screenshots/chrome/BaseThemeTest-testTheme_ANY_Chrome__labels_1.png b/uitest/reference-screenshots/chrome/BaseThemeTest-testTheme_ANY_Chrome__labels_1.png
new file mode 100644 (file)
index 0000000..e9624f1
Binary files /dev/null and b/uitest/reference-screenshots/chrome/BaseThemeTest-testTheme_ANY_Chrome__labels_1.png differ
diff --git a/uitest/reference-screenshots/chrome/RunoThemeTest-testTheme_ANY_Chrome__labels_1.png b/uitest/reference-screenshots/chrome/RunoThemeTest-testTheme_ANY_Chrome__labels_1.png
new file mode 100644 (file)
index 0000000..302afa7
Binary files /dev/null and b/uitest/reference-screenshots/chrome/RunoThemeTest-testTheme_ANY_Chrome__labels_1.png differ
diff --git a/uitest/src/main/java/com/vaadin/tests/components/composite/CompositeVerticalLayoutGridResize.java b/uitest/src/main/java/com/vaadin/tests/components/composite/CompositeVerticalLayoutGridResize.java
new file mode 100644 (file)
index 0000000..68663c9
--- /dev/null
@@ -0,0 +1,82 @@
+package com.vaadin.tests.components.composite;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.AbstractTestUI;
+import com.vaadin.ui.Component;
+import com.vaadin.ui.Composite;
+import com.vaadin.ui.Grid;
+import com.vaadin.ui.VerticalLayout;
+
+public class CompositeVerticalLayoutGridResize extends AbstractTestUI {
+
+    @Override
+    protected void setup(VaadinRequest request) {
+        addComponent(new CompositeGrid());
+
+        getLayout().setSizeFull();
+        getLayout().getParent().setSizeFull();
+    }
+
+    public class CompositeGrid extends Composite {
+        public CompositeGrid() {
+            VerticalLayout root = new VerticalLayout();
+            root.setId("root");
+            root.setMargin(false);
+            root.addComponentsAndExpand(buildGrid());
+
+            setCompositionRoot(root);
+            setSizeFull();
+        }
+
+        private Component buildGrid() {
+            List<Person> persons = new ArrayList<>();
+            for (int i = 0; i < 100; i++) {
+                persons.add(new Person("Firstname" + i, "Lastname" + i));
+            }
+
+            Grid<Person> grid = new Grid<Person>(Person.class);
+            grid.setItems(persons);
+            grid.setSizeFull();
+            return grid;
+        }
+    }
+
+    public class Person {
+        private String firstName, lastName;
+
+        public Person(String firstName, String lastName) {
+            this.firstName = firstName;
+            this.lastName = lastName;
+        }
+
+        public String getLastName() {
+            return lastName;
+        }
+
+        public void setLastName(String lastName) {
+            this.lastName = lastName;
+        }
+
+        public String getFirstName() {
+            return firstName;
+        }
+
+        public void setFirstName(String firstName) {
+            this.firstName = firstName;
+        }
+    }
+
+    @Override
+    protected String getTestDescription() {
+        return "Composite contents should resize without a delay when the"
+                + " browser is resized, not only when interacted with.";
+    }
+
+    @Override
+    protected Integer getTicketNumber() {
+        return 12153;
+    }
+}
diff --git a/uitest/src/main/java/com/vaadin/tests/components/composite/CompositeVerticalLayoutSplitPanelResize.java b/uitest/src/main/java/com/vaadin/tests/components/composite/CompositeVerticalLayoutSplitPanelResize.java
new file mode 100644 (file)
index 0000000..a9e4ab4
--- /dev/null
@@ -0,0 +1,59 @@
+package com.vaadin.tests.components.composite;
+
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.AbstractTestUI;
+import com.vaadin.ui.Composite;
+import com.vaadin.ui.HorizontalSplitPanel;
+import com.vaadin.ui.VerticalLayout;
+import com.vaadin.ui.VerticalSplitPanel;
+
+public class CompositeVerticalLayoutSplitPanelResize extends AbstractTestUI {
+
+    @Override
+    protected void setup(VaadinRequest request) {
+        addComponent(new CompositeVSP());
+
+        getLayout().setSizeFull();
+        getLayout().getParent().setSizeFull();
+    }
+
+    public class CompositeVSP extends Composite {
+        public CompositeVSP() {
+            VerticalSplitPanel verticalSplitPanel = new VerticalSplitPanel();
+            verticalSplitPanel.setSecondComponent(new CompositeHSP());
+
+            VerticalLayout root = new VerticalLayout();
+            root.setId("root");
+            root.setMargin(false);
+            root.addComponent(verticalSplitPanel);
+
+            setCompositionRoot(root);
+            setSizeFull();
+        }
+    }
+
+    public class CompositeHSP extends Composite {
+        public CompositeHSP() {
+            HorizontalSplitPanel horizontalSplitPanel = new HorizontalSplitPanel();
+
+            VerticalLayout root = new VerticalLayout();
+            root.setSizeFull();
+            root.setMargin(false);
+            root.addComponent(horizontalSplitPanel);
+
+            setCompositionRoot(root);
+            setSizeFull();
+        }
+    }
+
+    @Override
+    protected String getTestDescription() {
+        return "Composite contents should resize without a delay when the"
+                + " browser is resized, not only when interacted with.";
+    }
+
+    @Override
+    protected Integer getTicketNumber() {
+        return 12153;
+    }
+}
diff --git a/uitest/src/test/java/com/vaadin/tests/components/composite/CompositeVerticalLayoutGridResizeTest.java b/uitest/src/test/java/com/vaadin/tests/components/composite/CompositeVerticalLayoutGridResizeTest.java
new file mode 100644 (file)
index 0000000..41adf85
--- /dev/null
@@ -0,0 +1,43 @@
+package com.vaadin.tests.components.composite;
+
+import org.junit.Test;
+import org.openqa.selenium.By;
+import org.openqa.selenium.Dimension;
+import org.openqa.selenium.WebElement;
+
+import com.vaadin.testbench.elements.GridElement;
+import com.vaadin.testbench.elements.GridElement.GridCellElement;
+import com.vaadin.tests.tb3.MultiBrowserTest;
+
+public class CompositeVerticalLayoutGridResizeTest extends MultiBrowserTest {
+
+    @Test
+    public void testResize() {
+        getDriver().manage().window().setSize(new Dimension(600, 400));
+        openTestURL();
+
+        WebElement root = findElement(By.id("root"));
+        Dimension oldRootSize = root.getSize();
+
+        GridElement grid = $(GridElement.class).first();
+        // inner level element that is expected to resize
+        GridCellElement content = grid.getHeaderCell(0, 0);
+        Dimension oldContentSize = content.getSize();
+
+        // resize
+        getDriver().manage().window().setSize(new Dimension(500, 500));
+        waitUntilLoadingIndicatorNotVisible();
+
+        Dimension newRootSize = root.getSize();
+        Dimension newContentSize = content.getSize();
+
+        assertGreater("Unexpected vertical root size.", newRootSize.getHeight(),
+                oldRootSize.getHeight());
+        assertGreater("Unexpected horizontal root size.",
+                oldRootSize.getWidth(), newRootSize.getWidth());
+
+        // header height is not expected to change, only test width
+        assertGreater("Unexpected horizontal content size.",
+                oldContentSize.getWidth(), newContentSize.getWidth());
+    }
+}
diff --git a/uitest/src/test/java/com/vaadin/tests/components/composite/CompositeVerticalLayoutSplitPanelResizeTest.java b/uitest/src/test/java/com/vaadin/tests/components/composite/CompositeVerticalLayoutSplitPanelResizeTest.java
new file mode 100644 (file)
index 0000000..362a81e
--- /dev/null
@@ -0,0 +1,44 @@
+package com.vaadin.tests.components.composite;
+
+import org.junit.Test;
+import org.openqa.selenium.By;
+import org.openqa.selenium.Dimension;
+import org.openqa.selenium.WebElement;
+
+import com.vaadin.testbench.elements.HorizontalSplitPanelElement;
+import com.vaadin.tests.tb3.MultiBrowserTest;
+
+public class CompositeVerticalLayoutSplitPanelResizeTest
+        extends MultiBrowserTest {
+
+    @Test
+    public void testResize() {
+        getDriver().manage().window().setSize(new Dimension(600, 400));
+        openTestURL();
+
+        WebElement root = findElement(By.id("root"));
+        Dimension oldRootSize = root.getSize();
+
+        // inner level element that is expected to resize
+        HorizontalSplitPanelElement content = $(
+                HorizontalSplitPanelElement.class).first();
+        Dimension oldContentSize = content.getSize();
+
+        // resize
+        getDriver().manage().window().setSize(new Dimension(500, 500));
+        waitUntilLoadingIndicatorNotVisible();
+
+        Dimension newRootSize = root.getSize();
+        Dimension newContentSize = content.getSize();
+
+        assertGreater("Unexpected vertical root size.", newRootSize.getHeight(),
+                oldRootSize.getHeight());
+        assertGreater("Unexpected horizontal root size.",
+                oldRootSize.getWidth(), newRootSize.getWidth());
+
+        assertGreater("Unexpected vertical content size.",
+                newContentSize.getHeight(), oldContentSize.getHeight());
+        assertGreater("Unexpected horizontal content size.",
+                oldContentSize.getWidth(), newContentSize.getWidth());
+    }
+}