aboutsummaryrefslogtreecommitdiffstats
path: root/uitest
diff options
context:
space:
mode:
authorJohannes Dahlström <johannesd@vaadin.com>2016-09-26 18:45:28 +0300
committerJohannes Dahlström <johannesd@vaadin.com>2016-09-28 00:44:10 +0300
commit96119ab0224421d69393d9d41ed02900121a683e (patch)
treeadc27cf326fdf007c24db9a742f2f41f2637fc94 /uitest
parent680b7009d4f453dc8eec42975192094b2e0e8e2f (diff)
downloadvaadin-framework-96119ab0224421d69393d9d41ed02900121a683e.tar.gz
vaadin-framework-96119ab0224421d69393d9d41ed02900121a683e.zip
Implement default header row in new Grid
Change-Id: Id26a98caca022ed2a4dbe0128a79721a54f5b267
Diffstat (limited to 'uitest')
-rw-r--r--uitest/src/main/java/com/vaadin/tests/components/grid/basics/GridBasics.java31
-rw-r--r--uitest/src/test/java/com/vaadin/tests/components/grid/basics/GridHeaderFooterTest.java82
2 files changed, 99 insertions, 14 deletions
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 bf0aa3ea56..f75dbd27cc 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
@@ -16,7 +16,9 @@ import com.vaadin.tests.components.AbstractTestUIWithLog;
import com.vaadin.ui.Button;
import com.vaadin.ui.Component;
import com.vaadin.ui.Grid;
+import com.vaadin.ui.Grid.Column;
import com.vaadin.ui.Grid.DetailsGenerator;
+import com.vaadin.ui.Grid.HeaderRow;
import com.vaadin.ui.Label;
import com.vaadin.ui.MenuBar;
import com.vaadin.ui.MenuBar.Command;
@@ -33,8 +35,6 @@ 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";
@@ -46,6 +46,10 @@ public class GridBasics extends AbstractTestUIWithLog {
public static final String CELL_STYLE_GENERATOR_EMPTY = "Empty string";
public static final String CELL_STYLE_GENERATOR_NULL = "Null";
+ public static final String[] COLUMN_CAPTIONS = { "Column 0", "Column 1",
+ "Column 2", "Row Number", "Date", "HTML String", "Big Random",
+ "Small Random" };
+
private static class DetailedDetailsGenerator
implements DetailsGenerator<DataObject> {
@@ -139,7 +143,8 @@ public class GridBasics extends AbstractTestUIWithLog {
grid.addColumn(COLUMN_CAPTIONS[3], DataObject::getRowNumber,
new NumberRenderer());
- grid.addColumn(COLUMN_CAPTIONS[4], DataObject::getDate, new DateRenderer());
+ grid.addColumn(COLUMN_CAPTIONS[4], DataObject::getDate,
+ new DateRenderer());
grid.addColumn(COLUMN_CAPTIONS[5], DataObject::getHtmlString,
new HtmlRenderer());
grid.addColumn(COLUMN_CAPTIONS[6], DataObject::getBigRandom,
@@ -298,14 +303,30 @@ public class GridBasics extends AbstractTestUIWithLog {
private void createHeaderMenu(MenuItem headerMenu) {
headerMenu.addItem("Append header row", menuItem -> {
- grid.appendHeaderRow();
+ HeaderRow row = grid.appendHeaderRow();
+
+ int i = 0;
+ for (Column<?, ?> column : grid.getColumns()) {
+ row.getCell(column).setText("Header cell " + i++);
+ }
});
headerMenu.addItem("Prepend header row", menuItem -> {
- grid.prependHeaderRow();
+ HeaderRow row = grid.prependHeaderRow();
+
+ int i = 0;
+ for (Column<?, ?> column : grid.getColumns()) {
+ row.getCell(column).setText("Header cell " + i++);
+ }
});
headerMenu.addItem("Remove first header row", menuItem -> {
grid.removeHeaderRow(0);
});
+ headerMenu.addItem("Set first row as default", menuItem -> {
+ grid.setDefaultHeaderRow(grid.getHeaderRow(0));
+ });
+ headerMenu.addItem("Set no default row", menuItem -> {
+ grid.setDefaultHeaderRow(null);
+ });
}
/* DetailsGenerator related things */
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
index c1a4cfc2b0..5b594a980d 100644
--- 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
@@ -16,8 +16,11 @@
package com.vaadin.tests.components.grid.basics;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
import java.util.List;
+import java.util.stream.IntStream;
import org.junit.Test;
@@ -26,17 +29,15 @@ import com.vaadin.testbench.elements.GridElement.GridCellElement;
public class GridHeaderFooterTest extends GridBasicsTest {
+ protected static final String[] HEADER_TEXTS = IntStream
+ .range(0, GridBasics.COLUMN_CAPTIONS.length)
+ .mapToObj(i -> "Header cell " + i)
+ .toArray(String[]::new);
+
@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));
- }
+ assertHeaderTexts(0, GridBasics.COLUMN_CAPTIONS);
}
@Test
@@ -44,13 +45,17 @@ public class GridHeaderFooterTest extends GridBasicsTest {
selectMenuPath("Component", "Header", "Append header row");
assertEquals(2, getGridElement().getHeaderCount());
+ assertHeaderTexts(0, GridBasics.COLUMN_CAPTIONS);
+ assertHeaderTexts(1, HEADER_TEXTS);
}
@Test
- public void prependHeaderRow_addedToBottom() {
+ public void prependHeaderRow_addedToTop() {
selectMenuPath("Component", "Header", "Prepend header row");
assertEquals(2, getGridElement().getHeaderCount());
+ assertHeaderTexts(0, HEADER_TEXTS);
+ assertHeaderTexts(1, GridBasics.COLUMN_CAPTIONS);
}
@Test
@@ -60,10 +65,69 @@ public class GridHeaderFooterTest extends GridBasicsTest {
assertEquals(0, getGridElement().getHeaderCount());
}
+ @Test
+ public void setDefaultRow_headerCaptionsUpdated() {
+ selectMenuPath("Component", "Header", "Prepend header row");
+ selectMenuPath("Component", "Header", "Set first row as default");
+
+ assertHeaderTexts(0, GridBasics.COLUMN_CAPTIONS);
+ }
+
+ @Test
+ public void clickDefaultHeaderCell_sortIndicatorPresent() {
+ GridCellElement headerCell = getGridElement().getHeaderCell(0, 2);
+ headerCell.click();
+
+ assertSortIndicator(headerCell, "sort-asc");
+
+ headerCell.click();
+ assertNoSortIndicator(headerCell, "sort-asc");
+ assertSortIndicator(headerCell, "sort-desc");
+
+ GridCellElement anotherCell = getGridElement().getHeaderCell(0, 3);
+ anotherCell.click();
+
+ assertNoSortIndicator(headerCell, "sort-asc");
+ assertNoSortIndicator(headerCell, "sort-desc");
+ assertSortIndicator(anotherCell, "sort-asc");
+ }
+
+ @Test
+ public void noDefaultRow_clickHeaderCell_sortIndicatorsNotPresent() {
+ selectMenuPath("Component", "Header", "Set no default row");
+
+ GridCellElement headerCell = getGridElement().getHeaderCell(0, 2);
+ headerCell.click();
+
+ assertNoSortIndicator(headerCell, "sort-asc");
+ assertNoSortIndicator(headerCell, "sort-desc");
+ }
+
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);
}
+
+ protected void assertHeaderTexts(int rowIndex, String[] texts) {
+ List<GridCellElement> headerCells = getGridElement().getHeaderCells(
+ rowIndex);
+
+ assertEquals(texts.length, headerCells.size());
+ for (int i = 0; i < headerCells.size(); i++) {
+ assertText(texts[i], headerCells.get(i));
+ }
+ }
+
+ protected void assertSortIndicator(GridCellElement cell, String classname) {
+ assertTrue("Header cell should have sort indicator " + classname, cell
+ .getAttribute("class").contains(classname));
+ }
+
+ protected void assertNoSortIndicator(GridCellElement cell,
+ String classname) {
+ assertFalse("Header cell should not have sort indicator " + classname,
+ cell.getAttribute("class").contains(classname));
+ }
}