Class MenuItemNavigation

java.lang.Object
com.vaadin.browserless.internal.MenuItemNavigation

public final class MenuItemNavigation extends Object
Menu item lookup shared by the menu testers.

A path addresses an item the way the browser shows it: by the text of each item in the hierarchy, or by the zero-based position of each item among the visible ones. The item at the end of the path must be enabled and visible, since a user cannot click anything else.

For internal use only.

  • Method Details

    • findByPath

      public static <C extends ContextMenuBase<C, I, S>, I extends MenuItemBase<C, I, S>, S extends SubMenuBase<C, I, S>> I findByPath(List<I> rootItems, String topLevelText, String... nestedItemsText)
      Finds the menu item addressed by the given text path.
      Type Parameters:
      C - menu type
      I - menu item type
      S - sub menu type
      Parameters:
      rootItems - the items of the top level menu
      topLevelText - the text content of the top level menu item, not null
      nestedItemsText - text content of the nested menu items
      Returns:
      the menu item at the given path
      Throws:
      IllegalArgumentException - if the provided text does not identify a menu item
      IllegalStateException - if there are multiple visible matching items at any level, or if the item at the given path is disabled or not visible
    • findByPath

      public static <C extends ContextMenuBase<C, I, S>, I extends MenuItemBase<C, I, S>, S extends SubMenuBase<C, I, S>> I findByPath(List<I> rootItems, int topLevelPosition, int... nestedItemsPositions)
      Finds the menu item addressed by the given position path.
      Type Parameters:
      C - menu type
      I - menu item type
      S - sub menu type
      Parameters:
      rootItems - the items of the top level menu
      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 menu item at the given path
      Throws:
      IllegalArgumentException - if the provided position does not identify a menu item
      IllegalStateException - if the item at the given position is disabled or not visible
    • visibleTexts

      public static List<String> visibleTexts(List<? extends MenuItemBase<?,?,?>> items)
      Gets the texts of the given menu items as the browser shows them, i.e. only the visible ones, in their order.

      An item created from a component has no text of its own, so it is reported as an empty string.

      Parameters:
      items - the items of a menu level
      Returns:
      the texts of the visible items
    • visibleSubMenuTexts

      public static <C extends ContextMenuBase<C, I, S>, I extends MenuItemBase<C, I, S>, S extends SubMenuBase<C, I, S>> List<String> visibleSubMenuTexts(List<I> rootItems, String topLevelText, String... nestedItemsText)
      Gets the texts of the visible items of the sub menu of the item addressed by the given text path.
      Type Parameters:
      C - menu type
      I - menu item type
      S - sub menu type
      Parameters:
      rootItems - the items of the top level menu
      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
      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 there are multiple matching items at any level, or if the item at the given path is disabled or not visible
    • requireCheckable

      public static void requireCheckable(MenuItemBase<?,?,?> menuItem, String path)
      Ensures that the given menu item is checkable, as only a checkable item has a checked state to read.
      Parameters:
      menuItem - the menu item to check
      path - the path the item was addressed by, for the error message
      Throws:
      IllegalArgumentException - if the menu item is not checkable
    • pathToString

      public static String pathToString(String topLevelText, String... nestedItemsText)
      Renders a text path the way it is reported in error messages.
      Parameters:
      topLevelText - the text content of the top level menu item
      nestedItemsText - text content of the nested menu items
      Returns:
      the path as a string
    • pathToString

      public static String pathToString(int topLevelPosition, int... nestedItemsPositions)
      Renders a position path the way it is reported in error messages.
      Parameters:
      topLevelPosition - the position of the top level menu item
      nestedItemsPositions - positions of the nested menu items
      Returns:
      the path as a string