mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-29 10:42:44 +00:00
Merge branch 'main' into conditional-keybinds
This commit is contained in:
82
tests-ui/tests/store/executionStore.test.ts
Normal file
82
tests-ui/tests/store/executionStore.test.ts
Normal file
@@ -0,0 +1,82 @@
|
||||
import { createPinia, setActivePinia } from 'pinia'
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
|
||||
import { useExecutionStore } from '@/stores/executionStore'
|
||||
|
||||
// Remove any previous global types
|
||||
declare global {
|
||||
// Empty interface to override any previous declarations
|
||||
interface Window {}
|
||||
}
|
||||
|
||||
const mockShowChatHistory = vi.fn()
|
||||
vi.mock('@/composables/node/useNodeChatHistory', () => ({
|
||||
useNodeChatHistory: () => ({
|
||||
showChatHistory: mockShowChatHistory
|
||||
})
|
||||
}))
|
||||
|
||||
vi.mock('@/composables/node/useNodeProgressText', () => ({
|
||||
useNodeProgressText: () => ({
|
||||
showTextPreview: vi.fn()
|
||||
})
|
||||
}))
|
||||
|
||||
// Create a local mock instead of using global to avoid conflicts
|
||||
const mockApp = {
|
||||
graph: {
|
||||
getNodeById: vi.fn()
|
||||
}
|
||||
}
|
||||
|
||||
describe('executionStore - display_component handling', () => {
|
||||
function createDisplayComponentEvent(
|
||||
nodeId: string,
|
||||
component = 'ChatHistoryWidget'
|
||||
) {
|
||||
return new CustomEvent('display_component', {
|
||||
detail: {
|
||||
node_id: nodeId,
|
||||
component,
|
||||
props: {
|
||||
history: JSON.stringify([{ prompt: 'Test', response: 'Response' }])
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function handleDisplayComponentMessage(event: CustomEvent) {
|
||||
const { node_id, component } = event.detail
|
||||
const node = mockApp.graph.getNodeById(node_id)
|
||||
if (node && component === 'ChatHistoryWidget') {
|
||||
mockShowChatHistory(node)
|
||||
}
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
setActivePinia(createPinia())
|
||||
useExecutionStore()
|
||||
vi.clearAllMocks()
|
||||
})
|
||||
|
||||
it('handles ChatHistoryWidget display_component messages', () => {
|
||||
const mockNode = { id: '123' }
|
||||
mockApp.graph.getNodeById.mockReturnValue(mockNode)
|
||||
|
||||
const event = createDisplayComponentEvent('123')
|
||||
handleDisplayComponentMessage(event)
|
||||
|
||||
expect(mockApp.graph.getNodeById).toHaveBeenCalledWith('123')
|
||||
expect(mockShowChatHistory).toHaveBeenCalledWith(mockNode)
|
||||
})
|
||||
|
||||
it('does nothing if node is not found', () => {
|
||||
mockApp.graph.getNodeById.mockReturnValue(null)
|
||||
|
||||
const event = createDisplayComponentEvent('non-existent')
|
||||
handleDisplayComponentMessage(event)
|
||||
|
||||
expect(mockApp.graph.getNodeById).toHaveBeenCalledWith('non-existent')
|
||||
expect(mockShowChatHistory).not.toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
@@ -52,8 +52,12 @@ vi.mock('firebase/auth', () => ({
|
||||
signOut: vi.fn(),
|
||||
onAuthStateChanged: vi.fn(),
|
||||
signInWithPopup: vi.fn(),
|
||||
GoogleAuthProvider: vi.fn(),
|
||||
GithubAuthProvider: vi.fn(),
|
||||
GoogleAuthProvider: class {
|
||||
setCustomParameters = vi.fn()
|
||||
},
|
||||
GithubAuthProvider: class {
|
||||
setCustomParameters = vi.fn()
|
||||
},
|
||||
browserLocalPersistence: 'browserLocalPersistence',
|
||||
setPersistence: vi.fn().mockResolvedValue(undefined)
|
||||
}))
|
||||
|
||||
@@ -115,4 +115,42 @@ describe('TaskItemImpl', () => {
|
||||
expect(output.isVideo).toBe(true)
|
||||
expect(output.isImage).toBe(false)
|
||||
})
|
||||
|
||||
describe('audio format detection', () => {
|
||||
const audioFormats = [
|
||||
{ extension: 'mp3', mimeType: 'audio/mpeg' },
|
||||
{ extension: 'wav', mimeType: 'audio/wav' },
|
||||
{ extension: 'ogg', mimeType: 'audio/ogg' },
|
||||
{ extension: 'flac', mimeType: 'audio/flac' }
|
||||
]
|
||||
|
||||
audioFormats.forEach(({ extension, mimeType }) => {
|
||||
it(`should recognize ${extension} audio`, () => {
|
||||
const taskItem = new TaskItemImpl(
|
||||
'History',
|
||||
[0, 'prompt-id', {}, { client_id: 'client-id' }, []],
|
||||
{ status_str: 'success', messages: [], completed: true },
|
||||
{
|
||||
'node-1': {
|
||||
audio: [
|
||||
{
|
||||
filename: `test.${extension}`,
|
||||
type: 'output',
|
||||
subfolder: ''
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
const output = taskItem.flatOutputs[0]
|
||||
|
||||
expect(output.htmlAudioType).toBe(mimeType)
|
||||
expect(output.isAudio).toBe(true)
|
||||
expect(output.isVideo).toBe(false)
|
||||
expect(output.isImage).toBe(false)
|
||||
expect(output.supportsPreview).toBe(true)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -271,7 +271,7 @@ describe('useWorkflowStore', () => {
|
||||
|
||||
// Set up initial bookmark
|
||||
expect(workflow.path).toBe('workflows/dir/test.json')
|
||||
bookmarkStore.setBookmarked(workflow.path, true)
|
||||
await bookmarkStore.setBookmarked(workflow.path, true)
|
||||
expect(bookmarkStore.isBookmarked(workflow.path)).toBe(true)
|
||||
|
||||
// Mock super.rename
|
||||
@@ -351,7 +351,7 @@ describe('useWorkflowStore', () => {
|
||||
vi.spyOn(workflow, 'delete').mockResolvedValue()
|
||||
|
||||
// Bookmark the workflow
|
||||
bookmarkStore.setBookmarked(workflow.path, true)
|
||||
await bookmarkStore.setBookmarked(workflow.path, true)
|
||||
expect(bookmarkStore.isBookmarked(workflow.path)).toBe(true)
|
||||
|
||||
// Delete the workflow
|
||||
|
||||
Reference in New Issue
Block a user