mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-03-02 03:30:04 +00:00
CodeRabbit Generated Unit Tests: Add tests for ensureCorrectLayoutScale and LGraph types
This commit is contained in:
committed by
GitHub
parent
405fcb3ee5
commit
6d61dcbbe1
161
tests-ui/LGraph.type.test.ts
Normal file
161
tests-ui/LGraph.type.test.ts
Normal file
@@ -0,0 +1,161 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import type { RendererType, LGraphExtra } from '../src/lib/litegraph/src/LGraph'
|
||||
|
||||
/**
|
||||
* Tests for the RendererType (formerly rendererType) type definition
|
||||
*
|
||||
* This tests the type rename from 'rendererType' to 'RendererType' to follow
|
||||
* TypeScript naming conventions where types should use PascalCase.
|
||||
*/
|
||||
describe('RendererType', () => {
|
||||
describe('type definition', () => {
|
||||
it('should accept "LG" as a valid value', () => {
|
||||
const renderer: RendererType = 'LG'
|
||||
expect(renderer).toBe('LG')
|
||||
})
|
||||
|
||||
it('should accept "Vue" as a valid value', () => {
|
||||
const renderer: RendererType = 'Vue'
|
||||
expect(renderer).toBe('Vue')
|
||||
})
|
||||
|
||||
it('should be assignable to LGraphExtra workflowRendererVersion property', () => {
|
||||
const extra: LGraphExtra = {
|
||||
workflowRendererVersion: 'LG'
|
||||
}
|
||||
expect(extra.workflowRendererVersion).toBe('LG')
|
||||
|
||||
extra.workflowRendererVersion = 'Vue'
|
||||
expect(extra.workflowRendererVersion).toBe('Vue')
|
||||
})
|
||||
|
||||
it('should allow undefined for workflowRendererVersion', () => {
|
||||
const extra: LGraphExtra = {
|
||||
workflowRendererVersion: undefined
|
||||
}
|
||||
expect(extra.workflowRendererVersion).toBeUndefined()
|
||||
})
|
||||
|
||||
it('should work with optional chaining', () => {
|
||||
const extra: LGraphExtra = {}
|
||||
const version = extra.workflowRendererVersion
|
||||
expect(version).toBeUndefined()
|
||||
})
|
||||
})
|
||||
|
||||
describe('type safety', () => {
|
||||
it('should prevent assignment of invalid string values at compile time', () => {
|
||||
// This test validates TypeScript compiler behavior
|
||||
// The following would cause a compile error:
|
||||
// const invalid: RendererType = 'Invalid'
|
||||
|
||||
// We can test runtime validation if needed
|
||||
const validValues: RendererType[] = ['LG', 'Vue']
|
||||
validValues.forEach((value) => {
|
||||
expect(['LG', 'Vue']).toContain(value)
|
||||
})
|
||||
})
|
||||
|
||||
it('should work with type guards', () => {
|
||||
const isValidRendererType = (value: string): value is RendererType => {
|
||||
return value === 'LG' || value === 'Vue'
|
||||
}
|
||||
|
||||
expect(isValidRendererType('LG')).toBe(true)
|
||||
expect(isValidRendererType('Vue')).toBe(true)
|
||||
expect(isValidRendererType('Invalid')).toBe(false)
|
||||
})
|
||||
|
||||
it('should work in switch statements', () => {
|
||||
const testSwitch = (renderer: RendererType): string => {
|
||||
switch (renderer) {
|
||||
case 'LG':
|
||||
return 'Legacy LiteGraph'
|
||||
case 'Vue':
|
||||
return 'Vue Renderer'
|
||||
default:
|
||||
// TypeScript should ensure this is unreachable
|
||||
const _exhaustive: never = renderer
|
||||
return _exhaustive
|
||||
}
|
||||
}
|
||||
|
||||
expect(testSwitch('LG')).toBe('Legacy LiteGraph')
|
||||
expect(testSwitch('Vue')).toBe('Vue Renderer')
|
||||
})
|
||||
})
|
||||
|
||||
describe('usage in graph serialization', () => {
|
||||
it('should serialize and deserialize RendererType correctly', () => {
|
||||
const extra: LGraphExtra = {
|
||||
workflowRendererVersion: 'Vue'
|
||||
}
|
||||
|
||||
const serialized = JSON.stringify(extra)
|
||||
const deserialized: LGraphExtra = JSON.parse(serialized)
|
||||
|
||||
expect(deserialized.workflowRendererVersion).toBe('Vue')
|
||||
})
|
||||
|
||||
it('should handle missing workflowRendererVersion in deserialization', () => {
|
||||
const json = '{}'
|
||||
const extra: LGraphExtra = JSON.parse(json)
|
||||
|
||||
expect(extra.workflowRendererVersion).toBeUndefined()
|
||||
})
|
||||
|
||||
it('should handle null workflowRendererVersion', () => {
|
||||
const extra: LGraphExtra = {
|
||||
workflowRendererVersion: undefined
|
||||
}
|
||||
|
||||
expect(extra.workflowRendererVersion).toBeUndefined()
|
||||
})
|
||||
})
|
||||
|
||||
describe('backward compatibility considerations', () => {
|
||||
it('should work with both old and new renderer formats', () => {
|
||||
// Even though the type is renamed, the values remain the same
|
||||
const lgRenderer: RendererType = 'LG'
|
||||
const vueRenderer: RendererType = 'Vue'
|
||||
|
||||
expect(lgRenderer).toBe('LG')
|
||||
expect(vueRenderer).toBe('Vue')
|
||||
})
|
||||
|
||||
it('should support migration scenarios', () => {
|
||||
// Simulating reading from an old format
|
||||
const oldFormat = { workflowRendererVersion: 'LG' as RendererType }
|
||||
|
||||
// Converting to new format (type is already compatible)
|
||||
const newFormat: LGraphExtra = {
|
||||
workflowRendererVersion: oldFormat.workflowRendererVersion
|
||||
}
|
||||
|
||||
expect(newFormat.workflowRendererVersion).toBe('LG')
|
||||
})
|
||||
})
|
||||
|
||||
describe('default values and initialization', () => {
|
||||
it('should handle default initialization', () => {
|
||||
const extra: LGraphExtra = {}
|
||||
|
||||
// workflowRendererVersion should be undefined by default
|
||||
expect(extra.workflowRendererVersion).toBeUndefined()
|
||||
})
|
||||
|
||||
it('should support nullish coalescing', () => {
|
||||
const extra: LGraphExtra = {}
|
||||
const renderer = extra.workflowRendererVersion ?? 'LG'
|
||||
|
||||
expect(renderer).toBe('LG')
|
||||
})
|
||||
|
||||
it('should support optional chaining with default', () => {
|
||||
let extra: LGraphExtra | undefined = undefined
|
||||
const renderer = extra?.workflowRendererVersion ?? 'LG'
|
||||
|
||||
expect(renderer).toBe('LG')
|
||||
})
|
||||
})
|
||||
})
|
||||
1115
tests-ui/ensureCorrectLayoutScale.test.ts
Normal file
1115
tests-ui/ensureCorrectLayoutScale.test.ts
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user