1import { render } from '@testing-library/react'; 2import * as React from 'react'; 3 4import { resolveTypeName } from './APISectionUtils'; 5 6describe('APISectionUtils.resolveTypeName', () => { 7 test('void', () => { 8 const { container } = render(<>{resolveTypeName({ type: 'intrinsic', name: 'void' })}</>); 9 expect(container).toMatchSnapshot(); 10 }); 11 12 test('generic type', () => { 13 const { container } = render(<>{resolveTypeName({ type: 'intrinsic', name: 'string' })}</>); 14 expect(container).toMatchSnapshot(); 15 }); 16 17 test('custom type', () => { 18 const { container } = render( 19 <>{resolveTypeName({ type: 'reference', name: 'SpeechSynthesisEvent' })}</> 20 ); 21 expect(container).toMatchSnapshot(); 22 }); 23 24 test('custom type array', () => { 25 const { container } = render( 26 <> 27 {resolveTypeName({ 28 type: 'array', 29 elementType: { type: 'reference', name: 'AppleAuthenticationScope' }, 30 })} 31 </> 32 ); 33 expect(container).toMatchSnapshot(); 34 }); 35 36 test('Promise', () => { 37 const { container } = render( 38 <> 39 {resolveTypeName({ 40 type: 'reference', 41 typeArguments: [{ type: 'intrinsic', name: 'void' }], 42 name: 'Promise', 43 })} 44 </> 45 ); 46 expect(container).toMatchSnapshot(); 47 }); 48 49 test('Promise with custom type', () => { 50 const { container } = render( 51 <> 52 {resolveTypeName({ 53 type: 'reference', 54 typeArguments: [{ type: 'reference', name: 'AppleAuthenticationCredential' }], 55 name: 'Promise', 56 })} 57 </> 58 ); 59 expect(container).toMatchSnapshot(); 60 }); 61 62 test('Record', () => { 63 const { container } = render( 64 <> 65 {resolveTypeName({ 66 type: 'reference', 67 typeArguments: [ 68 { type: 'intrinsic', name: 'string' }, 69 { type: 'intrinsic', name: 'any' }, 70 ], 71 name: 'Record', 72 })} 73 </> 74 ); 75 expect(container).toMatchSnapshot(); 76 }); 77 78 test('union', () => { 79 const { container } = render( 80 <> 81 {resolveTypeName({ 82 type: 'union', 83 types: [ 84 { type: 'reference', name: 'SpeechEventCallback' }, 85 { type: 'literal', value: null }, 86 ], 87 })} 88 </> 89 ); 90 expect(container).toMatchSnapshot(); 91 }); 92 93 test('union with array', () => { 94 const { container } = render( 95 <> 96 {resolveTypeName({ 97 type: 'union', 98 types: [ 99 { type: 'array', elementType: { type: 'intrinsic', name: 'number' } }, 100 { type: 'literal', value: null }, 101 ], 102 })} 103 </> 104 ); 105 expect(container).toMatchSnapshot(); 106 }); 107 108 test('function', () => { 109 const { container } = render( 110 <> 111 {resolveTypeName({ 112 type: 'reflection', 113 declaration: { 114 signatures: [ 115 { 116 type: { 117 type: 'union', 118 types: [ 119 { type: 'intrinsic', name: 'void' }, 120 { 121 type: 'reference', 122 name: 'SpeechEventCallback', 123 }, 124 ], 125 }, 126 }, 127 ], 128 }, 129 })} 130 </> 131 ); 132 expect(container).toMatchSnapshot(); 133 }); 134 135 test('function with arguments', () => { 136 const { container } = render( 137 <> 138 {resolveTypeName({ 139 type: 'reflection', 140 declaration: { 141 signatures: [ 142 { 143 parameters: [ 144 { 145 name: 'error', 146 type: { type: 'reference', name: 'Error' }, 147 }, 148 ], 149 type: { 150 type: 'union', 151 types: [ 152 { type: 'intrinsic', name: 'void' }, 153 { type: 'reference', name: 'SpeechEventCallback' }, 154 ], 155 }, 156 }, 157 ], 158 }, 159 })} 160 </> 161 ); 162 expect(container).toMatchSnapshot(); 163 }); 164}); 165