Class GridContextMenuTester<T extends GridContextMenu<Y>,Y>
- Type Parameters:
T- component typeY- item type
- All Implemented Interfaces:
Clickable<T>
open(int) therefore takes
the row to open the menu on, addressed by its zero-based index among the rows
the user sees, the same way GridTester
addresses rows.
The menu content is not part of the UI until the menu opens, so
clickItem(...) and find(Class) only see the items of an open
menu.-
Constructor Summary
ConstructorsConstructorDescriptionGridContextMenuTester(T component) Wrap grid context menu for testing.GridContextMenuTester(T component, int row) Wrap grid context menu for testing, targeting the given row. -
Method Summary
Modifier and TypeMethodDescriptionvoidclickItem(int topLevelPosition, int... nestedItemsPositions) Simulates a click on the item at the given position in the menu.voidSimulates a click on the item that matches the given text.voidclose()Closes the context menu.<R extends Component>
ComponentQuery<R> Gets aComponentQueryto search for component of the given type nested inside the wrapped component.Gets the texts of the menu items, as the browser shows them.getItemTexts(String topLevelText, String... nestedItemsText) Gets the texts of the items of the sub menu of the item matching the given text, as the browser shows them.getItemTooltipText(int topLevelPosition, int... nestedItemsPositions) Gets the tooltip text of the menu item at the given position in the menu.getItemTooltipText(String topLevelText, String... nestedItemsText) Gets the tooltip text of the menu item matching the given text.booleanisItemChecked(int topLevelPosition, int... nestedItemsPositions) Checks if the checkable menu item at given position is checked.booleanisItemChecked(String topLevelText, String... nestedItemsText) Checks if the checkable menu item matching given text is checked.voidopen()Opens the context menu on the row it currently targets, as if the user had asked for it in the browser.voidopen(int row) Opens the context menu on the given row, as if the user had asked for it in the browser.voidOpens the context menu on the given row and column, as if the user had asked for it in the browser.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
-
GridContextMenuTester
Wrap grid context menu for testing. The menu targets no row, so it has to be opened withopen(int).- Parameters:
component- target grid context menu
-
GridContextMenuTester
Wrap grid context menu for testing, targeting the given row. The index is 0 based and counts the rows the user sees. Opening the menu withopen()opens it on that row.- Parameters:
component- target grid context menurow- row the menu is about
-
-
Method Details
-
open
public void open()Opens the context menu on the row it currently targets, as if the user had asked for it in the browser. The target row is the one given toGridTester.contextMenu(int), so this method is the counterpart of that entry point. Useopen(int)to open the menu on a row directly. It does not render any client-side overlay, it only simulates the server-side state changes that opening the menu produces: the menu is attached to the UI, so its items become findable and clickable, and aGridContextMenuOpenedEventreporting the target row is fired.- Throws:
IllegalStateException- if the menu does not target a row, if it is already open, or if a dynamic content handler prevented it from opening
-
open
public void open(int row) Opens the context menu on the given row, as if the user had asked for it in the browser. The index is 0 based and counts the rows the user sees. The row is reported by the events the menu fires, soGridContextMenuItemClickEvent.getItem()andGridContextMenuOpenedEvent.getItem()hold the item on that row.- Parameters:
row- row to open the menu on- Throws:
IllegalStateException- if the menu is already open, or if a dynamic content handler prevented it from openingIndexOutOfBoundsException- if the grid has no such row
-
open
Opens the context menu on the given row and column, as if the user had asked for it in the browser. The column is reported byGridContextMenuOpenedEvent.getColumnId().- Parameters:
row- row to open the menu on, 0 basedcolumnKey- key of the column to open the menu on, as set withGrid.Column.setKey(String)- Throws:
IllegalArgumentException- if the grid has no column with the given keyIllegalStateException- if the column is not visible, if the menu is already open, or if a dynamic content handler prevented it from openingIndexOutOfBoundsException- if the grid has no such row
-
close
public void close()Closes the context menu.- Throws:
IllegalStateException- if the menu is not open
-
clickItem
Simulates a click on the item that matches the given text. For a 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. If there are multiple visible items at the same level with the same text, anIllegalStateExceptionis thrown because the target is ambiguous. Disabled or invisible items cannot be clicked and will also cause anIllegalStateException. The menu has to be open, since its items are not part of the UI before that.- Parameters:
topLevelText- the text content of the top level menu item, not null.nestedItemsText- text content of the nested menu items- Throws:
IllegalArgumentException- if the provided text does not identify a menu item.IllegalStateException- if the menu is not open, if there are multiple visible matching items at any level, or if the item at the given path is disabled or not visible.
-
clickItem
public void clickItem(int topLevelPosition, int... nestedItemsPositions) Simulates a click on the item at the given position in the menu. For a nested menu item, provide the position of each sub menu that should be navigated to reach the requested item. Positions are zero-based and refer only to items that are visible at each menu level, i.e. hidden items are ignored (the same way as in the browser). Disabled or invisible items cannot be clicked and will cause anIllegalStateException. The menu has to be open, since its items are not part of the UI before that.- 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 menu- Throws:
IllegalArgumentException- if the provided position does not identify a menu item.IllegalStateException- if the menu is not open, or if the item at the given position is disabled or not visible.
-
isItemChecked
Checks if the checkable menu item matching given text is checked. For a nested menu item, provide the text of each menu item in the hierarchy.- Parameters:
topLevelText- the text content of the top level menu item, not null.nestedItemsText- text content of the nested menu items- Returns:
- 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 menu is not open, or 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 a nested menu item, provide the position of each sub menu that should be navigated to reach the requested item.- 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 menu- Returns:
- true if the item at given position is checked, otherwise false.
- Throws:
IllegalArgumentException- if the provided position does not identify a menu item or if the menu item is not checkable.IllegalStateException- if the menu is not open, or if the item at given position is not usable.
-
getItemTooltipText
Gets the tooltip text of the menu item matching the given text. For a nested menu item, provide the text of each menu item in the hierarchy.- Parameters:
topLevelText- the text content of the top level menu item, not null.nestedItemsText- text content of the nested menu items- Returns:
- the tooltip text of the menu item at given path, or null if the item has no tooltip set.
- Throws:
IllegalArgumentException- if the provided text does not identify a menu item.IllegalStateException- if the menu is not open, or if the item at given path is not usable.
-
getItemTooltipText
Gets the tooltip text of the menu item at the given position in the menu. For a nested menu item, provide the position of each sub menu that should be navigated to reach the requested item.- 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 menu- Returns:
- the tooltip text of the menu item at given position, or null if the item has no tooltip set.
- Throws:
IllegalArgumentException- if the provided position does not identify a menu item.IllegalStateException- if the menu is not open, or if the item at given position is not usable.
-
getItemTexts
Gets the texts of the menu items, as the browser shows them. Hidden items are ignored, so the returned texts are aligned with the positions used byclickItem(int, int...). A text can also be given toclickItem(String, String...), as long as it identifies a single enabled item: a text that several visible items share is ambiguous, and a disabled item cannot be clicked. An item created from a component has no text of its own, and is reported as an empty string. Usefind(Class)to reach such an item. The menu has to be open, since its items are not part of the UI before that. The items are the ones the menu offers for the row it was opened on, so a dynamic content handler has run by then.menu.addItem("Edit", event -> { }); menu.addItem("Hidden", event -> { }).setVisible(false); menu.addItem("Share"); tester.open(0); // ["Edit", "Share"] tester.getItemTexts();- Returns:
- the texts of the visible top level menu items, in the order they are shown in
- Throws:
IllegalStateException- if the menu is not open, or is not visible
-
getItemTexts
Gets the texts of the items of the sub menu of the item matching the given text, as the browser shows them. For a nested sub menu, provide the text of each menu item in the hierarchy, the same way as inclickItem(String, String...). Hidden items are ignored at every level, both when following the path and in the returned texts. The menu has to be open, since its items are not part of the UI before that.var subMenu = menu.addItem("Share").getSubMenu(); subMenu.addItem("Copy link", event -> { }); subMenu.addItem("Email", event -> { }); tester.open(0); // ["Copy link", "Email"] tester.getItemTexts("Share");- Parameters:
topLevelText- the text content of the top level menu item, not null.nestedItemsText- text content of the nested menu items- Returns:
- the texts of the visible items of the sub menu, in the order they are shown in
- Throws:
IllegalArgumentException- if the provided text does not identify a menu item, or if the item at the given path has no sub menu.IllegalStateException- if the menu is not open or not visible, if there are multiple matching items at any level, or if the item at the given path is disabled or not visible.
-
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.Can be used to find components in the context menu. The menu content is only part of the UI while the menu is open, so components are returned in a detached state unless
open(int)has been called previously.// view: GridContextMenu<Person> menu = grid.addContextMenu(); menu.addItem(new Checkbox("Show inactive"), event -> { }); // test: GridContextMenuTester<GridContextMenu<Person>, Person> menuTester = test( view.menu); menuTester.open(0); Checkbox checkbox = menuTester.find(Checkbox.class).single();- Overrides:
findin classComponentTester<T extends GridContextMenu<Y>>- 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.
-