瀏覽代碼

📝 docs(testing): 更新测试文档和测试用例

- 移除测试文件中重复的全局类型声明(describe, it, expect, jest, beforeEach)
- 将测试用例描述从英文翻译为中文,提升可读性
- 更新测试文件中的注释,统一使用中文描述
- 移除已过时的Taro mock配置注释
- 优化测试用例描述,使其更符合中文表达习惯

✅ test(personal-info-ui): 更新个人中心测试用例

- 更新PersonalInfoPage测试用例描述为中文
- 统一测试用例中的注释语言为中文
- 优化测试描述,使其更清晰易懂
- 保持测试逻辑和断言不变,仅更新描述语言

✅ test(components): 更新组件单元测试描述

- 更新BankCardItem组件测试用例描述为中文
- 更新DocumentPhotoItem组件测试用例描述为中文
- 更新PersonalBasicInfo组件测试用例描述为中文
- 统一测试用例中的注释和描述语言
- 移除重复的全局类型声明
yourname 3 周之前
父節點
當前提交
4344b3efcf

+ 5 - 23
docs/architecture/mini-ui-testing-standards.md

@@ -155,15 +155,6 @@ import '@testing-library/jest-dom'
 import ComponentName, { PropsInterface } from '../../../src/components/ComponentName'
 import Taro from '@tarojs/taro'
 
