mirror of
https://github.com/langgenius/dify.git
synced 2026-05-06 10:28:10 +08:00
test: add unit tests for base components (#32818)
Co-authored-by: CodingOnStar <hanxujiang@dify.com>
This commit is contained in:
@ -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 = {
|
||||
@ -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 {
|
||||
@ -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,
|
||||
}))
|
||||
@ -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 = {
|
||||
@ -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,
|
||||
@ -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
|
||||
|
||||
@ -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,
|
||||
@ -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 {
|
||||
@ -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(),
|
||||
@ -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')
|
||||
Reference in New Issue
Block a user