diff --git a/test/components/DropdownMenu.spec.ts b/test/components/DropdownMenu.spec.ts index c9cb2dd8..86881e80 100644 --- a/test/components/DropdownMenu.spec.ts +++ b/test/components/DropdownMenu.spec.ts @@ -3,28 +3,125 @@ import DropdownMenu, { type DropdownMenuProps, type DropdownMenuSlots } from '.. import ComponentRender from '../component-render' describe('DropdownMenu', () => { - const items = [{ - label: 'Profile', - avatar: { - src: 'https://avatars.githubusercontent.com/u/739984?v=4' - } - }, { - label: 'Edit', - icon: 'i-heroicons-pencil-square-20-solid', - kbds: ['E'] - }, { - label: 'Duplicate', - icon: 'i-heroicons-document-duplicate-20-solid', - kbds: ['D'], - disabled: true, - slot: 'custom' - }] + const items = [ + [{ + label: 'My account', + avatar: { + src: 'https://avatars.githubusercontent.com/u/739984?v=4' + }, + type: 'label' + }], + [{ + label: 'Profile', + icon: 'i-heroicons-user', + slot: 'custom', + select(e: Event) { + e.preventDefault() + console.log('Profile clicked') + } + }, { + label: 'Billing', + icon: 'i-heroicons-credit-card', + kbds: ['meta', 'b'], + select() { + console.log('Billing clicked') + } + }, { + label: 'Settings', + icon: 'i-heroicons-cog', + kbds: ['?'], + select() { + console.log('Settings clicked') + } + }], [{ + label: 'Team', + icon: 'i-heroicons-users' + }, { + label: 'Invite users', + icon: 'i-heroicons-user-plus', + children: [[{ + label: 'Invite by email', + icon: 'i-heroicons-paper-airplane' + }, { + label: 'Invite by link', + icon: 'i-heroicons-link', + kbds: ['meta', 'i'], + select(e: Event) { + e?.preventDefault() + console.log('Invite by link clicked') + } + }], [{ + label: 'More', + icon: 'i-heroicons-plus-circle', + children: [{ + label: 'Import from Slack', + icon: 'i-simple-icons-slack', + to: 'https://slack.com', + target: '_blank', + select(e: Event) { + e.preventDefault() + console.log('Import from Slack clicked') + } + }, { + label: 'Import from Trello', + icon: 'i-simple-icons-trello', + select(e: Event) { + e.preventDefault() + console.log('Import from Trello clicked') + } + }, { + label: 'Import from Asana', + icon: 'i-simple-icons-asana', + select(e: Event) { + e.preventDefault() + console.log('Import from Asana clicked') + } + }] + }]] + }, { + label: 'New team', + icon: 'i-heroicons-plus', + kbds: ['meta', 'n'], + select() { + console.log('New team clicked') + } + }], [{ + label: 'GitHub', + icon: 'i-simple-icons-github', + to: 'https://github.com/nuxt/ui', + target: '_blank', + select(e: Event) { + e.preventDefault() + } + }, { + label: 'Support', + icon: 'i-heroicons-lifebuoy', + to: '/dropdown-menu' + }, { + type: 'separator' + }, { + label: 'Keyboard Shortcuts', + icon: 'i-heroicons-key' + }, { + label: 'API', + icon: 'i-heroicons-cube', + disabled: true + }], [{ + label: 'Logout', + icon: 'i-heroicons-arrow-right-start-on-rectangle', + kbds: ['shift', 'meta', 'q'], + select() { + console.log('Logout clicked') + } + }] + ] const props = { open: true, portal: false, items } it.each([ // Props ['with items', { props }], + ['with disabled', { props: { ...props, disabled: true } }], ['with class', { props: { ...props, class: 'min-w-96' } }], ['with ui', { props: { ...props, ui: { linkLeadingIcon: 'size-4' } } }], // Slots @@ -34,7 +131,7 @@ describe('DropdownMenu', () => { ['with trailing slot', { props, slots: { trailing: () => 'Trailing slot' } }], ['with item slot', { props, slots: { item: () => 'Item slot' } }], ['with custom slot', { props, slots: { custom: () => 'Custom slot' } }] - ])('renders %s correctly', async (nameOrHtml: string, options: { props?: DropdownMenuProps, slots?: Partial> }) => { + ])('renders %s correctly', async (nameOrHtml: string, options: { props?: DropdownMenuProps, slots?: Partial> }) => { const html = await ComponentRender(nameOrHtml, options, DropdownMenu) expect(html).toMatchSnapshot() }) diff --git a/test/components/__snapshots__/DropdownMenu.spec.ts.snap b/test/components/__snapshots__/DropdownMenu.spec.ts.snap index ef254e48..900f4c70 100644 --- a/test/components/__snapshots__/DropdownMenu.spec.ts.snap +++ b/test/components/__snapshots__/DropdownMenu.spec.ts.snap @@ -7,13 +7,50 @@ exports[`DropdownMenu > renders with class correctly 1`] = `
-
@@ -30,12 +67,48 @@ exports[`DropdownMenu > renders with custom slot correctly 1`] = `
- +
+ + + + +
+
+ GitHub + + + Support + + + +
+
@@ -51,13 +124,110 @@ exports[`DropdownMenu > renders with default slot correctly 1`] = `
- +
+ + + +" +`; + +exports[`DropdownMenu > renders with disabled correctly 1`] = ` +" + + + + +
+
@@ -74,10 +244,24 @@ exports[`DropdownMenu > renders with item slot correctly 1`] = `
- @@ -94,12 +278,49 @@ exports[`DropdownMenu > renders with items correctly 1`] = `
@@ -116,13 +337,50 @@ exports[`DropdownMenu > renders with label slot correctly 1`] = `
-
@@ -139,10 +397,35 @@ exports[`DropdownMenu > renders with leading slot correctly 1`] = `
-
@@ -158,11 +441,42 @@ exports[`DropdownMenu > renders with trailing slot correctly 1`] = `
-
@@ -179,13 +493,50 @@ exports[`DropdownMenu > renders with ui correctly 1`] = `
-