aboutsummaryrefslogtreecommitdiffstats
path: root/uitest
diff options
context:
space:
mode:
authorAnna Koskinen <Ansku@users.noreply.github.com>2018-03-23 15:09:10 +0200
committerTeemu Suo-Anttila <tsuoanttila@users.noreply.github.com>2018-03-23 15:09:10 +0200
commit0f052d4fcb5eabccfaae5a2e486c38cb5eabc08d (patch)
treec085dc3a9d5dca10804115567a151f599fc79003 /uitest
parentc78069eb3ece1b450c8fe911bf3c3a4dafef02c3 (diff)
downloadvaadin-framework-0f052d4fcb5eabccfaae5a2e486c38cb5eabc08d.tar.gz
vaadin-framework-0f052d4fcb5eabccfaae5a2e486c38cb5eabc08d.zip
Fix VComboBox internal state cleanup (#10693)
Fixes vaadin/testbench#1009
Diffstat (limited to 'uitest')
-rw-r--r--uitest/src/main/java/com/vaadin/tests/components/combobox/ComboBoxTestBenchPerformance.java42
-rw-r--r--uitest/src/test/java/com/vaadin/tests/components/combobox/ComboBoxSelectingWithNewItemsAllowedTest.java4
-rw-r--r--uitest/src/test/java/com/vaadin/tests/components/combobox/ComboBoxTestBenchPerformanceTest.java55
3 files changed, 99 insertions, 2 deletions
diff --git a/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboBoxTestBenchPerformance.java b/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboBoxTestBenchPerformance.java
new file mode 100644
index 0000000000..c22bcebd5f
--- /dev/null
+++ b/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboBoxTestBenchPerformance.java
@@ -0,0 +1,42 @@
+package com.vaadin.tests.components.combobox;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import com.vaadin.annotations.Widgetset;
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.AbstractTestUI;
+import com.vaadin.ui.ComboBox;
+
+@Widgetset("com.vaadin.DefaultWidgetSet")
+public class ComboBoxTestBenchPerformance extends AbstractTestUI {
+
+ @SuppressWarnings("deprecation")
+ @Override
+ protected void setup(VaadinRequest request) {
+ List<String> items = new ArrayList<>();
+ for (int i = 0; i < 20; i++) {
+ items.add(i + "");
+ }
+ ComboBox<String> combo = new ComboBox<>("ComboBox with NewItemHandler");
+ combo.setItems(items);
+ combo.setEmptySelectionAllowed(false);
+ combo.setNewItemHandler(inputString -> {
+ items.add(inputString);
+ combo.setItems(items);
+ combo.setSelectedItem(inputString);
+ });
+ combo.setSelectedItem(items.iterator().next());
+ addComponent(combo);
+ }
+
+ @Override
+ protected String getTestDescription() {
+ return "Selecting values through TestBench shouldn't take minutes.";
+ }
+
+ @Override
+ protected Integer getTicketNumber() {
+ return 10284;
+ }
+}
diff --git a/uitest/src/test/java/com/vaadin/tests/components/combobox/ComboBoxSelectingWithNewItemsAllowedTest.java b/uitest/src/test/java/com/vaadin/tests/components/combobox/ComboBoxSelectingWithNewItemsAllowedTest.java
index 533b651cb7..88c3c21015 100644
--- a/uitest/src/test/java/com/vaadin/tests/components/combobox/ComboBoxSelectingWithNewItemsAllowedTest.java
+++ b/uitest/src/test/java/com/vaadin/tests/components/combobox/ComboBoxSelectingWithNewItemsAllowedTest.java
@@ -131,14 +131,14 @@ public class ComboBoxSelectingWithNewItemsAllowedTest extends MultiBrowserTest {
}
@Test
- public void noSelectionAfterMouseOut() {
+ public void selectionOnMouseOut() {
typeInputAndHitEnter("a20");
comboBoxElement.sendKeys(Keys.ARROW_DOWN, Keys.ARROW_DOWN);
findElement(By.className("v-app")).click();
assertInitialItemCount();
- assertThatSelectedValueIs("a20");
+ assertThatSelectedValueIs("", "null");
}
@Test
diff --git a/uitest/src/test/java/com/vaadin/tests/components/combobox/ComboBoxTestBenchPerformanceTest.java b/uitest/src/test/java/com/vaadin/tests/components/combobox/ComboBoxTestBenchPerformanceTest.java
new file mode 100644
index 0000000000..a9b6aff66f
--- /dev/null
+++ b/uitest/src/test/java/com/vaadin/tests/components/combobox/ComboBoxTestBenchPerformanceTest.java
@@ -0,0 +1,55 @@
+package com.vaadin.tests.components.combobox;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.number.IsCloseTo.closeTo;
+
+import org.junit.Test;
+import org.openqa.selenium.Keys;
+
+import com.vaadin.testbench.elements.ComboBoxElement;
+import com.vaadin.tests.tb3.SingleBrowserTest;
+
+public class ComboBoxTestBenchPerformanceTest extends SingleBrowserTest {
+
+ /**
+ * TestBench timeout is 20s, require 15s to make sure cluster load won't
+ * affect the result badly.
+ */
+ private static final double TIME_LIMIT = 15000d;
+
+ @Test
+ public void testSelectionPerformance() throws Exception {
+ openTestURL();
+
+ long before = System.currentTimeMillis();
+ setComboBoxValue("abc123"); // new
+ long after = System.currentTimeMillis();
+ assertThat((double) after - before, closeTo(0d, TIME_LIMIT));
+
+ before = System.currentTimeMillis();
+ setComboBoxValue("11"); // existing (2nd page)
+ after = System.currentTimeMillis();
+ assertThat((double) after - before, closeTo(0d, TIME_LIMIT));
+
+ before = System.currentTimeMillis();
+ setComboBoxValue("abc123"); // previously added (3rd page)
+ after = System.currentTimeMillis();
+ assertThat((double) after - before, closeTo(0d, TIME_LIMIT));
+ }
+
+ public void setComboBoxValue(final String value) {
+ ComboBoxElement combobox = $(ComboBoxElement.class).first();
+ if (combobox.getPopupSuggestions().contains(value)) {
+ // Select existing item
+ combobox.selectByText(value);
+ } else {
+ // Enter new item
+ combobox.clear();
+ combobox.sendKeys(value);
+ combobox.sendKeys(Keys.ENTER);
+ }
+
+ // Make sure Vaadin is ready before leaving the method
+ testBench().waitForVaadin();
+ }
+}