fix: bug
This commit is contained in:
17
components/blocks/__tests__/AuthForm.simple.test.tsx
Normal file
17
components/blocks/__tests__/AuthForm.simple.test.tsx
Normal file
@@ -0,0 +1,17 @@
|
||||
import React from 'react'
|
||||
import { Text, View } from 'react-native'
|
||||
import { render } from '@testing-library/react-native'
|
||||
|
||||
// 最简单的测试组件
|
||||
const SimpleComponent = () => (
|
||||
<View>
|
||||
<Text>Hello Test</Text>
|
||||
</View>
|
||||
)
|
||||
|
||||
describe('Simple Test', () => {
|
||||
test('renders simple component', () => {
|
||||
const { getByText } = render(<SimpleComponent />)
|
||||
expect(getByText('Hello Test')).toBeTruthy()
|
||||
})
|
||||
})
|
||||
92
components/blocks/__tests__/AuthForm.test.tsx
Normal file
92
components/blocks/__tests__/AuthForm.test.tsx
Normal file
@@ -0,0 +1,92 @@
|
||||
import React from 'react'
|
||||
import { render, fireEvent, waitFor } from '@testing-library/react-native'
|
||||
import { AuthForm } from '../AuthForm'
|
||||
import { storage } from '@/lib/storage'
|
||||
|
||||
// Mock entire UI module to avoid complex dependencies
|
||||
jest.mock('@/components/ui', () => {
|
||||
const mockReact = require('react')
|
||||
const mockRN = require('react-native')
|
||||
|
||||
const Block = ({ children, onClick, ...props }: any) => {
|
||||
if (onClick) {
|
||||
return mockReact.createElement(mockRN.Pressable, { onPress: onClick, ...props }, children)
|
||||
}
|
||||
return mockReact.createElement(mockRN.View, props, children)
|
||||
}
|
||||
|
||||
const Text = ({ children, onClick, ...props }: any) => {
|
||||
if (onClick) {
|
||||
return mockReact.createElement(mockRN.Pressable, { onPress: onClick },
|
||||
mockReact.createElement(mockRN.Text, props, children)
|
||||
)
|
||||
}
|
||||
return mockReact.createElement(mockRN.Text, props, children)
|
||||
}
|
||||
|
||||
return {
|
||||
Block,
|
||||
Text,
|
||||
}
|
||||
})
|
||||
|
||||
// Mock button component separately since it's imported from a different path
|
||||
jest.mock('../../ui/button', () => {
|
||||
const mockReact = require('react')
|
||||
const mockRN = require('react-native')
|
||||
|
||||
const Button = ({ children, onPress, disabled, ...props }: any) => (
|
||||
mockReact.createElement(mockRN.Pressable, { onPress, disabled, ...props }, children)
|
||||
)
|
||||
|
||||
return {
|
||||
Button,
|
||||
}
|
||||
})
|
||||
|
||||
// Mock ModalPortal to avoid react-native-css-interop issues
|
||||
jest.mock('@/components/ui/ModalPortal', () => ({
|
||||
__esModule: true,
|
||||
default: ({ children }: any) => children,
|
||||
}))
|
||||
|
||||
// Mock storage
|
||||
jest.mock('@/lib/storage', () => ({
|
||||
storage: {
|
||||
getItem: jest.fn(),
|
||||
setItem: jest.fn(),
|
||||
removeItem: jest.fn(),
|
||||
},
|
||||
}))
|
||||
|
||||
// Mock auth client
|
||||
jest.mock('@/lib/auth', () => ({
|
||||
authClient: {
|
||||
signIn: {
|
||||
username: jest.fn(),
|
||||
},
|
||||
signUp: {
|
||||
email: jest.fn(),
|
||||
},
|
||||
},
|
||||
setAuthToken: jest.fn(),
|
||||
useSession: jest.fn(() => ({ data: null, isPending: false })),
|
||||
}))
|
||||
|
||||
// Mock react-i18next
|
||||
jest.mock('react-i18next', () => ({
|
||||
useTranslation: () => ({
|
||||
t: (key: string) => key,
|
||||
}),
|
||||
}))
|
||||
|
||||
describe('AuthForm - Remember Password', () => {
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks()
|
||||
})
|
||||
|
||||
test('renders remember password checkbox', () => {
|
||||
const { getByText } = render(<AuthForm />)
|
||||
expect(getByText('authForm.rememberPassword')).toBeTruthy()
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user