Skip to content

feat: Add ad-hoc component testing with BrowserlessUIContext#72

Draft
mstahv wants to merge 3 commits into
mainfrom
feat/test-components
Draft

feat: Add ad-hoc component testing with BrowserlessUIContext#72
mstahv wants to merge 3 commits into
mainfrom
feat/test-components

Conversation

@mstahv
Copy link
Copy Markdown
Member

@mstahv mstahv commented May 21, 2026

Description

Please list all relevant dependencies in this section and provide summary of the change, motivation and context.

Fixes #69

Type of change

  • Bugfix
  • Feature

mstahv and others added 3 commits May 21, 2026 12:40
Adds two pieces that together cover "test a single reusable component
without writing a @route view":

  - BrowserlessApplicationContext.create() — no-arg overload that
    defaults to an empty Routes. No view scanning needed.
  - BrowserlessUIContext.show(Component) — attaches a component
    directly to this window's UI, clearing any prior content first.
    Roundtrips before returning so attach effects flush.

End-user shape:

  try (var app = BrowserlessApplicationContext.create()) {
      var window = app.newUser().newWindow();
      MyForm form = window.show(new MyForm());
      window.findButton().withCaption("Save").click();
  }

Element-level manipulation stays inside the framework — tests no
longer need UI.getCurrent().getElement().appendChild(...) just to put
a component on screen. Tests cover attach lifecycle, replace-on-
subsequent-show semantics, layout-wrapped fixtures, and re-attaching a
component from a prior parent.

Scope: deliberately does not register an ad-hoc route. Components that
depend on router context (BeforeEnterObserver, role checks) still need
a real @route view, documented in the show() javadoc.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
For the common ad-hoc case — test a single component, no need for
multiple windows, users or custom credentials — the four-line setup
(create app, newUser, newWindow, show) collapses to one:

  try (var window = BrowserlessUIContext.adhoc(new MyForm())) {
      window.findButton().withCaption("Save").click();
  }

The returned window owns the bundled application context and closes it
on close(), so a single try-with-resources covers the whole lifecycle.
For multi-user / multi-window / routed tests the existing
BrowserlessApplicationContext.create(routes) + newUser().newWindow()
chain is unchanged.

The 'show' verb is retained — it pairs cleanly with navigate(Class) as
the route-vs-ad-hoc dichotomy, mirrors JavaFX/Swing precedent, and
doesn't collide with other Vaadin terms (attach is the lifecycle word,
open is for dialogs).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support ad-hoc testing of individual components (without a view)

1 participant