From: Vlad Date: Thu, 8 Nov 2018 12:33:01 +0000 (+0300) Subject: Fix Combo Box filtered on Property not showing results when page length is zero ... X-Git-Tag: 7.7.16~12 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=c60c8cb98a782037084314925213162f0f2a59c5;p=vaadin-framework.git Fix Combo Box filtered on Property not showing results when page length is zero (#11247) * Fix #11246 Take zero pageLength into account when calculating filtered ComboBox contents. * Create ComboboxPageLengthZeroFilterTest.java * add UI tests for fix --- diff --git a/server/src/main/java/com/vaadin/ui/ComboBox.java b/server/src/main/java/com/vaadin/ui/ComboBox.java index e6a50256cc..11557819e8 100644 --- a/server/src/main/java/com/vaadin/ui/ComboBox.java +++ b/server/src/main/java/com/vaadin/ui/ComboBox.java @@ -618,7 +618,8 @@ 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/tests/components/combobox/ComboboxPageLengthZeroFilter.java b/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboboxPageLengthZeroFilter.java new file mode 100755 index 0000000000..60ca0ba4d8 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboboxPageLengthZeroFilter.java @@ -0,0 +1,80 @@ +/* +* Copyright 2000-2014 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.tests.components.combobox; + +import com.vaadin.data.util.BeanContainer; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.ComboBox; +import com.vaadin.ui.AbstractSelect.ItemCaptionMode; + +/** + * Test for issue #11246 where ComboBox set to render from Property does not + * filter correctly when page size is 0 + * + * @since + * @author Vaadin Ltd + */ +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 container = new BeanContainer( + Topping.class); + container.setBeanIdProperty("id"); + for (int i = 0; i < 12; i++) { + container.addBean(new Topping(i, "Toping " + 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); + } + +} diff --git a/uitest/src/test/java/com/vaadin/tests/components/combobox/ComboboxPageLengthZeroFilterTest.java b/uitest/src/test/java/com/vaadin/tests/components/combobox/ComboboxPageLengthZeroFilterTest.java new file mode 100644 index 0000000000..8ef1be5671 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/components/combobox/ComboboxPageLengthZeroFilterTest.java @@ -0,0 +1,27 @@ +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 suggestions = getFilterSuggestions("T"); + + Assert.assertEquals("All items should be presented!", 12, + suggestions.size()); + } + + private List getFilterSuggestions(String string) { + ComboBoxElement comboBox = $(ComboBoxElement.class).first(); + comboBox.findElement(By.vaadin("#textbox")).sendKeys(string); + return comboBox.getPopupSuggestions(); + } +}