mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-03-14 17:37:46 +00:00
Fixes #8888 Refactors repetitive test cases in `widgetUtil.test.ts` to use Vitest's `it.for` syntax for parameterized testing. Tests that follow the same "returns default for type" pattern are consolidated while keeping unique test cases separate. ┆Issue is synchronized with this [Notion page](https://www.notion.so/PR-8971-test-refactor-widgetUtil-tests-to-use-it-for-parameterization-30c6d73d365081a48e2ecf52bb7b0f98) by [Unito](https://www.unito.io)
40 lines
1.2 KiB
TypeScript
40 lines
1.2 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
|
|
import type { InputSpec } from '@/schemas/nodeDef/nodeDefSchemaV2'
|
|
|
|
import { getWidgetDefaultValue } from '@/utils/widgetUtil'
|
|
|
|
describe('getWidgetDefaultValue', () => {
|
|
it('returns undefined for undefined spec', () => {
|
|
expect(getWidgetDefaultValue(undefined)).toBeUndefined()
|
|
})
|
|
|
|
it('returns explicit default when provided', () => {
|
|
const spec = { type: 'INT', default: 42 } as InputSpec
|
|
expect(getWidgetDefaultValue(spec)).toBe(42)
|
|
})
|
|
|
|
it.for([
|
|
{ type: 'INT', expected: 0 },
|
|
{ type: 'FLOAT', expected: 0 },
|
|
{ type: 'BOOLEAN', expected: false },
|
|
{ type: 'STRING', expected: '' }
|
|
])(
|
|
'returns $expected for $type type without default',
|
|
({ type, expected }) => {
|
|
const spec = { type } as InputSpec
|
|
expect(getWidgetDefaultValue(spec)).toBe(expected)
|
|
}
|
|
)
|
|
|
|
it('returns first option for array options without default', () => {
|
|
const spec = { type: 'COMBO', options: ['a', 'b', 'c'] } as InputSpec
|
|
expect(getWidgetDefaultValue(spec)).toBe('a')
|
|
})
|
|
|
|
it('returns undefined for unknown type without options', () => {
|
|
const spec = { type: 'CUSTOM' } as InputSpec
|
|
expect(getWidgetDefaultValue(spec)).toBeUndefined()
|
|
})
|
|
})
|