import React from 'react'; import { render, fireEvent } from '@testing-library/react-native'; import { ErrorMessage, FullScreenError } from '@/components/ui/ErrorMessage'; describe('ErrorMessage', () => { it('renders error message with retry button', () => { const onRetry = jest.fn(); const { getByText } = render( ); expect(getByText('Test error')).toBeTruthy(); expect(getByText('Retry')).toBeTruthy(); }); it('calls onRetry when retry button is pressed', () => { const onRetry = jest.fn(); const { getByText } = render( ); fireEvent.press(getByText('Retry')); expect(onRetry).toHaveBeenCalledTimes(1); }); it('renders without retry button when onRetry is not provided', () => { const { queryByText } = render(); expect(queryByText('Retry')).toBeNull(); }); it('renders with skip button when onSkip is provided', () => { const onSkip = jest.fn(); const { getByText } = render( ); expect(getByText('Skip')).toBeTruthy(); }); }); describe('FullScreenError', () => { it('renders full screen error with retry button', () => { const onRetry = jest.fn(); const { getByText } = render( ); expect(getByText('Something went wrong')).toBeTruthy(); expect(getByText('Connection failed')).toBeTruthy(); expect(getByText('Try Again')).toBeTruthy(); }); it('calls onRetry when Try Again button is pressed', () => { const onRetry = jest.fn(); const { getByText } = render( ); fireEvent.press(getByText('Try Again')); expect(onRetry).toHaveBeenCalledTimes(1); }); it('renders custom title', () => { const { getByText } = render( ); expect(getByText('Custom Error')).toBeTruthy(); }); it('renders without retry button when onRetry is not provided', () => { const { queryByText } = render( ); expect(queryByText('Try Again')).toBeNull(); }); });