mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-19 22:09:37 +00:00
fix: remove primitive UI stubs (Button, Dialog) from shared test-utils
Tests should import and register real PrimeVue components instead of relying on centralized primitive stubs that hide integration behavior. Addresses review feedback: https://github.com/Comfy-Org/ComfyUI_frontend/pull/10628#discussion_r3004203300
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/* eslint-disable vue/one-component-per-file, vue/no-reserved-component-names */
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
/* eslint-disable vue/one-component-per-file */
|
||||
import { describe, expect, it } from 'vitest'
|
||||
|
||||
import { render, screen, stubs } from '@/utils/test-utils'
|
||||
|
||||
@@ -33,41 +33,6 @@ describe('test-utils', () => {
|
||||
})
|
||||
|
||||
describe('stubs', () => {
|
||||
describe('Button', () => {
|
||||
it('renders as a button element with label', () => {
|
||||
const Wrapper = defineComponent({
|
||||
components: { Button: stubs.Button },
|
||||
setup() {
|
||||
return () => h(stubs.Button, { label: 'Save' })
|
||||
}
|
||||
})
|
||||
render(Wrapper)
|
||||
expect(screen.getByRole('button')).toHaveTextContent('Save')
|
||||
})
|
||||
|
||||
it('sets disabled when loading is true', () => {
|
||||
const Wrapper = defineComponent({
|
||||
setup() {
|
||||
return () => h(stubs.Button, { label: 'Save', loading: true })
|
||||
}
|
||||
})
|
||||
render(Wrapper)
|
||||
expect(screen.getByRole('button')).toBeDisabled()
|
||||
})
|
||||
|
||||
it('emits click event', async () => {
|
||||
const onClick = vi.fn()
|
||||
const Wrapper = defineComponent({
|
||||
setup() {
|
||||
return () => h(stubs.Button, { label: 'Go', onClick })
|
||||
}
|
||||
})
|
||||
const { user } = render(Wrapper)
|
||||
await user!.click(screen.getByRole('button'))
|
||||
expect(onClick).toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
|
||||
describe('Skeleton', () => {
|
||||
it('renders with data-testid', () => {
|
||||
const Wrapper = defineComponent({
|
||||
@@ -79,28 +44,4 @@ describe('stubs', () => {
|
||||
expect(screen.getByTestId('skeleton')).toBeDefined()
|
||||
})
|
||||
})
|
||||
|
||||
describe('Dialog', () => {
|
||||
it('renders children when visible', () => {
|
||||
const Wrapper = defineComponent({
|
||||
setup() {
|
||||
return () =>
|
||||
h(stubs.Dialog, { visible: true }, () => h('p', 'Dialog body'))
|
||||
}
|
||||
})
|
||||
render(Wrapper)
|
||||
expect(screen.getByRole('dialog')).toHaveTextContent('Dialog body')
|
||||
})
|
||||
|
||||
it('renders nothing when not visible', () => {
|
||||
const Wrapper = defineComponent({
|
||||
setup() {
|
||||
return () =>
|
||||
h(stubs.Dialog, { visible: false }, () => h('p', 'Hidden'))
|
||||
}
|
||||
})
|
||||
render(Wrapper)
|
||||
expect(screen.queryByRole('dialog')).toBeNull()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* eslint-disable vue/one-component-per-file, vue/require-prop-types, vue/no-reserved-component-names */
|
||||
/* eslint-disable vue/one-component-per-file, vue/require-prop-types */
|
||||
import type { RenderResult } from '@testing-library/vue'
|
||||
import type { ComponentMountingOptions } from '@vue/test-utils'
|
||||
|
||||
@@ -47,33 +47,6 @@ const defaultDirectiveStubs: Record<string, () => void> = {
|
||||
*
|
||||
* Or use `renderWithDefaults` which auto-applies these as defaults.
|
||||
*/
|
||||
const ButtonStub = defineComponent({
|
||||
name: 'Button',
|
||||
props: [
|
||||
'disabled',
|
||||
'loading',
|
||||
'variant',
|
||||
'size',
|
||||
'label',
|
||||
'icon',
|
||||
'severity'
|
||||
],
|
||||
emits: ['click'],
|
||||
setup(props, { slots, emit }) {
|
||||
return () =>
|
||||
h(
|
||||
'button',
|
||||
{
|
||||
disabled: props.disabled || props.loading,
|
||||
'data-testid': props.label,
|
||||
'data-icon': props.icon,
|
||||
onClick: () => emit('click')
|
||||
},
|
||||
slots.default?.() ?? props.label
|
||||
)
|
||||
}
|
||||
})
|
||||
|
||||
const SkeletonStub = defineComponent({
|
||||
name: 'Skeleton',
|
||||
setup() {
|
||||
@@ -107,27 +80,11 @@ const MessageStub = defineComponent({
|
||||
}
|
||||
})
|
||||
|
||||
const DialogStub = defineComponent({
|
||||
name: 'Dialog',
|
||||
props: ['visible', 'modal', 'header'],
|
||||
setup(props, { slots }) {
|
||||
return () =>
|
||||
props.visible
|
||||
? h('div', { role: 'dialog', 'data-testid': 'dialog' }, [
|
||||
props.header ? h('div', props.header) : null,
|
||||
slots.default?.()
|
||||
])
|
||||
: null
|
||||
}
|
||||
})
|
||||
|
||||
const stubs = {
|
||||
Button: ButtonStub,
|
||||
Skeleton: SkeletonStub,
|
||||
Tag: TagStub,
|
||||
Badge: BadgeStub,
|
||||
Message: MessageStub,
|
||||
Dialog: DialogStub
|
||||
Message: MessageStub
|
||||
} as const
|
||||
|
||||
type RenderWithDefaultsResult = RenderResult & {
|
||||
|
||||
Reference in New Issue
Block a user