mirror of
https://github.com/langgenius/dify.git
synced 2026-05-06 18:27:19 +08:00
Merge branch 'main' into jzh
This commit is contained in:
commit
534fd79377
@ -248,6 +248,19 @@ describe('InputsFormContent', () => {
|
||||
expect(mockSetCurrentConversationInputs).toHaveBeenCalledWith(expect.objectContaining({ sel: 'A' }))
|
||||
})
|
||||
|
||||
it('renders select dropdown above the settings dialog layer', async () => {
|
||||
const user = userEvent.setup()
|
||||
const context = createMockContext({
|
||||
inputsForms: [{ variable: 'sel', type: InputVarType.select, label: 'Sel', options: ['A', 'B'], default: 'B' }],
|
||||
currentConversationInputs: {},
|
||||
})
|
||||
|
||||
renderWithContext(<InputsFormContent />, context)
|
||||
await user.click(screen.getByText('B'))
|
||||
|
||||
expect(screen.getByText('A').closest('.z-\\[60\\]')).not.toBeNull()
|
||||
})
|
||||
|
||||
it('handles select input with existing value (value not in options -> shows placeholder)', () => {
|
||||
const context = createMockContext({
|
||||
inputsForms: [{ variable: 'sel', type: InputVarType.select, label: 'Sel', options: ['A'], default: undefined }],
|
||||
|
||||
@ -86,7 +86,7 @@ const InputsFormContent = ({ showTip }: Props) => {
|
||||
)}
|
||||
{form.type === InputVarType.select && (
|
||||
<PortalSelect
|
||||
popupClassName="w-[200px]"
|
||||
popupClassName="z-[60] w-[200px]"
|
||||
value={inputsFormValue?.[form.variable] ?? form.default ?? ''}
|
||||
items={form.options.map((option: string) => ({ value: option, name: option }))}
|
||||
onSelect={item => handleFormChange(form.variable, item.value as string)}
|
||||
|
||||
@ -200,6 +200,17 @@ describe('InputsFormContent', () => {
|
||||
expect(mockContextValue.handleNewConversationInputsChange).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('should render select dropdown above the settings dialog layer', async () => {
|
||||
render(<InputsFormContent />)
|
||||
const selectTrigger = screen.getAllByText(/Select Label/i).find(el => el.tagName === 'SPAN')
|
||||
if (!selectTrigger)
|
||||
throw new Error('Select trigger not found')
|
||||
|
||||
await user.click(selectTrigger)
|
||||
|
||||
expect(screen.getByText('Option 1').closest('.z-\\[60\\]')).not.toBeNull()
|
||||
})
|
||||
|
||||
it('should handle single file upload change', async () => {
|
||||
render(<InputsFormContent />)
|
||||
const uploadButtons = screen.getAllByText('Upload')
|
||||
|
||||
@ -86,7 +86,7 @@ const InputsFormContent = ({ showTip }: Props) => {
|
||||
)}
|
||||
{form.type === InputVarType.select && (
|
||||
<PortalSelect
|
||||
popupClassName="w-[200px]"
|
||||
popupClassName="z-[60] w-[200px]"
|
||||
value={inputsFormValue?.[form.variable] ?? form.default ?? ''}
|
||||
items={form.options.map((option: string) => ({ value: option, name: option }))}
|
||||
onSelect={item => handleFormChange(form.variable, item.value as string)}
|
||||
|
||||
@ -222,6 +222,21 @@ describe('FileItem (chat-input)', () => {
|
||||
expect(document.querySelector('audio')).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('should not throw when file type is missing', () => {
|
||||
expect(() => {
|
||||
render(
|
||||
<FileItem
|
||||
file={createFile({
|
||||
name: 'generated.png',
|
||||
type: undefined as unknown as string,
|
||||
supportFileType: 'document',
|
||||
})}
|
||||
canPreview
|
||||
/>,
|
||||
)
|
||||
}).not.toThrow()
|
||||
})
|
||||
|
||||
it('should close video preview', () => {
|
||||
render(
|
||||
<FileItem
|
||||
|
||||
@ -36,6 +36,7 @@ const FileItem = ({
|
||||
const [previewUrl, setPreviewUrl] = useState('')
|
||||
const ext = getFileExtension(name, type, isRemote)
|
||||
const uploadError = progress === -1
|
||||
const [typeCategory = '', typeSubtype = ''] = type?.split('/') ?? []
|
||||
|
||||
let tmp_preview_url = url || base64Url
|
||||
if (!tmp_preview_url && file?.originalFile)
|
||||
@ -121,7 +122,7 @@ const FileItem = ({
|
||||
</div>
|
||||
</div>
|
||||
{
|
||||
type.split('/')[0] === 'audio' && canPreview && previewUrl && (
|
||||
typeCategory === 'audio' && canPreview && previewUrl && (
|
||||
<AudioPreview
|
||||
title={name}
|
||||
url={previewUrl}
|
||||
@ -130,7 +131,7 @@ const FileItem = ({
|
||||
)
|
||||
}
|
||||
{
|
||||
type.split('/')[0] === 'video' && canPreview && previewUrl && (
|
||||
typeCategory === 'video' && canPreview && previewUrl && (
|
||||
<VideoPreview
|
||||
title={name}
|
||||
url={previewUrl}
|
||||
@ -139,7 +140,7 @@ const FileItem = ({
|
||||
)
|
||||
}
|
||||
{
|
||||
type.split('/')[1] === 'pdf' && canPreview && previewUrl && (
|
||||
typeSubtype === 'pdf' && canPreview && previewUrl && (
|
||||
<PdfPreview url={previewUrl} onCancel={() => { setPreviewUrl('') }} />
|
||||
)
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user