Skip to content

test(ui): add tests for mobile menu default closed state#2195

Open
howwohmm wants to merge 5 commits intonpmx-dev:mainfrom
howwohmm:test/mobile-menu-default-state
Open

test(ui): add tests for mobile menu default closed state#2195
howwohmm wants to merge 5 commits intonpmx-dev:mainfrom
howwohmm:test/mobile-menu-default-state

Conversation

@howwohmm
Copy link

🔗 Linked issue

Closes #1505

🧭 Context

The mobile menu had no tests verifying its default state or basic open/close behavior.

📚 Description

Adds a test suite for MobileMenu.client.vue covering:

  • Closed by default — dialog element is not in DOM when open is false
  • Opens on request — dialog with role="dialog" and aria-modal="true" appears when open is true
  • Closes on prop change — dialog removed when open goes from true to false
  • Backdrop click — emits update:open with false
  • Close button click — emits update:open with false

Mocks useConnector, useAtproto, and useFocusTrap to isolate the menu logic. Follows existing patterns from HeaderConnectorModal.spec.ts and Tooltip.spec.ts (Teleport + cleanup).

What it doesn't change

  • No changes to the component itself
  • No changes to existing tests

…vior

Covers issue requirements:
- Menu is closed by default (dialog not in DOM)
- Opens when prop is set to true
- Closes when prop changes back to false
- Emits update:open on backdrop click
- Emits update:open on close button click

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@vercel
Copy link

vercel bot commented Mar 22, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
npmx.dev Ready Ready Preview, Comment Mar 22, 2026 0:00am
2 Skipped Deployments
Project Deployment Actions Updated (UTC)
docs.npmx.dev Ignored Ignored Preview Mar 22, 2026 0:00am
npmx-lunaria Ignored Ignored Mar 22, 2026 0:00am

Request Review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 22, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: b13b18e3-5b7b-4066-9dfe-a91f5977667f

📥 Commits

Reviewing files that changed from the base of the PR and between 87dad03 and dd44bf8.

📒 Files selected for processing (1)
  • test/nuxt/components/Header/MobileMenu.spec.ts
✅ Files skipped from review due to trivial changes (1)
  • test/nuxt/components/Header/MobileMenu.spec.ts

📝 Walkthrough

Walkthrough

A new Vitest test suite for the Nuxt HeaderMobileMenu component was added at test/nuxt/components/Header/MobileMenu.spec.ts. The suite mocks Nuxt composables useConnector and useAtproto, stubs useFocusTrap, and provides an async mountMenu(open) helper that mounts HeaderMobileMenu with an open prop and sample links. Tests assert: no dialog when open is false; dialog appears with aria-modal="true" when open is true; dialog is removed after changing open from true to false; clicking the backdrop emits update:open with [false]; clicking the close button emits update:open with [false]. Lines changed: +118/-0.

Suggested reviewers

  • danielroe
🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description check ✅ Passed The pull request description clearly explains the addition of a test suite for MobileMenu.client.vue with specific test cases covering default closed state, opening on request, closing on prop change, and user interaction events.
Linked Issues check ✅ Passed The pull request successfully addresses all requirements from issue #1505: verifies default closed state, tests opening with proper accessibility attributes, confirms closing on prop change, and validates user interactions emit correct events.
Out of Scope Changes check ✅ Passed The pull request contains only additions to the test file (MobileMenu.spec.ts) with no modifications to component code or existing tests, remaining entirely within scope.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 24804db7-68df-4724-9496-6879bbe8aa62

📥 Commits

Reviewing files that changed from the base of the PR and between 7f2fc1a and 400ad78.

📒 Files selected for processing (1)
  • test/nuxt/components/Header/MobileMenu.spec.ts

Comment on lines +6 to +10
mockNuxtImport('useConnector', () => () => ({
isConnected: computed(() => false),
npmUser: computed(() => null),
avatar: computed(() => null),
}))
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Align the useConnector mock shape with the real composable contract.

Line 7 mocks isConnected, but the production useConnector contract appears to use connected. This mock can hide a real integration mismatch and give false confidence.

Suggested adjustment
 mockNuxtImport('useConnector', () => () => ({
-  isConnected: computed(() => false),
+  connected: computed(() => false),
   npmUser: computed(() => null),
   avatar: computed(() => null),
 }))

If MobileMenu.client.vue expects isConnected, consider aliasing at destructure time there (e.g. connected: isConnected) so both runtime and tests reflect the same contract.

📝 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
mockNuxtImport('useConnector', () => () => ({
isConnected: computed(() => false),
npmUser: computed(() => null),
avatar: computed(() => null),
}))
mockNuxtImport('useConnector', () => () => ({
connected: computed(() => false),
npmUser: computed(() => null),
avatar: computed(() => null),
}))

howwohmm and others added 2 commits March 22, 2026 17:19
The Nuxt auto-generated name for Header/MobileMenu.client.vue is
HeaderMobileMenu, not MobileMenuClient. Also removes unused `ref` import.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
test/nuxt/components/Header/MobileMenu.spec.ts (1)

88-89: Consider a more type-safe pattern for array access.

Lines 89 and 105 use the non-null assertion operator ! to access wrapper.emitted('update:open')![0]. Whilst the preceding .toBeTruthy() check ensures the array exists, it doesn't explicitly verify that index [0] exists.

♻️ Suggested refactor for stricter type safety

For lines 88-89:

-      expect(wrapper.emitted('update:open')).toBeTruthy()
-      expect(wrapper.emitted('update:open')![0]).toEqual([false])
+      const emitted = wrapper.emitted('update:open')
+      expect(emitted).toBeTruthy()
+      expect(emitted?.[0]).toEqual([false])

For lines 104-105:

-      expect(wrapper.emitted('update:open')).toBeTruthy()
-      expect(wrapper.emitted('update:open')![0]).toEqual([false])
+      const emitted = wrapper.emitted('update:open')
+      expect(emitted).toBeTruthy()
+      expect(emitted?.[0]).toEqual([false])

As per coding guidelines, strictly type-safe code should check when accessing an array value by index.

Also applies to: 104-105


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 1fe96943-99c4-4330-9b64-7f0e9f132fb1

📥 Commits

Reviewing files that changed from the base of the PR and between 400ad78 and 87dad03.

📒 Files selected for processing (1)
  • test/nuxt/components/Header/MobileMenu.spec.ts

howwohmm and others added 2 commits March 22, 2026 17:27
Switch from dynamic `await import('#components')` to static top-level
import to match the pattern used by HeaderConnectorModal.spec.ts.
Add required `type: 'link'` to NavigationLink test data.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@codecov
Copy link

codecov bot commented Mar 22, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

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.

Add a test that checks if the mobile menu is closed by default

1 participant