mirror of
https://github.com/langgenius/dify.git
synced 2026-04-27 14:08:18 +08:00
test: update GenericTable tests to use button interactions for method selection
This commit is contained in:
@ -3,40 +3,6 @@ import userEvent from '@testing-library/user-event'
|
||||
import { useState } from 'react'
|
||||
import GenericTable from '../generic-table'
|
||||
|
||||
vi.mock('@/app/components/base/select', () => ({
|
||||
SimpleSelect: ({
|
||||
items,
|
||||
defaultValue,
|
||||
onSelect,
|
||||
disabled,
|
||||
placeholder,
|
||||
}: {
|
||||
items: Array<{ name: string, value: string }>
|
||||
defaultValue?: string
|
||||
onSelect: (item: { name: string, value: string }) => void
|
||||
disabled?: boolean
|
||||
placeholder?: string
|
||||
}) => (
|
||||
<select
|
||||
aria-label={placeholder ?? 'Select'}
|
||||
disabled={disabled}
|
||||
value={defaultValue ?? ''}
|
||||
onChange={(e) => {
|
||||
const item = items.find(item => item.value === e.target.value)
|
||||
if (item)
|
||||
onSelect(item)
|
||||
}}
|
||||
>
|
||||
<option value="">{placeholder ?? 'Select'}</option>
|
||||
{items.map(item => (
|
||||
<option key={item.value} value={item.value}>
|
||||
{item.name}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
),
|
||||
}))
|
||||
|
||||
const columns = [
|
||||
{
|
||||
key: 'name',
|
||||
@ -178,11 +144,12 @@ describe('GenericTable', () => {
|
||||
<ControlledTable />,
|
||||
)
|
||||
|
||||
await user.selectOptions(screen.getAllByRole('combobox', { name: 'Choose method' })[0], 'post')
|
||||
await user.click(screen.getByRole('button', { name: 'Choose method' }))
|
||||
await user.click(await screen.findByRole('option', { name: 'POST' }))
|
||||
|
||||
await waitFor(() => {
|
||||
expect(onChange).toHaveBeenCalledWith([{ method: 'post', preview: '' }])
|
||||
expect(screen.getAllByRole('combobox', { name: 'Choose method' })[0]).toHaveValue('post')
|
||||
expect(screen.getByRole('button', { name: 'POST' })).toBeInTheDocument()
|
||||
})
|
||||
|
||||
onChange.mockClear()
|
||||
|
||||
Reference in New Issue
Block a user