-declare const describe: any
-declare const it: any
-declare const expect: any
-declare const jest: any
-declare const beforeEach: any
-
-// 使用 mini-testing-utils 提供的 Taro mock
-// jest.mock('@tarojs/taro') 在 testing/setup.ts 中已配置
-
 describe('ComponentName', () => {
   const mockProps: PropsInterface = {
     // mock props
@@ -174,7 +165,7 @@ describe('ComponentName', () => {
     ;(Taro.someApi as jest.Mock).mockClear()
   })
 
-  it('should render correctly', () => {
+  it('应该正确渲染', () => {
     render(<ComponentName {...mockProps} />)
     expect(screen.getByText('expected text')).toBeInTheDocument()
   })
@@ -197,15 +188,6 @@ import { apiClient } from '../../../src/api'
 import { useRequireAuth } from '@d8d/xxx-auth-ui/hooks'
 import Taro from '@tarojs/taro'
 
-declare const describe: any
-declare const it: any
-declare const expect: any
-declare const jest: any
-declare const beforeEach: any
-
-// 使用 mini-testing-utils 提供的 Taro mock
-// jest.mock('@tarojs/taro') 在 testing/setup.ts 中已配置
-
 // Mock auth hooks
 jest.mock('@d8d/xxx-auth-ui/hooks', () => ({
   useRequireAuth: jest.fn()
@@ -254,7 +236,7 @@ describe('PageName', () => {
     ;(Taro.showToast as jest.Mock).mockClear()
   })
 
-  it('should render page with correct data', async () => {
+  it('应该渲染带有正确数据的页面', async () => {
     // Mock API calls - 使用符合RPC类型的响应
     ;(apiClient.route.$get as jest.Mock).mockResolvedValue(
       createMockResponse(200, mockData)
@@ -298,7 +280,7 @@ describe('Component', () => {
     ;(Taro.showToast as jest.Mock).mockClear()
   })
 
-  it('should call Taro API', () => {
+  it('应该调用Taro API', () => {
     render(<Component />)
     expect(Taro.showToast).toHaveBeenCalledWith({ title: '成功' })
   })
@@ -337,7 +319,7 @@ const mockData = {
 使用 `waitFor` 处理异步状态更新:
 
 ```typescript
-it('should render data after loading', async () => {
+it('应该在加载完成后渲染数据', async () => {
   ; (apiClient.route.$get as jest.Mock).mockResolvedValue(
     createMockResponse(200, mockData)
   )
@@ -353,7 +335,7 @@ it('should render data after loading', async () => {
 ### 3. 用户交互测试
 
 ```typescript
-it('should handle click event', () => {
+it('应该处理点击事件', () => {
   const { fireEvent } = require('@testing-library/react')
 
   render(<Component />)

+ 15 - 18
mini-ui-packages/rencai-personal-info-ui/tests/pages/PersonalInfoPage/PersonalInfoPage.test.tsx

@@ -11,15 +11,12 @@ import { talentPersonalInfoClient } from '../../../src/api'
 import { useRequireAuth } from '@d8d/rencai-auth-ui/hooks'
 import Taro from '@tarojs/taro'
 
-// 使用 mini-testing-utils 提供的 Taro mock
-// jest.mock('@tarojs/taro') 在 testing/setup.ts 中已配置
-
-// Mock auth hooks
+// Mock 认证 hooks
 jest.mock('@d8d/rencai-auth-ui/hooks', () => ({
   useRequireAuth: jest.fn()
 }))
 
-// Mock API client - 使用真实的RPC类型
+// Mock API 客户端 - 使用真实的RPC类型
 jest.mock('../../../src/api', () => ({
   talentPersonalInfoClient: {
     personal: {
@@ -36,12 +33,12 @@ jest.mock('../../../src/api', () => ({
   }
 }))
 
-// Mock layouts
+// Mock 布局组件
 jest.mock('@d8d/rencai-shared-ui/components/RencaiTabBarLayout', () => ({
   RencaiTabBarLayout: ({ children }: { children: React.ReactNode }) => <div data-testid="tabbar-layout">{children}</div>
 }))
 
-// Mock Navbar
+// Mock 导航栏组件
 jest.mock('@d8d/mini-shared-ui-components/components/navbar', () => ({
   Navbar: ({ title }: { title: string }) => <div data-testid="navbar">{title}</div>
 }))
@@ -74,15 +71,15 @@ const createTestWrapper = () => {
 describe('PersonalInfoPage', () => {
   beforeEach(() => {
     jest.clearAllMocks()
-    // Mock useRequireAuth to do nothing (user is authenticated)
+    // Mock useRequireAuth 使其不做任何操作(用户已认证)
     ;(useRequireAuth as jest.Mock).mockImplementation(() => {})
-    // Reset Taro API mocks
+    // 清理 Taro API mock
     ;(Taro.setNavigationBarTitle as jest.Mock).mockClear()
     ;(Taro.showToast as jest.Mock).mockClear()
   })
 
-  it('should render navbar with correct title', async () => {
-    // Mock API calls - 使用符合RPC类型的响应
+  it('应该渲染带有正确标题的导航栏', async () => {
+    // Mock API 调用 - 使用符合RPC类型的响应
     ;(talentPersonalInfoClient.personal.info.$get as jest.Mock).mockResolvedValue(
       createMockResponse(200, {} as any)
     )
@@ -96,12 +93,12 @@ describe('PersonalInfoPage', () => {
     const wrapper = createTestWrapper()
     render(<PersonalInfoPage />, { wrapper })
 
-    // Check if Navbar is rendered with correct title
+    // 检查导航栏是否渲染了正确的标题
     expect(screen.getByTestId('navbar')).toHaveTextContent('我的')
     expect(Taro.setNavigationBarTitle).toHaveBeenCalledWith({ title: '我的' })
   })
 
-  it('should render personal basic info with correct RPC types', async () => {
+  it('应该渲染带有正确RPC类型的个人基本信息', async () => {
     // 符合RPC类型的个人信息数据
     const mockPersonalInfo = {
       name: '张三',
@@ -147,7 +144,7 @@ describe('PersonalInfoPage', () => {
     })
   })
 
-  it('should render bank cards with correct RPC types', async () => {
+  it('应该渲染带有正确RPC类型的银行卡信息', async () => {
     // 符合RPC类型的银行卡数据
     const mockBankCards = [
       {
@@ -183,7 +180,7 @@ describe('PersonalInfoPage', () => {
     })
   })
 
-  it('should render document photos with correct RPC types', async () => {
+  it('应该渲染带有正确RPC类型的证件照片', async () => {
     // 符合RPC类型的证件照片数据
     const mockPhotos = [
       {
@@ -214,7 +211,7 @@ describe('PersonalInfoPage', () => {
     })
   })
 
-  it('should show empty state when no data', async () => {
+  it('应该在没有数据时显示空状态', async () => {
     ;(talentPersonalInfoClient.personal.info.$get as jest.Mock).mockResolvedValue(
       createMockResponse(200, {} as any)
     )
@@ -234,8 +231,8 @@ describe('PersonalInfoPage', () => {
     })
   })
 
-  it('should show error toast when API calls fail', async () => {
-    // Mock API errors
+  it('应该在API调用失败时显示错误提示', async () => {
+    // Mock API 错误
     ;(talentPersonalInfoClient.personal.info.$get as jest.Mock).mockRejectedValue(
       new Error('获取个人信息失败')
     )

+ 8 - 12
mini-ui-packages/rencai-personal-info-ui/tests/unit/components/BankCardItem.test.tsx

@@ -7,10 +7,6 @@ import '@testing-library/jest-dom'
 import BankCardItem, { BankCardInfo } from '../../../src/components/BankCardItem'
 import { maskCardNumber } from '../../../src/utils/maskUtils'
 
-declare const describe: any
-declare const it: any
-declare const expect: any
-
 describe('BankCardItem', () => {
   const mockBankCard: BankCardInfo = {
     id: 1,
@@ -23,7 +19,7 @@ describe('BankCardItem', () => {
     fileUrl: null
   }
 
-  it('should render bank card info correctly', () => {
+  it('应该正确渲染银行卡信息', () => {
     render(<BankCardItem bankCard={mockBankCard} />)
 
     expect(screen.getByText('中国工商银行')).toBeInTheDocument()
@@ -31,38 +27,38 @@ describe('BankCardItem', () => {
     expect(screen.getByText('一类卡')).toBeInTheDocument()
   })
 
-  it('should show default badge for default card', () => {
+  it('应该为默认卡显示默认标识', () => {
     render(<BankCardItem bankCard={mockBankCard} />)
 
     expect(screen.getByText('默认')).toBeInTheDocument()
   })
 
-  it('should not show default badge for non-default card', () => {
+  it('不应该为非默认卡显示默认标识', () => {
     const nonDefaultCard = { ...mockBankCard, isDefault: 0 }
     render(<BankCardItem bankCard={nonDefaultCard} />)
 
     expect(screen.queryByText('默认')).not.toBeInTheDocument()
   })
 
-  it('should mask card number correctly', () => {
+  it('应该正确脱敏卡号', () => {
     render(<BankCardItem bankCard={mockBankCard} />)
 
-    // Card number should be masked like: **** **** **** 4567
+    // 卡号应该脱敏显示为: **** **** **** 4567
     expect(screen.getByText('**** **** **** 4567')).toBeInTheDocument()
   })
 
-  it('should use subBankName when bankName is null', () => {
+  it('应该在bankName为null时使用subBankName', () => {
     const cardWithoutBankName = { ...mockBankCard, bankName: null }
     render(<BankCardItem bankCard={cardWithoutBankName} />)
 
     expect(screen.getByText('中国工商银行北京分行朝阳支行')).toBeInTheDocument()
   })
 
-  it('should not render card type when null', () => {
+  it('不应该在cardType为null时渲染卡类型', () => {
     const cardWithoutType = { ...mockBankCard, cardType: null }
     render(<BankCardItem bankCard={cardWithoutType} />)
 
-    // Card type should not be rendered
+    // 卡类型不应该被渲染
     expect(screen.queryByText('一类卡')).not.toBeInTheDocument()
   })
 })

+ 5 - 14
mini-ui-packages/rencai-personal-info-ui/tests/unit/components/DocumentPhotoItem.test.tsx

@@ -7,15 +7,6 @@ import '@testing-library/jest-dom'
 import DocumentPhotoItem, { PhotoInfo } from '../../../src/components/DocumentPhotoItem'
 import Taro from '@tarojs/taro'
 
-declare const describe: any
-declare const it: any
-declare const expect: any
-declare const jest: any
-declare const beforeEach: any
-
-// 使用 mini-testing-utils 提供的 Taro mock
-// jest.mock('@tarojs/taro') 在 testing/setup.ts 中已配置
-
 describe('DocumentPhotoItem', () => {
   const mockPhoto: PhotoInfo = {
     id: 1,
@@ -30,22 +21,22 @@ describe('DocumentPhotoItem', () => {
     ;(Taro.previewImage as jest.Mock).mockClear()
   })
 
-  it('should render photo info correctly', () => {
+  it('应该正确渲染照片信息', () => {
     render(<DocumentPhotoItem photo={mockPhoto} />)
 
     expect(screen.getByText('身份证')).toBeInTheDocument()
   })
 
-  it('should show placeholder when no fileUrl', () => {
+  it('应该在fileUrl为空时显示占位符', () => {
     const photoWithoutUrl = { ...mockPhoto, fileUrl: null }
     render(<DocumentPhotoItem photo={photoWithoutUrl} />)
 
-    // Should show placeholder icon
+    // 应该显示占位图标
     const placeholderIcon = document.querySelector('.i-heroicons-photo-20-solid')
     expect(placeholderIcon).toBeInTheDocument()
   })
 
-  it('should call previewImage when clicking on photo', () => {
+  it('应该在点击照片时调用预览', () => {
     const { fireEvent } = require('@testing-library/react')
 
     render(<DocumentPhotoItem photo={mockPhoto} />)
@@ -61,7 +52,7 @@ describe('DocumentPhotoItem', () => {
     }
   })
 
-  it('should not call previewImage when no fileUrl', () => {
+  it('应该在fileUrl为空时不调用预览', () => {
     const { fireEvent } = require('@testing-library/react')
 
     const photoWithoutUrl = { ...mockPhoto, fileUrl: null }

+ 7 - 11
mini-ui-packages/rencai-personal-info-ui/tests/unit/components/PersonalBasicInfo.test.tsx

@@ -7,10 +7,6 @@ import '@testing-library/jest-dom'
 import PersonalBasicInfo, { PersonalInfoResponse } from '../../../src/components/PersonalBasicInfo'
 import { maskIdCard } from '../../../src/utils/maskUtils'
 
-declare const describe: any
-declare const it: any
-declare const expect: any
-
 describe('PersonalBasicInfo', () => {
   const mockPersonalInfo: PersonalInfoResponse = {
     name: '张三',
@@ -35,7 +31,7 @@ describe('PersonalBasicInfo', () => {
     specificDisability: '左腿小腿截肢'
   }
 
-  it('should render personal basic info correctly', () => {
+  it('应该正确渲染个人基本信息', () => {
     render(<PersonalBasicInfo personalInfo={mockPersonalInfo} loading={false} />)
 
     expect(screen.getByText('张三')).toBeInTheDocument()
@@ -46,26 +42,26 @@ describe('PersonalBasicInfo', () => {
     expect(screen.getByText('13800138000')).toBeInTheDocument()
   })
 
-  it('should render loading state', () => {
+  it('应该渲染加载状态', () => {
     render(<PersonalBasicInfo personalInfo={null} loading={true} />)
 
-    // Check for skeleton loading elements
+    // 检查骨架屏加载元素
     const skeletonElements = document.querySelectorAll('.animate-pulse')
     expect(skeletonElements.length).toBeGreaterThan(0)
   })
 
-  it('should render empty state when no data', () => {
+  it('应该在没有数据时显示空状态', () => {
     render(<PersonalBasicInfo personalInfo={null} loading={false} />)
 
     expect(screen.getByText('暂无个人信息')).toBeInTheDocument()
   })
 
-  it('should mask sensitive information', () => {
+  it('应该脱敏敏感信息', () => {
     render(<PersonalBasicInfo personalInfo={mockPersonalInfo} loading={false} />)
 
-    // Check if ID card is masked (前4位 + 10个星号 + 后4位)
+    // 检查身份证号是否已脱敏(前4位 + 10个星号 + 后4位)
     expect(screen.getByText('1101**********1234')).toBeInTheDocument()
-    // Check if disability card is masked (D123 + 10个星号 + 7890)
+    // 检查残疾证号是否已脱敏(D123 + 10个星号 + 7890)
     // D1234567890有11个字符,后4位是7890
     expect(screen.getByText('D123**********7890')).toBeInTheDocument()
   })