Class TreeGridTester<T extends TreeGrid<Y>,Y>

java.lang.Object
com.vaadin.browserless.ComponentTester<T>
com.vaadin.flow.component.grid.GridTester<T,Y>
com.vaadin.flow.component.treegrid.TreeGridTester<T,Y>
Type Parameters:
T - component type
Y - item type
All Implemented Interfaces:
Clickable<T>

public class TreeGridTester<T extends TreeGrid<Y>,Y> extends GridTester<T,Y>
Tester for TreeGrid components.

Adds the hierarchy interactions a user can perform on top of everything GridTester offers. Row indexes address the rows the user actually sees, so children of collapsed nodes are not counted.

The expand toggle lives in the hierarchy column, and a TreeGrid can be configured with none, one, or several of them. expand(int) and collapse(int) require at least one visible hierarchy column, since without one the user has nothing to click. Several hierarchy columns render several toggles for the same node, and clicking any of them has the same effect, so they need no special handling here.

  • Constructor Details

    • TreeGridTester

      public TreeGridTester(T component)
      Wrap tree grid for testing.
      Parameters:
      component - target tree grid
  • Method Details

    • expand

      public void expand(int row)
      Expands the node on the given row, as if the user clicked its expand toggle in the browser.

      The index is 0 based and counts only rows that are currently displayed, so children of collapsed nodes are skipped.

      The resulting ExpandEvent reports ComponentEvent.isFromClient() as true.

      Parameters:
      row - row of the node to expand
      Throws:
      IllegalStateException - if the component is not usable, if the tree grid has no visible hierarchy column, if the row has no children and thus no expand toggle, or if the node is already expanded
    • collapse

      public void collapse(int row)
      Collapses the node on the given row, as if the user clicked its collapse toggle in the browser.

      The index is 0 based and counts only rows that are currently displayed, so children of collapsed nodes are skipped.

      The resulting CollapseEvent reports ComponentEvent.isFromClient() as true.

      Parameters:
      row - row of the node to collapse
      Throws:
      IllegalStateException - if the component is not usable, if the tree grid has no visible hierarchy column, if the row has no children and thus no collapse toggle, or if the node is not expanded
    • isExpanded

      public boolean isExpanded(int row)
      Checks whether the node on the given row is expanded.

      The index is 0 based and counts only rows that are currently displayed, so children of collapsed nodes are skipped.

      Parameters:
      row - row to check
      Returns:
      true if the node on the row is expanded, otherwise false
      Throws:
      IllegalStateException - if the component is not visible
    • hasChildren

      public boolean hasChildren(int row)
      Checks whether the node on the given row has children, meaning the user is shown an expand toggle for it.

      The index is 0 based and counts only rows that are currently displayed, so children of collapsed nodes are skipped.

      Parameters:
      row - row to check
      Returns:
      true if the node on the row has children, otherwise false
      Throws:
      IllegalStateException - if the component is not visible
    • getCellText

      public String getCellText(int row, int column)
      Get the text that is shown on the client for the cell in the given position.

      A hierarchy column added with TreeGrid.addHierarchyColumn(com.vaadin.flow.function.ValueProvider) renders the item through a vaadin-grid-tree-toggle, so its text is read from the toggle's own value provider rather than from a column path. Every other column is read exactly as GridTester does.

      Overrides:
      getCellText in class GridTester<T extends TreeGrid<Y>,Y>
      Parameters:
      row - row of cell
      column - column of cell
      Returns:
      cell content that is sent to the client
      Throws:
      IllegalStateException - if component is not visible