mirror of
https://github.com/langgenius/dify.git
synced 2026-04-05 10:12:43 +08:00
Signed-off-by: yyh <yuanyouhuilyz@gmail.com> Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: CodingOnStar <hanxujiang@dify.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Coding On Star <447357187@qq.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: -LAN- <laipz8200@outlook.com> Co-authored-by: statxc <tyleradams93226@gmail.com>
49 lines
1.7 KiB
TypeScript
49 lines
1.7 KiB
TypeScript
import type { ReactNode } from 'react'
|
|
import { fireEvent, render, screen } from '@testing-library/react'
|
|
import ParameterItem from './parameter-item'
|
|
|
|
vi.mock('../hooks', () => ({
|
|
useLanguage: () => 'en_US',
|
|
}))
|
|
|
|
vi.mock('@/app/components/base/ui/select', () => ({
|
|
Select: ({ children, onValueChange }: { children: ReactNode, onValueChange: (value: string | undefined) => void }) => (
|
|
<div>
|
|
<button type="button" onClick={() => onValueChange('updated')}>select-updated</button>
|
|
<button type="button" onClick={() => onValueChange(undefined)}>select-empty</button>
|
|
{children}
|
|
</div>
|
|
),
|
|
SelectContent: ({ children }: { children: ReactNode }) => <div>{children}</div>,
|
|
SelectItem: ({ children }: { children: ReactNode }) => <div>{children}</div>,
|
|
SelectTrigger: ({ children }: { children: ReactNode }) => <div>{children}</div>,
|
|
SelectValue: () => <div>SelectValue</div>,
|
|
}))
|
|
|
|
describe('ParameterItem select mode', () => {
|
|
it('should propagate both explicit and empty select values', () => {
|
|
const onChange = vi.fn()
|
|
|
|
render(
|
|
<ParameterItem
|
|
parameterRule={{
|
|
name: 'format',
|
|
label: { en_US: 'Format', zh_Hans: 'Format' },
|
|
type: 'string',
|
|
options: ['json', 'text'],
|
|
required: false,
|
|
help: { en_US: 'Help', zh_Hans: 'Help' },
|
|
}}
|
|
value="json"
|
|
onChange={onChange}
|
|
/>,
|
|
)
|
|
|
|
fireEvent.click(screen.getByRole('button', { name: 'select-updated' }))
|
|
fireEvent.click(screen.getByRole('button', { name: 'select-empty' }))
|
|
|
|
expect(onChange).toHaveBeenNthCalledWith(1, 'updated')
|
|
expect(onChange).toHaveBeenNthCalledWith(2, undefined)
|
|
})
|
|
})
|