mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-01-31 05:19:53 +00:00
## Summary Only remaining use is in `buttonTypes.ts` which @viva-jinyi is going to be working on to consolidate our different buttons soon. ## Changes - **What**: Replace light/dark colors with theme aware design system tokens. ## Review Focus Double check the chosen colors for the components ## Screenshots | Before | After | | ------ | ----- | | <img width="607" height="432" alt="image" src="https://github.com/user-attachments/assets/6c0ee6d6-819f-40b1-b775-f8b25dd18104" /> | <img width="646" height="488" alt="image" src="https://github.com/user-attachments/assets/9c8532de-8ac6-4b48-9021-3fd0b3e0bc63" /> | ┆Issue is synchronized with this [Notion page](https://www.notion.so/PR-6705-Style-WIP-Design-System-use-across-more-components-2ab6d73d365081619115fc5f87a46341) by [Unito](https://www.unito.io) --------- Co-authored-by: github-actions <github-actions@github.com>
132 lines
3.9 KiB
TypeScript
132 lines
3.9 KiB
TypeScript
import { createPinia, setActivePinia } from 'pinia'
|
|
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
|
|
import { app } from '@/scripts/app'
|
|
import { useExecutionStore } from '@/stores/executionStore'
|
|
|
|
// Create mock functions that will be shared
|
|
const mockNodeExecutionIdToNodeLocatorId = vi.fn()
|
|
const mockNodeIdToNodeLocatorId = vi.fn()
|
|
const mockNodeLocatorIdToNodeExecutionId = vi.fn()
|
|
|
|
// Mock the workflowStore
|
|
vi.mock('@/platform/workflow/management/stores/workflowStore', async () => {
|
|
const { ComfyWorkflow } = await vi.importActual<
|
|
typeof import('@/platform/workflow/management/stores/workflowStore')
|
|
>('@/platform/workflow/management/stores/workflowStore')
|
|
return {
|
|
ComfyWorkflow,
|
|
useWorkflowStore: vi.fn(() => ({
|
|
nodeExecutionIdToNodeLocatorId: mockNodeExecutionIdToNodeLocatorId,
|
|
nodeIdToNodeLocatorId: mockNodeIdToNodeLocatorId,
|
|
nodeLocatorIdToNodeExecutionId: mockNodeLocatorIdToNodeExecutionId
|
|
}))
|
|
}
|
|
})
|
|
|
|
// Remove any previous global types
|
|
declare global {
|
|
interface Window {}
|
|
}
|
|
|
|
vi.mock('@/composables/node/useNodeProgressText', () => ({
|
|
useNodeProgressText: () => ({
|
|
showTextPreview: vi.fn()
|
|
})
|
|
}))
|
|
|
|
// Mock the app import with proper implementation
|
|
vi.mock('@/scripts/app', () => ({
|
|
app: {
|
|
graph: {
|
|
getNodeById: vi.fn(),
|
|
_nodes: [] // Add _nodes array for workflowStore iteration
|
|
},
|
|
revokePreviews: vi.fn(),
|
|
nodePreviewImages: {}
|
|
}
|
|
}))
|
|
|
|
describe('useExecutionStore - NodeLocatorId conversions', () => {
|
|
let store: ReturnType<typeof useExecutionStore>
|
|
|
|
beforeEach(() => {
|
|
vi.clearAllMocks()
|
|
// Reset mock implementations
|
|
mockNodeExecutionIdToNodeLocatorId.mockReset()
|
|
mockNodeIdToNodeLocatorId.mockReset()
|
|
mockNodeLocatorIdToNodeExecutionId.mockReset()
|
|
|
|
setActivePinia(createPinia())
|
|
store = useExecutionStore()
|
|
})
|
|
|
|
describe('executionIdToNodeLocatorId', () => {
|
|
it('should convert execution ID to NodeLocatorId', () => {
|
|
// Mock subgraph structure
|
|
const mockSubgraph = {
|
|
id: 'a1b2c3d4-e5f6-7890-abcd-ef1234567890',
|
|
_nodes: []
|
|
}
|
|
|
|
const mockNode = {
|
|
id: 123,
|
|
isSubgraphNode: () => true,
|
|
subgraph: mockSubgraph
|
|
} as any
|
|
|
|
// Mock app.graph.getNodeById to return the mock node
|
|
vi.mocked(app.graph.getNodeById).mockReturnValue(mockNode)
|
|
|
|
const result = store.executionIdToNodeLocatorId('123:456')
|
|
|
|
expect(result).toBe('a1b2c3d4-e5f6-7890-abcd-ef1234567890:456')
|
|
})
|
|
|
|
it('should convert simple node ID to NodeLocatorId', () => {
|
|
const result = store.executionIdToNodeLocatorId('123')
|
|
|
|
// For simple node IDs, it should return the ID as-is
|
|
expect(result).toBe('123')
|
|
})
|
|
|
|
it('should handle numeric node IDs', () => {
|
|
const result = store.executionIdToNodeLocatorId(123)
|
|
|
|
// For numeric IDs, it should convert to string and return as-is
|
|
expect(result).toBe('123')
|
|
})
|
|
|
|
it('should return undefined when conversion fails', () => {
|
|
// Mock app.graph.getNodeById to return null (node not found)
|
|
vi.mocked(app.graph.getNodeById).mockReturnValue(null)
|
|
|
|
expect(store.executionIdToNodeLocatorId('999:456')).toBe(undefined)
|
|
})
|
|
})
|
|
|
|
describe('nodeLocatorIdToExecutionId', () => {
|
|
it('should convert NodeLocatorId to execution ID', () => {
|
|
const mockExecutionId = '123:456'
|
|
mockNodeLocatorIdToNodeExecutionId.mockReturnValue(mockExecutionId)
|
|
|
|
const result = store.nodeLocatorIdToExecutionId(
|
|
'a1b2c3d4-e5f6-7890-abcd-ef1234567890:456'
|
|
)
|
|
|
|
expect(mockNodeLocatorIdToNodeExecutionId).toHaveBeenCalledWith(
|
|
'a1b2c3d4-e5f6-7890-abcd-ef1234567890:456'
|
|
)
|
|
expect(result).toBe(mockExecutionId)
|
|
})
|
|
|
|
it('should return null when conversion fails', () => {
|
|
mockNodeLocatorIdToNodeExecutionId.mockReturnValue(null)
|
|
|
|
const result = store.nodeLocatorIdToExecutionId('invalid:format')
|
|
|
|
expect(result).toBeNull()
|
|
})
|
|
})
|
|
})
|