mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-03-12 08:30:08 +00:00
* fix file upload widget disabled prop
* [test] extract createMockWidget to shared test utility - addresses @DrJKL's code replication concern
Creates testUtils.ts with shared createMockWidget and createMockFile functions
to reduce duplication across widget component tests. This ensures consistency
and maintainability of test setup code.
* [test] replace type assertions with type narrowing - addresses @DrJKL's type safety suggestion
Replaces unsafe `as HTMLInputElement` casts with proper instanceof checks
and error throwing. Also refactors File Type Detection tests to use it.for
instead of conditionals to eliminate anti-pattern.
* [feat] use destructuring with default value for readonly prop - addresses @DrJKL's Vue best practice suggestion
Replace manual fallback expressions like `readonly || false` with modern Vue 3
destructuring pattern: `const { readonly = false } = defineProps()`.
This is cleaner than withDefaults() and follows current Vue best practices.
* [test] improve test utilities usage - addresses @DrJKL's additional suggestions
- Replace findComponent with getComponent for better error handling
- Use optional chaining (?.()) instead of conditional checks for cleaner syntax
- Remove unnecessary existence checks since getComponent throws on failure
34 lines
882 B
TypeScript
34 lines
882 B
TypeScript
import type { SimplifiedWidget, WidgetValue } from '@/types/simplifiedWidget'
|
|
|
|
/**
|
|
* Creates a mock SimplifiedWidget for testing Vue Node widgets.
|
|
* This utility function is shared across widget component tests to ensure consistency.
|
|
*/
|
|
export function createMockWidget<T extends WidgetValue>(
|
|
value: T = null as T,
|
|
options: Record<string, any> = {},
|
|
callback?: (value: T) => void,
|
|
overrides: Partial<SimplifiedWidget<T>> = {}
|
|
): SimplifiedWidget<T> {
|
|
return {
|
|
name: 'test_widget',
|
|
type: 'default',
|
|
value,
|
|
options,
|
|
callback,
|
|
...overrides
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Creates a mock file for testing file upload widgets.
|
|
*/
|
|
export function createMockFile(name: string, type: string, size = 1024): File {
|
|
const file = new File(['mock content'], name, { type })
|
|
Object.defineProperty(file, 'size', {
|
|
value: size,
|
|
writable: false
|
|
})
|
|
return file
|
|
}
|