mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-02-01 13:59:54 +00:00
## Summary Migrates all unit tests from `tests-ui/` to colocate with their source files in `src/`, improving discoverability and maintainability. ## Changes - **What**: Relocated all unit tests to be adjacent to the code they test, following the `<source>.test.ts` naming convention - **Config**: Updated `vitest.config.ts` to remove `tests-ui` include pattern and `@tests-ui` alias - **Docs**: Moved testing documentation to `docs/testing/` with updated paths and patterns ## Review Focus - Migration patterns documented in `temp/plans/migrate-tests-ui-to-src.md` - Tests use `@/` path aliases instead of relative imports - Shared fixtures placed in `__fixtures__/` directories ┆Issue is synchronized with this [Notion page](https://www.notion.so/PR-7811-chore-migrate-tests-from-tests-ui-to-colocate-with-source-files-2da6d73d36508147a4cce85365dee614) by [Unito](https://www.unito.io) --------- Co-authored-by: Amp <amp@ampcode.com> Co-authored-by: GitHub Action <action@github.com>
99 lines
3.6 KiB
TypeScript
99 lines
3.6 KiB
TypeScript
import { createPinia, setActivePinia } from 'pinia'
|
|
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
|
|
import type { LGraphNode } from '@/lib/litegraph/src/litegraph'
|
|
import type { ExecutedWsMessage } from '@/schemas/apiSchema'
|
|
import { app } from '@/scripts/app'
|
|
import { useNodeOutputStore } from '@/stores/imagePreviewStore'
|
|
import * as litegraphUtil from '@/utils/litegraphUtil'
|
|
|
|
vi.mock('@/utils/litegraphUtil', () => ({
|
|
isVideoNode: vi.fn()
|
|
}))
|
|
|
|
vi.mock('@/scripts/app', () => ({
|
|
app: {
|
|
getPreviewFormatParam: vi.fn(() => '&format=test_webp')
|
|
}
|
|
}))
|
|
|
|
const createMockNode = (overrides: Partial<LGraphNode> = {}): LGraphNode =>
|
|
({
|
|
id: 1,
|
|
type: 'TestNode',
|
|
...overrides
|
|
}) as LGraphNode
|
|
|
|
const createMockOutputs = (
|
|
images?: ExecutedWsMessage['output']['images']
|
|
): ExecutedWsMessage['output'] => ({ images })
|
|
|
|
describe('imagePreviewStore getPreviewParam', () => {
|
|
beforeEach(() => {
|
|
setActivePinia(createPinia())
|
|
vi.clearAllMocks()
|
|
vi.mocked(litegraphUtil.isVideoNode).mockReturnValue(false)
|
|
})
|
|
|
|
it('should return empty string if node.animatedImages is true', () => {
|
|
const store = useNodeOutputStore()
|
|
// @ts-expect-error `animatedImages` property is not typed
|
|
const node = createMockNode({ animatedImages: true })
|
|
const outputs = createMockOutputs([{ filename: 'img.png' }])
|
|
expect(store.getPreviewParam(node, outputs)).toBe('')
|
|
expect(vi.mocked(app).getPreviewFormatParam).not.toHaveBeenCalled()
|
|
})
|
|
|
|
it('should return empty string if isVideoNode returns true', () => {
|
|
const store = useNodeOutputStore()
|
|
vi.mocked(litegraphUtil.isVideoNode).mockReturnValue(true)
|
|
const node = createMockNode()
|
|
const outputs = createMockOutputs([{ filename: 'img.png' }])
|
|
expect(store.getPreviewParam(node, outputs)).toBe('')
|
|
expect(vi.mocked(app).getPreviewFormatParam).not.toHaveBeenCalled()
|
|
})
|
|
|
|
it('should return empty string if outputs.images is undefined', () => {
|
|
const store = useNodeOutputStore()
|
|
const node = createMockNode()
|
|
const outputs: ExecutedWsMessage['output'] = {}
|
|
expect(store.getPreviewParam(node, outputs)).toBe('')
|
|
expect(vi.mocked(app).getPreviewFormatParam).not.toHaveBeenCalled()
|
|
})
|
|
|
|
it('should return empty string if outputs.images is empty', () => {
|
|
const store = useNodeOutputStore()
|
|
const node = createMockNode()
|
|
const outputs = createMockOutputs([])
|
|
expect(store.getPreviewParam(node, outputs)).toBe('')
|
|
expect(vi.mocked(app).getPreviewFormatParam).not.toHaveBeenCalled()
|
|
})
|
|
|
|
it('should return empty string if outputs.images contains SVG images', () => {
|
|
const store = useNodeOutputStore()
|
|
const node = createMockNode()
|
|
const outputs = createMockOutputs([{ filename: 'img.svg' }])
|
|
expect(store.getPreviewParam(node, outputs)).toBe('')
|
|
expect(vi.mocked(app).getPreviewFormatParam).not.toHaveBeenCalled()
|
|
})
|
|
|
|
it('should return format param for standard image outputs', () => {
|
|
const store = useNodeOutputStore()
|
|
const node = createMockNode()
|
|
const outputs = createMockOutputs([{ filename: 'img.png' }])
|
|
expect(store.getPreviewParam(node, outputs)).toBe('&format=test_webp')
|
|
expect(vi.mocked(app).getPreviewFormatParam).toHaveBeenCalledTimes(1)
|
|
})
|
|
|
|
it('should return format param for multiple standard images', () => {
|
|
const store = useNodeOutputStore()
|
|
const node = createMockNode()
|
|
const outputs = createMockOutputs([
|
|
{ filename: 'img1.png' },
|
|
{ filename: 'img2.jpg' }
|
|
])
|
|
expect(store.getPreviewParam(node, outputs)).toBe('&format=test_webp')
|
|
expect(vi.mocked(app).getPreviewFormatParam).toHaveBeenCalledTimes(1)
|
|
})
|
|
})
|