diff options
author | Henri Sara <henri.sara@gmail.com> | 2017-09-26 10:28:14 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-09-26 10:28:14 +0300 |
commit | 4d6cb7b107040ec9aedf9b73725675309a1c5729 (patch) | |
tree | b9ed625629cf2b247ee8758ac763721da62610bc /uitest | |
parent | e0b661fae56d52f36731945396b6b07c5c40a747 (diff) | |
download | vaadin-framework-4d6cb7b107040ec9aedf9b73725675309a1c5729.tar.gz vaadin-framework-4d6cb7b107040ec9aedf9b73725675309a1c5729.zip |
Relayout GridLayout when font loading completes (#10077)
If a GridLayout is used and font loading is not complete, force another layout after all fonts are loaded.
Fixes #9921
Fixes #8207
Diffstat (limited to 'uitest')
5 files changed, 143 insertions, 8 deletions
diff --git a/uitest/src/main/java/com/vaadin/tests/components/gridlayout/GridLayoutWithLabel.java b/uitest/src/main/java/com/vaadin/tests/components/gridlayout/GridLayoutWithLabel.java new file mode 100644 index 0000000000..c1ed6a5e42 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/components/gridlayout/GridLayoutWithLabel.java @@ -0,0 +1,27 @@ +package com.vaadin.tests.components.gridlayout; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.CheckBox; +import com.vaadin.ui.GridLayout; +import com.vaadin.ui.Label; + +public class GridLayoutWithLabel extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + GridLayout layout = new GridLayout(2, 1); + layout.setSpacing(true); + + layout.addComponent(new Label("This is the label"), 0, 0); + + CheckBox cb = new CheckBox("Unchecked"); + cb.addValueChangeListener(evt -> { + cb.setCaption(evt.getValue() ? "Checked" : "Unchecked"); + }); + + layout.addComponent(cb, 1, 0); + + addComponent(layout); + } +} diff --git a/uitest/src/main/java/com/vaadin/tests/fonticon/GridLayoutOnFontLoad.java b/uitest/src/main/java/com/vaadin/tests/fonticon/GridLayoutOnFontLoad.java new file mode 100644 index 0000000000..6b7d8222d7 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/fonticon/GridLayoutOnFontLoad.java @@ -0,0 +1,50 @@ +package com.vaadin.tests.fonticon; + +import com.vaadin.annotations.Widgetset; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.Button; +import com.vaadin.ui.CheckBox; +import com.vaadin.ui.Grid; +import com.vaadin.ui.GridLayout; +import com.vaadin.ui.Label; +import com.vaadin.ui.TextArea; + +@Widgetset("com.vaadin.DefaultWidgetSet") +public class GridLayoutOnFontLoad extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + GridLayout gl = new GridLayout(2, 3); + + // grid of components + addComponent(gl); + + // Basic components, caption icon only + gl.addComponents(new Button("Button"), new CheckBox("CheckBox"), + new Label("Label"), new TextArea("TextArea"), + new Label("Label")); + + // it should not be necessary to click a grid row to make the GridLayout + // have correct sizes + Grid<String> grid = new Grid<>("Grid"); + grid.setItems("item 1", "item 2", "item 3"); + grid.addColumn(string -> string).setCaption("column 1"); + // vaadin/framework#8207 + grid.setHeightByRows(3); + // grid.setHeight("150px"); + gl.addComponent(grid); + + } + + @Override + protected String getTestDescription() { + return "GridLayout should have the correct size and no overlapping components from the beginning"; + } + + @Override + protected Integer getTicketNumber() { + return null; + } + +} diff --git a/uitest/src/main/java/com/vaadin/tests/fonticon/VaadinIconSet.java b/uitest/src/main/java/com/vaadin/tests/fonticon/VaadinIconSet.java index 5e9a0158d8..39e973d680 100644 --- a/uitest/src/main/java/com/vaadin/tests/fonticon/VaadinIconSet.java +++ b/uitest/src/main/java/com/vaadin/tests/fonticon/VaadinIconSet.java @@ -1,7 +1,5 @@ package com.vaadin.tests.fonticon; -import java.util.List; - import com.vaadin.icons.VaadinIcons; import com.vaadin.server.FontIcon; import com.vaadin.server.Page; @@ -40,8 +38,6 @@ import com.vaadin.ui.VerticalLayout; public class VaadinIconSet extends AbstractTestUI { - private List<Component> componentz; - @Override protected void setup(VaadinRequest request) { buildUI(com.vaadin.icons.VaadinIcons.VAADIN_V); @@ -68,7 +64,7 @@ public class VaadinIconSet extends AbstractTestUI { n.setDelayMsec(300000); n.show(Page.getCurrent()); - // grid of compoents + // grid of components layout.addComponent(gl); // Basic components, caption icon only @@ -112,9 +108,7 @@ public class VaadinIconSet extends AbstractTestUI { grid.setItems("item 1", "item 2", "item 3"); grid.addColumn(string -> string).setCaption("column 1"); grid.addColumn(string -> "Another " + string).setCaption("column 2"); - // vaadin/framework#8207 - // grid.setHeightByRows(3); - grid.setHeight("150px"); + grid.setHeightByRows(3); gl.addComponent(grid); // Selects, caption + item icons diff --git a/uitest/src/test/java/com/vaadin/tests/components/gridlayout/GridLayoutWithLabelTest.java b/uitest/src/test/java/com/vaadin/tests/components/gridlayout/GridLayoutWithLabelTest.java new file mode 100644 index 0000000000..b8caac693d --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/components/gridlayout/GridLayoutWithLabelTest.java @@ -0,0 +1,28 @@ +package com.vaadin.tests.components.gridlayout; + +import org.junit.Assert; +import org.junit.Test; + +import com.vaadin.testbench.elements.CheckBoxElement; +import com.vaadin.testbench.elements.GridLayoutElement; +import com.vaadin.testbench.elementsbase.AbstractElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class GridLayoutWithLabelTest extends MultiBrowserTest { + + @Test + public void selectingOptionShouldNotCauseLabelToChangeSize() { + openTestURL(); + AbstractElement gridLayout = $(GridLayoutElement.class).first(); + CheckBoxElement cb = $(CheckBoxElement.class).first(); + + int before = gridLayout.getSize().getWidth(); + cb.click(); // Turn on + cb.click(); // Turn off + int after = gridLayout.getSize().getWidth(); + + Assert.assertEquals( + "layout width should not have changed after checkbox was toggled", + before, after); + } +} diff --git a/uitest/src/test/java/com/vaadin/tests/fonticon/GridLayoutOnFontLoadTest.java b/uitest/src/test/java/com/vaadin/tests/fonticon/GridLayoutOnFontLoadTest.java new file mode 100644 index 0000000000..db5c08c653 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/fonticon/GridLayoutOnFontLoadTest.java @@ -0,0 +1,36 @@ +package com.vaadin.tests.fonticon; + +import org.junit.Assert; +import org.junit.Test; + +import com.vaadin.testbench.elements.ButtonElement; +import com.vaadin.testbench.elements.CheckBoxElement; +import com.vaadin.testbench.elements.GridElement; +import com.vaadin.testbench.elements.TextAreaElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class GridLayoutOnFontLoadTest extends MultiBrowserTest { + + @Test + public void testComponentsDontOverlap() throws Exception { + openTestURL(); + + // Make sure fonts are loaded. + sleep(1000); + + ButtonElement button = $(ButtonElement.class).first(); + CheckBoxElement checkbox = $(CheckBoxElement.class).first(); + TextAreaElement textarea = $(TextAreaElement.class).first(); + GridElement grid = $(GridElement.class).first(); + + Assert.assertTrue( + "Button overlaps with checkbox (layout done before fonts loaded)", + button.getLocation().getX() + button.getSize().width <= checkbox + .getLocation().getX()); + Assert.assertTrue( + "TextArea overlaps with grid caption (layout done before fonts loaded)", + textarea.getLocation().getY() + textarea.getSize().height + + 10 < grid.getLocation().getY()); + } + +} |