diff options
author | Aleksi Hietanen <aleksi@vaadin.com> | 2017-03-16 08:53:38 +0200 |
---|---|---|
committer | Pekka Hyvönen <pekka@vaadin.com> | 2017-03-16 08:53:38 +0200 |
commit | 71679dfd1626737081b86127e6c547e37c77923f (patch) | |
tree | f0813ec2bde85fbd7f82d80b2b8f7eebaf9d6725 /testbench-api/src | |
parent | e5488dff791afe585bf7ab42e268c3e1f342c142 (diff) | |
download | vaadin-framework-71679dfd1626737081b86127e6c547e37c77923f.tar.gz vaadin-framework-71679dfd1626737081b86127e6c547e37c77923f.zip |
Hierarchical data (#8842)
* Initial HierarchicalDataProvider for TreeGrid
* Initial in-memory hierarchical data implementation
* TreeGrid declarative support
Fixes #8611, Fixes #8620
Diffstat (limited to 'testbench-api/src')
-rw-r--r-- | testbench-api/src/main/java/com/vaadin/testbench/elements/TreeGridElement.java | 112 |
1 files changed, 112 insertions, 0 deletions
diff --git a/testbench-api/src/main/java/com/vaadin/testbench/elements/TreeGridElement.java b/testbench-api/src/main/java/com/vaadin/testbench/elements/TreeGridElement.java index 71c47bcc6e..0ca81a56ef 100644 --- a/testbench-api/src/main/java/com/vaadin/testbench/elements/TreeGridElement.java +++ b/testbench-api/src/main/java/com/vaadin/testbench/elements/TreeGridElement.java @@ -15,6 +15,11 @@ */ package com.vaadin.testbench.elements; +import org.openqa.selenium.NoSuchElementException; +import org.openqa.selenium.WebElement; + +import com.vaadin.testbench.By; + /** * TestBench Element API for TreeGrid * @@ -22,4 +27,111 @@ package com.vaadin.testbench.elements; */ public class TreeGridElement extends GridElement { + /** + * Expands the row at the given index in the grid. This expects the first + * column to have the hierarchy data. + * + * @param rowIndex + * 0-based row index to expand + * @see #expandWithClick(int, int) + */ + public void expandWithClick(int rowIndex) { + expandWithClick(rowIndex, 0); + } + + /** + * Expands the row at the given index in the grid with the given + * hierarchical column index. + * + * @param rowIndex + * 0-based row index to expand + * @param hierarchyColumnIndex + * 0-based index of the hierarchy column + */ + public void expandWithClick(int rowIndex, int hierarchyColumnIndex) { + if (isRowExpanded(rowIndex, hierarchyColumnIndex)) { + throw new IllegalStateException( + "The element at row " + rowIndex + " was expanded already"); + } + getExpandElement(rowIndex, hierarchyColumnIndex).click(); + } + + /** + * Collapses the row at the given index in the grid. This expects the first + * column to have the hierarchy data. + * + * @param rowIndex + * 0-based row index to collapse + * @see #collapseWithClick(int, int) + */ + public void collapseWithClick(int rowIndex) { + collapseWithClick(rowIndex, 0); + } + + /** + * Collapses the row at the given index in the grid with the given + * hierarchical column index. + * + * @param rowIndex + * 0-based row index to collapse + * @param hierarchyColumnIndex + * 0-based index of the hierarchy column + */ + public void collapseWithClick(int rowIndex, int hierarchyColumnIndex) { + if (isRowCollapsed(rowIndex, hierarchyColumnIndex)) { + throw new IllegalStateException("The element at row " + rowIndex + + " was collapsed already"); + } + getExpandElement(rowIndex, hierarchyColumnIndex).click(); + } + + /** + * Returns whether the row at the given index is expanded or not. + * + * @param rowIndex + * 0-based row index + * @param hierarchyColumnIndex + * 0-based index of the hierarchy column + * @return {@code true} if expanded, {@code false} if collapsed + */ + public boolean isRowExpanded(int rowIndex, int hierarchyColumnIndex) { + WebElement expandElement = getExpandElement(rowIndex, + hierarchyColumnIndex); + return expandElement.getAttribute("expanded") != null + && expandElement.getAttribute("collapsed") == null; + } + + /** + * Returns whether the row at the given index is collapsed or not. + * + * @param rowIndex + * 0-based row index + * @param hierarchyColumnIndex + * 0-based index of the hierarchy column + * @return {@code true} if collapsed, {@code false} if expanded + */ + public boolean isRowCollapsed(int rowIndex, int hierarchyColumnIndex) { + WebElement expandElement = getExpandElement(rowIndex, + hierarchyColumnIndex); + return expandElement.getAttribute("collapsed") != null + && expandElement.getAttribute("expanded") == null; + } + + /** + * Gets the expand/collapse element for the given row. + * + * @param rowIndex + * 0-based row index + * @param hierarchyColumnIndex + * 0-based index of the hierarchy column + * @return the {@code span} element that is clicked for expanding/collapsing + * a rows + * @throws NoSuchElementException + * if there is no expand element for this row + */ + public WebElement getExpandElement(int rowIndex, int hierarchyColumnIndex) { + return getCell(rowIndex, hierarchyColumnIndex) + .findElement(By.className("v-tree-grid-expander")); + + } } |