mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-05-02 12:11:58 +00:00
refactor: moved all the tests into the main executionstore test file
This commit is contained in:
@@ -4,6 +4,12 @@ import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { app } from '@/scripts/app'
|
||||
import { useExecutionStore } from '@/stores/executionStore'
|
||||
|
||||
import type { LGraphNode } from '@/lib/litegraph/src/litegraph'
|
||||
import {
|
||||
createTestSubgraph,
|
||||
createTestSubgraphNode
|
||||
} from '../litegraph/subgraph/fixtures/subgraphHelpers'
|
||||
|
||||
// Create mock functions that will be shared
|
||||
const mockNodeExecutionIdToNodeLocatorId = vi.fn()
|
||||
const mockNodeIdToNodeLocatorId = vi.fn()
|
||||
@@ -297,3 +303,103 @@ describe('useExecutionStore - Node Error Lookups', () => {
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('useExecutionStore - executingNode with subgraphs', () => {
|
||||
let store: ReturnType<typeof useExecutionStore>
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
setActivePinia(createPinia())
|
||||
store = useExecutionStore()
|
||||
})
|
||||
|
||||
it('should find executing node in root graph', () => {
|
||||
const mockNode = {
|
||||
id: '123',
|
||||
title: 'Test Node',
|
||||
type: 'TestNode'
|
||||
} as LGraphNode
|
||||
|
||||
vi.mocked(app.rootGraph.getNodeById).mockReturnValue(mockNode)
|
||||
|
||||
// Simulate node execution starting
|
||||
store.nodeProgressStates = {
|
||||
'123': {
|
||||
state: 'running',
|
||||
value: 0,
|
||||
max: 100,
|
||||
display_node_id: '123',
|
||||
prompt_id: 'test-prompt',
|
||||
node_id: '123'
|
||||
}
|
||||
}
|
||||
|
||||
expect(store.executingNode).toBe(mockNode)
|
||||
})
|
||||
|
||||
it('should find executing node in subgraph using execution ID', () => {
|
||||
const mockNodeInSubgraph = {
|
||||
id: '789',
|
||||
title: 'Nested Node',
|
||||
type: 'NestedNode'
|
||||
} as LGraphNode
|
||||
|
||||
// Create a real subgraph with the test helper
|
||||
const testSubgraph = createTestSubgraph({
|
||||
id: 'sub-uuid'
|
||||
})
|
||||
// Add the mock node to the subgraph
|
||||
testSubgraph._nodes.push(mockNodeInSubgraph)
|
||||
|
||||
// Create a subgraph node using the helper
|
||||
const mockSubgraphNode = createTestSubgraphNode(testSubgraph, {
|
||||
id: '456'
|
||||
})
|
||||
|
||||
// Mock the subgraph's getNodeById to return our mock node
|
||||
vi.spyOn(testSubgraph, 'getNodeById').mockImplementation(
|
||||
(id: string | number | null | undefined) =>
|
||||
id === '789' ? mockNodeInSubgraph : null
|
||||
)
|
||||
|
||||
vi.mocked(app.rootGraph.getNodeById).mockReturnValue(mockSubgraphNode)
|
||||
|
||||
// Simulate node execution in subgraph with hierarchical execution ID "456:789"
|
||||
store.nodeProgressStates = {
|
||||
'456:789': {
|
||||
state: 'running',
|
||||
value: 0,
|
||||
max: 100,
|
||||
display_node_id: '456:789',
|
||||
prompt_id: 'test-prompt',
|
||||
node_id: '456:789'
|
||||
}
|
||||
}
|
||||
|
||||
// The executingNode should resolve to the nested node
|
||||
expect(store.executingNode).toBe(mockNodeInSubgraph)
|
||||
})
|
||||
|
||||
it('should return null when no node is executing', () => {
|
||||
store.nodeProgressStates = {}
|
||||
|
||||
expect(store.executingNode).toBeNull()
|
||||
})
|
||||
|
||||
it('should return null when executing node cannot be found', () => {
|
||||
vi.mocked(app.rootGraph.getNodeById).mockReturnValue(null)
|
||||
|
||||
store.nodeProgressStates = {
|
||||
'999': {
|
||||
state: 'running',
|
||||
value: 0,
|
||||
max: 100,
|
||||
display_node_id: '999',
|
||||
prompt_id: 'test-prompt',
|
||||
node_id: '999'
|
||||
}
|
||||
}
|
||||
|
||||
expect(store.executingNode).toBeNull()
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user