skillhub/web/src/pages/namespace.test.tsx
dongmucat e5a3aa6006 test(web): add colocated frontend coverage
变更摘要:
- 将前端测试共置到 web/src,保留并迁移 app 样式相关用例
- 为 pages、features、shared UI 与 hooks 补齐大范围 Vitest 覆盖
- 强化 governance、file preview、namespace header 与 API client 的关键分支测试
- 重新验证 pnpm run test 与 pnpm run typecheck,当前均已通过

关键文件:
- web/src/pages/dashboard/governance.test.ts
- web/src/features/governance/governance-inbox.test.ts
- web/src/features/skill/file-preview-dialog.test.ts
- web/src/features/namespace/namespace-header.test.ts
- web/src/api/client.test.ts
2026-03-23 16:13:34 +08:00

63 lines
1.6 KiB
TypeScript

import { describe, expect, it, vi } from 'vitest'
vi.mock('@tanstack/react-router', () => ({
useNavigate: () => vi.fn(),
useParams: () => ({ namespace: 'global' }),
}))
vi.mock('react-i18next', async () => {
const actual = await vi.importActual<typeof import('react-i18next')>('react-i18next')
return {
...actual,
useTranslation: () => ({
t: (key: string) => key,
}),
}
})
vi.mock('@/features/namespace/namespace-header', () => ({
NamespaceHeader: () => null,
}))
vi.mock('@/features/skill/skill-card', () => ({
SkillCard: () => null,
}))
vi.mock('@/shared/components/skeleton-loader', () => ({
SkeletonList: () => null,
}))
vi.mock('@/shared/components/empty-state', () => ({
EmptyState: ({ title }: { title: string }) => <div>{title}</div>,
}))
const useNamespaceDetailMock = vi.fn()
vi.mock('@/shared/hooks/use-namespace-queries', () => ({
useNamespaceDetail: () => useNamespaceDetailMock(),
}))
vi.mock('@/shared/hooks/use-skill-queries', () => ({
useSearchSkills: () => ({
data: { items: [] },
isLoading: false,
}),
}))
import { renderToStaticMarkup } from 'react-dom/server'
import { NamespacePage } from './namespace'
describe('NamespacePage', () => {
it('exports a named component function', () => {
expect(typeof NamespacePage).toBe('function')
})
it('renders the not-found state when namespace data is missing', () => {
useNamespaceDetailMock.mockReturnValue({
data: null,
isLoading: false,
})
const html = renderToStaticMarkup(<NamespacePage />)
expect(html).toContain('namespace.notFound')
})
})