import React from 'react'; import { Text, View } from 'react-native'; import { render, fireEvent } from '@testing-library/react-native'; import { ScreenLoading, RefreshableScreen, EmptyState, LoadingButtonState, } from '@/components/ui/ScreenLoading'; describe('ScreenLoading', () => { it('renders children when not loading and no error', () => { const { getByText } = render( Content ); expect(getByText('Content')).toBeTruthy(); }); it('renders loading state when isLoading is true', () => { const { getByText } = render( Content ); expect(getByText('Loading...')).toBeTruthy(); }); it('renders custom loading message', () => { const { getByText } = render( Content ); expect(getByText('Fetching data...')).toBeTruthy(); }); it('renders error state when error is provided', () => { const { getByText } = render( Content ); expect(getByText('Something went wrong')).toBeTruthy(); expect(getByText('Network error')).toBeTruthy(); }); it('renders retry button when onRetry is provided', () => { const onRetry = jest.fn(); const { getByText } = render( Content ); expect(getByText('Try Again')).toBeTruthy(); }); it('calls onRetry when retry button is pressed', () => { const onRetry = jest.fn(); const { getByText } = render( Content ); fireEvent.press(getByText('Try Again')); expect(onRetry).toHaveBeenCalledTimes(1); }); it('does not render retry button when onRetry is not provided', () => { const { queryByText } = render( Content ); expect(queryByText('Try Again')).toBeNull(); }); }); describe('RefreshableScreen', () => { it('renders children', () => { const onRefresh = jest.fn(); const { getByText } = render( Content ); expect(getByText('Content')).toBeTruthy(); }); }); describe('EmptyState', () => { it('renders title and description', () => { const { getByText } = render( ); expect(getByText('No items')).toBeTruthy(); expect(getByText('Add some items to get started')).toBeTruthy(); }); it('renders action button when provided', () => { const onAction = jest.fn(); const { getByText } = render( ); expect(getByText('Add Item')).toBeTruthy(); }); it('calls onAction when action button is pressed', () => { const onAction = jest.fn(); const { getByText } = render( ); fireEvent.press(getByText('Add Item')); expect(onAction).toHaveBeenCalledTimes(1); }); it('does not render action button when onAction is not provided', () => { const { queryByText } = render( ); expect(queryByText('Add Item')).toBeNull(); }); }); describe('LoadingButtonState', () => { it('renders children when not loading', () => { const { getByText } = render( Submit ); expect(getByText('Submit')).toBeTruthy(); }); it('renders loading state when isLoading is true', () => { const { getByText } = render( Submit ); expect(getByText('Loading...')).toBeTruthy(); }); it('renders custom loading text', () => { const { getByText } = render( Submit ); expect(getByText('Saving...')).toBeTruthy(); }); });