aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--server/src/main/java/com/vaadin/ui/RadioButtonGroup.java1
-rw-r--r--uitest/src/main/java/com/vaadin/tests/components/radiobuttongroup/RadioButtonGroupChangeDataProvider.java25
-rw-r--r--uitest/src/test/java/com/vaadin/tests/components/radiobuttongroup/RadioButtonGroupChangeDataProviderTest.java51
3 files changed, 77 insertions, 0 deletions
diff --git a/server/src/main/java/com/vaadin/ui/RadioButtonGroup.java b/server/src/main/java/com/vaadin/ui/RadioButtonGroup.java
index 649c35d736..c234d6cfb5 100644
--- a/server/src/main/java/com/vaadin/ui/RadioButtonGroup.java
+++ b/server/src/main/java/com/vaadin/ui/RadioButtonGroup.java
@@ -321,6 +321,7 @@ public class RadioButtonGroup<T> extends AbstractSingleSelect<T>
@Override
public void setDataProvider(DataProvider<T, ?> dataProvider) {
+ setSelectedItem(null);
internalSetDataProvider(dataProvider);
}
}
diff --git a/uitest/src/main/java/com/vaadin/tests/components/radiobuttongroup/RadioButtonGroupChangeDataProvider.java b/uitest/src/main/java/com/vaadin/tests/components/radiobuttongroup/RadioButtonGroupChangeDataProvider.java
new file mode 100644
index 0000000000..64fe81a14c
--- /dev/null
+++ b/uitest/src/main/java/com/vaadin/tests/components/radiobuttongroup/RadioButtonGroupChangeDataProvider.java
@@ -0,0 +1,25 @@
+package com.vaadin.tests.components.radiobuttongroup;
+
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.AbstractTestUIWithLog;
+import com.vaadin.ui.RadioButtonGroup;
+import com.vaadin.ui.Button;
+
+public class RadioButtonGroupChangeDataProvider extends AbstractTestUIWithLog {
+ @Override
+ protected void setup(VaadinRequest request) {
+ RadioButtonGroup<String> radio = new RadioButtonGroup<>();
+ radio.setItems("aaa", "bbb", "ccc", "ddd");
+ radio.setId("radioButton");
+ radio.addValueChangeListener(event -> {
+ log("Selected value: " + event.getValue());
+ });
+
+ addComponent(radio);
+ Button changeProvider = new Button(
+ "New Data Provider - without selected item",
+ e -> radio.setItems("111", "222", "333", "444"));
+ changeProvider.setId("changeProvider");
+ addComponent(changeProvider);
+ }
+}
diff --git a/uitest/src/test/java/com/vaadin/tests/components/radiobuttongroup/RadioButtonGroupChangeDataProviderTest.java b/uitest/src/test/java/com/vaadin/tests/components/radiobuttongroup/RadioButtonGroupChangeDataProviderTest.java
new file mode 100644
index 0000000000..8648ea1f21
--- /dev/null
+++ b/uitest/src/test/java/com/vaadin/tests/components/radiobuttongroup/RadioButtonGroupChangeDataProviderTest.java
@@ -0,0 +1,51 @@
+package com.vaadin.tests.components.radiobuttongroup;
+
+import com.vaadin.testbench.elements.RadioButtonGroupElement;
+import com.vaadin.tests.tb3.MultiBrowserTest;
+import org.junit.Test;
+import org.openqa.selenium.By;
+import org.openqa.selenium.WebElement;
+
+import java.util.List;
+
+import static junit.framework.TestCase.assertEquals;
+import static junit.framework.TestCase.assertTrue;
+
+public class RadioButtonGroupChangeDataProviderTest extends MultiBrowserTest {
+ @Test
+ public void verifyOptionIsSelectable() {
+ openTestURL();
+
+ getRadioButtonGroupElement().selectByText("ccc");
+ isSelectedOnClientSide("ccc");
+ findElement(By.id("changeProvider")).click();
+ assertTrue(findElement(By.id("radioButton"))
+ .findElements(By.className("v-select-option-selected"))
+ .isEmpty());
+ isValueChangeListenerFired("null");
+ getRadioButtonGroupElement().selectByText("222");
+ isSelectedOnClientSide("222");
+ }
+
+ private RadioButtonGroupElement getRadioButtonGroupElement() {
+ RadioButtonGroupElement radioButtonGroup = $(
+ RadioButtonGroupElement.class).first();
+ return radioButtonGroup;
+ }
+
+ private void isSelectedOnClientSide(String selectedText) {
+ List<WebElement> selectOptions = findElement(By.id("radioButton"))
+ .findElements(By.className("v-select-option-selected"));
+ assertEquals("One item should be selected", selectOptions.size(), 1);
+ String value = selectOptions.get(0).getText();
+ assertTrue(String.format("Expected value was %s, but %s is selected",
+ selectedText, value), value.equals(selectedText));
+ isValueChangeListenerFired(selectedText);
+ }
+
+ private void isValueChangeListenerFired(String value) {
+ assertTrue(String.format(
+ "ValueChangeListener was not fired. Current value: %s ", value),
+ findElement(By.id("Log_row_0")).getText().contains(value));
+ }
+}