summaryrefslogtreecommitdiffstats
path: root/uitest
diff options
context:
space:
mode:
authorAnastasia Smirnova <anasmi@utu.fi>2019-04-04 14:45:38 +0300
committerSun Zhe <31067185+ZheSun88@users.noreply.github.com>2019-04-04 14:45:38 +0300
commit64d5b3af3d117cc8871d07fddf375118fefd5bbc (patch)
treee7d696c3521b0f8c9ecba43f7c0d7c84c44f8423 /uitest
parent049e6f39aadab1785d78bceaac575d25ea56dad4 (diff)
downloadvaadin-framework-64d5b3af3d117cc8871d07fddf375118fefd5bbc.tar.gz
vaadin-framework-64d5b3af3d117cc8871d07fddf375118fefd5bbc.zip
Reset selection on DataProvider change in RadioButtonGroup (#11526)
* Reset selection on DataProvider change in RadioButtonGroup Fixes #11454 Other components needing the same fix are ListSelect,NativeSelect,Combobox (The ones implementing HasDataProvider and extending AbstractSingleSelect. Grid is not affected as it extends AbstractListing and hadles selection differently) * Added test case Verify that ValueChangeListener is actually fired after value is reset setting new DataProvider
Diffstat (limited to 'uitest')
-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
2 files changed, 76 insertions, 0 deletions
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));
+ }
+}