Skip to content

fix: make ContextMenuTester open and close the menu like a real user (#249) (CP: 25.3) - #254

Merged
mcollovati merged 1 commit into
25.3from
cherry-pick-249-to-25.3-1789745936385
Sep 18, 2026
Merged

mcollovati merged 1 commit into
25.3from
cherry-pick-249-to-25.3-1789745936385

Conversation

@vaadin-bot

Copy link
Copy Markdown
Collaborator

This PR cherry-picks changes from the original PR #249 to branch 25.3.

Original PR description

Summary

ContextMenuTester.open() and close() changed the menu's opened property from the server, so the resulting OpenedChangeEvent said it did not come from the client. The tester now pushes that property through the client path, and a refused open no longer leaves the menu half-opened.

Fixes #233

What changed

Behavior change (affects tests that open or close a ContextMenu or GridContextMenu through the testers):

  • OpenedChangeEvent from ContextMenuTester.open() and close() now reports isFromClient() == true. Application code that branches on isFromClient() now takes the "user action" path, as it does in a real browser. Tests asserting isFromClient() == false for tester-driven opens will need updating.
  • An open() that is refused because the menu is not usable (for example hidden) now leaves the menu closed and detached from the UI. Before, the menu was left with its content attached, so a top level find(...) could still reach items of a closed menu.
  • GridContextMenuTester.open(int, String) now checks usability before it marks the menu as opened. A refused open no longer fires a GridContextMenuOpenedEvent, and it fails with the tester's own "is not usable" message instead of the generic "unable to simulate a client side update".

Internal cleanup: the shared "undo the attach when the usability check refuses the open" logic now lives once in ComponentTester#ensureComponentIsUsableOrDetach(), used by both menu testers. This is additive for subclasses.

Also fixes a stale test expectation: getItemTexts() now expects the visible "Duplicated Hidden" item that was appended to the test view, so the list is 10 items instead of 9.

API Changes

com.vaadin.browserless.ComponentTester

// Added
protected void ensureComponentIsUsableOrDetach() // like ensureComponentIsUsable(), but detaches the component from the UI before rethrowing

Test summary

  • Opening and closing a context menu through the tester reports both opened-change events as user actions.
  • Opening a context menu that is not usable fails, and leaves the menu closed, detached, and its content unreachable through a top level find(...).
  • The failure message for a refused open is the tester's "is not usable" message, not a generic client-update error.
  • Opening a grid context menu on a row when the menu is not usable fails the same way and leaves no open menu behind.
  • The list of visible item texts includes every item the user can see, in browser order.

…249)

`ContextMenuTester.open()` and `close()` changed the menu's `opened`
property from the server, so the resulting `OpenedChangeEvent` said it
did not come from the client. The tester now pushes that property
through the client path, and a refused open no longer leaves the menu
half-opened.

Fixes #233
@mcollovati
mcollovati merged commit 39f05e3 into 25.3 Sep 18, 2026
6 checks passed
@mcollovati
mcollovati deleted the cherry-pick-249-to-25.3-1789745936385 branch September 18, 2026 16:04
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.

2 participants