aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnna Koskinen <Ansku@users.noreply.github.com>2020-05-20 10:39:17 +0300
committerGitHub <noreply@github.com>2020-05-20 10:39:17 +0300
commit222705a48b80a23d6cd3f2884367a249a0130638 (patch)
tree4d19f3e00d906f153206c244944bda072dd6284e
parent452357791fe20aae1e9b650c646bc70e8446d86c (diff)
downloadvaadin-framework-222705a48b80a23d6cd3f2884367a249a0130638.tar.gz
vaadin-framework-222705a48b80a23d6cd3f2884367a249a0130638.zip
Fix compatibility ComboBox filtering when page length is zero. (#12016)
Issue #11246, slightly modified cherry-pick from #11247
-rw-r--r--compatibility-server/src/main/java/com/vaadin/v7/ui/ComboBox.java4
-rw-r--r--uitest/src/main/java/com/vaadin/v7/tests/components/combobox/ComboboxPageLengthZeroFilter.java89
-rw-r--r--uitest/src/test/java/com/vaadin/v7/tests/components/combobox/ComboboxPageLengthZeroFilterTest.java28
3 files changed, 120 insertions, 1 deletions
diff --git a/compatibility-server/src/main/java/com/vaadin/v7/ui/ComboBox.java b/compatibility-server/src/main/java/com/vaadin/v7/ui/ComboBox.java
index aaccdb8b25..f502aedd8e 100644
--- a/compatibility-server/src/main/java/com/vaadin/v7/ui/ComboBox.java
+++ b/compatibility-server/src/main/java/com/vaadin/v7/ui/ComboBox.java
@@ -620,7 +620,9 @@ public class ComboBox extends AbstractSelect
// page length usable for non-null items
int effectivePageLength = pageLength
- (needNullSelectOption && (currentPage == 0) ? 1 : 0);
- return Math.min(size - 1, first + effectivePageLength - 1);
+ // zero pageLength implies infinite page size
+ return pageLength == 0 ? size - 1
+ : Math.min(size - 1, first + effectivePageLength - 1);
}
/**
diff --git a/uitest/src/main/java/com/vaadin/v7/tests/components/combobox/ComboboxPageLengthZeroFilter.java b/uitest/src/main/java/com/vaadin/v7/tests/components/combobox/ComboboxPageLengthZeroFilter.java
new file mode 100644
index 0000000000..0bde409332
--- /dev/null
+++ b/uitest/src/main/java/com/vaadin/v7/tests/components/combobox/ComboboxPageLengthZeroFilter.java
@@ -0,0 +1,89 @@
+/*
+* Copyright 2000-2020 Vaadin Ltd.
+*
+* Licensed under the Apache License, Version 2.0 (the "License"); you may not
+* use this file except in compliance with the License. You may obtain a copy of
+* the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+* License for the specific language governing permissions and limitations under
+* the License.
+*/
+package com.vaadin.v7.tests.components.combobox;
+
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.AbstractTestUI;
+import com.vaadin.v7.data.util.BeanContainer;
+import com.vaadin.v7.ui.AbstractSelect.ItemCaptionMode;
+import com.vaadin.v7.ui.ComboBox;
+
+/**
+ * Test for issue #11246 where ComboBox set to render from Property does not
+ * filter correctly when page size is 0
+ *
+ * @author Vaadin Ltd
+ */
+@SuppressWarnings("deprecation")
+public class ComboboxPageLengthZeroFilter extends AbstractTestUI {
+
+ public static class Topping {
+ private int id;
+ private String name;
+
+ public Topping(int id, String name) {
+ this.id = id;
+ this.name = name;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ public int getId() {
+ return id;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+ }
+
+ @Override
+ protected void setup(VaadinRequest request) {
+ BeanContainer<Integer, Topping> container = new BeanContainer<Integer, Topping>(
+ Topping.class);
+ container.setBeanIdProperty("id");
+ for (int i = 0; i < 12; i++) {
+ container.addBean(new Topping(i, "Topping " + i));
+ }
+
+ final ComboBox comboBox = new ComboBox();
+ comboBox.setPageLength(0);
+ comboBox.setItemCaptionMode(ItemCaptionMode.PROPERTY);
+ comboBox.setItemCaptionPropertyId("name");
+ comboBox.setContainerDataSource(container);
+ comboBox.setInvalidAllowed(false);
+ comboBox.setNullSelectionAllowed(false);
+ comboBox.setTextInputAllowed(true);
+
+ getLayout().addComponent(comboBox);
+ }
+
+ @Override
+ protected Integer getTicketNumber() {
+ return 11246;
+ }
+
+ @Override
+ protected String getTestDescription() {
+ return "Filtering should work even when ComboBox page length is zero.";
+ }
+}
diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/combobox/ComboboxPageLengthZeroFilterTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/combobox/ComboboxPageLengthZeroFilterTest.java
new file mode 100644
index 0000000000..2df375b3e9
--- /dev/null
+++ b/uitest/src/test/java/com/vaadin/v7/tests/components/combobox/ComboboxPageLengthZeroFilterTest.java
@@ -0,0 +1,28 @@
+package com.vaadin.v7.tests.components.combobox;
+import java.util.List;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import com.vaadin.testbench.By;
+import com.vaadin.testbench.elements.ComboBoxElement;
+import com.vaadin.tests.tb3.MultiBrowserTest;
+
+public class ComboboxPageLengthZeroFilterTest extends MultiBrowserTest {
+
+ @Test
+ public void testOptionsNotEmpty() {
+ openTestURL();
+
+ List<String> suggestions = getFilterSuggestions("T");
+
+ Assert.assertEquals("All items should be presented!", 12,
+ suggestions.size());
+ }
+
+ private List<String> getFilterSuggestions(String string) {
+ ComboBoxElement comboBox = $(ComboBoxElement.class).first();
+ comboBox.findElement(By.vaadin("#textbox")).sendKeys(string);
+ return comboBox.getPopupSuggestions();
+ }
+}