mirror of
https://github.com/ArthurDanjou/ui.git
synced 2026-01-25 17:30:37 +01:00
test(ContextMenu): fix snapshots (#3055)
Co-authored-by: Benjamin Canac <canacb1@gmail.com>
This commit is contained in:
@@ -1,9 +1,23 @@
|
||||
import { h, defineComponent } from 'vue'
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import ContextMenu, { type ContextMenuProps, type ContextMenuSlots } from '../../src/runtime/components/ContextMenu.vue'
|
||||
import ComponentRender from '../component-render'
|
||||
import theme from '#build/ui/context-menu'
|
||||
import { mountSuspended } from '@nuxt/test-utils/runtime'
|
||||
|
||||
const ContextMenuWrapper = defineComponent({
|
||||
components: {
|
||||
UContextMenu: ContextMenu as any
|
||||
},
|
||||
inheritAttrs: false,
|
||||
template: `<UContextMenu v-bind="$attrs">
|
||||
<span>Right Click</span>
|
||||
|
||||
<template v-for="(_, name) in $slots" #[name]="slotData">
|
||||
<slot :name="name" v-bind="slotData" />
|
||||
</template>
|
||||
</UContextMenu>`
|
||||
})
|
||||
|
||||
// FIXME: Can't force open state
|
||||
describe('ContextMenu', () => {
|
||||
const sizes = Object.keys(theme.variants.size) as any
|
||||
|
||||
@@ -69,14 +83,17 @@ describe('ContextMenu', () => {
|
||||
['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 default slot', { props, slots: { default: () => h('span', '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?: ContextMenuProps<typeof items[number][number]>, slots?: Partial<ContextMenuSlots<any>> }) => {
|
||||
const html = await ComponentRender(nameOrHtml, options, ContextMenu)
|
||||
expect(html).toMatchSnapshot()
|
||||
const wrapper = await mountSuspended(ContextMenuWrapper, options as any)
|
||||
|
||||
await wrapper.find('span').trigger('click.right')
|
||||
|
||||
expect(wrapper.html()).toMatchSnapshot()
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user