Skip to content

Commit

Permalink
test(ContextMenu): fix snapshots (#3055)
Browse files Browse the repository at this point in the history
Co-authored-by: Benjamin Canac <[email protected]>
  • Loading branch information
Barbapapazes and benjamincanac authored Jan 9, 2025
1 parent 039788a commit 0531211
Show file tree
Hide file tree
Showing 3 changed files with 1,110 additions and 67 deletions.
27 changes: 22 additions & 5 deletions test/components/ContextMenu.spec.ts
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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()
})
})
Loading

0 comments on commit 0531211

Please sign in to comment.