Skip to content

Commit f4f0c96

Browse files
authored
Fix combo input default value (#242)
* Fix combo input default value * Supress logs and fix failure
1 parent c0875d0 commit f4f0c96

File tree

4 files changed

+38
-3
lines changed

4 files changed

+38
-3
lines changed

src/stores/nodeDefStore.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,8 @@ export class ComfyInputsSpec {
120120
name,
121121
type,
122122
...spec,
123-
comboOptions: typeRaw
123+
comboOptions: typeRaw,
124+
default: spec.default ?? typeRaw[0]
124125
})
125126
default:
126127
return plainToClass(CustomInputSpec, { name, type, ...spec })

tests-ui/afterSetup.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,25 @@ import lg from './utils/litegraph'
33

44
// Load things once per test file before to ensure its all warmed up for the tests
55
beforeAll(async () => {
6+
const originalWarn = console.warn
7+
console.error = function (...args) {
8+
if (['Error: Not implemented: window.alert'].includes(args[0])) {
9+
return
10+
}
11+
}
12+
console.warn = function (...args) {
13+
if (
14+
[
15+
"sMethod=='pointer' && !window.PointerEvent",
16+
'Warning, nodes missing on pasting'
17+
].includes(args[0])
18+
) {
19+
return
20+
}
21+
originalWarn.apply(console, args)
22+
}
23+
console.log = function (...args) {}
24+
625
lg.setup(global)
726
await start({ resetEnv: true })
827
lg.teardown(global)

tests-ui/tests/nodeDef.test.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ describe('ComfyInputsSpec', () => {
8989
expect(floatInput.step).toBe(0.1)
9090
})
9191

92-
it('should handle custom input specs', () => {
92+
it('should handle combo input specs', () => {
9393
const plainObject = {
9494
optional: {
9595
comboInput: [[1, 2, 3], { default: 2 }]
@@ -103,6 +103,21 @@ describe('ComfyInputsSpec', () => {
103103
expect(result.optional.comboInput.default).toBe(2)
104104
})
105105

106+
it('should handle combo input specs (auto-default)', () => {
107+
const plainObject = {
108+
optional: {
109+
comboInput: [[1, 2, 3], {}]
110+
}
111+
}
112+
113+
const result = plainToClass(ComfyInputsSpec, plainObject)
114+
115+
expect(result.optional.comboInput).toBeInstanceOf(ComboInputSpec)
116+
expect(result.optional.comboInput.type).toBe('COMBO')
117+
// Should pick the first choice as default
118+
expect(result.optional.comboInput.default).toBe(1)
119+
})
120+
106121
it('should handle custom input specs', () => {
107122
const plainObject = {
108123
optional: {

tests-ui/tests/nodeSearchService.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const EXAMPLE_NODE_DEFS: ComfyNodeDefImpl[] = [
66
{
77
input: {
88
required: {
9-
ckpt_name: [['model1.safetensors', 'model2.ckpt']]
9+
ckpt_name: [['model1.safetensors', 'model2.ckpt'], {}]
1010
}
1111
},
1212
output: ['MODEL', 'CLIP', 'VAE'],

0 commit comments

Comments
 (0)