mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-20 14:30:41 +00:00
test: address PR review feedback
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { setActivePinia } from 'pinia'
|
||||
import { createTestingPinia } from '@pinia/testing'
|
||||
import { describe, expect, test } from 'vitest'
|
||||
import { describe, expect, test, vi } from 'vitest'
|
||||
import { LGraph, LGraphNode } from '@/lib/litegraph/src/litegraph'
|
||||
import { transformInputSpecV1ToV2 } from '@/schemas/nodeDef/migration'
|
||||
import type { InputSpec } from '@/schemas/nodeDefSchema'
|
||||
@@ -185,19 +185,44 @@ describe('Autogrow', () => {
|
||||
await nextTick()
|
||||
expect(node.inputs.length).toBe(5)
|
||||
})
|
||||
test('Removing a connection ignores stale autogrow callbacks after group removal', async () => {
|
||||
test('Removing a connection ignores stale autogrow callbacks after group removal', () => {
|
||||
const graph = new LGraph()
|
||||
const node = testNode()
|
||||
const node = testNode() as TestAutogrowNode
|
||||
const onConnectionsChange = vi.fn()
|
||||
node.onConnectionsChange = onConnectionsChange
|
||||
graph.add(node)
|
||||
addAutogrow(node, { min: 1, input: inputsSpec, prefix: 'test' })
|
||||
|
||||
connectInput(node, 0, graph)
|
||||
expect(node.inputs.length).toBe(2)
|
||||
const rafCallbacks: FrameRequestCallback[] = []
|
||||
const requestAnimationFrameSpy = vi
|
||||
.spyOn(window, 'requestAnimationFrame')
|
||||
.mockImplementation((callback) => {
|
||||
rafCallbacks.push(callback)
|
||||
return rafCallbacks.length
|
||||
})
|
||||
|
||||
node.disconnectInput(0)
|
||||
delete (node as TestAutogrowNode).comfyDynamic.autogrow['0']
|
||||
try {
|
||||
connectInput(node, 0, graph)
|
||||
expect(node.inputs.length).toBe(2)
|
||||
|
||||
await expect(nextTick()).resolves.toBeUndefined()
|
||||
rafCallbacks.shift()?.(0)
|
||||
|
||||
node.disconnectInput(0)
|
||||
|
||||
const staleDisconnectCallback = rafCallbacks.shift()
|
||||
expect(staleDisconnectCallback).toBeDefined()
|
||||
|
||||
delete node.comfyDynamic.autogrow['0']
|
||||
|
||||
const callbackCountBeforeFlush = onConnectionsChange.mock.calls.length
|
||||
staleDisconnectCallback?.(0)
|
||||
|
||||
expect(onConnectionsChange).toHaveBeenCalledTimes(
|
||||
callbackCountBeforeFlush
|
||||
)
|
||||
} finally {
|
||||
requestAnimationFrameSpy.mockRestore()
|
||||
}
|
||||
})
|
||||
test('Can deserialize a complex node', async () => {
|
||||
const graph = new LGraph()
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { fromPartial } from '@total-typescript/shoehorn'
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
|
||||
import type {
|
||||
@@ -7,6 +8,7 @@ import type {
|
||||
} from '@/lib/litegraph/src/litegraph'
|
||||
import type { LGraphNode } from '@/lib/litegraph/src/LGraphNode'
|
||||
import type { IBaseWidget } from '@/lib/litegraph/src/types/widgets'
|
||||
import { createMockLLink } from '@/utils/__tests__/litegraphTestUtils'
|
||||
|
||||
vi.mock('@/scripts/app', () => ({
|
||||
app: {
|
||||
@@ -25,33 +27,33 @@ function createWidget(
|
||||
value: unknown,
|
||||
callback = vi.fn()
|
||||
): IBaseWidget {
|
||||
return {
|
||||
return fromPartial<IBaseWidget>({
|
||||
name,
|
||||
value,
|
||||
callback
|
||||
} as unknown as IBaseWidget
|
||||
})
|
||||
}
|
||||
|
||||
function createTargetNode(
|
||||
widget: IBaseWidget,
|
||||
id = 7
|
||||
): Pick<LGraphNode, 'id' | 'inputs' | 'widgets'> {
|
||||
return {
|
||||
return fromPartial<Pick<LGraphNode, 'id' | 'inputs' | 'widgets'>>({
|
||||
id,
|
||||
inputs: [
|
||||
{
|
||||
fromPartial<INodeInputSlot>({
|
||||
widget: { name: widget.name }
|
||||
} as unknown as INodeInputSlot
|
||||
})
|
||||
],
|
||||
widgets: [widget]
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function createLink(targetId: LLink['target_id'], targetSlot = 0): LLink {
|
||||
return {
|
||||
return createMockLLink({
|
||||
target_id: targetId,
|
||||
target_slot: targetSlot
|
||||
} as LLink
|
||||
})
|
||||
}
|
||||
|
||||
function createSourceNode(options: {
|
||||
|
||||
Reference in New Issue
Block a user