diff options
author | Denis Anisimov <denis@vaadin.com> | 2016-09-26 13:01:26 +0300 |
---|---|---|
committer | Denis Anisimov <denis@vaadin.com> | 2016-09-27 07:50:27 +0000 |
commit | 211dd5336e47f31556f3f6f42f11b7f7a62ec887 (patch) | |
tree | eac070a60d247b468e041f00f444239ff492473f /compatibility-server/src/test | |
parent | 057fe21b68206fd15b3fc894924dced3b368dd22 (diff) | |
download | vaadin-framework-211dd5336e47f31556f3f6f42f11b7f7a62ec887.tar.gz vaadin-framework-211dd5336e47f31556f3f6f42f11b7f7a62ec887.zip |
Revert ComboBox in compatibility packages to V7 version (#201).
Change-Id: Icbe1c6a5c0e2b10255424801cada8c11a71decb7
Diffstat (limited to 'compatibility-server/src/test')
-rw-r--r-- | compatibility-server/src/test/java/com/vaadin/v7/tests/server/components/ComboBoxValueChangeTest.java | 26 | ||||
-rw-r--r-- | compatibility-server/src/test/java/com/vaadin/v7/ui/ComboBoxTest.java | 158 |
2 files changed, 165 insertions, 19 deletions
diff --git a/compatibility-server/src/test/java/com/vaadin/v7/tests/server/components/ComboBoxValueChangeTest.java b/compatibility-server/src/test/java/com/vaadin/v7/tests/server/components/ComboBoxValueChangeTest.java index ffb46c519a..e62358f272 100644 --- a/compatibility-server/src/test/java/com/vaadin/v7/tests/server/components/ComboBoxValueChangeTest.java +++ b/compatibility-server/src/test/java/com/vaadin/v7/tests/server/components/ComboBoxValueChangeTest.java @@ -1,10 +1,10 @@ package com.vaadin.v7.tests.server.components; +import java.util.HashMap; +import java.util.Map; + import org.junit.Before; -import com.vaadin.server.ServerRpcManager; -import com.vaadin.server.ServerRpcMethodInvocation; -import com.vaadin.v7.shared.ui.combobox.ComboBoxServerRpc; import com.vaadin.v7.tests.server.component.abstractfield.AbstractFieldValueChangeTestBase; import com.vaadin.v7.ui.AbstractField; import com.vaadin.v7.ui.ComboBox; @@ -20,28 +20,16 @@ public class ComboBoxValueChangeTest @Before public void setUp() { - ComboBox combo = new ComboBox() { - @Override - public String getConnectorId() { - return "id"; - } - }; + ComboBox combo = new ComboBox(); combo.addItem("myvalue"); super.setUp(combo); } @Override protected void setValue(AbstractField<Object> field) { - ComboBox combo = (ComboBox) field; - ServerRpcMethodInvocation invocation = new ServerRpcMethodInvocation( - combo.getConnectorId(), ComboBoxServerRpc.class, - "setSelectedItem", 1); - invocation.setParameters(new Object[] { "myvalue" }); - try { - ServerRpcManager.applyInvocation(combo, invocation); - } catch (Exception e) { - throw new RuntimeException(e); - } + Map<String, Object> variables = new HashMap<>(); + variables.put("selected", new String[] { "myvalue" }); + ((ComboBox) field).changeVariables(field, variables); } } diff --git a/compatibility-server/src/test/java/com/vaadin/v7/ui/ComboBoxTest.java b/compatibility-server/src/test/java/com/vaadin/v7/ui/ComboBoxTest.java new file mode 100644 index 0000000000..62a0c0bdbd --- /dev/null +++ b/compatibility-server/src/test/java/com/vaadin/v7/ui/ComboBoxTest.java @@ -0,0 +1,158 @@ +package com.vaadin.v7.ui; + +import java.util.HashMap; +import java.util.List; +import java.util.Locale; +import java.util.Map; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import com.vaadin.v7.shared.ui.combobox.FilteringMode; + +public class ComboBoxTest { + + private ComboBox comboBox; + + @Before + public void setup() { + comboBox = new ComboBox(); + comboBox.setLocale(Locale.ENGLISH); + } + + @Test + public void options_noFilter() { + ComboBox comboBox = new ComboBox(); + for (int i = 0; i < 10; i++) { + comboBox.addItem("" + i); + } + + List<?> options = comboBox.getFilteredOptions(); + Assert.assertEquals(10, options.size()); + for (int i = 0; i < 10; i++) { + Assert.assertEquals("" + i, options.get(i)); + } + + } + + @Test + public void options_inMemoryFilteringStartsWith() { + for (int i = 0; i < 21; i++) { + comboBox.addItem("" + i); + } + + setFilterAndCurrentPage(comboBox, "1", 0); + + List<?> options = comboBox.getFilteredOptions(); + Assert.assertEquals(11, options.size()); + + } + + @Test + public void options_inMemoryFilteringContains() { + comboBox.setFilteringMode(FilteringMode.CONTAINS); + for (int i = 0; i < 21; i++) { + comboBox.addItem("" + i); + } + + setFilterAndCurrentPage(comboBox, "2", 0); + List<?> options = comboBox.getFilteredOptions(); + Assert.assertEquals(3, options.size()); + + } + + private static void setFilterAndCurrentPage(ComboBox comboBox, + String filterString, int currentPage) { + Map<String, Object> variables = new HashMap<>(); + variables.put("filter", filterString); + variables.put("page", currentPage); + comboBox.changeVariables(null, variables); + + } + + @Test + public void getOptions_moreThanOnePage_noNullItem() { + int nrOptions = comboBox.getPageLength() * 2; + for (int i = 0; i < nrOptions; i++) { + comboBox.addItem("" + i); + } + setFilterAndCurrentPage(comboBox, "", 0); + + List<?> goingToClient = comboBox + .sanitizeList(comboBox.getFilteredOptions(), false); + Assert.assertEquals(comboBox.getPageLength(), goingToClient.size()); + + } + + @Test + public void getOptions_moreThanOnePage_nullItem() { + int nrOptions = comboBox.getPageLength() * 2; + for (int i = 0; i < nrOptions; i++) { + comboBox.addItem("" + i); + } + + setFilterAndCurrentPage(comboBox, "", 0); + List<?> goingToClient = comboBox + .sanitizeList(comboBox.getFilteredOptions(), true); + // Null item is shown on first page + Assert.assertEquals(comboBox.getPageLength() - 1, goingToClient.size()); + + setFilterAndCurrentPage(comboBox, "", 1); + goingToClient = comboBox.sanitizeList(comboBox.getFilteredOptions(), + true); + // Null item is not shown on the second page + Assert.assertEquals(comboBox.getPageLength(), goingToClient.size()); + + } + + @Test + public void getOptions_lessThanOnePage_noNullItem() { + int nrOptions = comboBox.getPageLength() / 2; + for (int i = 0; i < nrOptions; i++) { + comboBox.addItem("" + i); + } + setFilterAndCurrentPage(comboBox, "", 0); + + List<?> goingToClient = comboBox + .sanitizeList(comboBox.getFilteredOptions(), false); + Assert.assertEquals(nrOptions, goingToClient.size()); + + } + + @Test + public void getOptions_lessThanOnePage_withNullItem() { + int nrOptions = comboBox.getPageLength() / 2; + for (int i = 0; i < nrOptions; i++) { + comboBox.addItem("" + i); + } + setFilterAndCurrentPage(comboBox, "", 0); + + List<?> goingToClient = comboBox + .sanitizeList(comboBox.getFilteredOptions(), true); + // All items + null still fit on one page + Assert.assertEquals(nrOptions, goingToClient.size()); + + } + + @Test + public void getOptions_exactlyOnePage_withNullItem() { + int nrOptions = comboBox.getPageLength(); + for (int i = 0; i < nrOptions; i++) { + comboBox.addItem("" + i); + } + setFilterAndCurrentPage(comboBox, "", 0); + + List<?> goingToClient = comboBox + .sanitizeList(comboBox.getFilteredOptions(), true); + // Null item on first page + Assert.assertEquals(nrOptions - 1, goingToClient.size()); + + setFilterAndCurrentPage(comboBox, "", 1); + goingToClient = comboBox.sanitizeList(comboBox.getFilteredOptions(), + true); + // All but one was on the first page + Assert.assertEquals(1, goingToClient.size()); + + } +} |