test: add comprehensive unit and integration tests for dataset module (#32187)

Co-authored-by: CodingOnStar <hanxujiang@dify.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Coding On Star
2026-02-12 10:00:32 +08:00
committed by GitHub
parent f953331f91
commit 10f85074e8
388 changed files with 22637 additions and 15567 deletions

View File

@ -1,7 +1,7 @@
import type { CreateExternalAPIReq, FormSchema } from '../declarations'
import type { CreateExternalAPIReq, FormSchema } from '../../declarations'
import { fireEvent, render, screen } from '@testing-library/react'
import { beforeEach, describe, expect, it, vi } from 'vitest'
import Form from './Form'
import Form from '../Form'
// Mock context for i18n doc link
vi.mock('@/context/i18n', () => ({

View File

@ -1,17 +1,16 @@
import type { CreateExternalAPIReq } from '../declarations'
import type { CreateExternalAPIReq } from '../../declarations'
import { fireEvent, render, screen, waitFor } from '@testing-library/react'
import { beforeEach, describe, expect, it, vi } from 'vitest'
// Import mocked service
import { createExternalAPI } from '@/service/datasets'
import AddExternalAPIModal from './index'
import AddExternalAPIModal from '../index'
// Mock API service
vi.mock('@/service/datasets', () => ({
createExternalAPI: vi.fn(),
}))
// Mock toast context
const mockNotify = vi.fn()
vi.mock('@/app/components/base/toast', () => ({
useToastContext: () => ({

View File

@ -1,7 +1,7 @@
import type { ExternalAPIItem } from '@/models/datasets'
import { fireEvent, render, screen, waitFor } from '@testing-library/react'
import { beforeEach, describe, expect, it, vi } from 'vitest'
import ExternalAPIPanel from './index'
import ExternalAPIPanel from '../index'
// Mock external contexts (only mock context providers, not base components)
const mockSetShowExternalKnowledgeAPIModal = vi.fn()
@ -28,7 +28,7 @@ vi.mock('@/context/i18n', () => ({
}))
// Mock the ExternalKnowledgeAPICard to avoid mocking its internal dependencies
vi.mock('../external-knowledge-api-card', () => ({
vi.mock('../../external-knowledge-api-card', () => ({
default: ({ api }: { api: ExternalAPIItem }) => (
<div data-testid={`api-card-${api.id}`}>{api.name}</div>
),

View File

@ -4,7 +4,7 @@ import { beforeEach, describe, expect, it, vi } from 'vitest'
// Import mocked services
import { checkUsageExternalAPI, deleteExternalAPI, fetchExternalAPI } from '@/service/datasets'
import ExternalKnowledgeAPICard from './index'
import ExternalKnowledgeAPICard from '../index'
// Mock API services
vi.mock('@/service/datasets', () => ({