test: add unit tests for base components (#32818)

Co-authored-by: CodingOnStar <hanxujiang@dify.com>
This commit is contained in:
Coding On Star
2026-03-02 11:40:43 +08:00
committed by GitHub
parent 8cc775d9f2
commit 335b500aea
401 changed files with 820 additions and 819 deletions

View File

@ -1,6 +1,6 @@
import { render, screen } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import AudioPreview from './audio-preview'
import AudioPreview from '../audio-preview'
describe('AudioPreview', () => {
const defaultProps = {

View File

@ -1,9 +1,9 @@
import type { useLocalFileUploader } from './hooks'
import type { useLocalFileUploader } from '../hooks'
import type { ImageFile, VisionSettings } from '@/types/app'
import { render, screen } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import { Resolution, TransferMethod } from '@/types/app'
import ChatImageUploader from './chat-image-uploader'
import ChatImageUploader from '../chat-image-uploader'
type LocalUploaderArgs = Parameters<typeof useLocalFileUploader>[0]
@ -12,7 +12,7 @@ const mocks = vi.hoisted(() => ({
handleLocalFileUpload: vi.fn<(file: File) => void>(),
}))
vi.mock('./hooks', () => ({
vi.mock('../hooks', () => ({
useLocalFileUploader: (args: LocalUploaderArgs) => {
mocks.hookArgs = args
return {

View File

@ -2,7 +2,7 @@ import type { ClipboardEvent, DragEvent } from 'react'
import type { ImageFile, VisionSettings } from '@/types/app'
import { act, renderHook } from '@testing-library/react'
import { Resolution, TransferMethod } from '@/types/app'
import { useClipboardUploader, useDraggableUploader, useImageFiles, useLocalFileUploader } from './hooks'
import { useClipboardUploader, useDraggableUploader, useImageFiles, useLocalFileUploader } from '../hooks'
const mockNotify = vi.fn()
vi.mock('@/app/components/base/toast', () => ({
@ -17,7 +17,7 @@ const { mockImageUpload, mockGetImageUploadErrorMessage } = vi.hoisted(() => ({
mockImageUpload: vi.fn(),
mockGetImageUploadErrorMessage: vi.fn(() => 'Upload error'),
}))
vi.mock('./utils', () => ({
vi.mock('../utils', () => ({
imageUpload: mockImageUpload,
getImageUploadErrorMessage: mockGetImageUploadErrorMessage,
}))

View File

@ -1,7 +1,7 @@
import { render, screen } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import { TransferMethod } from '@/types/app'
import ImageLinkInput from './image-link-input'
import ImageLinkInput from '../image-link-input'
describe('ImageLinkInput', () => {
const defaultProps = {

View File

@ -2,7 +2,7 @@ import type { ImageFile } from '@/types/app'
import { fireEvent, render, screen } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import { TransferMethod } from '@/types/app'
import ImageList from './image-list'
import ImageList from '../image-list'
const createLocalFile = (overrides: Partial<ImageFile> = {}): ImageFile => ({
type: TransferMethod.local_file,

View File

@ -1,6 +1,6 @@
import { act, render, screen, waitFor } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import ImagePreview from './image-preview'
import ImagePreview from '../image-preview'
type HotkeyHandler = () => void

View File

@ -1,9 +1,9 @@
import type { useLocalFileUploader } from './hooks'
import type { useLocalFileUploader } from '../hooks'
import type { ImageFile, VisionSettings } from '@/types/app'
import { render, screen, waitFor } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import { Resolution, TransferMethod } from '@/types/app'
import TextGenerationImageUploader from './text-generation-image-uploader'
import TextGenerationImageUploader from '../text-generation-image-uploader'
type LocalUploaderArgs = Parameters<typeof useLocalFileUploader>[0]
@ -18,7 +18,7 @@ const mocks = vi.hoisted(() => ({
localUploaderArgs: undefined as LocalUploaderArgs | undefined,
}))
vi.mock('./hooks', () => ({
vi.mock('../hooks', () => ({
useImageFiles: () => ({
files: mocks.files,
onUpload: mocks.onUpload,

View File

@ -1,9 +1,9 @@
import type { ComponentProps } from 'react'
import type { useLocalFileUploader } from './hooks'
import type { useLocalFileUploader } from '../hooks'
import { render, screen } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import { ALLOW_FILE_EXTENSIONS } from '@/types/app'
import Uploader from './uploader'
import Uploader from '../uploader'
type LocalUploaderArgs = Parameters<typeof useLocalFileUploader>[0]
@ -12,7 +12,7 @@ const mocks = vi.hoisted(() => ({
handleLocalFileUpload: vi.fn<(file: File) => void>(),
}))
vi.mock('./hooks', () => ({
vi.mock('../hooks', () => ({
useLocalFileUploader: (args: LocalUploaderArgs) => {
mocks.hookArgs = args
return {

View File

@ -1,7 +1,7 @@
import type { TFunction } from 'i18next'
import { waitFor } from '@testing-library/react'
import { upload } from '@/service/base'
import { getImageUploadErrorMessage, imageUpload } from './utils'
import { getImageUploadErrorMessage, imageUpload } from '../utils'
vi.mock('@/service/base', () => ({
upload: vi.fn(),

View File

@ -1,6 +1,6 @@
import { render, screen } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import VideoPreview from './video-preview'
import VideoPreview from '../video-preview'
const getOverlay = () => screen.getByTestId('video-preview')
const getCloseButton = () => screen.getByTestId('close-button')