Cover structured human input panel rendering

This commit is contained in:
JzoNg 2026-04-22 08:33:32 +08:00
parent cbe2f66f1b
commit 703228ffed
3 changed files with 23 additions and 11 deletions

View File

@ -1,5 +1,6 @@
import type { HumanInputFilledFormData } from '@/types/workflow'
import { render, screen } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import { describe, expect, it } from 'vitest'
import HumanInputFilledFormList from '../human-input-filled-form-list'
@ -12,13 +13,15 @@ const createFormData = (
): HumanInputFilledFormData => ({
node_id: 'node-1',
node_title: 'Node Title',
rendered_content: 'fallback content',
action_id: 'approve',
action_text: 'Approve',
form_data: {
summary: 'Approved',
},
// 👇 IMPORTANT
// DO NOT guess properties like `inputs`
// Only include fields that actually exist in your project type.
// Leave everything else empty via spread.
...overrides,
} as HumanInputFilledFormData)
})
describe('HumanInputFilledFormList', () => {
it('renders nothing when list is empty', () => {
@ -27,12 +30,15 @@ describe('HumanInputFilledFormList', () => {
expect(screen.queryByText('Node Title')).not.toBeInTheDocument()
})
it('renders one form item', () => {
it('renders one form item', async () => {
const user = userEvent.setup()
const data = [createFormData()]
render(<HumanInputFilledFormList humanInputFilledFormDataList={data} />)
expect(screen.getByText('Node Title')).toBeInTheDocument()
await user.click(screen.getByTestId('expand-icon'))
expect(screen.getByTestId('submitted-field-summary')).toHaveTextContent('Approved')
})
it('renders multiple form items', () => {

View File

@ -9,6 +9,9 @@ const createFilledForm = (overrides: Partial<HumanInputFilledFormData> = {}): Hu
rendered_content: 'Approved by Alice',
action_id: 'approve',
action_text: 'Approve',
form_data: {
summary: 'Approved by Alice',
},
...overrides,
})
@ -33,11 +36,13 @@ describe('HumanInputFilledFormList', () => {
expect(screen.getByText('Approval'))!.toBeInTheDocument()
expect(screen.getByText('Review'))!.toBeInTheDocument()
expect(screen.getAllByTestId('submitted-content')).toHaveLength(2)
expect(screen.getAllByTestId('submitted-field-values')).toHaveLength(2)
expect(screen.getAllByTestId('executed-action')).toHaveLength(2)
expect(screen.getAllByTestId('submitted-field-summary')).toHaveLength(2)
expect(screen.getAllByTestId('submitted-field-summary')[0]).toHaveTextContent('Approved by Alice')
await user.click(screen.getAllByTestId('expand-icon')[0]!)
expect(screen.getAllByTestId('submitted-content')).toHaveLength(1)
expect(screen.getAllByTestId('submitted-field-values')).toHaveLength(1)
})
})

View File

@ -1,4 +1,5 @@
import type { Shape } from '../../store/workflow'
import type { HumanInputFieldValue } from '@/app/components/base/chat/chat/answer/human-input-content/field-renderer'
import type { HumanInputFilledFormData, HumanInputFormData } from '@/types/workflow'
import { toast } from '@langgenius/dify-ui/toast'
import { fireEvent, screen, waitFor } from '@testing-library/react'
@ -84,11 +85,11 @@ vi.mock('@/app/components/workflow/panel/human-input-form-list', () => ({
onHumanInputFormSubmit,
}: {
humanInputFormDataList: unknown[]
onHumanInputFormSubmit?: (token: string, formData: Record<string, string>) => Promise<void>
onHumanInputFormSubmit?: (token: string, formData: { inputs: Record<string, HumanInputFieldValue>, action: string }) => Promise<void>
}) => (
<div>
<div data-testid="human-form-list">{humanInputFormDataList.length}</div>
<button type="button" onClick={() => onHumanInputFormSubmit?.('form-token', { answer: 'ok' })}>
<button type="button" onClick={() => onHumanInputFormSubmit?.('form-token', { inputs: { answer: 'ok' }, action: 'approve' })}>
submit-human-form
</button>
</div>
@ -236,7 +237,7 @@ describe('WorkflowPreview', () => {
expect(screen.getByTestId('filled-form-list')).toHaveTextContent('1')
await user.click(screen.getByRole('button', { name: 'submit-human-form' }))
expect(mockSubmitHumanInputForm).toHaveBeenCalledWith('form-token', { answer: 'ok' })
expect(mockSubmitHumanInputForm).toHaveBeenCalledWith('form-token', { inputs: { answer: 'ok' }, action: 'approve' })
})
it('should copy successful string output and show a success toast', async () => {