import React from 'react'; import { render, fireEvent } from '@testing-library/react-native'; import { Text } from 'react-native'; import { OverlayWidget } from '../components/OverlayWidget'; describe('OverlayWidget rendering', () => { it('should render children when visible is true for bottom position', () => { const { getByText } = render( Bottom Widget ); expect(getByText('Bottom Widget')).toBeTruthy(); }); it('should render children when visible is true for top position', () => { const { getByText } = render( Top Widget ); expect(getByText('Top Widget')).toBeTruthy(); }); it('should render close button when visible is true', () => { const { getByText } = render( Content ); expect(getByText('✕')).toBeTruthy(); }); it('should call onClose when close button is pressed', () => { const mockOnClose = jest.fn(); const { getByText } = render( Content ); fireEvent.press(getByText('✕')); expect(mockOnClose).toHaveBeenCalledTimes(1); }); it('should call onClose when close button is pressed and component is controlled by parent', () => { const mockOnClose = jest.fn(); const { getByText } = render( Dismissible Content ); fireEvent.press(getByText('✕')); expect(mockOnClose).toHaveBeenCalledTimes(1); }); it('should not render when visible prop is false', () => { const { queryByText } = render( Top Content ); expect(queryByText('Top Content')).toBeNull(); expect(queryByText('✕')).toBeNull(); }); it('should hide content when visible prop changes to false', () => { const { queryByText, rerender } = render( Content ); rerender( Content ); expect(queryByText('Content')).toBeNull(); }); it('should not call onClose if onClose prop is not provided', () => { const { getByText } = render( Content ); expect(() => fireEvent.press(getByText('✕'))).not.toThrow(); }); it('should hide close button when visible is false', () => { const { queryByText } = render( Content ); expect(queryByText('✕')).toBeNull(); }); it('should render multiple children', () => { const { getByText } = render( First Second ); expect(getByText('First')).toBeTruthy(); expect(getByText('Second')).toBeTruthy(); }); });