1import { render, screen } from '@testing-library/react'; 2import { createRequire } from 'node:module'; 3 4import APISection from './APISection'; 5 6import { renderWithHeadings } from '~/common/test-utilities'; 7 8const require = createRequire(import.meta.url); 9 10describe('APISection', () => { 11 test('no data', () => { 12 const { container } = render(<APISection packageName="expo-none" testRequire={require} />); 13 14 expect(screen.getAllByText('No API data file found, sorry!')).toHaveLength(1); 15 16 expect(container).toMatchSnapshot(); 17 }); 18 19 test('expo-apple-authentication', () => { 20 const { container } = renderWithHeadings( 21 <APISection 22 packageName="expo-apple-authentication" 23 forceVersion="unversioned" 24 testRequire={require} 25 /> 26 ); 27 28 expect(screen.getAllByRole('heading', { level: 2 })).toHaveLength(6); 29 expect(screen.getAllByRole('heading', { level: 3 })).toHaveLength(25); 30 expect(screen.getAllByRole('table')).toHaveLength(11); 31 32 expect(screen.queryByText('Event Subscriptions')); 33 expect(screen.queryByText('Components')); 34 35 expect(screen.queryByDisplayValue('AppleAuthenticationButton')); 36 expect(screen.queryByDisplayValue('AppleAuthenticationButtonProps')); 37 expect(screen.queryByDisplayValue('Subscription')); 38 39 expect(screen.queryAllByText('Constants')).toHaveLength(0); 40 expect(screen.queryAllByText('Hooks')).toHaveLength(0); 41 expect(screen.queryAllByText('Interfaces')).toHaveLength(0); 42 43 expect(container).toMatchSnapshot(); 44 }); 45 46 test('expo-barcode-scanner', () => { 47 const { container } = renderWithHeadings( 48 <APISection 49 packageName="expo-barcode-scanner" 50 apiName="BarCodeScanner" 51 forceVersion="unversioned" 52 testRequire={require} 53 /> 54 ); 55 56 expect(screen.getAllByRole('heading', { level: 2 })).toHaveLength(7); 57 expect(screen.getAllByRole('heading', { level: 3 })).toHaveLength(19); 58 59 expect(screen.queryByText('Components')); 60 expect(screen.queryByText('Hooks')); 61 62 expect(screen.queryByDisplayValue('BarCodeEvent')); 63 expect(screen.queryByDisplayValue('BarCodeScannerProps')); 64 expect(screen.queryByDisplayValue('Subscription')); 65 expect(screen.queryByDisplayValue('usePermissions')); 66 expect(screen.queryByDisplayValue('Inherited Props')); 67 68 expect(screen.queryAllByText('Constants')).toHaveLength(0); 69 70 expect(container).toMatchSnapshot(); 71 }); 72 73 test('expo-pedometer', () => { 74 const { container } = renderWithHeadings( 75 <APISection packageName="expo-pedometer" forceVersion="unversioned" testRequire={require} /> 76 ); 77 78 expect(screen.getAllByRole('heading', { level: 2 })).toHaveLength(4); 79 expect(screen.getAllByRole('heading', { level: 3 })).toHaveLength(11); 80 expect(screen.getAllByRole('table')).toHaveLength(6); 81 82 expect(screen.queryByText('Methods')); 83 expect(screen.queryByText('Enums')); 84 expect(screen.queryByText('Interfaces')); 85 expect(screen.queryByText('Types')); 86 87 expect(screen.queryByDisplayValue('PermissionResponse')); 88 expect(screen.queryByDisplayValue('PermissionStatus')); 89 90 expect(screen.queryAllByText('Constants')).toHaveLength(0); 91 expect(screen.queryAllByText('Event Subscriptions')).toHaveLength(0); 92 expect(screen.queryAllByText('Hooks')).toHaveLength(0); 93 94 expect(container).toMatchSnapshot(); 95 }); 96 97 test('expo-asset', () => { 98 renderWithHeadings( 99 <APISection packageName="expo-asset" forceVersion="unversioned" testRequire={require} /> 100 ); 101 102 expect(screen.getAllByRole('heading', { level: 2 })).toHaveLength(3); 103 expect(screen.getAllByRole('heading', { level: 3 })).toHaveLength(18); 104 expect(screen.getAllByRole('table')).toHaveLength(7); 105 106 expect(screen.queryByText('Classes')); 107 expect(screen.queryByText('Asset Properties')); 108 expect(screen.queryByText('Asset Methods')); 109 110 expect(screen.queryByDisplayValue('localUri')); 111 expect(screen.queryByDisplayValue('fromURI()')); 112 113 expect(screen.queryAllByText('Props')).toHaveLength(0); 114 expect(screen.queryAllByText('Enums')).toHaveLength(0); 115 }); 116}); 117