summaryrefslogtreecommitdiffstats
path: root/uitest
diff options
context:
space:
mode:
authorAnna Koskinen <Ansku@users.noreply.github.com>2019-07-24 16:49:25 +0300
committerGitHub <noreply@github.com>2019-07-24 16:49:25 +0300
commit386c5cea7659a012bdf5cc4b61c352336bff8d2f (patch)
tree09fe35bc889ecde42c886c0f3d05863da4e787da /uitest
parent32aa5afc0217a767e85dd579525da5a2eb1163d9 (diff)
downloadvaadin-framework-386c5cea7659a012bdf5cc4b61c352336bff8d2f.tar.gz
vaadin-framework-386c5cea7659a012bdf5cc4b61c352336bff8d2f.zip
Ensure that VComboBox.selectedOptionKey gets initial selection. (#11665)
Fixes #10741
Diffstat (limited to 'uitest')
-rw-r--r--uitest/src/main/java/com/vaadin/tests/components/combobox/ComboBoxScrollToSelectedItem.java55
-rw-r--r--uitest/src/test/java/com/vaadin/tests/components/combobox/ComboBoxScrollToSelectedItemTest.java27
2 files changed, 82 insertions, 0 deletions
diff --git a/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboBoxScrollToSelectedItem.java b/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboBoxScrollToSelectedItem.java
new file mode 100644
index 0000000000..174d136fd5
--- /dev/null
+++ b/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboBoxScrollToSelectedItem.java
@@ -0,0 +1,55 @@
+package com.vaadin.tests.components.combobox;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.stream.LongStream;
+
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.AbstractTestUI;
+import com.vaadin.ui.ComboBox;
+
+public class ComboBoxScrollToSelectedItem extends AbstractTestUI {
+
+ @Override
+ protected void setup(VaadinRequest request) {
+ List<Item> items = new ArrayList<>();
+
+ LongStream.range(1, 100)
+ .forEach(l -> items.add(new Item(l, "item:" + l)));
+ Item selectedItem = new Item(50l, "SHOW ME");
+ items.set(50, selectedItem);
+
+ ComboBox<Item> box = new ComboBox<>("items", items);
+ box.setItemCaptionGenerator(Item::getName);
+ box.setScrollToSelectedItem(true);
+ box.setValue(selectedItem);
+
+ addComponent(box);
+ }
+
+ public class Item {
+ private Long id;
+ private String name;
+
+ public Item(long id, String name) {
+ this.id = id;
+ this.name = name;
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+ }
+}
diff --git a/uitest/src/test/java/com/vaadin/tests/components/combobox/ComboBoxScrollToSelectedItemTest.java b/uitest/src/test/java/com/vaadin/tests/components/combobox/ComboBoxScrollToSelectedItemTest.java
new file mode 100644
index 0000000000..312be6083d
--- /dev/null
+++ b/uitest/src/test/java/com/vaadin/tests/components/combobox/ComboBoxScrollToSelectedItemTest.java
@@ -0,0 +1,27 @@
+package com.vaadin.tests.components.combobox;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import org.junit.Test;
+import org.openqa.selenium.By;
+import org.openqa.selenium.WebElement;
+
+import com.vaadin.testbench.elements.ComboBoxElement;
+import com.vaadin.tests.tb3.MultiBrowserTest;
+
+public class ComboBoxScrollToSelectedItemTest extends MultiBrowserTest {
+
+ @Test
+ public void initialOpeningShouldScrollToSelected() {
+ openTestURL();
+
+ ComboBoxElement cb = $(ComboBoxElement.class).first();
+ cb.openPopup();
+
+ WebElement selected = cb.getSuggestionPopup()
+ .findElement(By.className("gwt-MenuItem-selected"));
+ assertNotNull(selected);
+ assertEquals("SHOW ME", selected.getText());
+ }
+}