|
1 | 1 | import 'jest-enzyme';
|
2 | 2 |
|
3 | 3 | import { mount, ReactWrapper } from 'enzyme';
|
4 |
| -import { JSONSchema4 } from 'json-schema'; |
| 4 | +import { JSONSchema4, JSONSchema7 } from 'json-schema'; |
5 | 5 | import * as React from 'react';
|
6 | 6 |
|
7 | 7 | import { JsonSchemaViewer } from '../components';
|
@@ -165,6 +165,228 @@ describe('HTML Output', () => {
|
165 | 165 | expect(dumpDom(<JsonSchemaViewer schema={schema} />)).toMatchSnapshot();
|
166 | 166 | });
|
167 | 167 |
|
| 168 | + it('given dictionary with defined properties, should not render them', () => { |
| 169 | + const schema: JSONSchema7 = { |
| 170 | + type: ['object', 'null'], |
| 171 | + properties: { |
| 172 | + id: { |
| 173 | + type: 'string', |
| 174 | + readOnly: true, |
| 175 | + }, |
| 176 | + description: { |
| 177 | + type: 'string', |
| 178 | + writeOnly: true, |
| 179 | + }, |
| 180 | + }, |
| 181 | + additionalProperties: { |
| 182 | + type: 'string', |
| 183 | + }, |
| 184 | + }; |
| 185 | + |
| 186 | + expect(dumpDom(<JsonSchemaViewer schema={schema} defaultExpandedDepth={Infinity} />)).toMatchInlineSnapshot(` |
| 187 | + "<div class=\\"\\" id=\\"mosaic-provider-react-aria-0-1\\"> |
| 188 | + <div data-overlay-container=\\"true\\"> |
| 189 | + <div class=\\"JsonSchemaViewer\\"> |
| 190 | + <div></div> |
| 191 | + <div data-id=\\"bf8b96e78f11d\\" data-test=\\"schema-row\\"> |
| 192 | + <div> |
| 193 | + <div> |
| 194 | + <div> |
| 195 | + <div> |
| 196 | + <span data-test=\\"property-type\\">dictionary[string, string]</span> |
| 197 | + <span>or</span> |
| 198 | + <span data-test=\\"property-type\\">null</span> |
| 199 | + </div> |
| 200 | + </div> |
| 201 | + </div> |
| 202 | + </div> |
| 203 | + </div> |
| 204 | + </div> |
| 205 | + </div> |
| 206 | + </div> |
| 207 | + " |
| 208 | + `); |
| 209 | + }); |
| 210 | + |
| 211 | + it('should render top-level dictionary', () => { |
| 212 | + const schema: JSONSchema7 = { |
| 213 | + type: 'object', |
| 214 | + additionalProperties: { |
| 215 | + type: 'string', |
| 216 | + }, |
| 217 | + }; |
| 218 | + |
| 219 | + expect(dumpDom(<JsonSchemaViewer schema={schema} defaultExpandedDepth={Infinity} />)).toMatchInlineSnapshot(` |
| 220 | + "<div class=\\"\\" id=\\"mosaic-provider-react-aria-0-1\\"> |
| 221 | + <div data-overlay-container=\\"true\\"> |
| 222 | + <div class=\\"JsonSchemaViewer\\"> |
| 223 | + <div></div> |
| 224 | + <div data-id=\\"bf8b96e78f11d\\" data-test=\\"schema-row\\"> |
| 225 | + <div> |
| 226 | + <div> |
| 227 | + <div><span data-test=\\"property-type\\">dictionary[string, string]</span></div> |
| 228 | + </div> |
| 229 | + </div> |
| 230 | + </div> |
| 231 | + </div> |
| 232 | + </div> |
| 233 | + </div> |
| 234 | + " |
| 235 | + `); |
| 236 | + }); |
| 237 | + |
| 238 | + it('should not merge array of dictionaries', () => { |
| 239 | + const schema: JSONSchema7 = { |
| 240 | + type: 'array', |
| 241 | + items: { |
| 242 | + type: 'object', |
| 243 | + additionalProperties: { |
| 244 | + type: 'string', |
| 245 | + }, |
| 246 | + }, |
| 247 | + }; |
| 248 | + |
| 249 | + expect(dumpDom(<JsonSchemaViewer schema={schema} defaultExpandedDepth={Infinity} />)).toMatchInlineSnapshot(` |
| 250 | + "<div class=\\"\\" id=\\"mosaic-provider-react-aria-0-1\\"> |
| 251 | + <div data-overlay-container=\\"true\\"> |
| 252 | + <div class=\\"JsonSchemaViewer\\"> |
| 253 | + <div></div> |
| 254 | + <div data-id=\\"bf8b96e78f11d\\" data-test=\\"schema-row\\"> |
| 255 | + <div> |
| 256 | + <div> |
| 257 | + <div role=\\"button\\"></div> |
| 258 | + <div><span data-test=\\"property-type\\">array</span></div> |
| 259 | + </div> |
| 260 | + </div> |
| 261 | + </div> |
| 262 | + <div data-level=\\"0\\"> |
| 263 | + <div data-id=\\"98538b996305d\\" data-test=\\"schema-row\\"> |
| 264 | + <div> |
| 265 | + <div> |
| 266 | + <div><span data-test=\\"property-type\\">dictionary[string, string]</span></div> |
| 267 | + </div> |
| 268 | + </div> |
| 269 | + </div> |
| 270 | + </div> |
| 271 | + </div> |
| 272 | + </div> |
| 273 | + </div> |
| 274 | + " |
| 275 | + `); |
| 276 | + }); |
| 277 | + |
| 278 | + it('should merge dictionaries with array values', () => { |
| 279 | + const schema: JSONSchema7 = { |
| 280 | + type: 'object', |
| 281 | + additionalProperties: { |
| 282 | + type: 'array', |
| 283 | + items: { |
| 284 | + type: 'string', |
| 285 | + }, |
| 286 | + }, |
| 287 | + }; |
| 288 | + |
| 289 | + expect(dumpDom(<JsonSchemaViewer schema={schema} defaultExpandedDepth={Infinity} />)).toMatchInlineSnapshot(` |
| 290 | + "<div class=\\"\\" id=\\"mosaic-provider-react-aria-0-1\\"> |
| 291 | + <div data-overlay-container=\\"true\\"> |
| 292 | + <div class=\\"JsonSchemaViewer\\"> |
| 293 | + <div></div> |
| 294 | + <div data-id=\\"bf8b96e78f11d\\" data-test=\\"schema-row\\"> |
| 295 | + <div> |
| 296 | + <div> |
| 297 | + <div role=\\"button\\"></div> |
| 298 | + <div><span data-test=\\"property-type\\">dictionary[string, array]</span></div> |
| 299 | + </div> |
| 300 | + </div> |
| 301 | + </div> |
| 302 | + <div data-level=\\"0\\"> |
| 303 | + <div data-id=\\"98538b996305d\\" data-test=\\"schema-row\\"> |
| 304 | + <div> |
| 305 | + <div> |
| 306 | + <div><span data-test=\\"property-type\\">string</span></div> |
| 307 | + </div> |
| 308 | + </div> |
| 309 | + </div> |
| 310 | + </div> |
| 311 | + </div> |
| 312 | + </div> |
| 313 | + </div> |
| 314 | + " |
| 315 | + `); |
| 316 | + }); |
| 317 | + |
| 318 | + it('should not render true/false additionalProperties', () => { |
| 319 | + const schema: JSONSchema7 = { |
| 320 | + type: 'object', |
| 321 | + properties: { |
| 322 | + id: { |
| 323 | + type: 'string', |
| 324 | + }, |
| 325 | + }, |
| 326 | + additionalProperties: true, |
| 327 | + }; |
| 328 | + |
| 329 | + const additionalTrue = dumpDom(<JsonSchemaViewer schema={schema} defaultExpandedDepth={Infinity} />); |
| 330 | + const additionalFalse = dumpDom( |
| 331 | + <JsonSchemaViewer schema={{ ...schema, additionalProperties: false }} defaultExpandedDepth={Infinity} />, |
| 332 | + ); |
| 333 | + expect(additionalTrue).toEqual(additionalFalse); |
| 334 | + expect(additionalTrue).toMatchInlineSnapshot(` |
| 335 | + "<div class=\\"\\" id=\\"mosaic-provider-react-aria-0-1\\"> |
| 336 | + <div data-overlay-container=\\"true\\"> |
| 337 | + <div class=\\"JsonSchemaViewer\\"> |
| 338 | + <div></div> |
| 339 | + <div data-level=\\"0\\"> |
| 340 | + <div data-id=\\"8074f410d9775\\" data-test=\\"schema-row\\"> |
| 341 | + <div> |
| 342 | + <div> |
| 343 | + <div> |
| 344 | + <div data-test=\\"property-name-id\\">id</div> |
| 345 | + <span data-test=\\"property-type\\">string</span> |
| 346 | + </div> |
| 347 | + </div> |
| 348 | + </div> |
| 349 | + </div> |
| 350 | + </div> |
| 351 | + </div> |
| 352 | + </div> |
| 353 | + </div> |
| 354 | + " |
| 355 | + `); |
| 356 | + }); |
| 357 | + |
| 358 | + it('should not render additionalItems', () => { |
| 359 | + const schema: JSONSchema7 = { |
| 360 | + type: 'array', |
| 361 | + additionalItems: { |
| 362 | + type: 'object', |
| 363 | + properties: { |
| 364 | + id: { |
| 365 | + type: 'string', |
| 366 | + }, |
| 367 | + }, |
| 368 | + }, |
| 369 | + }; |
| 370 | + |
| 371 | + expect(dumpDom(<JsonSchemaViewer schema={schema} defaultExpandedDepth={Infinity} />)).toMatchInlineSnapshot(` |
| 372 | + "<div class=\\"\\" id=\\"mosaic-provider-react-aria-0-1\\"> |
| 373 | + <div data-overlay-container=\\"true\\"> |
| 374 | + <div class=\\"JsonSchemaViewer\\"> |
| 375 | + <div></div> |
| 376 | + <div data-id=\\"bf8b96e78f11d\\" data-test=\\"schema-row\\"> |
| 377 | + <div> |
| 378 | + <div> |
| 379 | + <div><span data-test=\\"property-type\\">array</span></div> |
| 380 | + </div> |
| 381 | + </div> |
| 382 | + </div> |
| 383 | + </div> |
| 384 | + </div> |
| 385 | + </div> |
| 386 | + " |
| 387 | + `); |
| 388 | + }); |
| 389 | + |
168 | 390 | describe('top level descriptions', () => {
|
169 | 391 | const schema: JSONSchema4 = {
|
170 | 392 | description: 'This is a description that should be rendered',
|
|
0 commit comments