aboutsummaryrefslogtreecommitdiffstats
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
parentc78069eb3ece1b450c8fe911bf3c3a4dafef02c3 (diff)
downloadvaadin-framework-0f052d4fcb5eabccfaae5a2e486c38cb5eabc08d.tar.gz
vaadin-framework-0f052d4fcb5eabccfaae5a2e486c38cb5eabc08d.zip
Fix VComboBox internal state cleanup (#10693)
Fixes vaadin/testbench#1009
-rw-r--r--client/src/main/java/com/vaadin/client/ui/VComboBox.java5
-rw-r--r--client/src/main/java/com/vaadin/client/ui/combobox/ComboBoxConnector.java5
-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
5 files changed, 107 insertions, 4 deletions
diff --git a/client/src/main/java/com/vaadin/client/ui/VComboBox.java b/client/src/main/java/com/vaadin/client/ui/VComboBox.java
index 863b56decc..d67615d4b2 100644
--- a/client/src/main/java/com/vaadin/client/ui/VComboBox.java
+++ b/client/src/main/java/com/vaadin/client/ui/VComboBox.java
@@ -257,12 +257,12 @@ public class VComboBox extends Composite implements Field, KeyDownHandler,
return $entry(function(e) {
var deltaX = e.deltaX ? e.deltaX : -0.5*e.wheelDeltaX;
var deltaY = e.deltaY ? e.deltaY : -0.5*e.wheelDeltaY;
-
+
// IE8 has only delta y
if (isNaN(deltaY)) {
deltaY = -0.5*e.wheelDelta;
}
-
+
@com.vaadin.client.ui.VComboBox.JsniUtil::moveScrollFromEvent(*)(widget, deltaX, deltaY, e, e.deltaMode);
});
}-*/;
@@ -1561,6 +1561,7 @@ public class VComboBox extends Composite implements Field, KeyDownHandler,
*/
private void cancelPendingPostFiltering() {
pendingUserInput = null;
+ waitingForFilteringResponse = false;
}
/**
diff --git a/client/src/main/java/com/vaadin/client/ui/combobox/ComboBoxConnector.java b/client/src/main/java/com/vaadin/client/ui/combobox/ComboBoxConnector.java
index 21b4c0b02f..8178640900 100644
--- a/client/src/main/java/com/vaadin/client/ui/combobox/ComboBoxConnector.java
+++ b/client/src/main/java/com/vaadin/client/ui/combobox/ComboBoxConnector.java
@@ -130,6 +130,11 @@ public class ComboBoxConnector extends AbstractListingConnector
getWidget().selectedOptionKey = null;
getWidget().currentSuggestion = null;
}
+ if (isNewItemStillPending()
+ && pendingNewItemValue == getState().selectedItemCaption) {
+ // no automated selection handling required
+ clearNewItemHandling();
+ }
getDataReceivedHandler().updateSelectionFromServer(
getState().selectedItemKey, getState().selectedItemCaption,
getState().selectedItemIcon);
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();
+ }
+}