-
-
Notifications
You must be signed in to change notification settings - Fork 366
test(ui): add tests for mobile menu default closed state #2195
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
ghostdevv
merged 5 commits into
npmx-dev:main
from
howwohmm:test/mobile-menu-default-state
Mar 23, 2026
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
400ad78
test(ui): add tests for mobile menu default state and open/close behaβ¦
howwohmm a92bbc0
fix(test): correct component name and remove unused import
howwohmm 87dad03
[autofix.ci] apply automated fixes
autofix-ci[bot] 63493f8
fix(test): use static import and add missing type field
howwohmm dd44bf8
[autofix.ci] apply automated fixes
autofix-ci[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| import { describe, it, expect, vi } from 'vitest' | ||
| import { mockNuxtImport, mountSuspended } from '@nuxt/test-utils/runtime' | ||
| import { computed, nextTick } from 'vue' | ||
| import { HeaderMobileMenu } from '#components' | ||
|
|
||
| // Mock useConnector | ||
| mockNuxtImport('useConnector', () => () => ({ | ||
| isConnected: computed(() => false), | ||
| npmUser: computed(() => null), | ||
| avatar: computed(() => null), | ||
| })) | ||
|
|
||
| // Mock useAtproto | ||
| mockNuxtImport('useAtproto', () => () => ({ | ||
| user: computed(() => null), | ||
| })) | ||
|
|
||
| // Mock useFocusTrap (from @vueuse/integrations) | ||
| vi.mock('@vueuse/integrations/useFocusTrap', () => ({ | ||
| useFocusTrap: () => ({ | ||
| activate: vi.fn(), | ||
| deactivate: vi.fn(), | ||
| }), | ||
| })) | ||
|
|
||
| describe('MobileMenu', () => { | ||
| async function mountMenu(open = false) { | ||
| return mountSuspended(HeaderMobileMenu, { | ||
| props: { | ||
| open, | ||
| links: [ | ||
| { | ||
| type: 'group' as const, | ||
| name: 'main', | ||
| label: 'Navigation', | ||
| items: [ | ||
| { | ||
| type: 'link' as const, | ||
| name: 'home', | ||
| label: 'Home', | ||
| to: '/', | ||
| iconClass: 'i-lucide:home', | ||
| }, | ||
| ], | ||
| }, | ||
| ], | ||
| }, | ||
| attachTo: document.body, | ||
| }) | ||
| } | ||
|
|
||
| it('is closed by default', async () => { | ||
| const wrapper = await mountMenu(false) | ||
| try { | ||
| // Menu content is behind v-if="isOpen" inside a Teleport | ||
| expect(document.querySelector('[role="dialog"]')).toBeNull() | ||
| } finally { | ||
| wrapper.unmount() | ||
| } | ||
| }) | ||
|
|
||
| it('opens when the open prop is set to true', async () => { | ||
| const wrapper = await mountMenu(true) | ||
| try { | ||
| await nextTick() | ||
| const dialog = document.querySelector('[role="dialog"]') | ||
| expect(dialog).not.toBeNull() | ||
| expect(dialog?.getAttribute('aria-modal')).toBe('true') | ||
| } finally { | ||
| wrapper.unmount() | ||
| } | ||
| }) | ||
|
|
||
| it('closes when open prop changes from true to false', async () => { | ||
| const wrapper = await mountMenu(true) | ||
| try { | ||
| await nextTick() | ||
| expect(document.querySelector('[role="dialog"]')).not.toBeNull() | ||
|
|
||
| await wrapper.setProps({ open: false }) | ||
| await nextTick() | ||
| expect(document.querySelector('[role="dialog"]')).toBeNull() | ||
| } finally { | ||
| wrapper.unmount() | ||
| } | ||
| }) | ||
|
|
||
| it('emits update:open false when backdrop is clicked', async () => { | ||
| const wrapper = await mountMenu(true) | ||
| try { | ||
| await nextTick() | ||
| const backdrop = document.querySelector('[role="dialog"] > button') | ||
| expect(backdrop).not.toBeNull() | ||
| backdrop?.dispatchEvent(new Event('click', { bubbles: true })) | ||
| await nextTick() | ||
| expect(wrapper.emitted('update:open')).toBeTruthy() | ||
| expect(wrapper.emitted('update:open')![0]).toEqual([false]) | ||
| } finally { | ||
| wrapper.unmount() | ||
| } | ||
| }) | ||
|
|
||
| it('emits update:open false when close button is clicked', async () => { | ||
| const wrapper = await mountMenu(true) | ||
| try { | ||
| await nextTick() | ||
| // Close button has aria-label matching $t('common.close') β find it inside nav | ||
| const closeBtn = document.querySelector('nav button[aria-label]') | ||
| expect(closeBtn).not.toBeNull() | ||
| closeBtn?.dispatchEvent(new Event('click', { bubbles: true })) | ||
| await nextTick() | ||
| expect(wrapper.emitted('update:open')).toBeTruthy() | ||
| expect(wrapper.emitted('update:open')![0]).toEqual([false]) | ||
| } finally { | ||
| wrapper.unmount() | ||
| } | ||
| }) | ||
| }) | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.