Class MultiSelectComboBoxTester<T extends MultiSelectComboBox<Y>,Y>

java.lang.Object
com.vaadin.browserless.ComponentTester<T>
com.vaadin.flow.component.combobox.MultiSelectComboBoxTester<T,Y>
Type Parameters:
T - component type
Y - item type
All Implemented Interfaces:
Clickable<T>

public class MultiSelectComboBoxTester<T extends MultiSelectComboBox<Y>,Y> extends ComponentTester<T>
Tester for MultiSelectComboBox components.
Since:
1.0
  • Constructor Details

    • MultiSelectComboBoxTester

      public MultiSelectComboBoxTester(T component)
      Wrap given component for testing.
      Parameters:
      component - target component
  • Method Details

    • setFilter

      public void setFilter(String filter)
      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's filter property.

      Use getSuggestions() to get the string values show in the dropdown or getSuggestionItems() to get the actual items in the suggestion.

      Parameters:
      filter - string to use for filtering
    • selectItem

      public void selectItem(String... selection)
      Select items by client string representation.
      Parameters:
      selection - item representations as strings
      Throws:
      IllegalStateException - if the component is not usable
    • selectItemContaining

      public void selectItemContaining(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.

      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; use selectItem to pick an item by its exact label. This rule does not depend on the component's PartialMatchMode. Use selectItemsContaining(String...) to pick every item a text matches.

      As in the browser, the item is added to the current selection. Unlike the browser, where picking an already selected item deselects it, an already selected item stays selected. Afterwards the filter is cleared, or kept at the text when keepFilter is enabled, as in the browser. It also stays when a value change listener disables, hides or detaches the component, or makes it inert, 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"); // adds "Helsinki"
       comboBoxTester.selectItemContaining("bernau"); // adds "Bernau"
       comboBoxTester.selectItemContaining("bern"); // throws, "Bern" and
                                                    // "Bernau" match
       
      Parameters:
      text - the text the user types to find the item, not null
      Throws:
      IllegalArgumentException - if the text is null, matches no item, or matches more than one item
      IllegalStateException - if the component is not usable
      See Also:
    • selectItemsContaining

      public void selectItemsContaining(String... texts)
      Selects every item matching partial texts, as if the user typed each text into the combobox and ticked all remaining suggestions.

      Each 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. Every text has to match at least one item. Use selectItemContaining(String) to pick exactly one item.

      As in the browser, the matched items are added to the current selection. Unlike the browser, where picking an already selected item deselects it, already selected matches stay selected, so an item matched by more than one text is selected once. All matches are committed in one value change. In the browser, ticking several matches of one text needs keepFilter, because the filter is otherwise cleared after each pick, and every pick is its own value change. Afterwards the filter is cleared, or kept at the last text when keepFilter is enabled, as in the browser. It also stays when a value change listener disables, hides or detaches the component, or makes it inert, 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", "Helsinki"
       comboBoxTester.selectItemsContaining("ber"); // adds Berlin, Bern
       comboBoxTester.selectItemsContaining("hel", "lin"); // adds Helsinki,
                                                           // Berlin
       
      Parameters:
      texts - the texts the user types to find the items, at least one, none of them null
      Throws:
      IllegalArgumentException - if no text is given, a text is null, or a text matches no item
      IllegalStateException - 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...) with null clears the selection without that requirement.

      Throws:
      IllegalStateException - if the component is not usable, or its clear button is not visible
      Since:
      25.3
    • getSelected

      public Set<Y> getSelected()
      Get the currently selected item.
      Returns:
      current selection
    • getSuggestions

      public List<String> 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

      public List<Y> getSuggestionItems()
      Get the actual items for the dropdown as a List. Any filter that is set is taken into account.
      Returns:
      List of items