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('query type', () => { 37 const { container } = render( 38 <> 39 {resolveTypeName({ 40 type: 'reference', 41 typeArguments: [{ queryType: { type: 'reference', name: 'View' }, type: 'query' }], 42 name: 'React.ComponentProps', 43 })} 44 </> 45 ); 46 expect(container).toMatchSnapshot(); 47 }); 48 49 test('Promise', () => { 50 const { container } = render( 51 <> 52 {resolveTypeName({ 53 type: 'reference', 54 typeArguments: [{ type: 'intrinsic', name: 'void' }], 55 name: 'Promise', 56 })} 57 </> 58 ); 59 expect(container).toMatchSnapshot(); 60 }); 61 62 test('Promise with custom type', () => { 63 const { container } = render( 64 <> 65 {resolveTypeName({ 66 type: 'reference', 67 typeArguments: [{ type: 'reference', name: 'AppleAuthenticationCredential' }], 68 name: 'Promise', 69 })} 70 </> 71 ); 72 expect(container).toMatchSnapshot(); 73 }); 74 75 test('Record', () => { 76 const { container } = render( 77 <> 78 {resolveTypeName({ 79 type: 'reference', 80 typeArguments: [ 81 { type: 'intrinsic', name: 'string' }, 82 { type: 'intrinsic', name: 'any' }, 83 ], 84 name: 'Record', 85 })} 86 </> 87 ); 88 expect(container).toMatchSnapshot(); 89 }); 90 91 test('Record with union', () => { 92 const { container } = render( 93 <> 94 {resolveTypeName({ 95 type: 'reference', 96 typeArguments: [ 97 { type: 'intrinsic', name: 'string' }, 98 { 99 type: 'union', 100 types: [ 101 { type: 'intrinsic', name: 'number' }, 102 { type: 'intrinsic', name: 'boolean' }, 103 { type: 'intrinsic', name: 'string' }, 104 ], 105 }, 106 ], 107 name: 'Record', 108 })} 109 </> 110 ); 111 expect(container).toMatchSnapshot(); 112 }); 113 114 test('union', () => { 115 const { container } = render( 116 <> 117 {resolveTypeName({ 118 type: 'union', 119 types: [ 120 { type: 'reference', name: 'SpeechEventCallback' }, 121 { type: 'literal', value: null }, 122 ], 123 })} 124 </> 125 ); 126 expect(container).toMatchSnapshot(); 127 }); 128 129 test('union with array', () => { 130 const { container } = render( 131 <> 132 {resolveTypeName({ 133 type: 'union', 134 types: [ 135 { type: 'array', elementType: { type: 'intrinsic', name: 'number' } }, 136 { type: 'literal', value: null }, 137 ], 138 })} 139 </> 140 ); 141 expect(container).toMatchSnapshot(); 142 }); 143 144 test('function', () => { 145 const { container } = render( 146 <> 147 {resolveTypeName({ 148 type: 'reflection', 149 declaration: { 150 signatures: [ 151 { 152 type: { 153 type: 'union', 154 types: [ 155 { type: 'intrinsic', name: 'void' }, 156 { 157 type: 'reference', 158 name: 'SpeechEventCallback', 159 }, 160 ], 161 }, 162 }, 163 ], 164 }, 165 })} 166 </> 167 ); 168 expect(container).toMatchSnapshot(); 169 }); 170 171 test('function with arguments', () => { 172 const { container } = render( 173 <> 174 {resolveTypeName({ 175 type: 'reflection', 176 declaration: { 177 signatures: [ 178 { 179 parameters: [ 180 { 181 name: 'error', 182 type: { type: 'reference', name: 'Error' }, 183 }, 184 ], 185 type: { 186 type: 'union', 187 types: [ 188 { type: 'intrinsic', name: 'void' }, 189 { type: 'reference', name: 'SpeechEventCallback' }, 190 ], 191 }, 192 }, 193 ], 194 }, 195 })} 196 </> 197 ); 198 expect(container).toMatchSnapshot(); 199 }); 200 201 test('function with non-linkable custom type', () => { 202 const { container } = render( 203 <> 204 {resolveTypeName({ 205 type: 'reflection', 206 declaration: { 207 signatures: [ 208 { 209 parameters: [ 210 { 211 name: 'error', 212 type: { type: 'reference', name: 'Error' }, 213 }, 214 ], 215 type: { type: 'intrinsic', name: 'void' }, 216 }, 217 ], 218 }, 219 })} 220 </> 221 ); 222 expect(container).toMatchSnapshot(); 223 }); 224}); 225