import React from 'react'; import { render } from '@testing-library/react-native'; import { Text, Platform } from 'react-native'; import { GlassCard } from '@/components/ui/GlassCard'; // Mock expo-blur jest.mock('expo-blur', () => { const React = require('react'); const { View } = require('react-native'); return { BlurView: ({ children, intensity, tint, style, ...props }: any) => React.createElement( View, { ...props, style, testID: 'blur-view', 'data-intensity': intensity, 'data-tint': tint }, children ), }; }); // Store original Platform.OS const originalPlatformOS = Platform.OS; describe('GlassCard', () => { beforeEach(() => { jest.clearAllMocks(); // Reset to iOS for consistent testing Object.defineProperty(Platform, 'OS', { get: () => 'ios', }); }); afterAll(() => { Object.defineProperty(Platform, 'OS', { get: () => originalPlatformOS, }); }); describe('rendering', () => { it('renders children correctly', () => { const { getByText } = render( Card Content ); expect(getByText('Card Content')).toBeTruthy(); }); it('renders multiple children', () => { const { getByText } = render( First Child Second Child ); expect(getByText('First Child')).toBeTruthy(); expect(getByText('Second Child')).toBeTruthy(); }); it('renders nested components', () => { const { getByText, getByTestId } = render( Nested Content ); expect(getByTestId('nested-text')).toBeTruthy(); expect(getByText('Nested Content')).toBeTruthy(); }); }); describe('platform behavior', () => { // GlassCard now uses solid backgrounds instead of BlurView for reliability it('renders correctly on iOS', () => { Object.defineProperty(Platform, 'OS', { get: () => 'ios', }); const { getByText } = render( iOS Card ); expect(getByText('iOS Card')).toBeTruthy(); }); it('renders correctly', () => { const { getByText } = render( Card Content ); expect(getByText('Card Content')).toBeTruthy(); }); }); describe('intensity prop', () => { // Note: intensity prop is kept for API compatibility but no longer affects visual rendering // since BlurView was replaced with solid backgrounds for reliability beforeEach(() => { Object.defineProperty(Platform, 'OS', { get: () => 'ios', }); }); it('accepts light intensity prop', () => { const { getByText } = render( Light Card ); expect(getByText('Light Card')).toBeTruthy(); }); it('accepts medium intensity by default', () => { const { getByText } = render( Medium Card ); expect(getByText('Medium Card')).toBeTruthy(); }); it('accepts heavy intensity prop', () => { const { getByText } = render( Heavy Card ); expect(getByText('Heavy Card')).toBeTruthy(); }); }); describe('variant prop', () => { it('renders default variant', () => { const { getByText } = render( Default Card ); expect(getByText('Default Card')).toBeTruthy(); }); it('renders elevated variant', () => { const { getByText } = render( Elevated Card ); expect(getByText('Elevated Card')).toBeTruthy(); }); it('renders subtle variant', () => { const { getByText } = render( Subtle Card ); expect(getByText('Subtle Card')).toBeTruthy(); }); }); describe('noPadding prop', () => { it('has padding by default', () => { const { getByText } = render( Padded Card ); expect(getByText('Padded Card')).toBeTruthy(); }); it('removes padding when noPadding is true', () => { const { getByText } = render( No Padding Card ); expect(getByText('No Padding Card')).toBeTruthy(); }); }); describe('style prop', () => { it('applies custom style', () => { const customStyle = { marginTop: 20, backgroundColor: 'red' }; const { getByText } = render( Styled Card ); expect(getByText('Styled Card')).toBeTruthy(); }); it('merges custom style with default styles', () => { const { getByText } = render( Merged Styles Card ); expect(getByText('Merged Styles Card')).toBeTruthy(); }); }); describe('default props', () => { it('has default intensity of medium', () => { const { getByText } = render( Default Intensity ); expect(getByText('Default Intensity')).toBeTruthy(); }); it('has default variant of default', () => { const { getByText } = render( Default Variant ); expect(getByText('Default Variant')).toBeTruthy(); }); it('has noPadding false by default', () => { const { getByText } = render( Has Padding ); expect(getByText('Has Padding')).toBeTruthy(); }); }); describe('gradient highlight', () => { it('renders highlight gradient', () => { Object.defineProperty(Platform, 'OS', { get: () => 'ios', }); const { getByText } = render( Card with Highlight ); // LinearGradient is mocked to render as View, so we just verify the card renders expect(getByText('Card with Highlight')).toBeTruthy(); }); }); describe('accessibility', () => { it('renders children accessible to screen readers', () => { const { getByText } = render( Content ); const text = getByText('Content'); expect(text.props.accessibilityLabel).toBe('Accessible content'); }); }); describe('combination of props', () => { it('handles all props together', () => { const customStyle = { margin: 10 }; const { getByText } = render( Full Props Card ); expect(getByText('Full Props Card')).toBeTruthy(); }); }); });