mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-02-22 15:54:09 +00:00
Fix remote widget undefined arg (#2551)
This commit is contained in:
@@ -15,7 +15,7 @@ export const useComboWidget = () => {
|
||||
inputData: InputSpec
|
||||
) => {
|
||||
const widgetStore = useWidgetStore()
|
||||
const { remote, options } = inputData[1]
|
||||
const { remote, options } = inputData[1] || {}
|
||||
const defaultValue = widgetStore.getDefaultValue(inputData)
|
||||
|
||||
const res = {
|
||||
|
||||
@@ -47,9 +47,11 @@ export const useWidgetStore = defineStore('widget', () => {
|
||||
if (Array.isArray(inputData[0]))
|
||||
return getDefaultValue(transformComboInput(inputData))
|
||||
|
||||
const widgetType = getWidgetType(inputData[0], inputData[1].name)
|
||||
const widgetType = getWidgetType(inputData[0], inputData[1]?.name)
|
||||
|
||||
const [_, props] = inputData
|
||||
|
||||
if (!props) return undefined
|
||||
if (props.default) return props.default
|
||||
|
||||
if (widgetType === 'COMBO' && props.options?.length) return props.options[0]
|
||||
@@ -63,7 +65,7 @@ export const useWidgetStore = defineStore('widget', () => {
|
||||
'COMBO',
|
||||
{
|
||||
options: inputData[0],
|
||||
...Object(inputData[1])
|
||||
...Object(inputData[1] || {})
|
||||
}
|
||||
]
|
||||
: inputData
|
||||
|
||||
44
tests-ui/tests/composables/widgets/useComboWidget.test.ts
Normal file
44
tests-ui/tests/composables/widgets/useComboWidget.test.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
import { createPinia, setActivePinia } from 'pinia'
|
||||
|
||||
import { useComboWidget } from '@/composables/widgets/useComboWidget'
|
||||
import type { InputSpec } from '@/types/apiTypes'
|
||||
|
||||
jest.mock('@/scripts/widgets', () => ({
|
||||
addValueControlWidgets: jest.fn()
|
||||
}))
|
||||
|
||||
describe('useComboWidget', () => {
|
||||
beforeEach(() => {
|
||||
setActivePinia(createPinia())
|
||||
jest.clearAllMocks()
|
||||
})
|
||||
|
||||
it('should handle undefined spec', () => {
|
||||
const constructor = useComboWidget()
|
||||
const mockNode = {
|
||||
addWidget: jest.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: 'COMBO'
|
||||
})
|
||||
)
|
||||
expect(widget).toEqual({
|
||||
widget: { options: {} }
|
||||
})
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user