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 find, which searches every slot of the card and not only its default content slot.
-
-
Constructor Summary
Constructors Constructor Description CardTester(T component)Wrap given component for testing.
-
Method Summary
Modifier and Type Method Description StringgetTitleAsText()Gets the title text shown on the card. ComponentgetTitle()Gets the component used as the card's title. ComponentgetSubtitle()Gets the component used as the card's subtitle. StringgetSubtitleAsText()Gets the subtitle text shown on the card. ComponentgetHeader()Gets the component used as the card's header. ComponentgetHeaderPrefix()Gets the component shown before the card's header content. ComponentgetHeaderSuffix()Gets the component shown after the card's header content. ComponentgetMedia()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. -
Methods inherited from class com.vaadin.browserless.ComponentTester
ensureComponentIsUsable, getComponent, 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
nullif the title is not a component
-
getSubtitle
@Nullable() Component getSubtitle()
Gets the component used as the card's subtitle.
- Returns:
the subtitle component, or
nullif 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
nullwhen 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
nullif 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
nullif no header is set
-
getHeaderPrefix
@Nullable() Component getHeaderPrefix()
Gets the component shown before the card's header content.
- Returns:
the header prefix component, or
nullif none is set
-
getHeaderSuffix
@Nullable() Component getHeaderSuffix()
Gets the component shown after the card's header content.
- Returns:
the header suffix component, or
nullif none is set
-
getMedia
@Nullable() Component getMedia()
Gets the component shown as the card's media.
- Returns:
the media component, or
nullif 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, does not exist until something renders it, and the content of an overlay, such as a context menu, is attached only while the overlay is open. Neither is in the tree until then, 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()} or clickItem(...)} for menus.
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 a single named slot, filter on the
slotattribute the card puts on the component it places in that slot, for examplefind(Button.class).withAttribute("slot", "footer"). Two limits are worth knowing: the attribute is only on the component sitting directly in the slot, not on the ones nested inside it, and components added withCard.add(...)sit in the unnamed default content slot and carry noslotattribute at all, so no named-slot filter matches them — usewithoutAttribute("slot")to single those out.
-
-
-
-