test(workflow): add unit tests for workflow components (#33910)

Co-authored-by: CodingOnStar <hanxujiang@dify.com>
This commit is contained in:
Coding On Star
2026-03-23 16:37:03 +08:00
committed by GitHub
parent abda859075
commit fdc880bc67
54 changed files with 12469 additions and 189 deletions

View File

@ -0,0 +1,39 @@
import type { CodeDependency } from '../types'
import { render, screen, waitFor } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import DependencyPicker from '../dependency-picker'
const dependencies: CodeDependency[] = [
{ name: 'numpy', version: '1.0.0' },
{ name: 'pandas', version: '2.0.0' },
]
describe('DependencyPicker', () => {
it('should open the dependency list, filter by search text, and select a new dependency', async () => {
const user = userEvent.setup()
const onChange = vi.fn()
render(
<DependencyPicker
value={dependencies[0]!}
available_dependencies={dependencies}
onChange={onChange}
/>,
)
expect(screen.getByText('numpy')).toBeInTheDocument()
await user.click(screen.getByText('numpy'))
await user.type(screen.getByRole('textbox'), 'pan')
expect(screen.getByRole('textbox')).toHaveValue('pan')
expect(screen.getByText('pandas')).toBeInTheDocument()
await user.click(screen.getByText('pandas'))
expect(onChange).toHaveBeenCalledWith(dependencies[1])
await waitFor(() => {
expect(screen.queryByRole('textbox')).not.toBeInTheDocument()
})
})
})