summaryrefslogtreecommitdiffstats
path: root/server/tests
diff options
context:
space:
mode:
authorTeemu Suo-Anttila <teemusa@vaadin.com>2015-04-13 10:56:53 +0300
committerVaadin Code Review <review@vaadin.com>2015-04-14 13:12:41 +0000
commit9298d87e5c0c2fd14278e96af3d49a7a7a092dd2 (patch)
tree84de8f9f7827eebb4a722a069c950f0b9fdc967a /server/tests
parent05ce7f4158231b9ddcea69ead3bc26681c6d77f8 (diff)
downloadvaadin-framework-9298d87e5c0c2fd14278e96af3d49a7a7a092dd2.tar.gz
vaadin-framework-9298d87e5c0c2fd14278e96af3d49a7a7a092dd2.zip
Fix Grid Columns declarative support (#16596)
Change-Id: I62e06ca7be62d81f8cca619775e150250a478b39
Diffstat (limited to 'server/tests')
-rw-r--r--server/tests/src/com/vaadin/tests/server/component/grid/declarative/GridColumnDeclarativeTest.java91
-rw-r--r--server/tests/src/com/vaadin/tests/server/component/grid/declarative/GridDeclarativeTestBase.java71
-rw-r--r--server/tests/src/com/vaadin/tests/server/component/grid/declarative/GridStructureDeclarativeTest.java50
3 files changed, 212 insertions, 0 deletions
diff --git a/server/tests/src/com/vaadin/tests/server/component/grid/declarative/GridColumnDeclarativeTest.java b/server/tests/src/com/vaadin/tests/server/component/grid/declarative/GridColumnDeclarativeTest.java
new file mode 100644
index 0000000000..735a1ab502
--- /dev/null
+++ b/server/tests/src/com/vaadin/tests/server/component/grid/declarative/GridColumnDeclarativeTest.java
@@ -0,0 +1,91 @@
+/*
+ * 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.server.component.grid.declarative;
+
+import org.junit.Test;
+
+import com.vaadin.ui.Grid;
+
+public class GridColumnDeclarativeTest extends GridDeclarativeTestBase {
+
+ @Test
+ public void testSimpleGridColumns() {
+ String design = "<v-grid><table>"//
+ + "<colgroup>"
+ + " <col sortable=true width='100' property-id='Column1'>"
+ + " <col sortable=false max-width='200' expand='2' property-id='Column2'>"
+ + " <col sortable=true editable=false min-width='15' expand='1' property-id='Column3'>"
+ + "</colgroup>" //
+ + "</table></v-grid>";
+ Grid grid = new Grid();
+ grid.addColumn("Column1", String.class).setWidth(100);
+ grid.addColumn("Column2", String.class).setMaximumWidth(200)
+ .setExpandRatio(2).setSortable(false);
+ grid.addColumn("Column3", String.class).setMinimumWidth(15)
+ .setExpandRatio(1).setEditable(false);
+
+ // Use the read grid component to do another pass on write.
+ testRead(design, grid, true);
+ testWrite(design, grid);
+ }
+
+ @Test
+ public void testReadColumnsWithoutPropertyId() {
+ String design = "<v-grid><table>"//
+ + "<colgroup>"
+ + " <col sortable=true width='100' property-id='Column1'>"
+ + " <col sortable=true max-width='200' expand='2'>" // property-id="property-1"
+ + " <col sortable=true min-width='15' expand='1' property-id='Column3'>"
+ + "</colgroup>" //
+ + "</table></v-grid>";
+ Grid grid = new Grid();
+ grid.addColumn("Column1", String.class).setWidth(100);
+ grid.addColumn("property-1", String.class).setMaximumWidth(200)
+ .setExpandRatio(2);
+ grid.addColumn("Column3", String.class).setMinimumWidth(15)
+ .setExpandRatio(1);
+
+ testRead(design, grid);
+ }
+
+ @Test
+ public void testReadEmptyExpand() {
+ String design = "<v-grid><table>"//
+ + "<colgroup>"
+ + " <col sortable=true expand />"
+ + "</colgroup>" //
+ + "</table></v-grid>";
+
+ Grid grid = new Grid();
+ grid.addColumn("property-0", String.class).setExpandRatio(1);
+
+ testRead(design, grid);
+ }
+
+ @Test
+ public void testReadColumnWithNoAttributes() {
+ String design = "<v-grid><table>"//
+ + "<colgroup>" //
+ + " <col />" //
+ + "</colgroup>" //
+ + "</table></v-grid>";
+
+ Grid grid = new Grid();
+ grid.addColumn("property-0", String.class);
+
+ testRead(design, grid);
+ }
+}
diff --git a/server/tests/src/com/vaadin/tests/server/component/grid/declarative/GridDeclarativeTestBase.java b/server/tests/src/com/vaadin/tests/server/component/grid/declarative/GridDeclarativeTestBase.java
new file mode 100644
index 0000000000..56f4647e90
--- /dev/null
+++ b/server/tests/src/com/vaadin/tests/server/component/grid/declarative/GridDeclarativeTestBase.java
@@ -0,0 +1,71 @@
+/*
+ * 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.server.component.grid.declarative;
+
+import java.util.List;
+
+import org.junit.Assert;
+
+import com.vaadin.tests.design.DeclarativeTestBase;
+import com.vaadin.ui.Grid;
+import com.vaadin.ui.Grid.Column;
+
+public class GridDeclarativeTestBase extends DeclarativeTestBase<Grid> {
+
+ @Override
+ public Grid testRead(String design, Grid expected) {
+ return testRead(design, expected, false);
+ }
+
+ public Grid testRead(String design, Grid expected, boolean retestWrite) {
+ Grid readGrid = super.testRead(design, expected);
+
+ compareGridColumns(expected, readGrid);
+
+ if (retestWrite) {
+ testWrite(design, readGrid);
+ }
+
+ return readGrid;
+ }
+
+ private void compareGridColumns(Grid expected, Grid actual) {
+ List<Column> columns = expected.getColumns();
+ List<Column> actualColumns = actual.getColumns();
+ Assert.assertEquals("Different amount of columns", columns.size(),
+ actualColumns.size());
+ for (int i = 0; i < columns.size(); ++i) {
+ Column col1 = columns.get(i);
+ Column col2 = actualColumns.get(i);
+ String baseError = "Error when comparing columns for property "
+ + col1.getPropertyId() + ": ";
+ assertEquals(baseError + "Property id", col1.getPropertyId(),
+ col2.getPropertyId());
+ assertEquals(baseError + "Width", col1.getWidth(), col2.getWidth());
+ assertEquals(baseError + "Maximum width", col1.getMaximumWidth(),
+ col2.getMaximumWidth());
+ assertEquals(baseError + "Minimum width", col1.getMinimumWidth(),
+ col2.getMinimumWidth());
+ assertEquals(baseError + "Expand ratio", col1.getExpandRatio(),
+ col2.getExpandRatio());
+ assertEquals(baseError + "Sortable", col1.isSortable(),
+ col2.isSortable());
+ assertEquals(baseError + "Editable", col1.isEditable(),
+ col2.isEditable());
+
+ }
+ }
+}
diff --git a/server/tests/src/com/vaadin/tests/server/component/grid/declarative/GridStructureDeclarativeTest.java b/server/tests/src/com/vaadin/tests/server/component/grid/declarative/GridStructureDeclarativeTest.java
new file mode 100644
index 0000000000..dc74f46d4d
--- /dev/null
+++ b/server/tests/src/com/vaadin/tests/server/component/grid/declarative/GridStructureDeclarativeTest.java
@@ -0,0 +1,50 @@
+/*
+ * 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.server.component.grid.declarative;
+
+import org.junit.Test;
+
+import com.vaadin.ui.Grid;
+import com.vaadin.ui.declarative.DesignException;
+
+public class GridStructureDeclarativeTest extends GridDeclarativeTestBase {
+
+ @Test
+ public void testReadEmptyGrid() {
+ String design = "<v-grid />";
+ testRead(design, new Grid(), false);
+ }
+
+ @Test
+ public void testEmptyGrid() {
+ String design = "<v-grid></v-grid>";
+ Grid expected = new Grid();
+ testWrite(design, expected);
+ testRead(design, expected, true);
+ }
+
+ @Test(expected = DesignException.class)
+ public void testMalformedGrid() {
+ String design = "<v-grid><v-label /></v-grid>";
+ testRead(design, new Grid());
+ }
+
+ @Test(expected = DesignException.class)
+ public void testGridWithNoColGroup() {
+ String design = "<v-grid><table><thead><tr><th>Foo</tr></thead></table></v-grid>";
+ testRead(design, new Grid());
+ }
+}