Files
ComfyUI_frontend/tests-ui/renderer/extensions/vueNodes/components/NodeWidgets.test.ts
Arjan Singh 8849d54e20 fix: use WidgetSelectDropdown for models (#6607)
## Summary

As the commit says, the model loaders were broken in cloud if you
enabled Vue Nodes (not a thing I think user does yet).

This fixes it by configuring the `WidgetSelectDropdown` to load so the
user load models like they would load a input or output asset.

## Review Focus

Probably `useAssetWidgetData` to make sure it's idomatic.

This part of
[assetsStore](https://github.com/Comfy-Org/ComfyUI_frontend/pull/6607/files#diff-18a5914c9f12c16d9c9c3a9f6d0e203a9c00598414d3d1c8637da9ca77339d83R158-R234)
as well.

## Screenshots

<img width="1196" height="1005" alt="Screenshot 2025-11-05 at 5 34
22 PM"
src="https://github.com/user-attachments/assets/804cd3c4-3370-4667-b606-bed52fcd6278"
/>

┆Issue is synchronized with this [Notion
page](https://www.notion.so/PR-6607-fix-use-WidgetSelectDropdown-for-models-2a36d73d36508143b185d06d736e4af9)
by [Unito](https://www.unito.io)

---------

Co-authored-by: GitHub Action <action@github.com>
2025-11-06 03:34:17 +00:00

124 lines
3.4 KiB
TypeScript

import { createTestingPinia } from '@pinia/testing'
import { mount } from '@vue/test-utils'
import { describe, expect, it } from 'vitest'
import type {
SafeWidgetData,
VueNodeData
} from '@/composables/graph/useGraphNodeManager'
import NodeWidgets from '@/renderer/extensions/vueNodes/components/NodeWidgets.vue'
describe('NodeWidgets', () => {
const createMockWidget = (
overrides: Partial<SafeWidgetData> = {}
): SafeWidgetData => ({
name: 'test_widget',
type: 'combo',
value: 'test_value',
options: {
values: ['option1', 'option2']
},
callback: undefined,
spec: undefined,
label: undefined,
isDOMWidget: false,
slotMetadata: undefined,
...overrides
})
const createMockNodeData = (
nodeType: string = 'TestNode',
widgets: SafeWidgetData[] = []
): VueNodeData => ({
id: '1',
type: nodeType,
widgets,
title: 'Test Node',
mode: 0,
selected: false,
executing: false,
inputs: [],
outputs: []
})
const mountComponent = (nodeData?: VueNodeData) => {
return mount(NodeWidgets, {
props: {
nodeData
},
global: {
plugins: [createTestingPinia()],
stubs: {
// Stub InputSlot to avoid complex slot registration dependencies
InputSlot: true
},
mocks: {
$t: (key: string) => key
}
}
})
}
describe('node-type prop passing', () => {
it('passes node type to widget components', () => {
const widget = createMockWidget()
const nodeData = createMockNodeData('CheckpointLoaderSimple', [widget])
const wrapper = mountComponent(nodeData)
// Find the dynamically rendered widget component
const widgetComponent = wrapper.find('.lg-node-widget')
expect(widgetComponent.exists()).toBe(true)
// Verify node-type prop is passed
const component = widgetComponent.findComponent({ name: 'WidgetSelect' })
if (component.exists()) {
expect(component.props('nodeType')).toBe('CheckpointLoaderSimple')
}
})
it('passes empty string when nodeData is undefined', () => {
const wrapper = mountComponent(undefined)
// No widgets should be rendered
const widgetComponents = wrapper.findAll('.lg-node-widget')
expect(widgetComponents).toHaveLength(0)
})
it('passes empty string when nodeData.type is undefined', () => {
const widget = createMockWidget()
const nodeData = createMockNodeData('', [widget])
const wrapper = mountComponent(nodeData)
const widgetComponent = wrapper.find('.lg-node-widget')
if (widgetComponent.exists()) {
const component = widgetComponent.findComponent({
name: 'WidgetSelect'
})
if (component.exists()) {
expect(component.props('nodeType')).toBe('')
}
}
})
it.for(['CheckpointLoaderSimple', 'LoraLoader', 'VAELoader', 'KSampler'])(
'passes correct node type: %s',
(nodeType) => {
const widget = createMockWidget()
const nodeData = createMockNodeData(nodeType, [widget])
const wrapper = mountComponent(nodeData)
const widgetComponent = wrapper.find('.lg-node-widget')
expect(widgetComponent.exists()).toBe(true)
const component = widgetComponent.findComponent({
name: 'WidgetSelect'
})
if (component.exists()) {
expect(component.props('nodeType')).toBe(nodeType)
}
}
)
})
})