diff options
author | elmot <elmot@vaadin.com> | 2016-09-29 18:52:35 +0300 |
---|---|---|
committer | elmot <elmot@vaadin.com> | 2016-09-30 08:02:54 +0300 |
commit | db3a91c9b4d8d0451c8f1c5e875f4c6f6f50324a (patch) | |
tree | 27a2193cbae9dc25869cf2240eeaa9ffd3d5e8af /uitest | |
parent | 2bee988272657df4d886ea79b04be9fbc54d3928 (diff) | |
download | vaadin-framework-db3a91c9b4d8d0451c8f1c5e875f4c6f6f50324a.tar.gz vaadin-framework-db3a91c9b4d8d0451c8f1c5e875f4c6f6f50324a.zip |
Fix RadioButtonGroup client-side NPE which breaks item icons.
Change-Id: I3a9c887196b503eaa8c2307d7a714ce61e6deacc
Diffstat (limited to 'uitest')
-rw-r--r-- | uitest/src/main/java/com/vaadin/tests/components/radiobutton/RadioButtonGroupTestUI.java | 47 | ||||
-rw-r--r-- | uitest/src/test/java/com/vaadin/tests/components/radiobutton/RadioButtonGroupTest.java | 47 |
2 files changed, 79 insertions, 15 deletions
diff --git a/uitest/src/main/java/com/vaadin/tests/components/radiobutton/RadioButtonGroupTestUI.java b/uitest/src/main/java/com/vaadin/tests/components/radiobutton/RadioButtonGroupTestUI.java index 041c578f1b..036512a514 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/radiobutton/RadioButtonGroupTestUI.java +++ b/uitest/src/main/java/com/vaadin/tests/components/radiobutton/RadioButtonGroupTestUI.java @@ -15,14 +15,15 @@ */ package com.vaadin.tests.components.radiobutton; -import java.util.LinkedHashMap; -import java.util.stream.IntStream; - +import com.vaadin.server.FontAwesome; import com.vaadin.shared.data.selection.SelectionModel; import com.vaadin.tests.components.abstractlisting.AbstractListingTestUI; import com.vaadin.ui.ItemCaptionGenerator; import com.vaadin.ui.RadioButtonGroup; +import java.util.LinkedHashMap; +import java.util.stream.IntStream; + /** * Test UI for RadioButtonGroup component * @@ -44,7 +45,8 @@ public class RadioButtonGroupTestUI super.createActions(); createListenerMenu(); createSelectionMenu(); - createItemGeneratorMenu(); + createItemIconGeneratorMenu(); + createItemCaptionGeneratorMenu(); } protected void createSelectionMenu() { @@ -60,15 +62,30 @@ public class RadioButtonGroupTestUI .forEach(item -> createClickAction("Toggle " + item, selectionCategory, toggleSelection, item)); } + private void createItemIconGeneratorMenu() { + createBooleanAction("Use Item Icon Generator", "Item Icon Generator", false, + this::useItemIconGenerator); + } - private void createItemGeneratorMenu() { + private void useItemIconGenerator(RadioButtonGroup<Object> group, + boolean activate, Object data) { + if (activate) { + group.setItemIconGenerator( + item -> FontAwesome.values()[getIndex(item) + 1]); + } else { + group.setItemIconGenerator(item -> null); + } + group.getDataSource().refreshAll(); + } + + private void createItemCaptionGeneratorMenu() { LinkedHashMap<String, ItemCaptionGenerator<Object>> options = new LinkedHashMap<>(); options.put("Null Caption Generator", item -> null); options.put("Default Caption Generator", item -> item.toString()); options.put("Custom Caption Generator", item -> item.toString() + " Caption"); - createSelectAction("Item Caption Generator", "Item Generator", options, + createSelectAction("Item Caption Generator", "Item Caption Generator", options, "None", (radioButtonGroup, captionGenerator, data) -> { radioButtonGroup.setItemCaptionGenerator(captionGenerator); radioButtonGroup.getDataSource().refreshAll(); @@ -91,4 +108,22 @@ public class RadioButtonGroupTestUI e -> log("Selected: " + e.getSelectedItem()))); } + + private int getIndex(Object item) { + int index = item.toString().indexOf(' '); + if (index < 0) { + return 0; + } + String postfix = item.toString().substring(index + 1); + index = postfix.indexOf(' '); + if (index >= 0) { + postfix = postfix.substring(0, index); + } + try { + return Integer.parseInt(postfix); + } catch (NumberFormatException e) { + return 0; + } + } + } diff --git a/uitest/src/test/java/com/vaadin/tests/components/radiobutton/RadioButtonGroupTest.java b/uitest/src/test/java/com/vaadin/tests/components/radiobutton/RadioButtonGroupTest.java index 42d912edd6..b2546347dd 100644 --- a/uitest/src/test/java/com/vaadin/tests/components/radiobutton/RadioButtonGroupTest.java +++ b/uitest/src/test/java/com/vaadin/tests/components/radiobutton/RadioButtonGroupTest.java @@ -15,17 +15,20 @@ */ package com.vaadin.tests.components.radiobutton; -import static org.junit.Assert.assertEquals; - -import java.util.Arrays; - +import com.vaadin.server.FontAwesome; +import com.vaadin.testbench.By; +import com.vaadin.testbench.customelements.RadioButtonGroupElement; +import com.vaadin.tests.tb3.MultiBrowserTest; import org.junit.Assert; import org.junit.Before; import org.junit.Test; -import org.openqa.selenium.By; +import org.openqa.selenium.WebElement; -import com.vaadin.testbench.customelements.RadioButtonGroupElement; -import com.vaadin.tests.tb3.MultiBrowserTest; +import java.util.Arrays; +import java.util.List; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; /** * Test for RadioButtonGroup @@ -93,6 +96,23 @@ public class RadioButtonGroupTest extends MultiBrowserTest { } @Test + public void itemIconGenerator() { + selectMenuPath("Component", "Item Icon Generator", "Use Item Icon Generator"); + assertItemsSuffices(20); + + List<WebElement> icons = getSelect().findElements(By. + cssSelector(".v-select-optiongroup .v-icon")); + + assertEquals(20,icons.size()); + + for (int i = 0; i < icons.size(); i++) { + Assert.assertEquals(FontAwesome.values()[i + 1].getCodepoint(), + icons.get(i).getText().charAt(0)); + } + } + + + @Test public void clickToSelect_reenable() { selectMenuPath("Component", "State", "Enabled"); selectMenuPath("Component", "Listeners", "Selection listener"); @@ -113,14 +133,14 @@ public class RadioButtonGroupTest extends MultiBrowserTest { @Test public void itemCaptionGenerator() { - selectMenuPath("Component", "Item Generator", "Item Caption Generator", + selectMenuPath("Component", "Item Caption Generator", "Item Caption Generator", "Custom Caption Generator"); assertItems(20, " Caption"); } @Test public void nullItemCaptionGenerator() { - selectMenuPath("Component", "Item Generator", "Item Caption Generator", + selectMenuPath("Component", "Item Caption Generator", "Item Caption Generator", "Null Caption Generator"); for (String text : getSelect().getOptions()) { Assert.assertEquals("", text); @@ -171,4 +191,13 @@ public class RadioButtonGroupTest extends MultiBrowserTest { } assertEquals("Number of items", count, i); } + + protected void assertItemsSuffices(int count) { + int i = 0; + for (String text : getSelect().getOptions()) { + assertTrue(text.endsWith("Item " + i)); + i++; + } + assertEquals("Number of items", count, i); + } } |