fix: 修复表单相册上传失败bug,优化FormData构造方式
- 移除uploadFile.ts中不必要的Platform判断逻辑 - 保持原始URI不做修改,让React Native底层处理平台差异 - 添加uploadFile单元测试,覆盖主要上传场景 - 简化代码结构,提高可维护性 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,8 +1,14 @@
|
||||
import React from 'react'
|
||||
import { render, waitFor } from '@testing-library/react-native'
|
||||
import { SafeAreaProvider } from 'react-native-safe-area-context'
|
||||
import HomeScreen from '../index'
|
||||
|
||||
// Mock react-native-safe-area-context FIRST
|
||||
jest.mock('react-native-safe-area-context', () => ({
|
||||
SafeAreaProvider: ({ children }: any) => children,
|
||||
SafeAreaView: ({ children }: any) => children,
|
||||
useSafeAreaInsets: () => ({ top: 0, right: 0, bottom: 0, left: 0 }),
|
||||
}))
|
||||
|
||||
// Mock expo-linear-gradient
|
||||
jest.mock('expo-linear-gradient', () => ({
|
||||
LinearGradient: 'LinearGradient',
|
||||
@@ -94,15 +100,16 @@ jest.mock('@/hooks/use-categories', () => ({
|
||||
})),
|
||||
}))
|
||||
|
||||
jest.mock('@/hooks/use-user-balance', () => ({
|
||||
useUserBalance: jest.fn(() => ({
|
||||
balance: 1234,
|
||||
loading: false,
|
||||
error: null,
|
||||
})),
|
||||
}))
|
||||
|
||||
const renderWithProviders = (component: React.ReactElement) => {
|
||||
return render(
|
||||
<SafeAreaProvider initialMetrics={{
|
||||
frame: { x: 0, y: 0, width: 375, height: 812 },
|
||||
insets: { top: 44, left: 0, right: 0, bottom: 34 },
|
||||
}}>
|
||||
{component}
|
||||
</SafeAreaProvider>
|
||||
)
|
||||
return render(component)
|
||||
}
|
||||
|
||||
describe('HomeScreen', () => {
|
||||
@@ -137,4 +144,12 @@ describe('HomeScreen', () => {
|
||||
expect(queryByText('加载中')).toBeNull()
|
||||
})
|
||||
})
|
||||
|
||||
it('should display user balance from useUserBalance hook', async () => {
|
||||
const { getByText } = renderWithProviders(<HomeScreen />)
|
||||
|
||||
await waitFor(() => {
|
||||
expect(getByText('1234')).toBeTruthy()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user