Files
ComfyUI_frontend/tests-ui/tests/litegraph/subgraph/SubgraphSlotVisualFeedback.test.ts
Arjan Singh 5869b04e57 Merge main (as of 10-06-2025) into rh-test (#5965)
## Summary

Merges latest changes from `main` as of 10-06-2025.

┆Issue is synchronized with this [Notion
page](https://www.notion.so/PR-5965-Merge-main-as-of-10-06-2025-into-rh-test-2856d73d3650812cb95fd8917278a770)
by [Unito](https://www.unito.io)

---------

Signed-off-by: Marcel Petrick <mail@marcelpetrick.it>
Co-authored-by: filtered <176114999+webfiltered@users.noreply.github.com>
Co-authored-by: Christian Byrne <cbyrne@comfy.org>
Co-authored-by: github-actions <github-actions@github.com>
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Alexander Brown <drjkl@comfy.org>
Co-authored-by: Benjamin Lu <benceruleanlu@proton.me>
Co-authored-by: Terry Jia <terryjia88@gmail.com>
Co-authored-by: snomiao <snomiao@gmail.com>
Co-authored-by: Simula_r <18093452+simula-r@users.noreply.github.com>
Co-authored-by: Jake Schroeder <jake.schroeder@isophex.com>
Co-authored-by: Comfy Org PR Bot <snomiao+comfy-pr@gmail.com>
Co-authored-by: AustinMroz <4284322+AustinMroz@users.noreply.github.com>
Co-authored-by: GitHub Action <action@github.com>
Co-authored-by: Johnpaul Chiwetelu <49923152+Myestery@users.noreply.github.com>
Co-authored-by: Marcel Petrick <mail@marcelpetrick.it>
Co-authored-by: Alexander Brown <DrJKL0424@gmail.com>
Co-authored-by: Benjamin Lu <benjaminlu1107@gmail.com>
Co-authored-by: Alexander Piskun <13381981+bigcat88@users.noreply.github.com>
Co-authored-by: Rizumu Ayaka <rizumu@ayaka.moe>
Co-authored-by: JakeSchroeder <jake@axiom.co>
Co-authored-by: AustinMroz <austin@comfy.org>
Co-authored-by: DrJKL <DrJKL@users.noreply.github.com>
Co-authored-by: ComfyUI Wiki <contact@comfyui-wiki.com>
2025-10-08 19:06:40 -07:00

183 lines
5.8 KiB
TypeScript

// TODO: Fix these tests after migration
import { beforeEach, describe, expect, it, vi } from 'vitest'
import { LGraphNode } from '@/lib/litegraph/src/litegraph'
import { createTestSubgraph } from './fixtures/subgraphHelpers'
describe.skip('SubgraphSlot visual feedback', () => {
let mockCtx: CanvasRenderingContext2D
let mockColorContext: any
let globalAlphaValues: number[]
beforeEach(() => {
// Clear the array before each test
globalAlphaValues = []
// Create a mock canvas context that tracks all globalAlpha values
const mockContext = {
_globalAlpha: 1,
get globalAlpha() {
return this._globalAlpha
},
set globalAlpha(value: number) {
this._globalAlpha = value
globalAlphaValues.push(value)
},
fillStyle: '',
strokeStyle: '',
lineWidth: 1,
beginPath: vi.fn(),
arc: vi.fn(),
fill: vi.fn(),
stroke: vi.fn(),
rect: vi.fn(),
fillText: vi.fn()
}
mockCtx = mockContext as unknown as CanvasRenderingContext2D
// Create a mock color context
mockColorContext = {
defaultInputColor: '#FF0000',
defaultOutputColor: '#00FF00',
getConnectedColor: vi.fn().mockReturnValue('#0000FF'),
getDisconnectedColor: vi.fn().mockReturnValue('#AAAAAA')
}
})
it('should render SubgraphInput slots with full opacity when dragging from compatible slot', () => {
const subgraph = createTestSubgraph()
const node = new LGraphNode('TestNode')
node.addInput('in', 'number')
subgraph.add(node)
// Add a subgraph input
const subgraphInput = subgraph.addInput('value', 'number')
// Simulate dragging from the subgraph input (which acts as output inside subgraph)
const nodeInput = node.inputs[0]
// Draw the slot with a compatible fromSlot
subgraphInput.draw({
ctx: mockCtx,
colorContext: mockColorContext,
fromSlot: nodeInput,
editorAlpha: 1
})
// Should render with full opacity (not 0.4)
// Check that 0.4 was NOT set during drawing
expect(globalAlphaValues).not.toContain(0.4)
})
it('should render SubgraphInput slots with 40% opacity when dragging from another SubgraphInput', () => {
const subgraph = createTestSubgraph()
// Add two subgraph inputs
const subgraphInput1 = subgraph.addInput('value1', 'number')
const subgraphInput2 = subgraph.addInput('value2', 'number')
// Draw subgraphInput2 while dragging from subgraphInput1 (incompatible - both are outputs inside subgraph)
subgraphInput2.draw({
ctx: mockCtx,
colorContext: mockColorContext,
fromSlot: subgraphInput1,
editorAlpha: 1
})
// Should render with 40% opacity
// Check that 0.4 was set during drawing
expect(globalAlphaValues).toContain(0.4)
})
it('should render SubgraphOutput slots with full opacity when dragging from compatible slot', () => {
const subgraph = createTestSubgraph()
const node = new LGraphNode('TestNode')
node.addOutput('out', 'number')
subgraph.add(node)
// Add a subgraph output
const subgraphOutput = subgraph.addOutput('result', 'number')
// Simulate dragging from a node output
const nodeOutput = node.outputs[0]
// Draw the slot with a compatible fromSlot
subgraphOutput.draw({
ctx: mockCtx,
colorContext: mockColorContext,
fromSlot: nodeOutput,
editorAlpha: 1
})
// Should render with full opacity (not 0.4)
// Check that 0.4 was NOT set during drawing
expect(globalAlphaValues).not.toContain(0.4)
})
it('should render SubgraphOutput slots with 40% opacity when dragging from another SubgraphOutput', () => {
const subgraph = createTestSubgraph()
// Add two subgraph outputs
const subgraphOutput1 = subgraph.addOutput('result1', 'number')
const subgraphOutput2 = subgraph.addOutput('result2', 'number')
// Draw subgraphOutput2 while dragging from subgraphOutput1 (incompatible - both are inputs inside subgraph)
subgraphOutput2.draw({
ctx: mockCtx,
colorContext: mockColorContext,
fromSlot: subgraphOutput1,
editorAlpha: 1
})
// Should render with 40% opacity
// Check that 0.4 was set during drawing
expect(globalAlphaValues).toContain(0.4)
})
// "not implemented yet"
// it("should render slots with full opacity when dragging between compatible SubgraphInput and SubgraphOutput", () => {
// const subgraph = createTestSubgraph()
// // Add subgraph input and output with matching types
// const subgraphInput = subgraph.addInput("value", "number")
// const subgraphOutput = subgraph.addOutput("result", "number")
// // Draw SubgraphOutput slot while dragging from SubgraphInput
// subgraphOutput.draw({
// ctx: mockCtx,
// colorContext: mockColorContext,
// fromSlot: subgraphInput,
// editorAlpha: 1,
// })
// // Should render with full opacity
// expect(mockCtx.globalAlpha).toBe(1)
// })
it('should render slots with 40% opacity when dragging between incompatible types', () => {
const subgraph = createTestSubgraph()
const node = new LGraphNode('TestNode')
node.addOutput('string_output', 'string')
subgraph.add(node)
// Add subgraph output with incompatible type
const subgraphOutput = subgraph.addOutput('result', 'number')
// Get the string output slot from the node
const nodeStringOutput = node.outputs[0]
// Draw the SubgraphOutput slot while dragging from a node output with incompatible type
subgraphOutput.draw({
ctx: mockCtx,
colorContext: mockColorContext,
fromSlot: nodeStringOutput,
editorAlpha: 1
})
// Should render with 40% opacity due to type mismatch
// Check that 0.4 was set during drawing
expect(globalAlphaValues).toContain(0.4)
})
})