Package com.vaadin.browserless.internal
Class BasicUtils
java.lang.Object
com.vaadin.browserless.internal.BasicUtils
Basic utilities for firing events on components and checking their state.
For internal use only. May be renamed or removed in a future release.
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T extends com.vaadin.flow.component.Component & com.vaadin.flow.component.Focusable<?>>
void_blur(T component) FiresBlurNotifier.BlurEventon the component, but only if it's editable.static void_close(com.vaadin.flow.component.UI ui) Closes the UI and simulates the end of the request.static void_fireDomEvent(com.vaadin.flow.component.Component component, String eventType) Fires a DOM event with empty event data on given component.static void_fireDomEvent(com.vaadin.flow.component.Component component, String eventType, tools.jackson.databind.node.ObjectNode eventData) Fires a DOM event on given component.static <T extends com.vaadin.flow.component.Component & com.vaadin.flow.component.Focusable<?>>
void_focus(T component) FiresFocusNotifier.FocusEventon the component, but only if it's editable.static boolean_isVisible(com.vaadin.flow.component.Component component) Checks whether the component is visible (usuallyComponent.isVisible()but forTextthe text must be non-empty).static voidcheckEditableByUser(com.vaadin.flow.component.Component component) Checks that a component is actually editable by the user: The component must be effectively visible: it itself must be visible, its parent must be visible and all of its ascendants must be visible.static voidexpectNotEditableByUser(com.vaadin.flow.component.Component component) Fails if the component is editable.static intReturns a fetch limit that is safe to pass to data providers.static booleanisEffectivelyEnabled(com.vaadin.flow.component.Component component) Computes whether this component and all of its parents are enabled.static booleanisEffectivelyVisible(com.vaadin.flow.component.Component component) Computes whether this component and all of its parents are visible.static booleanmatches(com.vaadin.flow.component.Component component, Consumer<SearchSpec<com.vaadin.flow.component.Component>> spec) Checks whether this component matches given spec.
-
Method Details
-
_fireDomEvent
public static void _fireDomEvent(com.vaadin.flow.component.Component component, String eventType, tools.jackson.databind.node.ObjectNode eventData) Fires a DOM event on given component.- Parameters:
component- the component, not null.eventType- the event type, e.g. "click"eventData- the event data, not null.
-
_fireDomEvent
Fires a DOM event with empty event data on given component.- Parameters:
component- the component, not null.eventType- the event type, e.g. "click"
-
_isVisible
public static boolean _isVisible(com.vaadin.flow.component.Component component) Checks whether the component is visible (usuallyComponent.isVisible()but forTextthe text must be non-empty).- Parameters:
component- the component, not null.- Returns:
- true if the component is visible.
-
checkEditableByUser
public static void checkEditableByUser(com.vaadin.flow.component.Component component) Checks that a component is actually editable by the user:- The component must be effectively visible: it itself must be visible,
its parent must be visible and all of its ascendants must be visible. For
the purpose of testing individual components not attached to the
UI, a component may be considered visible even though it's not currently nested in aUI. - The component must be effectively enabled: it itself must be enabled, its parent must be enabled and all of its ascendants must be enabled.
- If the component is
HasValue, it must not beHasValue.isReadOnly().
- Parameters:
component- the component, not null.- Throws:
IllegalStateException- if any of the above doesn't hold.
- The component must be effectively visible: it itself must be visible,
its parent must be visible and all of its ascendants must be visible. For
the purpose of testing individual components not attached to the
-
expectNotEditableByUser
public static void expectNotEditableByUser(com.vaadin.flow.component.Component component) Fails if the component is editable. SeecheckEditableByUser(Component)for more details.- Parameters:
component- the component, not null.- Throws:
AssertionError- if the component is editable.
-
isEffectivelyVisible
public static boolean isEffectivelyVisible(com.vaadin.flow.component.Component component) Computes whether this component and all of its parents are visible.- Parameters:
component- the component, not null.- Returns:
- true if the component and all of its ascendants are visible.
-
isEffectivelyEnabled
public static boolean isEffectivelyEnabled(com.vaadin.flow.component.Component component) Computes whether this component and all of its parents are enabled.Recursively checks that all ancestors are also enabled (the "implicitly disabled" effect, see
HasEnabled.isEnabled()javadoc for more details).Also check that the component is not inert due to there being a modal component.
- Parameters:
component- the component, not null.- Returns:
- false if this component or any of its parent is disabled or is inert.
-
matches
public static boolean matches(com.vaadin.flow.component.Component component, Consumer<SearchSpec<com.vaadin.flow.component.Component>> spec) Checks whether this component matches given spec. All rules are matched except thecountrule. The rules are matched against given component only (not against its children).- Parameters:
component- the component, not null.spec- configures the search spec, not null.- Returns:
- true if the component matches the spec.
-
_focus
public static <T extends com.vaadin.flow.component.Component & com.vaadin.flow.component.Focusable<?>> void _focus(T component) FiresFocusNotifier.FocusEventon the component, but only if it's editable.- Type Parameters:
T- the component type- Parameters:
component- the component, not null.
-
_blur
public static <T extends com.vaadin.flow.component.Component & com.vaadin.flow.component.Focusable<?>> void _blur(T component) FiresBlurNotifier.BlurEventon the component, but only if it's editable.- Type Parameters:
T- the component type- Parameters:
component- the component, not null.
-
_close
public static void _close(com.vaadin.flow.component.UI ui) Closes the UI and simulates the end of the request. TheUI.close()is called unless the UI is already closing, and then the UI is removed from its session, which fires the detach listeners and makes the UI and all of its components detached.- Parameters:
ui- the UI, not null.
-
get_saneFetchLimit
public static int get_saneFetchLimit()Returns a fetch limit that is safe to pass to data providers.- Returns:
- the fetch limit.
-