@@ -338,6 +338,232 @@ describe('mergeQueryParamsIntoFormData', () => {
338338 expect ( result ) . toEqual ( { language : 'Spanish' } ) ;
339339 } ) ;
340340
341+ it ( 'coerces numeric enum values' , ( ) => {
342+ const schema = {
343+ type : 'object' ,
344+ properties : {
345+ priority : {
346+ type : 'integer' ,
347+ enum : [ 1 , 2 , 3 ] ,
348+ } ,
349+ } ,
350+ } as JSONSchema7 ;
351+ const searchParams = new URLSearchParams ( 'priority=2' ) ;
352+ const baseData = { } ;
353+
354+ const result = mergeQueryParamsIntoFormData ( schema , searchParams , baseData ) ;
355+
356+ expect ( result ) . toEqual ( { priority : 2 } ) ;
357+ } ) ;
358+
359+ it ( 'skips numeric enum when value is not in enum' , ( ) => {
360+ const schema = {
361+ type : 'object' ,
362+ properties : {
363+ priority : {
364+ type : 'integer' ,
365+ enum : [ 1 , 2 , 3 ] ,
366+ } ,
367+ } ,
368+ } as JSONSchema7 ;
369+ const searchParams = new URLSearchParams ( 'priority=5' ) ;
370+ const baseData = { priority : 1 } ;
371+
372+ const result = mergeQueryParamsIntoFormData ( schema , searchParams , baseData ) ;
373+
374+ expect ( result ) . toEqual ( { priority : 1 } ) ;
375+ } ) ;
376+
377+ it ( 'coerces boolean enum values' , ( ) => {
378+ const schema = {
379+ type : 'object' ,
380+ properties : {
381+ enabled : {
382+ type : 'boolean' ,
383+ enum : [ true , false ] ,
384+ } ,
385+ } ,
386+ } as JSONSchema7 ;
387+ const searchParams = new URLSearchParams ( 'enabled=true' ) ;
388+ const baseData = { } ;
389+
390+ const result = mergeQueryParamsIntoFormData ( schema , searchParams , baseData ) ;
391+
392+ expect ( result ) . toEqual ( { enabled : true } ) ;
393+ } ) ;
394+
395+ it ( 'coerces boolean enum values (case-insensitive)' , ( ) => {
396+ const schema = {
397+ type : 'object' ,
398+ properties : {
399+ enabled : {
400+ type : 'boolean' ,
401+ enum : [ true , false ] ,
402+ } ,
403+ } ,
404+ } as JSONSchema7 ;
405+ const searchParams = new URLSearchParams ( 'enabled=FALSE' ) ;
406+ const baseData = { } ;
407+
408+ const result = mergeQueryParamsIntoFormData ( schema , searchParams , baseData ) ;
409+
410+ expect ( result ) . toEqual ( { enabled : false } ) ;
411+ } ) ;
412+
413+ it ( 'coerces plain number field without enum' , ( ) => {
414+ const schema = {
415+ type : 'object' ,
416+ properties : {
417+ count : { type : 'number' } ,
418+ } ,
419+ } as JSONSchema7 ;
420+ const searchParams = new URLSearchParams ( 'count=42.5' ) ;
421+ const baseData = { } ;
422+
423+ const result = mergeQueryParamsIntoFormData ( schema , searchParams , baseData ) ;
424+
425+ expect ( result ) . toEqual ( { count : 42.5 } ) ;
426+ } ) ;
427+
428+ it ( 'coerces plain integer field without enum' , ( ) => {
429+ const schema = {
430+ type : 'object' ,
431+ properties : {
432+ count : { type : 'integer' } ,
433+ } ,
434+ } as JSONSchema7 ;
435+ const searchParams = new URLSearchParams ( 'count=42' ) ;
436+ const baseData = { } ;
437+
438+ const result = mergeQueryParamsIntoFormData ( schema , searchParams , baseData ) ;
439+
440+ expect ( result ) . toEqual ( { count : 42 } ) ;
441+ } ) ;
442+
443+ it ( 'skips integer field when value is not an integer' , ( ) => {
444+ const schema = {
445+ type : 'object' ,
446+ properties : {
447+ count : { type : 'integer' } ,
448+ } ,
449+ } as JSONSchema7 ;
450+ const searchParams = new URLSearchParams ( 'count=42.5' ) ;
451+ const baseData = { count : 10 } ;
452+
453+ const result = mergeQueryParamsIntoFormData ( schema , searchParams , baseData ) ;
454+
455+ expect ( result ) . toEqual ( { count : 10 } ) ;
456+ } ) ;
457+
458+ it ( 'coerces plain boolean field without enum' , ( ) => {
459+ const schema = {
460+ type : 'object' ,
461+ properties : {
462+ active : { type : 'boolean' } ,
463+ } ,
464+ } as JSONSchema7 ;
465+ const searchParams = new URLSearchParams ( 'active=true' ) ;
466+ const baseData = { } ;
467+
468+ const result = mergeQueryParamsIntoFormData ( schema , searchParams , baseData ) ;
469+
470+ expect ( result ) . toEqual ( { active : true } ) ;
471+ } ) ;
472+
473+ it ( 'prepopulates fields defined via $ref in $defs' , ( ) => {
474+ const schema = {
475+ type : 'object' ,
476+ $defs : {
477+ LanguageField : {
478+ type : 'string' ,
479+ enum : [ 'English' , 'Spanish' ] ,
480+ } ,
481+ } ,
482+ properties : {
483+ language : { $ref : '#/$defs/LanguageField' } ,
484+ name : { type : 'string' } ,
485+ } ,
486+ } as JSONSchema7 ;
487+ const searchParams = new URLSearchParams ( 'language=english&name=alice' ) ;
488+ const baseData = { } ;
489+
490+ const result = mergeQueryParamsIntoFormData ( schema , searchParams , baseData ) ;
491+
492+ expect ( result ) . toEqual ( { language : 'English' , name : 'alice' } ) ;
493+ } ) ;
494+
495+ it ( 'prepopulates nested fields when step uses $ref' , ( ) => {
496+ const schema = {
497+ type : 'object' ,
498+ $defs : {
499+ InputsStep : {
500+ type : 'object' ,
501+ properties : {
502+ language : { type : 'string' , enum : [ 'English' , 'Spanish' ] } ,
503+ name : { type : 'string' } ,
504+ } ,
505+ } ,
506+ } ,
507+ properties : {
508+ step1 : { $ref : '#/$defs/InputsStep' } ,
509+ } ,
510+ } as JSONSchema7 ;
511+ const searchParams = new URLSearchParams (
512+ 'step1.language=Spanish&step1.name=bob' ,
513+ ) ;
514+ const baseData = { } ;
515+
516+ const result = mergeQueryParamsIntoFormData ( schema , searchParams , baseData ) ;
517+
518+ expect ( result ) . toEqual ( {
519+ step1 : { language : 'Spanish' , name : 'bob' } ,
520+ } ) ;
521+ } ) ;
522+
523+ it ( 'prepopulates nested $ref with enum coercion' , ( ) => {
524+ const schema = {
525+ type : 'object' ,
526+ $defs : {
527+ LanguageEnum : {
528+ type : 'string' ,
529+ enum : [ 'English' , 'Spanish' , 'French' ] ,
530+ } ,
531+ } ,
532+ properties : {
533+ step1 : {
534+ type : 'object' ,
535+ properties : {
536+ language : { $ref : '#/$defs/LanguageEnum' } ,
537+ } ,
538+ } ,
539+ } ,
540+ } as JSONSchema7 ;
541+ const searchParams = new URLSearchParams ( 'step1.language=french' ) ;
542+ const baseData = { } ;
543+
544+ const result = mergeQueryParamsIntoFormData ( schema , searchParams , baseData ) ;
545+
546+ expect ( result ) . toEqual ( { step1 : { language : 'French' } } ) ;
547+ } ) ;
548+
549+ it ( 'prepopulates with #/definitions/ (legacy JSON Schema)' , ( ) => {
550+ const schema = {
551+ type : 'object' ,
552+ definitions : {
553+ NameField : { type : 'string' } ,
554+ } ,
555+ properties : {
556+ name : { $ref : '#/definitions/NameField' } ,
557+ } ,
558+ } as JSONSchema7 ;
559+ const searchParams = new URLSearchParams ( 'name=charlie' ) ;
560+ const baseData = { } ;
561+
562+ const result = mergeQueryParamsIntoFormData ( schema , searchParams , baseData ) ;
563+
564+ expect ( result ) . toEqual ( { name : 'charlie' } ) ;
565+ } ) ;
566+
341567 it ( 'does not mutate base data' , ( ) => {
342568 const schema = {
343569 type : 'object' ,
0 commit comments