diff options
author | Sun Zhe <31067185+ZheSun88@users.noreply.github.com> | 2018-12-11 11:08:21 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-12-11 11:08:21 +0200 |
commit | 96a7c2f99c657c14282fe9a721280d425565d4c6 (patch) | |
tree | 72677fafc9f726b653b611979e7bcfee2cf87737 | |
parent | 5480d82bb8554d3980a55714c6128cfe1d63ec92 (diff) | |
download | vaadin-framework-96a7c2f99c657c14282fe9a721280d425565d4c6.tar.gz vaadin-framework-96a7c2f99c657c14282fe9a721280d425565d4c6.zip |
Request data update before client response (#11341)
* Request data update before client response
* fix the accidental commit
* add tests
fixes #11320
4 files changed, 107 insertions, 5 deletions
diff --git a/server/src/main/java/com/vaadin/data/provider/DataCommunicator.java b/server/src/main/java/com/vaadin/data/provider/DataCommunicator.java index 449cbc5711..35dad20c49 100644 --- a/server/src/main/java/com/vaadin/data/provider/DataCommunicator.java +++ b/server/src/main/java/com/vaadin/data/provider/DataCommunicator.java @@ -530,6 +530,7 @@ public class DataCommunicator<T> extends AbstractExtension { public void reset() { // Only needed if a full reset is not pending. if (!reset) { + beforeClientResponse(true); // Soft reset through client-side re-request. getClientRpc().reset(getDataProviderSize()); } diff --git a/server/src/test/java/com/vaadin/data/provider/DataCommunicatorTest.java b/server/src/test/java/com/vaadin/data/provider/DataCommunicatorTest.java index c187c91471..98ae758b6d 100644 --- a/server/src/test/java/com/vaadin/data/provider/DataCommunicatorTest.java +++ b/server/src/test/java/com/vaadin/data/provider/DataCommunicatorTest.java @@ -1,9 +1,5 @@ package com.vaadin.data.provider; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - import java.util.ArrayList; import java.util.Collections; import java.util.concurrent.Future; @@ -25,6 +21,9 @@ import com.vaadin.ui.UI; import elemental.json.Json; import elemental.json.JsonArray; import elemental.json.JsonObject; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; /** * @author Vaadin Ltd @@ -303,7 +302,7 @@ public class DataCommunicatorTest { // Mark communicator clean ui.getConnectorTracker().markClean(communicator); - assertTrue("Communicator should be marked for hard reset", + assertFalse("Communicator should not be marked for hard reset", communicator.reset); assertFalse("DataCommunicator should not be marked as dirty", ui.getConnectorTracker().isDirty(communicator)); diff --git a/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboBoxItemSize.java b/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboBoxItemSize.java new file mode 100644 index 0000000000..ed30bac755 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboBoxItemSize.java @@ -0,0 +1,51 @@ +package com.vaadin.tests.components.combobox; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Optional; + +import com.vaadin.annotations.Widgetset; +import com.vaadin.data.provider.DataProvider; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.tests.widgetset.TestingWidgetSet; +import com.vaadin.ui.Button; +import com.vaadin.ui.ComboBox; +import com.vaadin.ui.Label; + +@Widgetset(TestingWidgetSet.NAME) +public class ComboBoxItemSize extends AbstractTestUI { + @Override + protected void setup(VaadinRequest request) { + List<String> items = new ArrayList<>(Arrays.asList("blue", "red", + "green", "purple", "grey", "orange")); + + ComboBox<String> comboBox = new ComboBox<>(); + comboBox.setId("combobox"); + comboBox.setPageLength(0); + comboBox.setItems(items); + DataProvider<String, ?> dataProvider = comboBox.getDataProvider(); + comboBox.setNewItemProvider(value -> { + items.add(value); + dataProvider.refreshAll(); + return Optional.ofNullable(value); + }); + + Button button = new Button("get value"); + Label label = new Label("value of combobox"); + button.addClickListener(event -> label + .setValue("combobox value " + comboBox.getValue())); + + Button reset = new Button("reset"); + reset.addClickListener(event -> { + items.clear(); + items.addAll(Arrays.asList("blue", "red", "green", "purple", "grey", + "orange")); + dataProvider.refreshAll(); + comboBox.setValue(null); + }); + + addComponents(comboBox, button, label, reset); + } +} diff --git a/uitest/src/test/java/com/vaadin/tests/components/combobox/ComboBoxItemSizeTest.java b/uitest/src/test/java/com/vaadin/tests/components/combobox/ComboBoxItemSizeTest.java new file mode 100644 index 0000000000..cdb14ae420 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/components/combobox/ComboBoxItemSizeTest.java @@ -0,0 +1,51 @@ +package com.vaadin.tests.components.combobox; + +import org.junit.Test; +import org.openqa.selenium.Keys; +import org.openqa.selenium.interactions.Actions; + +import com.vaadin.testbench.By; +import com.vaadin.testbench.elements.ComboBoxElement; +import com.vaadin.tests.tb3.SingleBrowserTest; + +import static org.junit.Assert.assertEquals; + +public class ComboBoxItemSizeTest extends SingleBrowserTest { + + ComboBoxElement comboBoxElement; + + @Test + public void comboBoxItemSizeDisplayCorrectly() { + + openTestURL(); + + comboBoxElement = $(ComboBoxElement.class).id("combobox"); + + // initial item size include the empty option + assertItemSizeInPopup(7); + + comboBoxElement.clear(); + sendKeysToInput("black"); + + assertItemSizeInPopup(8); + + } + + private void assertItemSizeInPopup(int expectedSize) { + comboBoxElement.findElement(By.className("v-filterselect-button")) + .click(); + waitForElementPresent(By.className("v-filterselect-suggestpopup")); + int itemSize = findElement(By.className("v-filterselect-suggestmenu")) + .findElements(By.tagName("span")).size(); + assertEquals("There should be " + expectedSize + "items in the popup.", + expectedSize, itemSize); + } + + private void sendKeysToInput(CharSequence... keys) { + // ensure mouse is located over the ComboBox to avoid hover issues + new Actions(getDriver()).moveToElement(comboBoxElement).perform(); + comboBoxElement.sendKeys(keys); + comboBoxElement.sendKeys(Keys.ENTER); + waitForElementNotPresent(By.className("v-filterselect-suggestpopup")); + } +} |