Class BaseUIUnitTest

  • All Implemented Interfaces:

    
    public abstract class BaseUIUnitTest
    
                        

    Base class for UI unit tests. Provides methods to set up and clean a mocked Vaadin environment. The class allows scan classpath for routes and error views. Subclasses should typically restrict classpath scanning to a specific packages for faster bootstrap, by using ViewPackages annotation. If the annotation is not present a full classpath scan is performed For internal use only. May be renamed or removed in a future release.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Constructor Summary

      Constructors 
      Constructor Description
      BaseUIUnitTest()
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      <T extends Component> T navigate(Class<T> navigationTarget) Navigate to the given view class if it is registered.
      <C, T extends Component, HasUrlParameter<C>> T navigate(Class<T> navigationTarget, C parameter) Navigate to view with url parameter.
      <T extends Component> T navigate(Class<T> navigationTarget, Map<String, String> parameters) Navigate to view corresponding to the given navigation target with the specified parameters.
      <T extends Component> T navigate(String location, Class<T> expectedTarget) Navigate to given location string.
      void fireShortcut(Key key, Array<KeyModifier> modifiers) Simulates a keyboard shortcut performed on the browser.
      HasElement getCurrentView() Get the current view instance that is shown on the ui.
      <T extends ComponentTester<Y>, Y extends Component> T test(Y component) Wrap component with ComponentTester best matching component type.
      <T extends ComponentTester<Y>, Y extends Component> T test(Class<T> tester, Y component) Wrap component in given ComponentTester.
      <T extends Component> ComponentQuery<T> $(Class<T> componentType) Gets a query object for finding a component inside the UI
      <T extends Component> ComponentQuery<T> $(Class<T> componentType, Component fromThis) Gets a query object for finding a component nested inside the given component.
      <T extends Component> ComponentQuery<T> $view(Class<T> componentType) Gets a query object for finding a component inside the current view
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • BaseUIUnitTest

        BaseUIUnitTest()
    • Method Detail

      • navigate

         <T extends Component> T navigate(Class<T> navigationTarget)

        Navigate to the given view class if it is registered.

        Parameters:
        navigationTarget - view class to navigate to
        Returns:

        instantiated view

      • navigate

         <C, T extends Component, HasUrlParameter<C>> T navigate(Class<T> navigationTarget, C parameter)

        Navigate to view with url parameter.

        Parameters:
        navigationTarget - view class to navigate to
        parameter - parameter to send to view
        Returns:

        instantiated view

      • navigate

         <T extends Component> T navigate(Class<T> navigationTarget, Map<String, String> parameters)

        Navigate to view corresponding to the given navigation target with the specified parameters.

        Parameters:
        navigationTarget - view class to navigate to
        parameters - parameters to pass to view.
        Returns:

        instantiated view

      • navigate

         <T extends Component> T navigate(String location, Class<T> expectedTarget)

        Navigate to given location string. Check that location navigated to is the expected view or throw exception.

        Parameters:
        location - location string for navigating
        expectedTarget - class that is expected for navigation
        Returns:

        instantiated view

      • fireShortcut

         void fireShortcut(Key key, Array<KeyModifier> modifiers)

        Simulates a keyboard shortcut performed on the browser.

        Parameters:
        key - Primary key of the shortcut.
        modifiers - Key modifiers.
      • getCurrentView

         HasElement getCurrentView()

        Get the current view instance that is shown on the ui.

        Returns:

        current view

      • test

         <T extends ComponentTester<Y>, Y extends Component> T test(Y component)

        Wrap component with ComponentTester best matching component type.

        Parameters:
        component - component to get test wrapper for
        Returns:

        component in wrapper with test helpers

      • test

         <T extends ComponentTester<Y>, Y extends Component> T test(Class<T> tester, Y component)

        Wrap component in given ComponentTester.

        Parameters:
        tester - test wrapper to use
        component - component to wrap
        Returns:

        initialized test wrapper for component

      • $

         <T extends Component> ComponentQuery<T> $(Class<T> componentType)

        Gets a query object for finding a component inside the UI

        Parameters:
        componentType - the type of the component(s) to search for
        Returns:

        a query object for finding components

      • $

         <T extends Component> ComponentQuery<T> $(Class<T> componentType, Component fromThis)

        Gets a query object for finding a component nested inside the given component.

        Parameters:
        componentType - the type of the component(s) to search for
        fromThis - component used as starting element for search.
        Returns:

        a query object for finding components

      • $view

         <T extends Component> ComponentQuery<T> $view(Class<T> componentType)

        Gets a query object for finding a component inside the current view

        Parameters:
        componentType - the type of the component(s) to search for
        Returns:

        a query object for finding components