mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-02-19 06:20:10 +00:00
[feat] Add I/O slot component tests (#5523)
* add i/o slot component component tests * refactor: use separate mount functions for type safety Replace generic mount helper with dedicated mountInputSlot and mountOutputSlot functions to avoid type casting and improve type safety per review feedback. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * [auto-fix] Apply ESLint and Prettier fixes * [refactor] rename test file from .spec.ts to .test.ts - addresses @DrJKL's naming convention feedback * [refactor] use component prop types instead of custom interface - addresses @DrJKL's type safety feedback * [refactor] add beforeEach for mock reset - addresses @DrJKL's test cleanup feedback * [refactor] use standard assertions instead of manual mock call extraction - addresses @DrJKL's assertion feedback * [auto-fix] Apply ESLint and Prettier fixes --------- Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: GitHub Action <action@github.com>
This commit is contained in:
@@ -0,0 +1,86 @@
|
||||
import { type ComponentMountingOptions, mount } from '@vue/test-utils'
|
||||
import { createPinia } from 'pinia'
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { createI18n } from 'vue-i18n'
|
||||
|
||||
import enMessages from '@/locales/en/main.json'
|
||||
import { useDomSlotRegistration } from '@/renderer/core/layout/slots/useDomSlotRegistration'
|
||||
|
||||
import InputSlot from './InputSlot.vue'
|
||||
import OutputSlot from './OutputSlot.vue'
|
||||
|
||||
// Mock composable used by InputSlot/OutputSlot so we can assert call params
|
||||
vi.mock('@/renderer/core/layout/slots/useDomSlotRegistration', () => ({
|
||||
useDomSlotRegistration: vi.fn(() => ({ remeasure: vi.fn() }))
|
||||
}))
|
||||
|
||||
type InputSlotProps = ComponentMountingOptions<typeof InputSlot>['props']
|
||||
type OutputSlotProps = ComponentMountingOptions<typeof OutputSlot>['props']
|
||||
|
||||
const mountInputSlot = (props: InputSlotProps) =>
|
||||
mount(InputSlot, {
|
||||
global: {
|
||||
plugins: [
|
||||
createI18n({
|
||||
legacy: false,
|
||||
locale: 'en',
|
||||
messages: { en: enMessages }
|
||||
}),
|
||||
createPinia()
|
||||
]
|
||||
},
|
||||
props
|
||||
})
|
||||
|
||||
const mountOutputSlot = (props: OutputSlotProps) =>
|
||||
mount(OutputSlot, {
|
||||
global: {
|
||||
plugins: [
|
||||
createI18n({
|
||||
legacy: false,
|
||||
locale: 'en',
|
||||
messages: { en: enMessages }
|
||||
}),
|
||||
createPinia()
|
||||
]
|
||||
},
|
||||
props
|
||||
})
|
||||
|
||||
describe('InputSlot/OutputSlot', () => {
|
||||
beforeEach(() => {
|
||||
vi.mocked(useDomSlotRegistration).mockClear()
|
||||
})
|
||||
|
||||
it('InputSlot registers with correct options', () => {
|
||||
mountInputSlot({
|
||||
nodeId: 'node-1',
|
||||
index: 3,
|
||||
slotData: { name: 'A', type: 'any', boundingRect: [0, 0, 0, 0] }
|
||||
})
|
||||
|
||||
expect(useDomSlotRegistration).toHaveBeenLastCalledWith(
|
||||
expect.objectContaining({
|
||||
nodeId: 'node-1',
|
||||
slotIndex: 3,
|
||||
isInput: true
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
it('OutputSlot registers with correct options', () => {
|
||||
mountOutputSlot({
|
||||
nodeId: 'node-2',
|
||||
index: 1,
|
||||
slotData: { name: 'B', type: 'any', boundingRect: [0, 0, 0, 0] }
|
||||
})
|
||||
|
||||
expect(useDomSlotRegistration).toHaveBeenLastCalledWith(
|
||||
expect.objectContaining({
|
||||
nodeId: 'node-2',
|
||||
slotIndex: 1,
|
||||
isInput: false
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user