Class CardTester<T extends Card>
- Type Parameters:
T- component type
- All Implemented Interfaces:
Clickable<T>
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(Class),
findInFooter(Class) or find(Class), which searches every
slot of the card and not only its default content slot.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<R extends Component>
ComponentQuery<R> Gets aComponentQueryto search for component of the given type nested inside the wrapped component.<R extends Component>
ComponentQuery<R> findInFooter(Class<R> componentType) Searches the card's footer for components of the given type.<R extends Component>
ComponentQuery<R> findInHeader(Class<R> componentType) Searches the card's header for components of the given type.Gets the components shown in the card's footer, in the order they were added.@Nullable ComponentGets the component used as the card's header.@Nullable ComponentGets the component shown before the card's header content.@Nullable ComponentGets the component shown after the card's header content.@Nullable ComponentgetMedia()Gets the component shown as the card's media.@Nullable ComponentGets the component used as the card's subtitle.@Nullable StringGets the subtitle text shown on the card.@Nullable ComponentgetTitle()Gets the component used as the card's title.Gets the title text shown on the card.Methods inherited from class com.vaadin.browserless.ComponentTester
canSetValueAsUser, clearAsUser, clickClearButtonAsUser, ensureComponentIsUsable, ensureComponentIsUsable, ensureComponentIsUsableOrDetach, ensureVisible, ensureVisible, findAllByQuery, findByQuery, fireDomEvent, fireDomEvent, fireDomEvent, getComponent, getField, getField, getMethod, getMethod, isComponentReadOnly, isUsable, isUsable, notUsableReasons, notUsableReasons, roundTrip, setModal, setPropertyAsUser, setValueAsUser, setValueAsUserMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.vaadin.browserless.Clickable
click, click, click, middleClick, middleClick, rightClick, rightClick
-
Constructor Details
-
CardTester
Wrap given component for testing.- Parameters:
component- target component
-
-
Method Details
-
getTitleAsText
Gets the title text shown on the card.- Returns:
- the title text, or an empty string if no textual title is set
- Throws:
IllegalStateException- if the card is not visible to the user, or if a header component is set so the title is not shown
-
getTitle
Gets the component used as the card's title.- Returns:
- the title component, or
nullif the title is not a component - Throws:
IllegalStateException- if the card is not visible to the user, or if a header component is set so the title is not shown
-
getSubtitle
Gets the component used as the card's subtitle.- Returns:
- the subtitle component, or
nullif no subtitle is set - Throws:
IllegalStateException- if the card is not visible to the user, or if a header component is set so the subtitle is not shown
-
getSubtitleAsText
Gets the subtitle text shown on the card.Card.setSubtitle(String)wraps the text in aSpan, so a subtitle set as text is reported here, and so is the text of aSpanset withCard.setSubtitle(Component)? the card stores the two the same way and cannot tell them apart. A subtitle set as any other component is not text and reportsnull; usegetSubtitle()to get the component itself.Note that this differs from
getTitleAsText(), which reports an empty string rather thannullwhen 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 - Throws:
IllegalStateException- if the card is not visible to the user, or if a header component is set so the subtitle is not shown
-
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 - Throws:
IllegalStateException- if the card is not visible to the user
-
getHeaderPrefix
Gets the component shown before the card's header content.- Returns:
- the header prefix component, or
nullif none is set - Throws:
IllegalStateException- if the card is not visible to the user
-
getHeaderSuffix
Gets the component shown after the card's header content.- Returns:
- the header suffix component, or
nullif none is set - Throws:
IllegalStateException- if the card is not visible to the user
-
getMedia
Gets the component shown as the card's media.- Returns:
- the media component, or
nullif none is set - Throws:
IllegalStateException- if the card is not visible to the user
-
find
Gets aComponentQueryto 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
ComponentRenderercolumn 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 thenclickItem(...)for a context menu, andGridTester.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(Class)orfindInFooter(Class). Any other slot is reachable withComponentQuery.withinSlot(String), for examplefind(Button.class).withinSlot("header-suffix").The default content slot has no name, so it has no such filter: components added with
Card.add(...)carry noslotattribute at all and are singled out withwithoutAttribute("slot"), which ? unlikeComponentQuery.withinSlot(String)? only sees the components sitting directly in the slot, not the ones nested inside them.- Overrides:
findin classComponentTester<T extends Card>- Type Parameters:
R- type of the component to search.- Parameters:
componentType- type of the component to search.- Returns:
- a
ComponentQueryinstance, searching for wrapped component children.
-
findInHeader
Searches the card's header for components of the given type.The header is the component set with
Card.setHeader(Component), 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.- Type Parameters:
R- the type of the components to search for- Parameters:
componentType- the type of the components to search for- Returns:
- a query for components of the given type in the card's header
- Throws:
IllegalStateException- if the card is not visible to the user
-