Class ComboBoxTester<T extends ComboBox<Y>,Y>
- Type Parameters:
T- component typeY- item type
- All Implemented Interfaces:
Clickable<T>
- Since:
- 1.0
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidClears the selection by clicking the clear button, as the user would.Get the currently selected item.Get the actual items for the dropdown as a List.Get dropdown suggestions as String representations sent to the client.voidselectItem(String selection) Selects an item by its string representation (label).voidselectItemContaining(String text) Selects the item matching a partial text, as if the user typed the text into the combobox and picked the only remaining suggestion.voidSimulate writing a filter to the combobox.Methods inherited from class com.vaadin.browserless.ComponentTester
blur, canSetValueAsUser, clearAsUser, clickClearButtonAsUser, ensureComponentIsUsable, ensureComponentIsUsable, ensureComponentIsUsableOrDetach, ensureVisible, ensureVisible, find, findAllByQuery, findByQuery, fireDomEvent, fireDomEvent, fireDomEvent, focus, getComponent, getField, getField, getMethod, getMethod, isComponentReadOnly, isFocused, 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
-
ComboBoxTester
Wrap given component for testing.- Parameters:
component- target component
-
-
Method Details
-
setFilter
Simulate writing a filter to the combobox. As typing does in the browser, the filter is applied to the data provider and to the component'sfilterproperty.Use
getSuggestions()to get the string values show in the dropdown orgetSuggestionItems()to get the actual items in the suggestion.- Parameters:
filter- string to use for filtering
-
selectItem
Selects an item by its string representation (label).This method searches for the item among the current suggestions, which are affected by any filter set via
setFilter(String). If no filter is set, all items are available for selection. If a filter is set, only the filtered items can be selected.To select an item when the ComboBox uses custom filtering logic (e.g., set via
setItems(ItemFilter, Collection)), first callsetFilter(String)to apply the filter, then call this method to select from the filtered results.Example usage with filtering:
// Apply filter first comboBoxTester.setFilter("search text"); // Then select from filtered items comboBoxTester.selectItem("Matching Item Label");- Parameters:
selection- the item's string representation (label) to select, ornullto clear the selection- Throws:
IllegalArgumentException- if no item with the given label is found among current suggestionsIllegalStateException- if the component is not usable- See Also:
-
selectItemContaining
Selects the item matching a partial text, as if the user typed the text into the combobox and picked the only remaining suggestion.The text is applied as a filter, so matching follows the component's own filtering: by default a case-insensitive "label contains" match, or the
ItemFilter/ data provider filter the application configured. Exactly one item has to match, so a test fails rather than picking an item it did not clearly name. This also applies when the text equals the full label of one of the matching items; useselectItemto pick an item by its exact label. This rule does not depend on the component'sPartialMatchMode. The filter is cleared afterwards, as the browser does once a value is committed. If a value change listener disables, hides or detaches the component, or makes it inert, the filter stays at the text, as the server then ignores the browser's update. If matching fails, the selection is left unchanged and the filter set before the call is restored.// items "Berlin", "Bern", "Bernau", "Helsinki" comboBoxTester.selectItemContaining("hel"); // selects "Helsinki" comboBoxTester.selectItemContaining("bernau"); // selects "Bernau" comboBoxTester.selectItemContaining("bern"); // throws, "Bern" and // "Bernau" match- Parameters:
text- the text the user types to find the item, notnull- Throws:
IllegalArgumentException- if the text isnull, matches no item, or matches more than one itemIllegalStateException- if the component is not usable- See Also:
-
clickClearButton
public void clickClearButton()Clears the selection by clicking the clear button, as the user would.Requires the clear button to be visible — a hidden clear button is not something the user can click.
selectItem(String)withnullclears the selection without that requirement.- Throws:
IllegalStateException- if the component is not usable, or its clear button is not visible- Since:
- 25.3
-
getSelected
Get the currently selected item.- Returns:
- current selection
-
getSuggestions
Get dropdown suggestions as String representations sent to the client. Any filter that is set is taken into account.- Returns:
- List of item representation strings
-
getSuggestionItems
Get the actual items for the dropdown as a List. Any filter that is set is taken into account.- Returns:
- List of items
-