refactor: moved all the tests into the main executionstore test file

This commit is contained in:
Csongor Czezar
2026-01-02 14:46:01 -08:00
parent 1bfd617265
commit 6866bd4792
2 changed files with 106 additions and 178 deletions

View File

@@ -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()
})
})