diff options
author | Johannes Dahlström <johannesd@vaadin.com> | 2016-09-21 13:08:16 +0300 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2016-09-27 14:14:38 +0000 |
commit | 680b7009d4f453dc8eec42975192094b2e0e8e2f (patch) | |
tree | 1b9685d189e29de82f4afdfff324044b8b7f461b /uitest/src | |
parent | 211dd5336e47f31556f3f6f42f11b7f7a62ec887 (diff) | |
download | vaadin-framework-680b7009d4f453dc8eec42975192094b2e0e8e2f.tar.gz vaadin-framework-680b7009d4f453dc8eec42975192094b2e0e8e2f.zip |
Initial support for multiple headers in new Grid
Change-Id: I7a3fa34749322451ab5cef4465d4d7c76029c097
Diffstat (limited to 'uitest/src')
3 files changed, 94 insertions, 8 deletions
diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/GridColumnResizing.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridColumnResizing.java index 67e6473850..a07550a20a 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/grid/GridColumnResizing.java +++ b/uitest/src/main/java/com/vaadin/tests/components/grid/GridColumnResizing.java @@ -2,6 +2,7 @@ package com.vaadin.tests.components.grid; import java.util.Arrays; +import com.vaadin.annotations.Widgetset; import com.vaadin.server.VaadinRequest; import com.vaadin.tests.components.AbstractTestUI; import com.vaadin.tests.data.bean.Person; @@ -11,6 +12,7 @@ import com.vaadin.ui.Label; import com.vaadin.ui.TextField; import com.vaadin.ui.renderers.NumberRenderer; +@Widgetset("com.vaadin.DefaultWidgetSet") public class GridColumnResizing extends AbstractTestUI { @Override diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/basics/GridBasics.java b/uitest/src/main/java/com/vaadin/tests/components/grid/basics/GridBasics.java index 3a0646ed27..bf0aa3ea56 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/grid/basics/GridBasics.java +++ b/uitest/src/main/java/com/vaadin/tests/components/grid/basics/GridBasics.java @@ -33,6 +33,8 @@ import com.vaadin.ui.renderers.ProgressBarRenderer; @Widgetset("com.vaadin.DefaultWidgetSet") public class GridBasics extends AbstractTestUIWithLog { + public static final String[] COLUMN_CAPTIONS = { "Column 0", "Column 1", "Column 2", "Row Number", "Date", "HTML String", "Big Random", "Small Random" }; + public static final String ROW_STYLE_GENERATOR_ROW_NUMBERS_FOR_3_OF_4 = "Row numbers for 3/4"; public static final String ROW_STYLE_GENERATOR_NONE = "None"; public static final String ROW_STYLE_GENERATOR_ROW_NUMBERS = "Row numbers"; @@ -128,21 +130,21 @@ public class GridBasics extends AbstractTestUIWithLog { grid = new Grid<>(); grid.setItems(data); - grid.addColumn("Column 0", + grid.addColumn(COLUMN_CAPTIONS[0], dataObj -> "(" + dataObj.getRowNumber() + ", 0)"); - grid.addColumn("Column 1", + grid.addColumn(COLUMN_CAPTIONS[1], dataObj -> "(" + dataObj.getRowNumber() + ", 1)"); - grid.addColumn("Column 2", + grid.addColumn(COLUMN_CAPTIONS[2], dataObj -> "(" + dataObj.getRowNumber() + ", 2)"); - grid.addColumn("Row Number", DataObject::getRowNumber, + grid.addColumn(COLUMN_CAPTIONS[3], DataObject::getRowNumber, new NumberRenderer()); - grid.addColumn("Date", DataObject::getDate, new DateRenderer()); - grid.addColumn("HTML String", DataObject::getHtmlString, + grid.addColumn(COLUMN_CAPTIONS[4], DataObject::getDate, new DateRenderer()); + grid.addColumn(COLUMN_CAPTIONS[5], DataObject::getHtmlString, new HtmlRenderer()); - grid.addColumn("Big Random", DataObject::getBigRandom, + grid.addColumn(COLUMN_CAPTIONS[6], DataObject::getBigRandom, new NumberRenderer()); - grid.addColumn("Small Random", data -> data.getSmallRandom() / 5d, + grid.addColumn(COLUMN_CAPTIONS[7], data -> data.getSmallRandom() / 5d, new ProgressBarRenderer()); grid.addSelectionListener(e -> log("Selected: " + e.getValue())); @@ -159,6 +161,7 @@ public class GridBasics extends AbstractTestUIWithLog { createSizeMenu(componentMenu.addItem("Size", null)); createDetailsMenu(componentMenu.addItem("Details", null)); createBodyMenu(componentMenu.addItem("Body rows", null)); + createHeaderMenu(componentMenu.addItem("Header", null)); return menu; } @@ -293,6 +296,18 @@ public class GridBasics extends AbstractTestUIWithLog { }); } + private void createHeaderMenu(MenuItem headerMenu) { + headerMenu.addItem("Append header row", menuItem -> { + grid.appendHeaderRow(); + }); + headerMenu.addItem("Prepend header row", menuItem -> { + grid.prependHeaderRow(); + }); + headerMenu.addItem("Remove first header row", menuItem -> { + grid.removeHeaderRow(0); + }); + } + /* DetailsGenerator related things */ private void createDetailsMenu(MenuItem detailsMenu) { diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/basics/GridHeaderFooterTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/basics/GridHeaderFooterTest.java new file mode 100644 index 0000000000..c1a4cfc2b0 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/components/grid/basics/GridHeaderFooterTest.java @@ -0,0 +1,69 @@ +/* + * 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.tests.components.grid.basics; + +import static org.junit.Assert.assertEquals; + +import java.util.List; + +import org.junit.Test; + +import com.vaadin.testbench.By; +import com.vaadin.testbench.elements.GridElement.GridCellElement; + +public class GridHeaderFooterTest extends GridBasicsTest { + + @Test + public void initialState_defaultHeaderPresent() { + assertEquals(1, getGridElement().getHeaderCount()); + + final String[] captions = GridBasics.COLUMN_CAPTIONS; + List<GridCellElement> headerCells = getGridElement().getHeaderCells(0); + + assertEquals(captions.length, headerCells.size()); + for (int i = 0; i < headerCells.size(); i++) { + assertText(captions[i], headerCells.get(i)); + } + } + + @Test + public void appendHeaderRow_addedToBottom() { + selectMenuPath("Component", "Header", "Append header row"); + + assertEquals(2, getGridElement().getHeaderCount()); + } + + @Test + public void prependHeaderRow_addedToBottom() { + selectMenuPath("Component", "Header", "Prepend header row"); + + assertEquals(2, getGridElement().getHeaderCount()); + } + + @Test + public void removeDefaultHeaderRow_noHeaderRows() { + selectMenuPath("Component", "Header", "Remove first header row"); + + assertEquals(0, getGridElement().getHeaderCount()); + } + + protected static void assertText(String expected, GridCellElement e) { + // TBE.getText returns "" if the element is scrolled out of view + String actual = e.findElement(By.tagName("div")).getAttribute( + "innerHTML"); + assertEquals(expected, actual); + } +} |