com.vaadin.flow.component.contextmenu.
Class ContextMenuTester<T extends ContextMenu>
Type Parameters:
T
- component type
Tester for ContextMenu components.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
clickItem
(int topLevelPosition, int... nestedItemsPositions) Simulates a click on the item at the given position in the menu.
void
Simulates a click on the item that matches the given text.
void
close()
Closes the context menu.
boolean
isItemChecked
(int topLevelPosition, int... nestedItemsPositions) Checks if the checkable menu item at given position is checked.
boolean
isItemChecked
(String topLevelText, String... nestedItemsText) Checks if the checkable menu item matching given text is checked.
void
open()
Opens the context menu, as if the action is done in the browser.
Methods inherited from class com.vaadin.testbench.unit.ComponentTester
ensureComponentIsUsable, ensureComponentIsUsable, ensureVisible, ensureVisible, find, findAllByQuery, findByQuery, fireDomEvent, fireDomEvent, fireDomEvent, getComponent, getField, getField, getMethod, getMethod, isUsable, isUsable, notUsableReasons, notUsableReasons, roundTrip, setModal
-
Constructor Details
-
ContextMenuTester
Wrap given component for testing.
Parameters:
component
- target component
-
-
Method Details
-
open
public void open()Opens the context menu, as if the action is done in the browser. It simulates for example a right click on a UI component with an assigned
ContextMenu
. -
close
public void close()Closes the context menu.
-
clickItem
Simulates a click on the item that matches the given text. For nested menu item provide the text of each menu item in the hierarchy. The path to the menu item must reflect what is seen in the browser, meaning that hidden items are ignored.
menu.addItem("Preview", event -> {}); var subMenu = menu.addItem("Share").getSubMenu(); subMenu.addItem("Copy link", event -> {}); subMenu.addItem("Email", event -> {}); // clicks top level menu item with text Preview tester.clickItem("Preview"); // clicks nested menu item with text Email tester.clickItem("Share", "Email");
Parameters:
topLevelText
- the text content of the top level menu item, not null.nestedItemsText
- text content of the nested menu itemsThrows:
IllegalArgumentException
- if the provided text does not identify a menu item.IllegalStateException
- if the item at given path is not usable. -
clickItem
public void clickItem(int topLevelPosition, int... nestedItemsPositions) Simulates a click on the item at the given position in the menu. For nested menu item provide the position of each sub menu that should be navigated to reach the request item. The position reflects what is seen in the browser, so hidden items are ignored.
menu.addItem("Preview", event -> {}); var subMenu = menu.addItem("Share").getSubMenu(); subMenu.addItem("Copy link", event -> {}); subMenu.addItem("Email", event -> {}); // clicks top level "Preview" menu item at position 0 tester.clickItem(0); // clicks then nested menu item at position 1 "Email" through the // item "Share" at position 1 tester.clickItem(1, 1);
Parameters:
topLevelPosition
- the zero-based position of the item in the menu, as it will be seen in the browser.nestedItemsPositions
- the zero-based position of the nested items, relative to the parent menuThrows:
IllegalArgumentException
- if the provided position does not identify a menu item.IllegalStateException
- if the item at given position is not usable. -
isItemChecked
Checks if the checkable menu item matching given text is checked. For nested menu item provide the text of each menu item in the hierarchy. The path to the menu item must reflect what is seen in the browser, meaning that hidden items are ignored.
menu.addItem("Preview", event -> {}).setCheckable(true); var subMenu = menu.addItem("Share").getSubMenu(); subMenu.addItem("Copy link", event -> {}).setCheckable(true); subMenu.addItem("Email", event -> {}).setCheckable(true); tester.isItemChecked("Preview"); tester.isItemChecked("Share", "Email");
Parameters:
topLevelText
- the text content of the top level menu item, not null.nestedItemsText
- text content of the nested menu itemsReturns:
true if the item at given path is checked, otherwise false.
Throws:
IllegalArgumentException
- if the provided text does not identify a menu item or if the menu item is not checkable.IllegalStateException
- if the item at given path is not usable. -
isItemChecked
public boolean isItemChecked(int topLevelPosition, int... nestedItemsPositions) Checks if the checkable menu item at given position is checked. For nested menu item provide the position of each sub menu that should be navigated to reach the requested item. The position reflects what is seen in the browser, so hidden items are ignored.
menu.addItem("Preview", event -> {}).setCheckable(true); var subMenu = menu.addItem("Share").getSubMenu(); subMenu.addItem("Copy link", event -> {}).setCheckable(true); subMenu.addItem("Email", event -> {}).setCheckable(true); // checks top level "Preview" menu item at position 0 tester.isItemChecked(0); // checks nested menu item at position 1 "Email" through the // item "Share" at position 1 tester.isItemChecked(1, 1);
Parameters:
topLevelPosition
- the zero-based position of the item in the menu, as it will be seen in the browser.nestedItemsPositions
- the zero-based position of the nested items, relative to the parent menuThrows:
IllegalArgumentException
- if the provided position does not identify a menu item or if the menu item is not checkable.IllegalStateException
- if the item at given position is not usable.
-