Fixes vaadin/testbench#1009tags/8.4.0.alpha1
@@ -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; | |||
} | |||
/** |
@@ -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); |
@@ -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; | |||
} | |||
} |
@@ -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 |
@@ -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(); | |||
} | |||
} |