Class GridTester

  • All Implemented Interfaces:
    com.vaadin.browserless.Clickable

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

    Tester for Grid components.

    Since:

    1.0

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
      public final T component
    • Constructor Summary

      Constructors 
      Constructor Description
      GridTester(T component) Wrap grid for testing.
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      int size() Get the amount of items in the grid.
      Y getRow(int row) Get the item at the given row index.
      void clickRow(int row) Click on grid row.
      void clickRow(int row, MouseButton button) Click on grid row with given button.
      void clickRow(int row, MetaKeys metaKeys) Click on grid row with given meta keys pressed.
      void clickRow(int row, MouseButton button, MetaKeys metaKeys) Click on grid row with given button and meta keys pressed.
      void doubleClickRow(int row) Double-click on grid row.
      void doubleClickRow(int row, MouseButton button) Double-click on grid row with given button.
      void doubleClickRow(int row, MetaKeys metaKeys) Double-click on grid row with given meta keys pressed.
      void doubleClickRow(int row, MouseButton button, MetaKeys metaKeys) Double-click on grid row with given button and meta keys pressed.
      void select(int row) Select the item on given row.
      void selectAll() Select all items in grid, running the same code as when the select all checkbox is checked.
      void deselect(int row) Deselect the item on given row.
      void deselectAll() Deselect all items in grid, running the same code as when the select all checkbox is unchecked.
      String getCellText(int row, int column) Get the text that is shown on the client for the cell in the given position.
      Component getCellComponent(int row, int column) Get the component the grid renders for the cell in the given position.
      Component getCellComponent(int row, String columnName) Get the component the grid renders for the cell in the given row of the column with the given key.
      Component renderCellComponent(int row, int column) Render the component for the cell in the given position on its own, without the grid, and attach it to the grid so that it can be used.
      Component renderCellComponent(int row, String columnName) Render the component for the cell in the given row of the column with the given key on its own, without the grid, and attach it to the grid so that it can be used.
      <V> V getLitRendererPropertyValue(int row, String columnName, String propertyName, Class<V> propertyClass) Get property value for item's LitRenderer in column.
      <V> V getLitRendererPropertyValue(int row, int column, String propertyName, Class<V> propertyClass) Get property value for item's LitRenderer in column.
      void invokeLitRendererFunction(int row, String columnName, String functionName, ArrayNode jsonArray) Invoke named function for item's LitRenderer in column using the supplied JSON arguments.
      void invokeLitRendererFunction(int row, String columnName, String functionName) Invoke named function for item's LitRenderer in column.
      void invokeLitRendererFunction(int row, int column, String functionName, ArrayNode jsonArray) Invoke named function for item's LitRenderer in column using the supplied JSON arguments.
      void invokeLitRendererFunction(int row, int column, String functionName) Invoke named function for item's LitRenderer in column.
      String getHeaderCell(int column) Get content in header for given column.
      int getColumnPosition(String property) Get the column position by column property.
      Grid.Column<Y> getColumn(String property) Gets the grid column by column property.
      String getFooterCell(int column) Get content in footer for given column.
      Collection<Y> getSelected() Get selected items.
      boolean isColumnSortable(int column) Checks if the column at the given index is sortable.
      boolean isColumnSortable(String property) Checks if the column for the given property is sortable.
      SortDirection getSortDirection(int column) Gets the current sort direction for column at the given index.
      SortDirection getSortDirection(String property) Gets the current sort direction for column corresponding to the at the given property.
      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.
      void sortByColumn(int column) Sorts the grid according to the given column sort status, as if the column header is pressed in the browser.
      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.
      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.
      GridContextMenuTester<GridContextMenu<Y>, Y> contextMenu(int row) Gets a tester for the context menu of this grid, targeting the given row.
      • Methods inherited from class com.vaadin.browserless.ComponentTester

        blur, ensureComponentIsUsable, find, focus, getComponent, isFocused, isUsable, setModal
      • Methods inherited from class com.vaadin.browserless.Clickable

        click, click, click, middleClick, middleClick, rightClick, rightClick
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • GridTester

        GridTester(T component)

        Wrap grid for testing.

        Parameters:
        component - target grid
    • Method Detail

      • size

         int size()

        Get the amount of items in the grid.

        Returns:

        items in grid

      • getRow

         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

         void clickRow(int row)

        Click on grid row.

        The index is 0 based.
        Parameters:
        row - row to click
      • clickRow

         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
      • clickRow

         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

         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
      • doubleClickRow

         void doubleClickRow(int row)

        Double-click on grid row.

        The index is 0 based.
        Parameters:
        row - row to click
      • doubleClickRow

         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
      • doubleClickRow

         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

         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
      • select

         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
      • selectAll

         void selectAll()

        Select all items in grid, running the same code as when the select all checkbox is checked.

        Only works for multi select, and only when the select all checkbox is actually shown - if it isn't, the user has no way to trigger this.
      • deselect

         void deselect(int row)

        Deselect the item on given row.

        The index is 0 based. Simulates the user deselecting a row: ctrl-clicking a selected row or unchecking the row's selection checkbox in multi select, clicking the selected row in single select. The row has to be selected. Deselecting a row that isn't selected is not a gesture the user has, so it fails instead of doing nothing. The call is ignored, exactly as the user's click would be, when the item is not selectable or when the grid is single select and deselecting is not allowed.
        Parameters:
        row - row to deselect
        Since:

        25.3

      • deselectAll

         void deselectAll()

        Deselect all items in grid, running the same code as when the select all checkbox is unchecked.

        Only works for multi select, and only when the select all checkbox is actually shown - if it isn't, the user has no way to trigger this. This is the counterpart of selectAll and behaves like the checkbox does: the selection is dropped in one selection event, without the per row toggle events the user would cause by unchecking rows one by one. Call deselect per row to model that instead.
        Since:

        25.3

      • getCellText

         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 text of the component the grid rendered for the cell, read through getCellComponent: a row the client has not asked for yet is scrolled into view first, and a cell the grid renders no component for fails the same way. A renderer that returns no component renders an empty cell, so the text is empty rather than null. 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

      • getCellComponent

         Component getCellComponent(int row, int column)

        Get the component the grid renders for the cell in the given position.

        A component renderer only produces a component when the grid renders a row for the client, so a renderer component is never part of the component tree that find(...) walks, and this method is the way to reach it. What comes back is the very component the browser shows: asking for the same cell twice returns the same instance, and the instance is replaced when the grid re-renders the row, for example after refreshItem(...). A row the client has not asked for yet is scrolled into view first, the way a user reaches it.

        Use renderCellComponent to render a cell on its own, without the grid.

        Parameters:
        row - item row
        column - column to get
        Returns:

        the component the grid rendered for the targeted cell

      • getCellComponent

         Component getCellComponent(int row, String columnName)

        Get the component the grid renders for the cell in the given row of the column with the given key.

        A component renderer only produces a component when the grid renders a row for the client, so a renderer component is never part of the component tree that find(...) walks, and this method is the way to reach it. What comes back is the very component the browser shows: asking for the same cell twice returns the same instance, and the instance is replaced when the grid re-renders the row, for example after refreshItem(...). A row the client has not asked for yet is scrolled into view first, the way a user reaches it.

        Use renderCellComponent to render a cell on its own, without the grid.

        Parameters:
        row - item row
        columnName - key/property of column
        Returns:

        the component the grid rendered for the target cell

      • renderCellComponent

         Component renderCellComponent(int row, int column)

        Render the component for the cell in the given position on its own, without the grid, and attach it to the grid so that it can be used.

        This asks the column's component renderer for a component for the item on the row, which is not the instance the grid renders for the client: every call renders the cell again and attaches the new instance to the grid, so asking twice for the same cell leaves two instances behind and a later find(...) reports both.

        Prefer getCellComponent, which returns the component the browser shows. This method is for tests written against the older behaviour of that method. A column index addresses the visible columns, so the cells the grid renders nothing for, those of a hidden column, are only reachable through renderCellComponent.

        Parameters:
        row - item row
        column - column to render
        Returns:

        a freshly rendered component for the targeted cell

        Since:

        25.3

      • renderCellComponent

         Component renderCellComponent(int row, String columnName)

        Render the component for the cell in the given row of the column with the given key on its own, without the grid, and attach it to the grid so that it can be used.

        This asks the column's component renderer for a component for the item on the row, which is not the instance the grid renders for the client: every call renders the cell again and attaches the new instance to the grid, so asking twice for the same cell leaves two instances behind and a later find(...) reports both.

        Prefer getCellComponent, which returns the component the browser shows. This method is for the cases the grid does not render itself, such as a hidden column.

        Parameters:
        row - item row
        columnName - key/property of column
        Returns:

        a freshly rendered component for the target cell

        Since:

        25.3

      • getLitRendererPropertyValue

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

        Get property value for item's LitRenderer in column.

        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

      • getLitRendererPropertyValue

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

        Get property value for item's LitRenderer in column.

        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

      • invokeLitRendererFunction

         void invokeLitRendererFunction(int row, String columnName, String functionName, ArrayNode 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

         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

         void invokeLitRendererFunction(int row, int column, String functionName, ArrayNode 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

         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() String getHeaderCell(int column)

        Get content in header for given column.

        Parameters:
        column - column to get header for
        Returns:

        header contents

      • getColumnPosition

         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

         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) String getFooterCell(int column)

        Get content in footer for given column.

        Parameters:
        column - column to get footer for
        Returns:

        footer contents

      • isColumnSortable

         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

      • isColumnSortable

         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

      • getSortDirection

         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

      • getSortDirection

         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

      • sortByColumn

         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

         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

         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

         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
      • contextMenu

         GridContextMenuTester<GridContextMenu<Y>, Y> contextMenu(int row)

        Gets a tester for the context menu of this grid, targeting the given row.

        The index is 0 based and counts the rows the user sees. The menu is not opened, so that assertions can be made on it first; open it with open.
        var menu = test(grid).contextMenu(0);
        menu.open();
        menu.clickItem("Edit");
        
        Parameters:
        row - row the context menu is about
        Returns:

        a tester for the context menu of this grid, targeting the given row

        Since:

        25.3