Skip to content

Commit

Permalink
Fix combo input default value (#242)
Browse files Browse the repository at this point in the history
* Fix combo input default value

* Supress logs and fix failure
  • Loading branch information
huchenlei committed Jul 28, 2024
1 parent c0875d0 commit f4f0c96
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/stores/nodeDefStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ export class ComfyInputsSpec {
name,
type,
...spec,
comboOptions: typeRaw
comboOptions: typeRaw,
default: spec.default ?? typeRaw[0]
})
default:
return plainToClass(CustomInputSpec, { name, type, ...spec })
Expand Down
19 changes: 19 additions & 0 deletions tests-ui/afterSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,25 @@ import lg from './utils/litegraph'

// Load things once per test file before to ensure its all warmed up for the tests
beforeAll(async () => {
const originalWarn = console.warn
console.error = function (...args) {
if (['Error: Not implemented: window.alert'].includes(args[0])) {
return
}
}
console.warn = function (...args) {
if (
[
"sMethod=='pointer' && !window.PointerEvent",
'Warning, nodes missing on pasting'
].includes(args[0])
) {
return
}
originalWarn.apply(console, args)
}
console.log = function (...args) {}

lg.setup(global)
await start({ resetEnv: true })
lg.teardown(global)
Expand Down
17 changes: 16 additions & 1 deletion tests-ui/tests/nodeDef.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ describe('ComfyInputsSpec', () => {
expect(floatInput.step).toBe(0.1)
})

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

it('should handle combo input specs (auto-default)', () => {
const plainObject = {
optional: {
comboInput: [[1, 2, 3], {}]
}
}

const result = plainToClass(ComfyInputsSpec, plainObject)

expect(result.optional.comboInput).toBeInstanceOf(ComboInputSpec)
expect(result.optional.comboInput.type).toBe('COMBO')
// Should pick the first choice as default
expect(result.optional.comboInput.default).toBe(1)
})

it('should handle custom input specs', () => {
const plainObject = {
optional: {
Expand Down
2 changes: 1 addition & 1 deletion tests-ui/tests/nodeSearchService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const EXAMPLE_NODE_DEFS: ComfyNodeDefImpl[] = [
{
input: {
required: {
ckpt_name: [['model1.safetensors', 'model2.ckpt']]
ckpt_name: [['model1.safetensors', 'model2.ckpt'], {}]
}
},
output: ['MODEL', 'CLIP', 'VAE'],
Expand Down

0 comments on commit f4f0c96

Please sign in to comment.