mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-30 03:01:54 +00:00
fix: code review items has been aligned
This commit is contained in:
@@ -1,22 +1,54 @@
|
|||||||
import { createPinia, setActivePinia } from 'pinia'
|
import { createPinia, setActivePinia } from 'pinia'
|
||||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||||
|
|
||||||
import type { LGraphNode } from '@/lib/litegraph/src/litegraph'
|
import type { LGraph, LGraphNode } from '@/lib/litegraph/src/litegraph'
|
||||||
import { useExecutionStore } from '@/stores/executionStore'
|
import { useExecutionStore } from '@/stores/executionStore'
|
||||||
|
|
||||||
|
// Mock factory function to create a root graph
|
||||||
|
const createMockRootGraph = (
|
||||||
|
options: Partial<Pick<LGraph, 'getNodeById' | 'nodes'>> = {}
|
||||||
|
): Partial<LGraph> => ({
|
||||||
|
getNodeById: options.getNodeById ?? vi.fn(() => null),
|
||||||
|
nodes: options.nodes ?? [],
|
||||||
|
...options
|
||||||
|
})
|
||||||
|
|
||||||
|
// Mock factory function to create a subgraph node
|
||||||
|
const createMockSubgraphNode = (
|
||||||
|
nodeId: string,
|
||||||
|
subgraphNodeId: string,
|
||||||
|
innerNode: LGraphNode
|
||||||
|
): LGraphNode =>
|
||||||
|
({
|
||||||
|
id: nodeId,
|
||||||
|
title: 'Node In Subgraph',
|
||||||
|
type: 'SubgraphNode',
|
||||||
|
isSubgraphNode: (() => true) as any,
|
||||||
|
subgraph: {
|
||||||
|
id: 'sub-uuid',
|
||||||
|
getNodeById: vi.fn((id) => (id === subgraphNodeId ? innerNode : null)),
|
||||||
|
_nodes: []
|
||||||
|
} as Partial<LGraph>
|
||||||
|
}) as unknown as LGraphNode
|
||||||
|
|
||||||
// Create mock functions
|
// Create mock functions
|
||||||
const mockNodeExecutionIdToNodeLocatorId = vi.fn()
|
const mockNodeExecutionIdToNodeLocatorId = vi.fn()
|
||||||
const mockNodeIdToNodeLocatorId = vi.fn()
|
const mockNodeIdToNodeLocatorId = vi.fn()
|
||||||
const mockNodeLocatorIdToNodeExecutionId = vi.fn()
|
const mockNodeLocatorIdToNodeExecutionId = vi.fn()
|
||||||
|
|
||||||
// Create a mocked graph that we can manipulate
|
// Keep track of the current mock root graph
|
||||||
let mockRootGraph: any
|
const mockAppState = {
|
||||||
|
rootGraph: createMockRootGraph()
|
||||||
|
}
|
||||||
|
|
||||||
// Mock the app import with proper implementation
|
// Mock the app import with proper implementation
|
||||||
vi.mock('@/scripts/app', () => ({
|
vi.mock('@/scripts/app', () => ({
|
||||||
app: {
|
app: {
|
||||||
get rootGraph() {
|
get rootGraph() {
|
||||||
return mockRootGraph
|
return mockAppState.rootGraph
|
||||||
|
},
|
||||||
|
set rootGraph(value) {
|
||||||
|
mockAppState.rootGraph = value
|
||||||
},
|
},
|
||||||
revokePreviews: vi.fn(),
|
revokePreviews: vi.fn(),
|
||||||
nodePreviewImages: {}
|
nodePreviewImages: {}
|
||||||
@@ -24,19 +56,23 @@ vi.mock('@/scripts/app', () => ({
|
|||||||
}))
|
}))
|
||||||
|
|
||||||
// Mock the workflowStore
|
// Mock the workflowStore
|
||||||
vi.mock('@/platform/workflow/management/stores/workflowStore', async () => {
|
vi.mock(
|
||||||
const { ComfyWorkflow } = await vi.importActual<
|
'@/platform/workflow/management/stores/workflowStore',
|
||||||
typeof import('@/platform/workflow/management/stores/workflowStore')
|
async (importOriginal) => {
|
||||||
>('@/platform/workflow/management/stores/workflowStore')
|
const { ComfyWorkflow } =
|
||||||
return {
|
await importOriginal<
|
||||||
ComfyWorkflow,
|
typeof import('@/platform/workflow/management/stores/workflowStore')
|
||||||
useWorkflowStore: vi.fn(() => ({
|
>()
|
||||||
nodeExecutionIdToNodeLocatorId: mockNodeExecutionIdToNodeLocatorId,
|
return {
|
||||||
nodeIdToNodeLocatorId: mockNodeIdToNodeLocatorId,
|
ComfyWorkflow,
|
||||||
nodeLocatorIdToNodeExecutionId: mockNodeLocatorIdToNodeExecutionId
|
useWorkflowStore: vi.fn(() => ({
|
||||||
}))
|
nodeExecutionIdToNodeLocatorId: mockNodeExecutionIdToNodeLocatorId,
|
||||||
|
nodeIdToNodeLocatorId: mockNodeIdToNodeLocatorId,
|
||||||
|
nodeLocatorIdToNodeExecutionId: mockNodeLocatorIdToNodeExecutionId
|
||||||
|
}))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
)
|
||||||
|
|
||||||
vi.mock('@/composables/node/useNodeProgressText', () => ({
|
vi.mock('@/composables/node/useNodeProgressText', () => ({
|
||||||
useNodeProgressText: () => ({
|
useNodeProgressText: () => ({
|
||||||
@@ -49,11 +85,8 @@ describe('useExecutionStore - executingNode with subgraphs', () => {
|
|||||||
setActivePinia(createPinia())
|
setActivePinia(createPinia())
|
||||||
vi.clearAllMocks()
|
vi.clearAllMocks()
|
||||||
|
|
||||||
// Reset the mock root graph
|
// Reset the mock root graph using factory
|
||||||
mockRootGraph = {
|
mockAppState.rootGraph = createMockRootGraph()
|
||||||
getNodeById: vi.fn(),
|
|
||||||
nodes: []
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should find executing node in root graph', () => {
|
it('should find executing node in root graph', () => {
|
||||||
@@ -63,8 +96,8 @@ describe('useExecutionStore - executingNode with subgraphs', () => {
|
|||||||
type: 'TestNode'
|
type: 'TestNode'
|
||||||
} as LGraphNode
|
} as LGraphNode
|
||||||
|
|
||||||
mockRootGraph.getNodeById = vi.fn((id) => {
|
mockAppState.rootGraph = createMockRootGraph({
|
||||||
return id === '123' ? mockNode : null
|
getNodeById: vi.fn((id) => (id === '123' ? mockNode : null))
|
||||||
})
|
})
|
||||||
|
|
||||||
const store = useExecutionStore()
|
const store = useExecutionStore()
|
||||||
@@ -91,23 +124,14 @@ describe('useExecutionStore - executingNode with subgraphs', () => {
|
|||||||
type: 'NestedNode'
|
type: 'NestedNode'
|
||||||
} as LGraphNode
|
} as LGraphNode
|
||||||
|
|
||||||
const mockSubgraphNode = {
|
const mockSubgraphNode = createMockSubgraphNode(
|
||||||
id: '456',
|
'456',
|
||||||
title: 'Node In Subgraph',
|
'789',
|
||||||
type: 'SubgraphNode',
|
mockNodeInSubgraph
|
||||||
isSubgraphNode: () => true,
|
) as LGraphNode
|
||||||
subgraph: {
|
|
||||||
id: 'sub-uuid',
|
|
||||||
getNodeById: vi.fn((id) => {
|
|
||||||
return id === '789' ? mockNodeInSubgraph : null
|
|
||||||
}),
|
|
||||||
_nodes: []
|
|
||||||
}
|
|
||||||
} as unknown as LGraphNode
|
|
||||||
|
|
||||||
// Mock the graph traversal
|
mockAppState.rootGraph = createMockRootGraph({
|
||||||
mockRootGraph.getNodeById = vi.fn((id) => {
|
getNodeById: vi.fn((id) => (id === '456' ? mockSubgraphNode : null))
|
||||||
return id === '456' ? mockSubgraphNode : null
|
|
||||||
})
|
})
|
||||||
|
|
||||||
const store = useExecutionStore()
|
const store = useExecutionStore()
|
||||||
@@ -137,7 +161,9 @@ describe('useExecutionStore - executingNode with subgraphs', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('should return null when executing node cannot be found', () => {
|
it('should return null when executing node cannot be found', () => {
|
||||||
mockRootGraph.getNodeById = vi.fn(() => null)
|
mockAppState.rootGraph = createMockRootGraph({
|
||||||
|
getNodeById: vi.fn(() => null)
|
||||||
|
})
|
||||||
|
|
||||||
const store = useExecutionStore()
|
const store = useExecutionStore()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user