Class CardTester

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

    
    public class CardTester<T extends Card>
    extends ComponentTester<T>
                        

    Tester for Card components.

    Gives access to the content of the card as the user sees it. A card that has a header component shows the header instead of the title and subtitle, so the title and subtitle accessors reject that case rather than reporting content that is not on screen.

    The accessors return the component sitting in a slot. To reach a component nested deeper inside a slot, use findInHeader, findInFooter or find, which searches every slot of the card and not only its default content slot.

    Since:

    25.3

    • 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
      CardTester(T component) Wrap given component for testing.
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      String getTitleAsText() Gets the title text shown on the card.
      Component getTitle() Gets the component used as the card's title.
      Component getSubtitle() Gets the component used as the card's subtitle.
      String getSubtitleAsText() Gets the subtitle text shown on the card.
      Component getHeader() Gets the component used as the card's header.
      Component getHeaderPrefix() Gets the component shown before the card's header content.
      Component getHeaderSuffix() Gets the component shown after the card's header content.
      Component getMedia() Gets the component shown as the card's media.
      List<Component> getFooterComponents() Gets the components shown in the card's footer, in the order they were added.
      <R extends Component> ComponentQuery<R> find(Class<R> componentType) Gets a to search for component of the given type nested inside the wrapped component.
      <R extends Component> ComponentQuery<R> findInHeader(Class<R> componentType) Searches the card's header for components of the given type.
      <R extends Component> ComponentQuery<R> findInFooter(Class<R> componentType) Searches the card's footer for components of the given type.
      • Methods inherited from class com.vaadin.browserless.ComponentTester

        blur, ensureComponentIsUsable, 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

      • CardTester

        CardTester(T component)

        Wrap given component for testing.

        Parameters:
        component - target component
    • Method Detail

      • getTitleAsText

         String getTitleAsText()

        Gets the title text shown on the card.

        Returns:

        the title text, or an empty string if no textual title is set

      • getTitle

        @Nullable() Component getTitle()

        Gets the component used as the card's title.

        Returns:

        the title component, or null if the title is not a component

      • getSubtitle

        @Nullable() Component getSubtitle()

        Gets the component used as the card's subtitle.

        Returns:

        the subtitle component, or null if no subtitle is set

      • getSubtitleAsText

        @Nullable() String getSubtitleAsText()

        Gets the subtitle text shown on the card.

        setSubtitle wraps the text in a Span, so a subtitle set as text is reported here, and so is the text of a Span set with setSubtitle — the card stores the two the same way and cannot tell them apart. A subtitle set as any other component is not text and reports null; use getSubtitle to get the component itself.

        Note that this differs from getTitleAsText, which reports an empty string rather than null when the card shows no textual title, because a card keeps its title text in a property of its own instead of in a component.

        Returns:

        the subtitle text, or null if no subtitle is set or the subtitle is not a text subtitle

      • getHeader

        @Nullable() Component getHeader()

        Gets the component used as the card's header. When set, the header is shown instead of the title and subtitle.

        Returns:

        the header component, or null if no header is set

      • getHeaderPrefix

        @Nullable() Component getHeaderPrefix()

        Gets the component shown before the card's header content.

        Returns:

        the header prefix component, or null if none is set

      • getHeaderSuffix

        @Nullable() Component getHeaderSuffix()

        Gets the component shown after the card's header content.

        Returns:

        the header suffix component, or null if none is set

      • getMedia

        @Nullable() Component getMedia()

        Gets the component shown as the card's media.

        Returns:

        the media component, or null if none is set

      • getFooterComponents

         List<Component> getFooterComponents()

        Gets the components shown in the card's footer, in the order they were added.

        Returns:

        the footer components, empty if the footer is empty

      • find

         <R extends Component> ComponentQuery<R> find(Class<R> componentType)

        Gets a to search for component of the given type nested inside the wrapped component.

        The query walks the server-side component tree. A component that another component renders per item, such as the component a ComponentRenderer} column renders for a grid row, is rendered into the column and not into the tree, and the content of an overlay, such as a context menu, is attached only while the overlay is open. Neither is reachable this way, and the lookup returns an empty result rather than failing, so reach those components through the owning component tester instead: GridTester.getCellComponent(row, column)} for grid cells, ContextMenuTester.open()} and then clickItem(...)} for a context menu, and GridTester.contextMenu(row).open()} for a grid context menu.

        Searches the whole card, so components in the title, subtitle, header, header prefix, header suffix, media and footer slots are found as well as the ones in the default content slot. Example usage:

        // view:
        Card card = new Card();
        card.setHeaderSuffix(new Button("Dismiss"));
        card.addToFooter(new Button("Book"));
        
        // test:
        CardTester<Card> cardTester = test(view.card);
        cardTester.find(Button.class).withText("Dismiss").single().click();
        Button book = cardTester.find(Button.class).withText("Book").single();
        

        To narrow the search to the header or the footer, use findInHeader or findInFooter. Any other slot is reachable with withinSlot, for example find(Button.class).withinSlot("header-suffix").

        The default content slot has no name, so it has no such filter: components added with Card.add(...) carry no slot attribute at all and are singled out with withoutAttribute("slot"), which — unlike withinSlot — only sees the components sitting directly in the slot, not the ones nested inside them.

      • findInHeader

         <R extends Component> ComponentQuery<R> findInHeader(Class<R> componentType)

        Searches the card's header for components of the given type.

        The header is the component set with setHeader, shown instead of the title and subtitle. Components nested inside it are found too, so a button inside a header layout is reached as well as a button set as the header itself.

        Parameters:
        componentType - the type of the components to search for
        Returns:

        a query for components of the given type in the card's header

      • findInFooter

         <R extends Component> ComponentQuery<R> findInFooter(Class<R> componentType)

        Searches the card's footer for components of the given type.

        The footer holds the components added with addToFooter. Components nested inside them are found too, so a button inside a footer layout is reached as well as a button added to the footer directly.

        Parameters:
        componentType - the type of the components to search for
        Returns:

        a query for components of the given type in the card's footer