mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-03-14 17:37:46 +00:00
* add image outputs on Vue nodes * add unit tests and update cursor pointer * use testing pinia * properly mock i18n in component test * get node via current graph * use subgraph ID from node creation * add better error handling for downloadFile util * refactor: simplify image preview component architecture - Replace awkward composable pattern with standard Vue component state - Fix reactivity issues where images didn't update on new outputs - Add proper subgraph-aware node resolution using NodeLocatorId - Enhance accessibility with keyboard navigation and ARIA labels - Add comprehensive error handling and loading states - Include PrimeVue Skeleton for better loading UX - Remove unused composable and test files The image preview now properly updates when new outputs are generated and follows standard Vue reactivity patterns. * resolve merge conflict with main - Keep both subgraphId field and hasErrors field from main - No conflicts in other files (LGraphNode.vue and main.json merged cleanly) * Fix LGraphNode test by adding proper Pinia testing setup Added createTestingPinia and i18n configuration following the pattern from working ImagePreview tests. Resolves test failures due to missing Pinia store dependencies. All 6 tests now pass successfully.
161 lines
4.2 KiB
TypeScript
161 lines
4.2 KiB
TypeScript
import { createTestingPinia } from '@pinia/testing'
|
|
import { mount } from '@vue/test-utils'
|
|
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
import { ref } from 'vue'
|
|
import { createI18n } from 'vue-i18n'
|
|
|
|
import type { VueNodeData } from '@/composables/graph/useGraphNodeManager'
|
|
import { SelectedNodeIdsKey } from '@/renderer/core/canvas/injectionKeys'
|
|
import LGraphNode from '@/renderer/extensions/vueNodes/components/LGraphNode.vue'
|
|
import { useVueElementTracking } from '@/renderer/extensions/vueNodes/composables/useVueNodeResizeTracking'
|
|
|
|
vi.mock(
|
|
'@/renderer/extensions/vueNodes/composables/useVueNodeResizeTracking',
|
|
() => ({
|
|
useVueElementTracking: vi.fn()
|
|
})
|
|
)
|
|
|
|
vi.mock('@/composables/useErrorHandling', () => ({
|
|
useErrorHandling: () => ({
|
|
toastErrorHandler: vi.fn()
|
|
})
|
|
}))
|
|
|
|
vi.mock('@/renderer/extensions/vueNodes/layout/useNodeLayout', () => ({
|
|
useNodeLayout: () => ({
|
|
position: { x: 100, y: 50 },
|
|
startDrag: vi.fn(),
|
|
handleDrag: vi.fn(),
|
|
endDrag: vi.fn()
|
|
})
|
|
}))
|
|
|
|
vi.mock('@/renderer/extensions/vueNodes/lod/useLOD', () => ({
|
|
useLOD: () => ({
|
|
lodLevel: { value: 0 },
|
|
shouldRenderWidgets: { value: true },
|
|
shouldRenderSlots: { value: true },
|
|
shouldRenderContent: { value: false },
|
|
lodCssClass: { value: '' }
|
|
}),
|
|
LODLevel: { MINIMAL: 0 }
|
|
}))
|
|
|
|
const i18n = createI18n({
|
|
legacy: false,
|
|
locale: 'en',
|
|
messages: {
|
|
en: {
|
|
'Node Render Error': 'Node Render Error'
|
|
}
|
|
}
|
|
})
|
|
|
|
describe('LGraphNode', () => {
|
|
const mockNodeData: VueNodeData = {
|
|
id: 'test-node-123',
|
|
title: 'Test Node',
|
|
type: 'TestNode',
|
|
mode: 0,
|
|
flags: {},
|
|
inputs: [],
|
|
outputs: [],
|
|
widgets: [],
|
|
selected: false,
|
|
executing: false
|
|
}
|
|
|
|
const mountLGraphNode = (props: any, selectedNodeIds = new Set()) => {
|
|
return mount(LGraphNode, {
|
|
props,
|
|
global: {
|
|
plugins: [
|
|
createTestingPinia({
|
|
createSpy: vi.fn
|
|
}),
|
|
i18n
|
|
],
|
|
provide: {
|
|
[SelectedNodeIdsKey as symbol]: ref(selectedNodeIds)
|
|
},
|
|
stubs: {
|
|
NodeHeader: true,
|
|
NodeSlots: true,
|
|
NodeWidgets: true,
|
|
NodeContent: true,
|
|
SlotConnectionDot: true
|
|
}
|
|
}
|
|
})
|
|
}
|
|
|
|
beforeEach(() => {
|
|
vi.clearAllMocks()
|
|
})
|
|
|
|
it('should call resize tracking composable with node ID', () => {
|
|
mountLGraphNode({ nodeData: mockNodeData })
|
|
|
|
expect(useVueElementTracking).toHaveBeenCalledWith('test-node-123', 'node')
|
|
})
|
|
|
|
it('should render with data-node-id attribute', () => {
|
|
const wrapper = mountLGraphNode({ nodeData: mockNodeData })
|
|
|
|
expect(wrapper.attributes('data-node-id')).toBe('test-node-123')
|
|
})
|
|
|
|
it('should render node title', () => {
|
|
// Don't stub NodeHeader for this test so we can see the title
|
|
const wrapper = mount(LGraphNode, {
|
|
props: { nodeData: mockNodeData },
|
|
global: {
|
|
plugins: [
|
|
createTestingPinia({
|
|
createSpy: vi.fn
|
|
}),
|
|
i18n
|
|
],
|
|
provide: {
|
|
[SelectedNodeIdsKey as symbol]: ref(new Set())
|
|
},
|
|
stubs: {
|
|
NodeSlots: true,
|
|
NodeWidgets: true,
|
|
NodeContent: true,
|
|
SlotConnectionDot: true
|
|
}
|
|
}
|
|
})
|
|
|
|
expect(wrapper.text()).toContain('Test Node')
|
|
})
|
|
|
|
it('should apply selected styling when selected prop is true', () => {
|
|
const wrapper = mountLGraphNode(
|
|
{ nodeData: mockNodeData, selected: true },
|
|
new Set(['test-node-123'])
|
|
)
|
|
expect(wrapper.classes()).toContain('outline-2')
|
|
expect(wrapper.classes()).toContain('outline-black')
|
|
expect(wrapper.classes()).toContain('dark-theme:outline-white')
|
|
})
|
|
|
|
it('should apply executing animation when executing prop is true', () => {
|
|
const wrapper = mountLGraphNode({ nodeData: mockNodeData, executing: true })
|
|
|
|
expect(wrapper.classes()).toContain('animate-pulse')
|
|
})
|
|
|
|
it('should emit node-click event on pointer up', async () => {
|
|
const wrapper = mountLGraphNode({ nodeData: mockNodeData })
|
|
|
|
await wrapper.trigger('pointerup')
|
|
|
|
expect(wrapper.emitted('node-click')).toHaveLength(1)
|
|
expect(wrapper.emitted('node-click')?.[0]).toHaveLength(3)
|
|
expect(wrapper.emitted('node-click')?.[0][1]).toEqual(mockNodeData)
|
|
})
|
|
})
|