Class DialogTester

java.lang.Object
com.vaadin.browserless.ComponentTester<Dialog>
com.vaadin.flow.component.dialog.DialogTester
All Implemented Interfaces:
Clickable<Dialog>

public class DialogTester extends ComponentTester<Dialog>
Since:
1.0
  • Constructor Details

    • DialogTester

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

    • open

      public void open()
      Open the dialog.
    • close

      public void close()
      Close the dialog from the server side, like the application calling Dialog.close().

      This is not something the user can do: the dialog is closed regardless of Dialog.isCloseOnEsc() and Dialog.isCloseOnOutsideClick(), and no Dialog.DialogCloseActionEvent is fired, so a close action listener cannot veto it. To simulate the user dismissing the dialog, use pressEscape() or clickOutside() instead.

    • pressEscape

      public void pressEscape()
      Simulates pressing Escape to close the dialog.

      If the application has registered a close action listener, a Dialog.DialogCloseActionEvent is fired instead of closing the dialog, leaving it up to the listener whether to close it.

      Throws:
      IllegalStateException - if the dialog is not usable, e.g. not open, or close-on-Esc is disabled
    • clickOutside

      public void clickOutside()
      Simulates clicking outside the dialog to close it.

      If the application has registered a close action listener, a Dialog.DialogCloseActionEvent is fired instead of closing the dialog, leaving it up to the listener whether to close it.

      Throws:
      IllegalStateException - if the dialog is not usable, e.g. not open, or close-on-outside-click is disabled
    • isOpen

      public boolean isOpen()
      Check if the dialog is open.
      Returns:
      true if the dialog is open
    • isUsable

      public boolean isUsable()
      Description copied from class: ComponentTester
      Validate that component can be interacted with and should be visible in the UI. Subclasses overriding this method should also override ComponentTester.notUsableReasons(Consumer) to provide additional details to the potential exception thrown by ComponentTester.ensureComponentIsUsable().
      Overrides:
      isUsable in class ComponentTester<Dialog>
      Returns:
      true if component can be interacted with by the user
      See Also:
    • notUsableReasons

      protected void notUsableReasons(Consumer<String> collector)
      Description copied from class: ComponentTester
      Provides messages explaining why the component is actually not usable. Subclasses overriding ComponentTester.isUsable() should also override this method to provide additional details to the potential exception throw by ComponentTester.ensureComponentIsUsable().
      Overrides:
      notUsableReasons in class ComponentTester<Dialog>
      See Also:
    • findInHeader

      public <R extends Component> ComponentQuery<R> findInHeader(Class<R> componentType)
      Searches the dialog's header for components of the given type.

      The header is the area above the dialog content, filled with dialog.getHeader().add(...). Components nested inside the header content are found too, so a button inside a header layout is reached as well as a button added to the header directly.

      Type Parameters:
      R - the type of the components to search for
      Parameters:
      componentType - the type of the components to search for
      Returns:
      a query for components of the given type in the dialog's header
      Throws:
      IllegalStateException - if the dialog is not usable, e.g. not open
    • findInFooter

      public <R extends Component> ComponentQuery<R> findInFooter(Class<R> componentType)
      Searches the dialog's footer for components of the given type.

      The footer is the area below the dialog content, filled with dialog.getFooter().add(...). Components nested inside the footer content are found too, so a button inside a footer layout is reached as well as a button added to the footer directly.

      Type Parameters:
      R - the type of the components to search for
      Parameters:
      componentType - the type of the components to search for
      Returns:
      a query for components of the given type in the dialog's footer
      Throws:
      IllegalStateException - if the dialog is not usable, e.g. not open