From a75117689e09e507c88bc6faa4144e56b041498b Mon Sep 17 00:00:00 2001 From: =?utf8?q?Petter=20Holmstr=C3=B6m?= Date: Mon, 4 Sep 2017 16:40:38 +0300 Subject: [PATCH] Force re-measurement of CheckBoxGroup and RadioButtonGroup (#9901) The related tests have a workaround for another (Chrome specific) GridLayout bug #9921. Those workarounds should be removed once that issue is fixed. Fixes #9148 --- .../optiongroup/CheckBoxGroupConnector.java | 1 + .../RadioButtonGroupConnector.java | 1 + tests/screenshots | 2 +- .../CheckBoxGroupInGridLayout.java | 26 +++++++++++++++ .../RadioButtonGroupInGridLayout.java | 26 +++++++++++++++ .../CheckBoxGroupInGridLayoutTest.java | 32 +++++++++++++++++++ .../RadioButtonGroupInGridLayoutTest.java | 32 +++++++++++++++++++ 7 files changed, 119 insertions(+), 1 deletion(-) create mode 100644 uitest/src/main/java/com/vaadin/tests/components/checkboxgroup/CheckBoxGroupInGridLayout.java create mode 100644 uitest/src/main/java/com/vaadin/tests/components/radiobuttongroup/RadioButtonGroupInGridLayout.java create mode 100644 uitest/src/test/java/com/vaadin/tests/components/checkboxgroup/CheckBoxGroupInGridLayoutTest.java create mode 100644 uitest/src/test/java/com/vaadin/tests/components/radiobuttongroup/RadioButtonGroupInGridLayoutTest.java diff --git a/client/src/main/java/com/vaadin/client/ui/optiongroup/CheckBoxGroupConnector.java b/client/src/main/java/com/vaadin/client/ui/optiongroup/CheckBoxGroupConnector.java index 18d4019611..1ab5c1d591 100644 --- a/client/src/main/java/com/vaadin/client/ui/optiongroup/CheckBoxGroupConnector.java +++ b/client/src/main/java/com/vaadin/client/ui/optiongroup/CheckBoxGroupConnector.java @@ -89,6 +89,7 @@ public class CheckBoxGroupConnector items.add(item); } getWidget().buildOptions(items); + getLayoutManager().setNeedsMeasure(this); } @Override diff --git a/client/src/main/java/com/vaadin/client/ui/optiongroup/RadioButtonGroupConnector.java b/client/src/main/java/com/vaadin/client/ui/optiongroup/RadioButtonGroupConnector.java index 882a91aa26..21ffec2507 100644 --- a/client/src/main/java/com/vaadin/client/ui/optiongroup/RadioButtonGroupConnector.java +++ b/client/src/main/java/com/vaadin/client/ui/optiongroup/RadioButtonGroupConnector.java @@ -121,6 +121,7 @@ public class RadioButtonGroupConnector options.add(dataSource.getRow(i)); } select.buildOptions(options); + getLayoutManager().setNeedsMeasure(this); updateSelectedItem(); } diff --git a/tests/screenshots b/tests/screenshots index 52b1a4148b..0cff74a599 160000 --- a/tests/screenshots +++ b/tests/screenshots @@ -1 +1 @@ -Subproject commit 52b1a4148ba8b3a6a74278e4d7d041aa6d6620b7 +Subproject commit 0cff74a59932e44a89ea1146b0e4b56b9928a209 diff --git a/uitest/src/main/java/com/vaadin/tests/components/checkboxgroup/CheckBoxGroupInGridLayout.java b/uitest/src/main/java/com/vaadin/tests/components/checkboxgroup/CheckBoxGroupInGridLayout.java new file mode 100644 index 0000000000..7a50255000 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/components/checkboxgroup/CheckBoxGroupInGridLayout.java @@ -0,0 +1,26 @@ +package com.vaadin.tests.components.checkboxgroup; + +import com.vaadin.data.provider.DataProvider; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.CheckBoxGroup; +import com.vaadin.ui.GridLayout; +import com.vaadin.ui.TextField; +import com.vaadin.ui.themes.ValoTheme; + +public class CheckBoxGroupInGridLayout extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + CheckBoxGroup cbGroup = new CheckBoxGroup<>(null, DataProvider.ofItems("A", "B", "C")); + cbGroup.addStyleName(ValoTheme.OPTIONGROUP_HORIZONTAL); + + GridLayout gridLayout = new GridLayout(2, 1); + gridLayout.addComponent(cbGroup, 0, 0); + gridLayout.setSpacing(true); + + gridLayout.addComponent(new TextField(), 1, 0); + + addComponent(gridLayout); + } +} diff --git a/uitest/src/main/java/com/vaadin/tests/components/radiobuttongroup/RadioButtonGroupInGridLayout.java b/uitest/src/main/java/com/vaadin/tests/components/radiobuttongroup/RadioButtonGroupInGridLayout.java new file mode 100644 index 0000000000..dcd0ab08f2 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/components/radiobuttongroup/RadioButtonGroupInGridLayout.java @@ -0,0 +1,26 @@ +package com.vaadin.tests.components.radiobuttongroup; + +import com.vaadin.data.provider.DataProvider; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.GridLayout; +import com.vaadin.ui.RadioButtonGroup; +import com.vaadin.ui.TextField; +import com.vaadin.ui.themes.ValoTheme; + +public class RadioButtonGroupInGridLayout extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + RadioButtonGroup cbGroup = new RadioButtonGroup<>(null, DataProvider.ofItems("A", "B", "C")); + cbGroup.addStyleName(ValoTheme.OPTIONGROUP_HORIZONTAL); + + GridLayout gridLayout = new GridLayout(2, 1); + gridLayout.addComponent(cbGroup, 0, 0); + gridLayout.setSpacing(true); + + gridLayout.addComponent(new TextField(), 1, 0); + + addComponent(gridLayout); + } +} diff --git a/uitest/src/test/java/com/vaadin/tests/components/checkboxgroup/CheckBoxGroupInGridLayoutTest.java b/uitest/src/test/java/com/vaadin/tests/components/checkboxgroup/CheckBoxGroupInGridLayoutTest.java new file mode 100644 index 0000000000..0aade000fd --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/components/checkboxgroup/CheckBoxGroupInGridLayoutTest.java @@ -0,0 +1,32 @@ +package com.vaadin.tests.components.checkboxgroup; + +import org.junit.Assert; +import org.junit.Test; + +import com.vaadin.testbench.elements.CheckBoxGroupElement; +import com.vaadin.testbench.elements.GridLayoutElement; +import com.vaadin.testbench.parallel.BrowserUtil; +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class CheckBoxGroupInGridLayoutTest extends MultiBrowserTest { + + @Test + public void slotSizeRemainsUnchangedAfterSelectingItem() { + openTestURL(); + GridLayoutElement gridLayout = $(GridLayoutElement.class).first(); + int before = gridLayout.getSize().getWidth(); + + CheckBoxGroupElement checkBoxGroup = $(CheckBoxGroupElement.class) + .first(); + checkBoxGroup.setValue("A"); + int after = gridLayout.getSize().getWidth(); + + boolean ok = (before == after); + // also accept broken layout for unrelated bug #9921 until it is fixed + if (!ok && BrowserUtil.isChrome(getDesiredCapabilities())) { + ok = (before == after + 4); + } + + Assert.assertTrue("GridLayout size changed when selecting a value", ok); + } +} diff --git a/uitest/src/test/java/com/vaadin/tests/components/radiobuttongroup/RadioButtonGroupInGridLayoutTest.java b/uitest/src/test/java/com/vaadin/tests/components/radiobuttongroup/RadioButtonGroupInGridLayoutTest.java new file mode 100644 index 0000000000..5d7aa373f4 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/components/radiobuttongroup/RadioButtonGroupInGridLayoutTest.java @@ -0,0 +1,32 @@ +package com.vaadin.tests.components.radiobuttongroup; + +import org.junit.Assert; +import org.junit.Test; + +import com.vaadin.testbench.elements.GridLayoutElement; +import com.vaadin.testbench.elements.RadioButtonGroupElement; +import com.vaadin.testbench.parallel.BrowserUtil; +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class RadioButtonGroupInGridLayoutTest extends MultiBrowserTest { + + @Test + public void slotSizeRemainsUnchangedAfterSelectingItem() { + openTestURL(); + GridLayoutElement gridLayout = $(GridLayoutElement.class).first(); + int before = gridLayout.getSize().getWidth(); + + RadioButtonGroupElement radioButtonGroup = $( + RadioButtonGroupElement.class).first(); + radioButtonGroup.setValue("A"); + int after = gridLayout.getSize().getWidth(); + + boolean ok = (before == after); + // also accept broken layout for unrelated bug #9921 until it is fixed + if (!ok && BrowserUtil.isChrome(getDesiredCapabilities())) { + ok = (before == after + 4); + } + + Assert.assertTrue("GridLayout size changed when selecting a value", ok); + } +} -- 2.39.5