@@ -364,3 +364,118 @@ describe("bug #5573: zero default and example values", function () {
364
364
expect ( props . onChange ) . toHaveBeenCalledWith ( paramValue , "0" , false )
365
365
} )
366
366
} )
367
+
368
+ describe ( "parameter constraints display" , ( ) => {
369
+ const createProps = ( { param, isOAS3 } ) => {
370
+ const getSystem = ( ) => ( {
371
+ getComponent : ( ) => "div" ,
372
+ specSelectors : {
373
+ parameterWithMetaByIdentity : ( ) => param ,
374
+ isOAS3 : ( ) => isOAS3 ,
375
+ isSwagger2 : ( ) => ! isOAS3 ,
376
+ } ,
377
+ fn : {
378
+ memoizedSampleFromSchema,
379
+ memoizedCreateXMLExample,
380
+ getSchemaObjectTypeLabel,
381
+ getSchemaObjectType,
382
+ getJsonSampleSchema : makeGetJsonSampleSchema ( getSystem ) ,
383
+ getYamlSampleSchema : makeGetYamlSampleSchema ( getSystem ) ,
384
+ getXmlSampleSchema : makeGetXmlSampleSchema ( getSystem ) ,
385
+ getSampleSchema : makeGetSampleSchema ( getSystem ) ,
386
+ mergeJsonSchema,
387
+ } ,
388
+ oas3Selectors : { activeExamplesMember : ( ) => { } } ,
389
+ getConfigs : ( ) => ( { } ) ,
390
+ } )
391
+
392
+ return {
393
+ ...getSystem ( ) ,
394
+ param,
395
+ rawParam : param ,
396
+ pathMethod : [ ] ,
397
+ }
398
+ }
399
+
400
+ it ( "should display minimum constraint" , ( ) => {
401
+ const param = fromJS ( {
402
+ name : "id" ,
403
+ in : "path" ,
404
+ required : true ,
405
+ schema : {
406
+ type : "integer" ,
407
+ minimum : 1
408
+ }
409
+ } )
410
+
411
+ const props = createProps ( { param, isOAS3 : true } )
412
+ const wrapper = render ( < ParameterRow { ...props } /> )
413
+
414
+ // Check if constraint text is rendered somewhere in the component
415
+ expect ( wrapper . html ( ) ) . toContain ( "≥ 1" )
416
+ } )
417
+
418
+ it ( "should display maximum constraint" , ( ) => {
419
+ const param = fromJS ( {
420
+ name : "limit" ,
421
+ in : "query" ,
422
+ schema : {
423
+ type : "integer" ,
424
+ maximum : 100
425
+ }
426
+ } )
427
+
428
+ const props = createProps ( { param, isOAS3 : true } )
429
+ const wrapper = render ( < ParameterRow { ...props } /> )
430
+
431
+ expect ( wrapper . html ( ) ) . toContain ( "≤ 100" )
432
+ } )
433
+
434
+ it ( "should display exclusive minimum constraint" , ( ) => {
435
+ const param = fromJS ( {
436
+ name : "price" ,
437
+ in : "query" ,
438
+ schema : {
439
+ type : "number" ,
440
+ exclusiveMinimum : 0
441
+ }
442
+ } )
443
+
444
+ const props = createProps ( { param, isOAS3 : true } )
445
+ const wrapper = render ( < ParameterRow { ...props } /> )
446
+
447
+ expect ( wrapper . html ( ) ) . toContain ( "> 0" )
448
+ } )
449
+
450
+ it ( "should display range constraints" , ( ) => {
451
+ const param = fromJS ( {
452
+ name : "range" ,
453
+ in : "query" ,
454
+ schema : {
455
+ type : "integer" ,
456
+ minimum : 1 ,
457
+ maximum : 100
458
+ }
459
+ } )
460
+
461
+ const props = createProps ( { param, isOAS3 : true } )
462
+ const wrapper = render ( < ParameterRow { ...props } /> )
463
+
464
+ expect ( wrapper . html ( ) ) . toContain ( "[1, 100]" )
465
+ } )
466
+
467
+ it ( "should not display constraints when none are present" , ( ) => {
468
+ const param = fromJS ( {
469
+ name : "name" ,
470
+ in : "query" ,
471
+ schema : {
472
+ type : "string"
473
+ }
474
+ } )
475
+
476
+ const props = createProps ( { param, isOAS3 : true } )
477
+ const wrapper = render ( < ParameterRow { ...props } /> )
478
+
479
+ expect ( wrapper . html ( ) ) . not . toContain ( "Constraints" )
480
+ } )
481
+ } )
0 commit comments