com.vaadin.flow.component.grid.

Class GridTester<T extends Grid<Y>,Y>

java.lang.Object
com.vaadin.testbench.unit.ComponentTester<T>
com.vaadin.flow.component.grid.GridTester<T,Y>

Type Parameters:

T - component type

Y - item type

public class GridTester<T extends Grid<Y>,Y> extends ComponentTester<T>

Tester for Grid components.

  • Constructor Details

    • GridTester

      public GridTester(T component)

      Wrap grid for testing.

      Parameters:

      component - target grid

  • Method Details

    • size

      public int size()

      Get the amount of items in the grid.

      Returns:

      items in grid

    • getRow

      public Y getRow(int row)

      Get the item at the given row index.

      The index is 0 based.

      Parameters:

      row - row index of to get

      Returns:

      grid item on row

    • clickRow

      public void clickRow(int row)

      Click on grid row.

      The index is 0 based.

      Parameters:

      row - row to click

    • clickRow

      public void clickRow(int row, MouseButton button)

      Click on grid row with given button.

      The index is 0 based.

      Parameters:

      row - row to click

      button - MouseButton that was clicked

      See Also:

    • clickRow

      public void clickRow(int row, MetaKeys metaKeys)

      Click on grid row with given meta keys pressed.

      The index is 0 based.

      Parameters:

      row - row to click

      metaKeys - meta key statuses for click

    • clickRow

      public void clickRow(int row, MouseButton button, MetaKeys metaKeys)

      Click on grid row with given button and meta keys pressed.

      The index is 0 based.

      Parameters:

      row - row to click

      button - MouseButton that was clicked

      metaKeys - meta key statuses for click

      See Also:

    • doubleClickRow

      public void doubleClickRow(int row)

      Double-click on grid row.

      The index is 0 based.

      Parameters:

      row - row to click

    • doubleClickRow

      public void doubleClickRow(int row, MouseButton button)

      Double-click on grid row with given button.

      The index is 0 based.

      Parameters:

      row - row to click

      button - MouseButton that was clicked

      See Also:

    • doubleClickRow

      public void doubleClickRow(int row, MetaKeys metaKeys)

      Double-click on grid row with given meta keys pressed.

      The index is 0 based.

      Parameters:

      row - row to click

      metaKeys - meta key statuses for click

    • doubleClickRow

      public void doubleClickRow(int row, MouseButton button, MetaKeys metaKeys)

      Double-click on grid row with given button and meta keys pressed.

      The index is 0 based.

      Parameters:

      row - row to click

      button - MouseButton that was clicked

      metaKeys - meta key statuses for click

      See Also:

    • select

      public void select(int row)

      Select the item on given row.

      The index is 0 based.

      Single select will clear any old selections. Multi select will add to selection.

      Parameters:

      row - row to select

      Throws:

      IllegalStateException - if not usable

    • selectAll

      public void selectAll()

      Select all items in grid.

      Only works for multi select.

      Throws:

      IllegalStateException - if not usable or not multi select

    • getCellText

      public String getCellText(int row, int column)

      Get the text that is shown on the client for the cell in the given position.

      The indexes for row and column are 0 based.

      For the default renderer ColumnPathRenderer the result is the sent text for defined object path.

      For a ComponentRenderer the result is the rendered component as prettyString.

      More to be added as we find other renderers that need handling.

      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

    • getCellComponent

      public Component getCellComponent(int row, int column)

      Get component for item in cell.

      Parameters:

      row - item row

      column - column to get

      Returns:

      initialized component for the targeted cell

      Throws:

      IllegalArgumentException - when the target column of the cell is not a component renderer

    • getCellComponent

      public Component getCellComponent(int row, String columnName)

      Get component for item in column.

      Parameters:

      row - item row

      columnName - key/property of column

      Returns:

      initialized component for the target cell

      Throws:

      IllegalArgumentException - when column for property doesn't exist or the target column of the cell is not a component renderer

    • getLitRendererPropertyValue

      public <V> V getLitRendererPropertyValue(int row, String columnName, String propertyName, Class<V> propertyClass)

      Get property value for item's LitRenderer in column.

      Type Parameters:

      V - the type of the LitRenderer property

      Parameters:

      row - item row

      columnName - key/property of column

      propertyName - the name of the LitRenderer property

      propertyClass - the class of the value of the LitRenderer property

      Returns:

      value of renderer's property for the target cell

      Throws:

      IllegalArgumentException - when column for property doesn't exist or the target column of the cell is not a LitRenderer or when the given type of the property does not match the actual property type

    • getLitRendererPropertyValue

      public <V> V getLitRendererPropertyValue(int row, int column, String propertyName, Class<V> propertyClass)

      Get property value for item's LitRenderer in column.

      Type Parameters:

      V - the type of the LitRenderer property

      Parameters:

      row - item row

      column - column to get

      propertyName - the name of the LitRenderer property

      propertyClass - the class of the value of the LitRenderer property

      Returns:

      value of renderer's property for the target cell

      Throws:

      IllegalArgumentException - when column for property doesn't exist or the target column of the cell is not a LitRenderer or when the given type of the property does not match the actual property type

    • invokeLitRendererFunction

      public void invokeLitRendererFunction(int row, String columnName, String functionName, elemental.json.JsonArray jsonArray)

      Invoke named function for item's LitRenderer in column using the supplied JSON arguments.

      Parameters:

      row - item row

      columnName - key/property of column

      functionName - the name of the LitRenderer function to invoke

      jsonArray - the arguments to pass to the function

    • invokeLitRendererFunction

      public void invokeLitRendererFunction(int row, String columnName, String functionName)

      Invoke named function for item's LitRenderer in column.

      Parameters:

      row - item row

      columnName - key/property of column

      functionName - the name of the LitRenderer function to invoke

    • invokeLitRendererFunction

      public void invokeLitRendererFunction(int row, int column, String functionName, elemental.json.JsonArray jsonArray)

      Invoke named function for item's LitRenderer in column using the supplied JSON arguments.

      Parameters:

      row - item row

      column - column to get

      functionName - the name of the LitRenderer function to invoke

      jsonArray - the arguments to pass to the function

    • invokeLitRendererFunction

      public void invokeLitRendererFunction(int row, int column, String functionName)

      Invoke named function for item's LitRenderer in column.

      Parameters:

      row - item row

      column - column to get

      functionName - the name of the LitRenderer function to invoke

    • getHeaderCell

      @Deprecated public String getHeaderCell(int column)
      Deprecated.
      Use AbstractColumn.getHeaderText() or AbstractColumn.getHeaderComponent()

      Get content in header for given column.

      Parameters:

      column - column to get header for

      Returns:

      header contents

      Throws:

      IllegalStateException - if component is not visible

    • getColumnPosition

      public int getColumnPosition(String property)

      Get the column position by column property.

      Parameters:

      property - the property name of the column, not null

      Returns:

      int position of column

    • getColumn

      public Grid.Column<Y> getColumn(String property)

      Gets the grid column by column property.

      Parameters:

      property - the property name of the column, not null

      Returns:

      Grid.Column for property

    • getFooterCell

      @Deprecated(forRemoval=true) public String getFooterCell(int column)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Use AbstractColumn.getFooterText() or AbstractColumn.getFooterComponent() directly

      Get content in footer for given column.

      Parameters:

      column - column to get footer for

      Returns:

      footer contents

      Throws:

      IllegalStateException - if component is not visible

    • getSelected

      public Collection<Y> getSelected()

      Get selected items.

      Returns:

      selected items

    • isColumnSortable

      public boolean isColumnSortable(int column)

      Checks if the column at the given index is sortable.

      The index is 0 based.

      Parameters:

      column - column index to check for sort feature

      Returns:

      true if the column is sortable, otherwise false

      Throws:

      IndexOutOfBoundsException - if column index is invalid

    • isColumnSortable

      public boolean isColumnSortable(String property)

      Checks if the column for the given property is sortable.

      Parameters:

      property - the property name of the column, not null

      Returns:

      true if the column is sortable, otherwise false

      Throws:

      IllegalArgumentException - if property name does not identify a column

    • getSortDirection

      public SortDirection getSortDirection(int column)

      Gets the current sort direction for column at the given index. Throws an exception if the column does not exist or is not sortable.

      Parameters:

      column - column index to get sort direction

      Returns:

      sort direction for the column, or null if grid is not sorted by given column

      Throws:

      IllegalArgumentException - if the column at given index is not sortable

      IndexOutOfBoundsException - if column index is invalid

    • getSortDirection

      public SortDirection getSortDirection(String property)

      Gets the current sort direction for column corresponding to the at the given property. Throws an exception if the column does not exist or is not sortable.

      Parameters:

      property - the property name of the column, not null

      Returns:

      sort direction for the column, or null if grid is not sorted by given column

      Throws:

      IllegalArgumentException - if property name does not identify a column or if the column is not sortable

    • sortByColumn

      public void sortByColumn(int column, SortDirection direction)

      Sorts the grid by the given column and sort direction, as if the column header is pressed in the browser until the requested direction is reached. Throws an exception if the column is not sortable or not visible.

      Parameters:

      column - column index

      direction - sort direction

    • sortByColumn

      public void sortByColumn(int column)

      Sorts the grid according to the given column sort status, as if the column header is pressed in the browser. Throws an exception if the column is not sortable or not visible.

      Parameters:

      column - column index

    • sortByColumn

      public void sortByColumn(String property)

      Sorts the grid according to sort status ot the column identified by the given property, as if the column header is pressed in the browser. Throws an exception if the column is not sortable or not visible.

      Parameters:

      property - the property name of the column, not null

    • sortByColumn

      public void sortByColumn(String property, SortDirection direction)

      Sorts the grid by the given column and sort direction, as if the column header is pressed in the browser until the requested direction is reached. Throws an exception if the column is not sortable or not visible.

      Parameters:

      property - the property name of the column, not null

      direction - sort direction