test: enhance type definitions in dataset component tests for better type safety

This commit is contained in:
CodingOnStar
2026-01-18 14:06:55 +08:00
parent 0bd198baa9
commit f272d68145
4 changed files with 29 additions and 7 deletions

View File

@ -4,7 +4,13 @@ import EconomicalRetrievalMethodConfig from './index'
// Mock dependencies
vi.mock('../../settings/option-card', () => ({
default: ({ children, title, description, disabled, id }: any) => (
default: ({ children, title, description, disabled, id }: {
children?: React.ReactNode
title?: string
description?: React.ReactNode
disabled?: boolean
id?: string
}) => (
<div data-testid="option-card" data-title={title} data-id={id} data-disabled={disabled}>
<div>{description}</div>
{children}
@ -13,7 +19,11 @@ vi.mock('../../settings/option-card', () => ({
}))
vi.mock('../retrieval-param-config', () => ({
default: ({ value, onChange, type }: any) => (
default: ({ value, onChange, type }: {
value: Record<string, unknown>
onChange: (value: Record<string, unknown>) => void
type?: string
}) => (
<div data-testid="retrieval-param-config" data-type={type}>
<button onClick={() => onChange({ ...value, newProp: 'changed' })}>
Change Value

View File

@ -3,10 +3,10 @@ import EmbeddingSkeleton from './index'
// Mock Skeleton components
vi.mock('@/app/components/base/skeleton', () => ({
SkeletonContainer: ({ children }: any) => <div data-testid="skeleton-container">{children}</div>,
SkeletonContainer: ({ children }: { children?: React.ReactNode }) => <div data-testid="skeleton-container">{children}</div>,
SkeletonPoint: () => <div data-testid="skeleton-point" />,
SkeletonRectangle: () => <div data-testid="skeleton-rectangle" />,
SkeletonRow: ({ children }: any) => <div data-testid="skeleton-row">{children}</div>,
SkeletonRow: ({ children }: { children?: React.ReactNode }) => <div data-testid="skeleton-row">{children}</div>,
}))
// Mock Divider

View File

@ -1,9 +1,14 @@
import { render, screen } from '@testing-library/react'
import NewDatasetCard from './index'
type MockOptionProps = {
text: string
href: string
}
// Mock dependencies
vi.mock('./option', () => ({
default: ({ text, href }: any) => (
default: ({ text, href }: MockOptionProps) => (
<a data-testid="option-link" href={href}>
{text}
</a>
@ -16,7 +21,7 @@ vi.mock('@remixicon/react', () => ({
}))
vi.mock('@/app/components/base/icons/src/vender/solid/development', () => ({
ApiConnectionMod: () => <svg data-testid="icon-api" />,
// ApiConnectionMod: () => <svg data-testid="icon-api" />,
}))
describe('NewDatasetCard', () => {

View File

@ -2,9 +2,16 @@ import { render, screen } from '@testing-library/react'
import { ChunkingMode } from '@/models/datasets'
import ChunkStructure from './index'
type MockOptionCardProps = {
id: string
title: string
isActive?: boolean
disabled?: boolean
}
// Mock dependencies
vi.mock('../option-card', () => ({
default: ({ id, title, isActive, disabled }: any) => (
default: ({ id, title, isActive, disabled }: MockOptionCardProps) => (
<div
data-testid="option-card"
data-id={id}