|
|
@@ -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('获取个人信息失败')
|
|
|
)
|