Class TestUI

java.lang.Object
com.vaadin.flow.component.Component
com.vaadin.flow.component.UI
io.jmix.flowui.testassist.vaadin.TestUI
All Implemented Interfaces:
com.vaadin.flow.component.AttachNotifier, com.vaadin.flow.component.DetachNotifier, com.vaadin.flow.component.HasComponents, com.vaadin.flow.component.HasElement, com.vaadin.flow.component.HasEnabled, com.vaadin.flow.component.HasStyle, com.vaadin.flow.component.PollNotifier, com.vaadin.flow.router.RouterLayout, Serializable

public class TestUI extends com.vaadin.flow.component.UI
UI for integration tests that emulates the client response cycle.

In a running application, tasks registered via UI.beforeClientResponse(com.vaadin.flow.component.Component, com.vaadin.flow.function.SerializableConsumer<com.vaadin.flow.internal.ExecutionContext>) are collected by the StateTree during request handling and executed as a single batch before the response is sent to the client. There is no client-server communication in tests, so these tasks would never run, leaving components that defer initialization partially initialized — e.g. JmixTabSheet attaches the selected tab content to the component tree in such a callback.

This UI emulates the cycle in two phases:

  • while a navigation is being handled, callbacks are only collected, then executed as one batch once the navigation finishes — exactly as a real request behaves;
  • at any other time there is no response to wait for, so each callback registered via beforeClientResponse(Component, SerializableConsumer) runs immediately, and programmatic changes or dialogs opened without navigation are handled without any explicit flush.
Known deviations from a running application:
  • only registrations made through UI.beforeClientResponse(com.vaadin.flow.component.Component, com.vaadin.flow.function.SerializableConsumer<com.vaadin.flow.internal.ExecutionContext>) trigger the immediate run; code that registers directly on the StateTree (e.g. Element#executeJs or data communicator flushes) is collected and executed at the next flush — the next navigation or beforeClientResponse call — or explicitly via runExecutionsBeforeClientResponse();
  • the immediate run happens synchronously inside the registering call, whereas in a running application the callback runs at the end of the request — caller code following the registration that the callback depends on (e.g. field = ui.beforeClientResponse(owner, ctx -> field = null)) observes the inverted order.
See Also:
  • Nested Class Summary

    Nested classes/interfaces inherited from class com.vaadin.flow.component.UI

    com.vaadin.flow.component.UI.BrowserLeaveNavigationEvent, com.vaadin.flow.component.UI.BrowserNavigateEvent, com.vaadin.flow.component.UI.BrowserRefreshEvent, com.vaadin.flow.component.UI.ClientViewPlaceholder
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected boolean
     

    Fields inherited from class com.vaadin.flow.component.UI

    CLIENT_NAVIGATE_TO, wrapperElement
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    com.vaadin.flow.internal.StateTree.ExecutionRegistration
    beforeClientResponse(com.vaadin.flow.component.Component component, com.vaadin.flow.function.SerializableConsumer<com.vaadin.flow.internal.ExecutionContext> execution)
     
    void
    doInit(com.vaadin.flow.server.VaadinRequest request, int uiId, String appId)
     
    void
    Runs the tasks collected via UI.beforeClientResponse(com.vaadin.flow.component.Component, com.vaadin.flow.function.SerializableConsumer<com.vaadin.flow.internal.ExecutionContext>), emulating the batch the framework executes before a client response.

    Methods inherited from class com.vaadin.flow.component.UI

    access, accessLater, accessLater, accessSynchronously, add, addAfterNavigationListener, addBeforeEnterListener, addBeforeLeaveListener, addHeartbeatListener, addModal, addShortcutListener, addShortcutListener, addToModalComponent, browserNavigate, close, getActiveDragSourceComponent, getActiveRouterTargetsChain, getActiveViewLocation, getChildren, getCsrfToken, getCurrent, getCurrentOrThrow, getCurrentView, getElement, getForwardToClientUrl, getInternals, getLoadingIndicatorConfiguration, getLocale, getNavigationListeners, getPage, getPollInterval, getPushConfiguration, getReconnectDialogConfiguration, getSession, getUI, getUIId, hasModalComponent, init, isClosing, isNavigationSupported, leaveNavigation, localeSignal, navigate, navigate, navigate, navigate, navigate, navigate, navigate, navigate, navigate, navigateToClient, onAttach, onDetach, push, refreshCurrentRoute, setChildComponentModal, setChildComponentModal, setCurrent, setDirection, setLocale, setPollInterval

    Methods inherited from class com.vaadin.flow.component.Component

    addListener, bindVisible, findAncestor, fireEvent, from, get, getEventBus, getId, getListeners, getParent, getTestId, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, hasListener, isAttached, isTemplateMapped, isVisible, onEnabledStateChanged, removeFromParent, scrollIntoView, scrollIntoView, set, setElement, setId, setTestId, setVisible

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface com.vaadin.flow.component.AttachNotifier

    addAttachListener

    Methods inherited from interface com.vaadin.flow.component.DetachNotifier

    addDetachListener

    Methods inherited from interface com.vaadin.flow.component.HasComponents

    add, add, addComponentAsFirst, addComponentAtIndex, bindChildren, getComponentAt, getComponentCount, indexOf, remove, remove, removeAll, replace

    Methods inherited from interface com.vaadin.flow.component.HasEnabled

    bindEnabled, isEnabled, setEnabled

    Methods inherited from interface com.vaadin.flow.component.HasStyle

    addClassName, addClassNames, bindClassName, bindClassNames, getClassName, getClassNames, getStyle, hasClassName, removeClassName, removeClassNames, setClassName, setClassName

    Methods inherited from interface com.vaadin.flow.component.PollNotifier

    addPollListener

    Methods inherited from interface com.vaadin.flow.router.RouterLayout

    removeRouterLayoutContent, showRouterLayoutContent
  • Field Details

    • runningExecutions

      protected boolean runningExecutions
  • Constructor Details

    • TestUI

      public TestUI()
  • Method Details

    • doInit

      public void doInit(com.vaadin.flow.server.VaadinRequest request, int uiId, String appId)
      Overrides:
      doInit in class com.vaadin.flow.component.UI
    • beforeClientResponse

      public com.vaadin.flow.internal.StateTree.ExecutionRegistration beforeClientResponse(com.vaadin.flow.component.Component component, com.vaadin.flow.function.SerializableConsumer<com.vaadin.flow.internal.ExecutionContext> execution)
      Overrides:
      beforeClientResponse in class com.vaadin.flow.component.UI
    • runExecutionsBeforeClientResponse

      public void runExecutionsBeforeClientResponse()
      Runs the tasks collected via UI.beforeClientResponse(com.vaadin.flow.component.Component, com.vaadin.flow.function.SerializableConsumer<com.vaadin.flow.internal.ExecutionContext>), emulating the batch the framework executes before a client response.