|
@@ -175,7 +175,7 @@ describe('个人中心页面测试', () => {
|
|
|
expect(screen.getByText('个人中心')).toBeInTheDocument()
|
|
expect(screen.getByText('个人中心')).toBeInTheDocument()
|
|
|
|
|
|
|
|
// 检查用户信息
|
|
// 检查用户信息
|
|
|
- expect(screen.getByText('测试用户')).toBeInTheDocument()
|
|
|
|
|
|
|
+ expect(screen.getByText('普通用户')).toBeInTheDocument()
|
|
|
expect(screen.getByText('ID: 1')).toBeInTheDocument()
|
|
expect(screen.getByText('ID: 1')).toBeInTheDocument()
|
|
|
|
|
|
|
|
// 检查功能菜单
|
|
// 检查功能菜单
|
|
@@ -449,4 +449,90 @@ describe('个人中心页面测试', () => {
|
|
|
expect(navbar).toHaveAttribute('data-text-color', 'text-white')
|
|
expect(navbar).toHaveAttribute('data-text-color', 'text-white')
|
|
|
expect(navbar).toHaveAttribute('data-border', 'false')
|
|
expect(navbar).toHaveAttribute('data-border', 'false')
|
|
|
})
|
|
})
|
|
|
|
|
+
|
|
|
|
|
+ test('应该显示默认头像当用户无头像时', () => {
|
|
|
|
|
+ // 模拟用户无头像的情况
|
|
|
|
|
+ const mockUseAuth = jest.requireMock('@/utils/auth').useAuth
|
|
|
|
|
+ mockUseAuth.mockImplementation(() => ({
|
|
|
|
|
+ user: {
|
|
|
|
|
+ ...mockUser,
|
|
|
|
|
+ avatarFile: null
|
|
|
|
|
+ },
|
|
|
|
|
+ logout: mockLogout,
|
|
|
|
|
+ isLoading: false,
|
|
|
|
|
+ updateUser: mockUpdateUser
|
|
|
|
|
+ }))
|
|
|
|
|
+
|
|
|
|
|
+ render(
|
|
|
|
|
+ <Wrapper>
|
|
|
|
|
+ <ProfilePage />
|
|
|
|
|
+ </Wrapper>
|
|
|
|
|
+ )
|
|
|
|
|
+
|
|
|
|
|
+ // 检查默认头像路径
|
|
|
|
|
+ const avatarUpload = screen.getByTestId('avatar-upload')
|
|
|
|
|
+ expect(avatarUpload).toHaveAttribute('data-current-avatar', '/images/default_avatar.jpg')
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ test('应该显示默认用户名', () => {
|
|
|
|
|
+ // 模拟用户无用户名的情况
|
|
|
|
|
+ const mockUseAuth = jest.requireMock('@/utils/auth').useAuth
|
|
|
|
|
+ mockUseAuth.mockImplementation(() => ({
|
|
|
|
|
+ user: {
|
|
|
|
|
+ ...mockUser,
|
|
|
|
|
+ username: ''
|
|
|
|
|
+ },
|
|
|
|
|
+ logout: mockLogout,
|
|
|
|
|
+ isLoading: false,
|
|
|
|
|
+ updateUser: mockUpdateUser
|
|
|
|
|
+ }))
|
|
|
|
|
+
|
|
|
|
|
+ render(
|
|
|
|
|
+ <Wrapper>
|
|
|
|
|
+ <ProfilePage />
|
|
|
|
|
+ </Wrapper>
|
|
|
|
|
+ )
|
|
|
|
|
+
|
|
|
|
|
+ // 检查用户名显示为"普通用户"
|
|
|
|
|
+ expect(screen.getByText('普通用户')).toBeInTheDocument()
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ test('头像上传功能应该在默认头像状态下正常工作', async () => {
|
|
|
|
|
+ // 模拟用户无头像的情况
|
|
|
|
|
+ const mockUseAuth = jest.requireMock('@/utils/auth').useAuth
|
|
|
|
|
+ mockUseAuth.mockImplementation(() => ({
|
|
|
|
|
+ user: {
|
|
|
|
|
+ ...mockUser,
|
|
|
|
|
+ avatarFile: null
|
|
|
|
|
+ },
|
|
|
|
|
+ logout: mockLogout,
|
|
|
|
|
+ isLoading: false,
|
|
|
|
|
+ updateUser: mockUpdateUser
|
|
|
|
|
+ }))
|
|
|
|
|
+
|
|
|
|
|
+ render(
|
|
|
|
|
+ <Wrapper>
|
|
|
|
|
+ <ProfilePage />
|
|
|
|
|
+ </Wrapper>
|
|
|
|
|
+ )
|
|
|
|
|
+
|
|
|
|
|
+ // 点击头像上传成功按钮
|
|
|
|
|
+ const uploadButton = screen.getByTestId('avatar-upload-button')
|
|
|
|
|
+ fireEvent.click(uploadButton)
|
|
|
|
|
+
|
|
|
|
|
+ // 检查上传成功处理
|
|
|
|
|
+ await waitFor(() => {
|
|
|
|
|
+ expect(taroMock.showLoading).toHaveBeenCalledWith({ title: '更新头像...' })
|
|
|
|
|
+ expect(taroMock.hideLoading).toHaveBeenCalled()
|
|
|
|
|
+ expect(taroMock.showToast).toHaveBeenCalledWith({
|
|
|
|
|
+ title: '头像更新成功',
|
|
|
|
|
+ icon: 'success'
|
|
|
|
|
+ })
|
|
|
|
|
+ expect(mockUpdateUser).toHaveBeenCalledWith({
|
|
|
|
|
+ ...mockUser,
|
|
|
|
|
+ avatarFile: null,
|
|
|
|
|
+ avatarFileId: 'test-file-id'
|
|
|
|
|
+ })
|
|
|
|
|
+ })
|
|
|
|
|
+ })
|
|
|
})
|
|
})
|