feat: Add ad-hoc component testing with BrowserlessUIContext#72
Draft
mstahv wants to merge 3 commits into
Draft
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Please list all relevant dependencies in this section and provide summary of the change, motivation and context.
Fixes #69
Type of change