mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-05-21 21:09:00 +00:00
test: expand TabSubgraphInputs coverage for drag-and-drop edge cases
- Add test for type guard: drop with non-number index does not call movePromotion - Add test for canvas.setDirty being called after a successful drop - Add test for promotionEntries watcher re-registering handlers after reorder
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { createTestingPinia } from '@pinia/testing'
|
||||
import { render } from '@testing-library/vue'
|
||||
import { render, waitFor } from '@testing-library/vue'
|
||||
import { fromAny } from '@total-typescript/shoehorn'
|
||||
import { setActivePinia } from 'pinia'
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
@@ -45,6 +45,11 @@ vi.mock('@atlaskit/pragmatic-drag-and-drop/element/adapter', () => ({
|
||||
dropTargetForElements: mockDropTargetForElements
|
||||
}))
|
||||
|
||||
const mockSetDirty = vi.hoisted(() => vi.fn())
|
||||
vi.mock('@/renderer/core/canvas/canvasStore', () => ({
|
||||
useCanvasStore: () => ({ canvas: { setDirty: mockSetDirty } })
|
||||
}))
|
||||
|
||||
vi.mock(
|
||||
'@/renderer/extensions/vueNodes/widgets/components/form/FormSearchInput.vue',
|
||||
() => ({ default: { template: '<div />' } })
|
||||
@@ -170,4 +175,37 @@ describe('TabSubgraphInputs drag-and-drop', () => {
|
||||
|
||||
expect(promotionStore.movePromotion).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('ignores drop when source index is not a number', () => {
|
||||
renderComponent()
|
||||
|
||||
const promotionStore = usePromotionStore()
|
||||
vi.spyOn(promotionStore, 'movePromotion')
|
||||
|
||||
capturedDropHandlers[1]({ source: { data: { index: 'invalid' } } })
|
||||
|
||||
expect(promotionStore.movePromotion).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('calls canvas setDirty after a successful drop', () => {
|
||||
const node = createMockNode()
|
||||
renderComponent(node)
|
||||
|
||||
capturedDropHandlers[1]({ source: { data: { index: 0 } } })
|
||||
|
||||
expect(mockSetDirty).toHaveBeenCalledWith(true, true)
|
||||
})
|
||||
|
||||
it('re-registers drag handlers when promotionEntries changes', async () => {
|
||||
const node = createMockNode()
|
||||
renderComponent(node)
|
||||
mockDraggable.mockClear()
|
||||
|
||||
const promotionStore = usePromotionStore()
|
||||
promotionStore.setPromotions('graph-1', '1', [
|
||||
fromAny({ sourceNodeId: 'node-1', widgetName: 'seed' })
|
||||
])
|
||||
|
||||
await waitFor(() => expect(mockDraggable).toHaveBeenCalledTimes(2))
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user