diff options
author | Leif Åstrand <leif@vaadin.com> | 2016-09-13 12:31:08 +0300 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2016-09-14 07:55:54 +0000 |
commit | 13e3d235e5ce62ad03a2da0046162e10bd5bd94c (patch) | |
tree | ab0d95605fa1ff865e015c3294054f73d49816e3 /server/src/test/java | |
parent | 7c2c1e614a1de491473877aba06cd6d81b7b2530 (diff) | |
download | vaadin-framework-13e3d235e5ce62ad03a2da0046162e10bd5bd94c.tar.gz vaadin-framework-13e3d235e5ce62ad03a2da0046162e10bd5bd94c.zip |
Add multi selection support to CheckBoxGroup
This patch adds multi selection support only for CheckBoxGroup without
even trying to generalize anything. Adopting the concepts to work with
other components will be done separately.
Change-Id: Id4ccd2c743b74cb022dc9dfd8cd8dae3bf8f0c54
Diffstat (limited to 'server/src/test/java')
-rw-r--r-- | server/src/test/java/com/vaadin/ui/CheckBoxGroupTest.java | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/server/src/test/java/com/vaadin/ui/CheckBoxGroupTest.java b/server/src/test/java/com/vaadin/ui/CheckBoxGroupTest.java new file mode 100644 index 0000000000..0ad1801e8b --- /dev/null +++ b/server/src/test/java/com/vaadin/ui/CheckBoxGroupTest.java @@ -0,0 +1,54 @@ +/* + * Copyright 2000-2016 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.ui; + +import java.util.ArrayList; +import java.util.Arrays; + +import org.junit.Assert; +import org.junit.Test; + +import com.vaadin.server.data.DataSource; +import com.vaadin.shared.data.selection.SelectionModel.Multi; + +public class CheckBoxGroupTest { + @Test + public void stableSelectionOrder() { + CheckBoxGroup<String> checkBoxGroup = new CheckBoxGroup<>(); + // Intentional deviation from upcoming selection order + checkBoxGroup + .setDataSource(DataSource.create("Third", "Second", "First")); + Multi<String> selectionModel = checkBoxGroup.getSelectionModel(); + + selectionModel.select("First"); + selectionModel.select("Second"); + selectionModel.select("Third"); + + assertSelectionOrder(selectionModel, "First", "Second", "Third"); + + selectionModel.deselect("First"); + assertSelectionOrder(selectionModel, "Second", "Third"); + + selectionModel.select("First"); + assertSelectionOrder(selectionModel, "Second", "Third", "First"); + } + + private static void assertSelectionOrder(Multi<String> selectionModel, + String... selectionOrder) { + Assert.assertEquals(Arrays.asList(selectionOrder), + new ArrayList<>(selectionModel.getSelectedItems())); + } +} |