summaryrefslogtreecommitdiffstats
path: root/server/tests
diff options
context:
space:
mode:
authorTeemu Suo-Anttila <teemusa@vaadin.com>2015-04-10 14:55:31 +0300
committerTeemu Suo-Anttila <teemusa@vaadin.com>2015-04-14 16:19:30 +0300
commitcda732dd1f5110ef60cdc9f1848e83cea6ebd830 (patch)
tree6cd91a280d5dc7fbe0b45127b3ce71ded01620ae /server/tests
parent9298d87e5c0c2fd14278e96af3d49a7a7a092dd2 (diff)
downloadvaadin-framework-cda732dd1f5110ef60cdc9f1848e83cea6ebd830.tar.gz
vaadin-framework-cda732dd1f5110ef60cdc9f1848e83cea6ebd830.zip
Fix Grid Header/Footer declarative support (#16596)
Change-Id: Iedd02738840b4d1a82681cf090c744f07166fdd4
Diffstat (limited to 'server/tests')
-rw-r--r--server/tests/src/com/vaadin/tests/server/component/grid/declarative/GridColumnDeclarativeTest.java4
-rw-r--r--server/tests/src/com/vaadin/tests/server/component/grid/declarative/GridDeclarativeTestBase.java85
-rw-r--r--server/tests/src/com/vaadin/tests/server/component/grid/declarative/GridHeaderFooterDeclarativeTest.java267
3 files changed, 352 insertions, 4 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
index 735a1ab502..1c22a69571 100644
--- 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
@@ -29,6 +29,7 @@ public class GridColumnDeclarativeTest extends GridDeclarativeTestBase {
+ " <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>" //
+ + "<thead />" //
+ "</table></v-grid>";
Grid grid = new Grid();
grid.addColumn("Column1", String.class).setWidth(100);
@@ -37,6 +38,9 @@ public class GridColumnDeclarativeTest extends GridDeclarativeTestBase {
grid.addColumn("Column3", String.class).setMinimumWidth(15)
.setExpandRatio(1).setEditable(false);
+ // Remove the default header
+ grid.removeHeaderRow(grid.getDefaultHeaderRow());
+
// Use the read grid component to do another pass on write.
testRead(design, grid, true);
testWrite(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
index 56f4647e90..0a32ec1734 100644
--- 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
@@ -22,6 +22,10 @@ import org.junit.Assert;
import com.vaadin.tests.design.DeclarativeTestBase;
import com.vaadin.ui.Grid;
import com.vaadin.ui.Grid.Column;
+import com.vaadin.ui.Grid.FooterCell;
+import com.vaadin.ui.Grid.FooterRow;
+import com.vaadin.ui.Grid.HeaderCell;
+import com.vaadin.ui.Grid.HeaderRow;
public class GridDeclarativeTestBase extends DeclarativeTestBase<Grid> {
@@ -31,15 +35,88 @@ public class GridDeclarativeTestBase extends DeclarativeTestBase<Grid> {
}
public Grid testRead(String design, Grid expected, boolean retestWrite) {
- Grid readGrid = super.testRead(design, expected);
+ Grid actual = super.testRead(design, expected);
- compareGridColumns(expected, readGrid);
+ compareGridColumns(expected, actual);
+ compareHeaders(expected, actual);
+ compareFooters(expected, actual);
if (retestWrite) {
- testWrite(design, readGrid);
+ testWrite(design, actual);
}
- return readGrid;
+ return actual;
+ }
+
+ private void compareHeaders(Grid expected, Grid actual) {
+ Assert.assertEquals("Different header row count",
+ expected.getHeaderRowCount(), actual.getHeaderRowCount());
+ for (int i = 0; i < expected.getHeaderRowCount(); ++i) {
+ HeaderRow expectedRow = expected.getHeaderRow(i);
+ HeaderRow actualRow = actual.getHeaderRow(i);
+
+ if (expectedRow.equals(expected.getDefaultHeaderRow())) {
+ Assert.assertEquals("Different index for default header row",
+ actual.getDefaultHeaderRow(), actualRow);
+ }
+
+ for (Column c : expected.getColumns()) {
+ String baseError = "Difference when comparing cell for "
+ + c.toString() + " on header row " + i + ": ";
+ Object propertyId = c.getPropertyId();
+ HeaderCell expectedCell = expectedRow.getCell(propertyId);
+ HeaderCell actualCell = actualRow.getCell(propertyId);
+
+ switch (expectedCell.getCellType()) {
+ case TEXT:
+ Assert.assertEquals(baseError + "Text content",
+ expectedCell.getText(), actualCell.getText());
+ break;
+ case HTML:
+ Assert.assertEquals(baseError + "HTML content",
+ expectedCell.getHtml(), actualCell.getHtml());
+ break;
+ case WIDGET:
+ assertEquals(baseError + "Component content",
+ expectedCell.getComponent(),
+ actualCell.getComponent());
+ break;
+ }
+ }
+ }
+ }
+
+ private void compareFooters(Grid expected, Grid actual) {
+ Assert.assertEquals("Different footer row count",
+ expected.getFooterRowCount(), actual.getFooterRowCount());
+ for (int i = 0; i < expected.getFooterRowCount(); ++i) {
+ FooterRow expectedRow = expected.getFooterRow(i);
+ FooterRow actualRow = actual.getFooterRow(i);
+
+ for (Column c : expected.getColumns()) {
+ String baseError = "Difference when comparing cell for "
+ + c.toString() + " on footer row " + i + ": ";
+ Object propertyId = c.getPropertyId();
+ FooterCell expectedCell = expectedRow.getCell(propertyId);
+ FooterCell actualCell = actualRow.getCell(propertyId);
+
+ switch (expectedCell.getCellType()) {
+ case TEXT:
+ Assert.assertEquals(baseError + "Text content",
+ expectedCell.getText(), actualCell.getText());
+ break;
+ case HTML:
+ Assert.assertEquals(baseError + "HTML content",
+ expectedCell.getHtml(), actualCell.getHtml());
+ break;
+ case WIDGET:
+ assertEquals(baseError + "Component content",
+ expectedCell.getComponent(),
+ actualCell.getComponent());
+ break;
+ }
+ }
+ }
}
private void compareGridColumns(Grid expected, Grid actual) {
diff --git a/server/tests/src/com/vaadin/tests/server/component/grid/declarative/GridHeaderFooterDeclarativeTest.java b/server/tests/src/com/vaadin/tests/server/component/grid/declarative/GridHeaderFooterDeclarativeTest.java
new file mode 100644
index 0000000000..b4e82950cb
--- /dev/null
+++ b/server/tests/src/com/vaadin/tests/server/component/grid/declarative/GridHeaderFooterDeclarativeTest.java
@@ -0,0 +1,267 @@
+/*
+ * 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.shared.ui.label.ContentMode;
+import com.vaadin.ui.Grid;
+import com.vaadin.ui.Grid.Column;
+import com.vaadin.ui.Grid.FooterRow;
+import com.vaadin.ui.Grid.HeaderRow;
+import com.vaadin.ui.Label;
+
+public class GridHeaderFooterDeclarativeTest extends GridDeclarativeTestBase {
+
+ @Test
+ public void testSingleDefaultHeader() {
+ String design = "<v-grid><table>"//
+ + "<colgroup>"
+ + " <col sortable=true property-id='Column1'>"
+ + " <col sortable=true property-id='Column2'>"
+ + " <col sortable=true property-id='Column3'>"
+ + "</colgroup>" //
+ + "<thead>" //
+ + " <tr default='true'><th plain-text=''>Column1<th plain-text=''>Column2<th plain-text=''>Column3</tr>" //
+ + "</thead>" //
+ + "</table></v-grid>";
+ Grid grid = new Grid();
+ grid.addColumn("Column1", String.class);
+ grid.addColumn("Column2", String.class);
+ grid.addColumn("Column3", String.class);
+
+ testWrite(design, grid);
+ testRead(design, grid, true);
+ }
+
+ @Test
+ public void testSingleDefaultHTMLHeader() {
+ String design = "<v-grid><table>"//
+ + "<colgroup>"
+ + " <col sortable=true property-id='Column1'>"
+ + " <col sortable=true property-id='Column2'>"
+ + " <col sortable=true property-id='Column3'>"
+ + "</colgroup>" //
+ + "<thead>" //
+ + " <tr default='true'><th>Column1<th>Column2<th>Column3</tr>" //
+ + "</thead>" //
+ + "</table></v-grid>";
+ Grid grid = new Grid();
+ grid.addColumn("Column1", String.class);
+ grid.addColumn("Column2", String.class);
+ grid.addColumn("Column3", String.class);
+
+ HeaderRow row = grid.getDefaultHeaderRow();
+ for (Column c : grid.getColumns()) {
+ row.getCell(c.getPropertyId()).setHtml(c.getHeaderCaption());
+ }
+
+ testWrite(design, grid);
+ testRead(design, grid, true);
+ }
+
+ @Test
+ public void testNoHeaderRows() {
+ String design = "<v-grid><table>"//
+ + "<colgroup>"
+ + " <col sortable=true property-id='Column1'>"
+ + "</colgroup>" //
+ + "<thead />" //
+ + "</table></v-grid>";
+
+ Grid grid = new Grid();
+ grid.addColumn("Column1", String.class);
+ grid.removeHeaderRow(grid.getDefaultHeaderRow());
+
+ testWrite(design, grid);
+ testRead(design, grid, true);
+ }
+
+ @Test
+ public void testMultipleHeadersWithColSpans() {
+ String design = "<v-grid><table>"//
+ + "<colgroup>"
+ + " <col sortable=true property-id='Column1'>"
+ + " <col sortable=true property-id='Column2'>"
+ + " <col sortable=true property-id='Column3'>"
+ + "</colgroup>" //
+ + "<thead>" //
+ + " <tr><th colspan=3>Baz</tr>"
+ + " <tr default='true'><th>Column1<th>Column2<th>Column3</tr>" //
+ + " <tr><th>Foo<th colspan=2>Bar</tr>" //
+ + "</thead>" //
+ + "</table></v-grid>";
+ Grid grid = new Grid();
+ grid.addColumn("Column1", String.class);
+ grid.addColumn("Column2", String.class);
+ grid.addColumn("Column3", String.class);
+
+ HeaderRow row = grid.getDefaultHeaderRow();
+ for (Column c : grid.getColumns()) {
+ row.getCell(c.getPropertyId()).setHtml(c.getHeaderCaption());
+ }
+
+ grid.prependHeaderRow().join("Column1", "Column2", "Column3")
+ .setHtml("Baz");
+ row = grid.appendHeaderRow();
+ row.getCell("Column1").setHtml("Foo");
+ row.join("Column2", "Column3").setHtml("Bar");
+
+ testWrite(design, grid);
+ testRead(design, grid, true);
+ }
+
+ @Test
+ public void testSingleDefaultFooter() {
+ String design = "<v-grid><table>"//
+ + "<colgroup>"
+ + " <col sortable=true property-id='Column1'>"
+ + " <col sortable=true property-id='Column2'>"
+ + " <col sortable=true property-id='Column3'>"
+ + "</colgroup>" //
+ + "<thead />" // No headers read or written
+ + "<tfoot>" //
+ + " <tr><td plain-text=''>Column1<td plain-text=''>Column2<td plain-text=''>Column3</tr>" //
+ + "</tfoot>" //
+ + "</table></v-grid>";
+ Grid grid = new Grid();
+ grid.addColumn("Column1", String.class);
+ grid.addColumn("Column2", String.class);
+ grid.addColumn("Column3", String.class);
+
+ FooterRow row = grid.appendFooterRow();
+ for (Column c : grid.getColumns()) {
+ row.getCell(c.getPropertyId()).setText(c.getHeaderCaption());
+ }
+
+ grid.removeHeaderRow(grid.getDefaultHeaderRow());
+
+ testWrite(design, grid);
+ testRead(design, grid, true);
+ }
+
+ @Test
+ public void testSingleDefaultHTMLFooter() {
+ String design = "<v-grid><table>"//
+ + "<colgroup>"
+ + " <col sortable=true property-id='Column1'>"
+ + " <col sortable=true property-id='Column2'>"
+ + " <col sortable=true property-id='Column3'>"
+ + "</colgroup>" //
+ + "<thead />" // No headers read or written
+ + "<tfoot>" //
+ + " <tr><td>Column1<td>Column2<td>Column3</tr>" //
+ + "</tfoot>" //
+ + "</table></v-grid>";
+ Grid grid = new Grid();
+ grid.addColumn("Column1", String.class);
+ grid.addColumn("Column2", String.class);
+ grid.addColumn("Column3", String.class);
+
+ FooterRow row = grid.appendFooterRow();
+ for (Column c : grid.getColumns()) {
+ row.getCell(c.getPropertyId()).setHtml(c.getHeaderCaption());
+ }
+
+ grid.removeHeaderRow(grid.getDefaultHeaderRow());
+
+ testWrite(design, grid);
+ testRead(design, grid, true);
+ }
+
+ @Test
+ public void testMultipleFootersWithColSpans() {
+ String design = "<v-grid><table>"//
+ + "<colgroup>"
+ + " <col sortable=true property-id='Column1'>"
+ + " <col sortable=true property-id='Column2'>"
+ + " <col sortable=true property-id='Column3'>"
+ + "</colgroup>" //
+ + "<thead />" // No headers read or written.
+ + "<tfoot>" //
+ + " <tr><td colspan=3>Baz</tr>"
+ + " <tr><td>Column1<td>Column2<td>Column3</tr>" //
+ + " <tr><td>Foo<td colspan=2>Bar</tr>" //
+ + "</tfoot>" //
+ + "</table></v-grid>";
+ Grid grid = new Grid();
+ grid.addColumn("Column1", String.class);
+ grid.addColumn("Column2", String.class);
+ grid.addColumn("Column3", String.class);
+
+ FooterRow row = grid.appendFooterRow();
+ for (Column c : grid.getColumns()) {
+ row.getCell(c.getPropertyId()).setHtml(c.getHeaderCaption());
+ }
+
+ grid.prependFooterRow().join("Column1", "Column2", "Column3")
+ .setHtml("Baz");
+ row = grid.appendFooterRow();
+ row.getCell("Column1").setHtml("Foo");
+ row.join("Column2", "Column3").setHtml("Bar");
+
+ grid.removeHeaderRow(grid.getDefaultHeaderRow());
+
+ testWrite(design, grid);
+ testRead(design, grid, true);
+ }
+
+ @Test
+ public void testComponentInGridHeader() {
+ String design = "<v-grid><table>"//
+ + "<colgroup>"
+ + " <col sortable=true property-id='Column1'>"
+ + "</colgroup>" //
+ + "<thead>" //
+ + "<tr default=true><th><v-label><b>Foo</b></v-label></tr>"
+ + "</thead>"//
+ + "</table></v-grid>";
+
+ Label component = new Label("<b>Foo</b>");
+ component.setContentMode(ContentMode.HTML);
+
+ Grid grid = new Grid();
+ grid.addColumn("Column1", String.class);
+ grid.getDefaultHeaderRow().getCell("Column1").setComponent(component);
+
+ testRead(design, grid, true);
+ testWrite(design, grid);
+ }
+
+ @Test
+ public void testComponentInGridFooter() {
+ String design = "<v-grid><table>"//
+ + "<colgroup>"
+ + " <col sortable=true property-id='Column1'>"
+ + "</colgroup>" //
+ + "<thead />" // No headers read or written
+ + "<tfoot>" //
+ + "<tr><td><v-label><b>Foo</b></v-label></tr>"//
+ + "</tfoot>" //
+ + "</table></v-grid>";
+
+ Label component = new Label("<b>Foo</b>");
+ component.setContentMode(ContentMode.HTML);
+
+ Grid grid = new Grid();
+ grid.addColumn("Column1", String.class);
+ grid.prependFooterRow().getCell("Column1").setComponent(component);
+ grid.removeHeaderRow(grid.getDefaultHeaderRow());
+
+ testRead(design, grid, true);
+ testWrite(design, grid);
+ }
+}