-
Notifications
You must be signed in to change notification settings - Fork 698
/
Copy pathDropdownMenu.spec.ts
135 lines (127 loc) · 4.59 KB
/
DropdownMenu.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
import { describe, it, expect, test } from 'vitest'
import DropdownMenu, { type DropdownMenuProps, type DropdownMenuSlots } from '../../src/runtime/components/DropdownMenu.vue'
import ComponentRender from '../component-render'
import theme from '#build/ui/dropdown-menu'
import { expectSlotProps } from '../utils/types'
describe('DropdownMenu', () => {
const sizes = Object.keys(theme.variants.size) as any
const items = [
[{
label: 'My account',
avatar: {
src: 'https://github.com/benjamincanac.png'
},
type: 'label'
}],
[{
label: 'Profile',
icon: 'i-lucide-user',
slot: 'custom'
}, {
label: 'Billing',
icon: 'i-lucide-credit-card',
kbds: ['meta', 'b']
}, {
label: 'Settings',
icon: 'i-lucide-cog',
kbds: ['?']
}], [{
label: 'Team',
icon: 'i-lucide-users'
}, {
label: 'Invite users',
icon: 'i-lucide-user-plus',
children: [[{
label: 'Invite by email',
icon: 'i-lucide-send-horizontal'
}, {
label: 'Invite by link',
icon: 'i-lucide-link',
kbds: ['meta', 'i']
}], [{
label: 'More',
icon: 'i-lucide-circle-plus',
children: [{
label: 'Import from Slack',
icon: 'i-simple-icons-slack',
to: 'https://slack.com',
target: '_blank'
}, {
label: 'Import from Trello',
icon: 'i-simple-icons-trello'
}, {
label: 'Import from Asana',
icon: 'i-simple-icons-asana'
}]
}]]
}, {
label: 'New team',
icon: 'i-lucide-plus',
kbds: ['meta', 'n']
}], [{
label: 'GitHub',
icon: 'i-simple-icons-github',
to: 'https://github.com/nuxt/ui',
target: '_blank'
}, {
label: 'Support',
icon: 'i-lucide-life-buoy',
to: '/components/dropdown-menu'
}, {
type: 'separator'
}, {
label: 'Keyboard Shortcuts',
icon: 'i-lucide-key-round'
}, {
label: 'API',
icon: 'i-lucide-box',
disabled: true
}], [{
label: 'Logout',
color: 'error',
icon: 'i-lucide-log-out',
kbds: ['shift', 'meta', 'q']
}]
]
const props = { open: true, portal: false, items }
it.each([
// Props
['with items', { props }],
['with labelKey', { props: { ...props, labelKey: 'icon' } }],
['with disabled', { props: { ...props, disabled: true } }],
['with arrow', { props: { ...props, arrow: true } }],
...sizes.map((size: string) => [`with size ${size}`, { props: { ...props, size } }]),
['with externalIcon', { props: { ...props, externalIcon: 'i-lucide-external-link' } }],
['without externalIcon', { props: { ...props, externalIcon: false } }],
['with class', { props: { ...props, class: 'min-w-96' } }],
['with ui', { props: { ...props, ui: { itemLeadingIcon: 'size-4' } } }],
// Slots
['with default slot', { props, slots: { default: () => 'Default slot' } }],
['with item slot', { props, slots: { item: () => 'Item slot' } }],
['with item-leading slot', { props, slots: { 'item-leading': () => 'Item leading slot' } }],
['with item-label slot', { props, slots: { 'item-label': () => 'Item label slot' } }],
['with item-trailing slot', { props, slots: { 'item-trailing': () => 'Item trailing slot' } }],
['with custom slot', { props, slots: { custom: () => 'Custom slot' } }]
])('renders %s correctly', async (nameOrHtml: string, options: { props?: DropdownMenuProps, slots?: Partial<DropdownMenuSlots> }) => {
const html = await ComponentRender(nameOrHtml, options, DropdownMenu)
expect(html).toMatchSnapshot()
})
test('should have the correct types', () => {
// normal
expectSlotProps('item', () => DropdownMenu({
items: [{ label: 'foo', value: 'bar' }]
})).toEqualTypeOf<{ item: { label: string, value: string }, index: number, active?: boolean }>()
// groups
expectSlotProps('item', () => DropdownMenu({
items: [[{ label: 'foo', value: 'bar' }]]
})).toEqualTypeOf<{ item: { label: string, value: string }, index: number, active?: boolean }>()
// custom
expectSlotProps('item', () => DropdownMenu({
items: [{ label: 'foo', value: 'bar', custom: 'nice' }]
})).toEqualTypeOf<{ item: { label: string, value: string, custom: string }, index: number, active?: boolean }>()
// custom + groups
expectSlotProps('item', () => DropdownMenu({
items: [[{ label: 'foo', value: 'bar', custom: 'nice' }]]
})).toEqualTypeOf<{ item: { label: string, value: string, custom: string }, index: number, active?: boolean }>()
})
})