mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-02-08 00:50:05 +00:00
52 lines
1.2 KiB
TypeScript
52 lines
1.2 KiB
TypeScript
import { createPinia, setActivePinia } from 'pinia'
|
|
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
|
|
import { useComboWidget } from '@/composables/widgets/useComboWidget'
|
|
import type { InputSpec } from '@/schemas/nodeDefSchema'
|
|
|
|
vi.mock('@/stores/widgetStore', () => ({
|
|
useWidgetStore: () => ({
|
|
getDefaultValue: vi.fn()
|
|
})
|
|
}))
|
|
|
|
vi.mock('@/scripts/widgets', () => ({
|
|
addValueControlWidgets: vi.fn()
|
|
}))
|
|
|
|
describe('useComboWidget', () => {
|
|
beforeEach(() => {
|
|
setActivePinia(createPinia())
|
|
vi.clearAllMocks()
|
|
})
|
|
|
|
it('should handle undefined spec', () => {
|
|
const constructor = useComboWidget()
|
|
const mockNode = {
|
|
addWidget: vi.fn().mockReturnValue({ options: {} } as any)
|
|
}
|
|
|
|
const inputSpec: InputSpec = ['COMBO', undefined]
|
|
|
|
const widget = constructor(
|
|
mockNode as any,
|
|
'inputName',
|
|
inputSpec,
|
|
undefined as any
|
|
)
|
|
|
|
expect(mockNode.addWidget).toHaveBeenCalledWith(
|
|
'combo',
|
|
'inputName',
|
|
undefined, // default value
|
|
expect.any(Function), // callback
|
|
expect.objectContaining({
|
|
values: []
|
|
})
|
|
)
|
|
expect(widget).toEqual({
|
|
widget: { options: {} }
|
|
})
|
|
})
|
|
})
|