mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-05-04 21:22:07 +00:00
Backport of #10123, #9967, and #9972 to `cloud/1.42` Includes three cherry-picks in dependency order: 1. #9972 — `fix: resolve all lint warnings` (clean) 2. #9967 — `test: harden subgraph test coverage and remove low-value tests` (clean) 3. #10123 — `test: subgraph integration contracts and expanded Playwright coverage` (1 conflict, auto-resolved by rerere from #10326) See #10326 for core/1.41 backport with detailed conflict resolution notes. --------- Co-authored-by: Amp <amp@ampcode.com> Co-authored-by: bymyself <cbyrne@comfy.org> Co-authored-by: GitHub Action <action@github.com>
107 lines
2.9 KiB
TypeScript
107 lines
2.9 KiB
TypeScript
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
|
|
import { LGraphNode, SubgraphNode } from '@/lib/litegraph/src/litegraph'
|
|
|
|
const mocks = vi.hoisted(() => ({
|
|
publishSubgraph: vi.fn(),
|
|
selectedItems: [] as unknown[]
|
|
}))
|
|
|
|
vi.mock('@/composables/canvas/useSelectedLiteGraphItems', () => ({
|
|
useSelectedLiteGraphItems: () => ({
|
|
getSelectedNodes: vi.fn(() => [])
|
|
})
|
|
}))
|
|
|
|
vi.mock('@/renderer/core/canvas/canvasStore', () => ({
|
|
useCanvasStore: () => ({
|
|
getCanvas: vi.fn(),
|
|
get selectedItems() {
|
|
return mocks.selectedItems
|
|
},
|
|
updateSelectedItems: vi.fn()
|
|
})
|
|
}))
|
|
|
|
vi.mock('@/platform/workflow/management/stores/workflowStore', () => ({
|
|
useWorkflowStore: () => ({
|
|
activeWorkflow: null
|
|
})
|
|
}))
|
|
|
|
vi.mock('@/stores/nodeOutputStore', () => ({
|
|
useNodeOutputStore: () => ({
|
|
revokeSubgraphPreviews: vi.fn()
|
|
})
|
|
}))
|
|
|
|
vi.mock('@/stores/subgraphStore', () => ({
|
|
useSubgraphStore: () => ({
|
|
publishSubgraph: mocks.publishSubgraph
|
|
})
|
|
}))
|
|
|
|
function createSubgraphNode(): SubgraphNode {
|
|
const node = Object.create(SubgraphNode.prototype)
|
|
return node
|
|
}
|
|
|
|
function createRegularNode(): LGraphNode {
|
|
return new LGraphNode('testnode')
|
|
}
|
|
|
|
describe('useSubgraphOperations', () => {
|
|
beforeEach(() => {
|
|
vi.clearAllMocks()
|
|
mocks.selectedItems = []
|
|
})
|
|
|
|
it('addSubgraphToLibrary calls publishSubgraph when single SubgraphNode selected', async () => {
|
|
mocks.selectedItems = [createSubgraphNode()]
|
|
|
|
const { useSubgraphOperations } =
|
|
await import('@/composables/graph/useSubgraphOperations')
|
|
const { addSubgraphToLibrary } = useSubgraphOperations()
|
|
|
|
await addSubgraphToLibrary()
|
|
|
|
expect(mocks.publishSubgraph).toHaveBeenCalledOnce()
|
|
})
|
|
|
|
it('addSubgraphToLibrary does not call publishSubgraph when no items selected', async () => {
|
|
mocks.selectedItems = []
|
|
|
|
const { useSubgraphOperations } =
|
|
await import('@/composables/graph/useSubgraphOperations')
|
|
const { addSubgraphToLibrary } = useSubgraphOperations()
|
|
|
|
await addSubgraphToLibrary()
|
|
|
|
expect(mocks.publishSubgraph).not.toHaveBeenCalled()
|
|
})
|
|
|
|
it('addSubgraphToLibrary does not call publishSubgraph when multiple items selected', async () => {
|
|
mocks.selectedItems = [createSubgraphNode(), createSubgraphNode()]
|
|
|
|
const { useSubgraphOperations } =
|
|
await import('@/composables/graph/useSubgraphOperations')
|
|
const { addSubgraphToLibrary } = useSubgraphOperations()
|
|
|
|
await addSubgraphToLibrary()
|
|
|
|
expect(mocks.publishSubgraph).not.toHaveBeenCalled()
|
|
})
|
|
|
|
it('addSubgraphToLibrary does not call publishSubgraph when selected item is not a SubgraphNode', async () => {
|
|
mocks.selectedItems = [createRegularNode()]
|
|
|
|
const { useSubgraphOperations } =
|
|
await import('@/composables/graph/useSubgraphOperations')
|
|
const { addSubgraphToLibrary } = useSubgraphOperations()
|
|
|
|
await addSubgraphToLibrary()
|
|
|
|
expect(mocks.publishSubgraph).not.toHaveBeenCalled()
|
|
})
|
|
})
|