aboutsummaryrefslogtreecommitdiffstats
path: root/server/src/test/java/com/vaadin/ui
diff options
context:
space:
mode:
authorLeif Åstrand <legioth@gmail.com>2017-02-02 12:33:57 +0200
committerDenis <denis@vaadin.com>2017-02-02 12:33:57 +0200
commit700742c85872c018af017f757fde64d564050811 (patch)
tree601e638e6a46b9636a8d267a685832a222a8d53c /server/src/test/java/com/vaadin/ui
parent567a43038a64b1acef395cc248bcda31b0a72949 (diff)
downloadvaadin-framework-700742c85872c018af017f757fde64d564050811.tar.gz
vaadin-framework-700742c85872c018af017f757fde64d564050811.zip
Add helpers for dealing with columns based on its id (#8411)
* Add helpers for dealing with columns based on its id setColumns(Column...) is removed since it's not possible to re-add a removed column instance. Fixes #8361
Diffstat (limited to 'server/src/test/java/com/vaadin/ui')
-rw-r--r--server/src/test/java/com/vaadin/ui/components/grid/StaticSectionTest.java137
1 files changed, 137 insertions, 0 deletions
diff --git a/server/src/test/java/com/vaadin/ui/components/grid/StaticSectionTest.java b/server/src/test/java/com/vaadin/ui/components/grid/StaticSectionTest.java
new file mode 100644
index 0000000000..1223cfaef8
--- /dev/null
+++ b/server/src/test/java/com/vaadin/ui/components/grid/StaticSectionTest.java
@@ -0,0 +1,137 @@
+/*
+ * 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.components.grid;
+
+import java.util.Arrays;
+import java.util.HashSet;
+
+import org.jsoup.nodes.Element;
+import org.jsoup.parser.Tag;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.vaadin.data.ValueProvider;
+import com.vaadin.ui.Grid;
+import com.vaadin.ui.Grid.Column;
+
+public class StaticSectionTest {
+ private final Grid<String> grid = new Grid<>();
+ private final Column<String, String> col1 = grid
+ .addColumn(ValueProvider.identity()).setId("col1");
+ private final Column<String, String> col2 = grid
+ .addColumn(ValueProvider.identity()).setId("col2");
+ private final Column<String, String> col3 = grid
+ .addColumn(ValueProvider.identity()).setId("col3");
+
+ private HeaderRow headerRow;
+ private FooterRow footerRow;
+
+ @Before
+ public void setUp() {
+ footerRow = grid.addFooterRowAt(0);
+ headerRow = grid.addHeaderRowAt(0);
+ }
+
+ @Test
+ public void joinFootersBySet() {
+ footerRow.join(new HashSet<>(Arrays.asList(footerRow.getCell(col1),
+ footerRow.getCell(col2))));
+
+ assertFootersJoined();
+ }
+
+ @Test
+ public void joinFootersByCells() {
+ footerRow.join(footerRow.getCell(col1), footerRow.getCell(col2));
+
+ assertFootersJoined();
+ }
+
+ @Test
+ public void joinFootersByColumns() {
+ footerRow.join(col1, col2);
+
+ assertFootersJoined();
+ }
+
+ @Test
+ public void joinFootersByIds() {
+ footerRow.join("col1", "col2");
+
+ assertFootersJoined();
+ }
+
+ @Test
+ public void joinHeadersBySet() {
+ headerRow.join(new HashSet<>(Arrays.asList(headerRow.getCell(col1),
+ headerRow.getCell(col2))));
+
+ assertHeadersJoined();
+ }
+
+ @Test
+ public void joinHeadersByCells() {
+ headerRow.join(headerRow.getCell(col1), headerRow.getCell(col2));
+
+ assertHeadersJoined();
+ }
+
+ @Test
+ public void joinHeadersByColumns() {
+ headerRow.join(col1, col2);
+
+ assertHeadersJoined();
+ }
+
+ @Test
+ public void joinHeadersByIds() {
+ headerRow.join("col1", "col2");
+
+ assertHeadersJoined();
+ }
+
+ @Test(expected = IllegalStateException.class)
+ public void joinHeadersByMissingIds() {
+ headerRow.join("col1", "col4");
+ }
+
+ @Test(expected = IllegalStateException.class)
+ public void joinFootersByMissingIds() {
+ headerRow.join("col1", "col4");
+ }
+
+ private void assertFootersJoined() {
+ assertJoined((StaticSection.StaticRow<?>) footerRow);
+ }
+
+ private void assertHeadersJoined() {
+ assertJoined((StaticSection.StaticRow<?>) headerRow);
+ }
+
+ private static void assertJoined(StaticSection.StaticRow<?> staticRow) {
+ // There doesn't seem to be any direct API for checking what's joined,
+ // so verifying the merging by checking the declarative output
+ Element container = new Element(Tag.valueOf("container"), "");
+
+ staticRow.writeDesign(container, null);
+
+ Assert.assertEquals(2, container.children().size());
+ Assert.assertEquals("col1,col2", container.child(0).attr("column-ids"));
+ Assert.assertEquals("col3", container.child(1).attr("column-ids"));
+ }
+
+}