Skip to content

test(DropdownMenu): pointer and keyboard hybrid interaction (#1814)#2091

Open
kotAPI wants to merge 3 commits into
mainfrom
test/issue-1814-dropdownmenu-hybrid-interaction
Open

test(DropdownMenu): pointer and keyboard hybrid interaction (#1814)#2091
kotAPI wants to merge 3 commits into
mainfrom
test/issue-1814-dropdownmenu-hybrid-interaction

Conversation

@kotAPI

@kotAPI kotAPI commented Jun 24, 2026

Copy link
Copy Markdown
Collaborator

Summary

cover mixed pointer and keyboard selection paths

Test plan

  • Related unit tests pass locally

Related to #1814

Summary by CodeRabbit

  • Tests
    • Added coverage for mixed mouse and keyboard interactions in the dropdown menu.
    • Verified that menu items display and hide correctly during selection flows.
    • Confirmed focus returns to the trigger after an item is chosen.

@changeset-bot

changeset-bot Bot commented Jun 24, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 0b8e9cf

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai

coderabbitai Bot commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

A new test file DropdownMenu.hybridInteraction.test.tsx is added with two async tests covering mixed input flows: one opens the menu via pointer click and navigates/selects via keyboard, and the other opens via keyboard and selects via pointer click. Both assert item disappearance and focus restoration to the trigger.

Changes

DropdownMenu Hybrid Interaction Tests

Layer / File(s) Summary
Hybrid pointer/keyboard interaction tests
src/components/ui/DropdownMenu/tests/DropdownMenu.hybridInteraction.test.tsx
Adds a new test suite rendering a DropdownMenu with three items. Two async tests cover pointer→keyboard and keyboard→pointer flows using userEvent, asserting item removal via waitFor and trigger focus restoration after selection.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~5 minutes

Suggested reviewers

  • mrkazmi333

Poem

🐇 Hop, click, press a key,
The menu opens—watch and see!
Pointer starts, the keyboard ends,
Focus returns, the trigger tends.
Every item fades away,
A hybrid dance for a hybrid day! 🎉

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: a DropdownMenu test covering hybrid pointer and keyboard interaction paths.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch test/issue-1814-dropdownmenu-hybrid-interaction

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install failed: one or more packages not found in the registry.


Comment @coderabbitai help to get the list of available commands.

@kotAPI

kotAPI commented Jun 24, 2026

Copy link
Copy Markdown
Collaborator Author

Code review

Reviewed and pushed follow-up fixes addressing handler composition, test patterns (rerender vs unmount), Theme/mockMatchMedia wrappers, and flaky focus assertions.

CI was green before fixes; please re-run checks on latest commit.

@github-actions

Copy link
Copy Markdown
Contributor

Coverage

This report compares the PR with the base branch. "Δ" shows how the PR affects each metric.

Metric PR Δ
Statements 78.32% +0.01%
Branches 61.17% +0.03%
Functions 63.7% +0.10%
Lines 79.91% +0.01%

Coverage improved or stayed the same. Great job!

Run npm run coverage:ci locally for detailed reports and target untested areas to raise these numbers.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@src/components/ui/DropdownMenu/tests/DropdownMenu.hybridInteraction.test.tsx`:
- Around line 20-29: The pointer-to-keyboard flow test currently only verifies
the menu is gone after selection, so it can miss a broken open state. Update the
test in DropdownMenu.hybridInteraction.test.tsx, around the pointer open and
keyboard navigation sequence in pointer open then keyboard navigation selects
item, to assert the menu is actually open immediately after
user.click(screen.getByText('Open')) and before sending keyboard input. Use the
existing screen queries and the menu item text 'One' to check the positive
opened state, then keep the selection and focus assertions as they are.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 5c946e37-b51e-47bd-9be9-40500f19cdbd

📥 Commits

Reviewing files that changed from the base of the PR and between e2e163f and 0b8e9cf.

📒 Files selected for processing (1)
  • src/components/ui/DropdownMenu/tests/DropdownMenu.hybridInteraction.test.tsx

Comment on lines +20 to +29
test('pointer open then keyboard navigation selects item', async() => {
const user = userEvent.setup();
render(menu());

await user.click(screen.getByText('Open'));
await user.keyboard('{ArrowDown}{ArrowDown}{Enter}');

await waitFor(() => expect(screen.queryByText('One')).not.toBeInTheDocument());
await waitFor(() => expect(screen.getByText('Open')).toHaveFocus());
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Add a positive “menu opened” assertion in the pointer→keyboard flow

This test can pass even if opening breaks: queryByText('One') is only checked after selection, so it already passes when the menu never appears. Assert open state before keyboard selection.

Suggested patch
     test('pointer open then keyboard navigation selects item', async() => {
         const user = userEvent.setup();
         render(menu());
 
         await user.click(screen.getByText('Open'));
+        expect(await screen.findByText('One')).toBeInTheDocument();
         await user.keyboard('{ArrowDown}{ArrowDown}{Enter}');
 
         await waitFor(() => expect(screen.queryByText('One')).not.toBeInTheDocument());
         await waitFor(() => expect(screen.getByText('Open')).toHaveFocus());
     });
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
test('pointer open then keyboard navigation selects item', async() => {
const user = userEvent.setup();
render(menu());
await user.click(screen.getByText('Open'));
await user.keyboard('{ArrowDown}{ArrowDown}{Enter}');
await waitFor(() => expect(screen.queryByText('One')).not.toBeInTheDocument());
await waitFor(() => expect(screen.getByText('Open')).toHaveFocus());
});
test('pointer open then keyboard navigation selects item', async() => {
const user = userEvent.setup();
render(menu());
await user.click(screen.getByText('Open'));
expect(await screen.findByText('One')).toBeInTheDocument();
await user.keyboard('{ArrowDown}{ArrowDown}{Enter}');
await waitFor(() => expect(screen.queryByText('One')).not.toBeInTheDocument());
await waitFor(() => expect(screen.getByText('Open')).toHaveFocus());
});
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/components/ui/DropdownMenu/tests/DropdownMenu.hybridInteraction.test.tsx`
around lines 20 - 29, The pointer-to-keyboard flow test currently only verifies
the menu is gone after selection, so it can miss a broken open state. Update the
test in DropdownMenu.hybridInteraction.test.tsx, around the pointer open and
keyboard navigation sequence in pointer open then keyboard navigation selects
item, to assert the menu is actually open immediately after
user.click(screen.getByText('Open')) and before sending keyboard input. Use the
existing screen queries and the menu item text 'One' to check the positive
opened state, then keep the selection and focus assertions as they are.

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