Cover file-based human input content items

This commit is contained in:
JzoNg 2026-04-22 08:40:34 +08:00
parent 4f63b2b162
commit ccb43eb856

View File

@ -1,7 +1,9 @@
import type { FileEntity } from '@/app/components/base/file-uploader/types'
import type { FormInputItem } from '@/app/components/workflow/nodes/human-input/types'
import { render, screen } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import { describe, expect, it, vi } from 'vitest'
import { TransferMethod } from '@/types/app'
import ContentItem from '../content-item'
vi.mock('@/app/components/base/markdown', () => ({
@ -118,4 +120,64 @@ describe('ContentItem', () => {
expect(mockOnInputChange).toHaveBeenCalledWith('user_bio', 'select')
})
it('should delegate single-file fields to the shared renderer', async () => {
const user = userEvent.setup()
render(
<ContentItem
content="{{#$output.attachment#}}"
formInputFields={[
{
type: 'file',
output_variable_name: 'attachment',
allowed_file_extensions: ['.pdf'],
allowed_file_types: ['document'],
allowed_file_upload_methods: ['local_file'],
} as FormInputItem,
]}
inputs={{ attachment: null }}
onInputChange={mockOnInputChange}
/>,
)
await user.click(screen.getByTestId('renderer-file'))
expect(mockOnInputChange).toHaveBeenCalledWith('attachment', 'file')
})
it('should delegate file-list fields to the shared renderer', async () => {
const user = userEvent.setup()
const existingFiles: FileEntity[] = [{
id: 'file-1',
name: 'brief.pdf',
size: 128,
type: 'document',
progress: 100,
transferMethod: TransferMethod.local_file,
supportFileType: 'document',
}]
render(
<ContentItem
content="{{#$output.attachments#}}"
formInputFields={[
{
type: 'file-list',
output_variable_name: 'attachments',
allowed_file_extensions: ['.pdf'],
allowed_file_types: ['document'],
allowed_file_upload_methods: ['local_file'],
max_upload_count: 4,
} as FormInputItem,
]}
inputs={{ attachments: existingFiles }}
onInputChange={mockOnInputChange}
/>,
)
await user.click(screen.getByTestId('renderer-file-list'))
expect(mockOnInputChange).toHaveBeenCalledWith('attachments', 'file-list')
})
})