@@ -22,6 +22,62 @@ export default function getDefaultFormStateTest(testValidator: TestValidatorType
2222 it ( 'throws error when schema is not an object' , ( ) => {
2323 expect ( ( ) => getDefaultFormState ( testValidator , null as unknown as RJSFSchema ) ) . toThrowError ( 'Invalid schema:' ) ;
2424 } ) ;
25+ it ( 'test an object const value merge with formData' , ( ) => {
26+ const schema : RJSFSchema = {
27+ type : 'object' ,
28+ properties : {
29+ localConst : {
30+ type : 'string' ,
31+ const : 'local' ,
32+ } ,
33+ RootConst : {
34+ type : 'object' ,
35+ properties : {
36+ attr1 : {
37+ type : 'number' ,
38+ } ,
39+ attr2 : {
40+ type : 'boolean' ,
41+ } ,
42+ } ,
43+ const : {
44+ attr1 : 1 ,
45+ attr2 : true ,
46+ } ,
47+ } ,
48+ RootAndLocalConst : {
49+ type : 'string' ,
50+ const : 'FromLocal' ,
51+ } ,
52+ fromFormData : {
53+ type : 'string' ,
54+ } ,
55+ } ,
56+ const : {
57+ RootAndLocalConst : 'FromRoot' ,
58+ } ,
59+ } ;
60+ expect (
61+ getDefaultFormState (
62+ testValidator ,
63+ schema ,
64+ {
65+ fromFormData : 'fromFormData' ,
66+ } ,
67+ schema ,
68+ false ,
69+ { emptyObjectFields : 'skipDefaults' }
70+ )
71+ ) . toEqual ( {
72+ localConst : 'local' ,
73+ RootConst : {
74+ attr1 : 1 ,
75+ attr2 : true ,
76+ } ,
77+ RootAndLocalConst : 'FromLocal' ,
78+ fromFormData : 'fromFormData' ,
79+ } ) ;
80+ } ) ;
2581 it ( 'getInnerSchemaForArrayItem() item of type boolean returns empty schema' , ( ) => {
2682 expect ( getInnerSchemaForArrayItem ( { items : [ true ] } , AdditionalItemsHandling . Ignore , 0 ) ) . toEqual ( { } ) ;
2783 } ) ;
@@ -48,7 +104,7 @@ export default function getDefaultFormStateTest(testValidator: TestValidatorType
48104 foo : 42 ,
49105 } ) ;
50106 } ) ;
51- it ( 'test computeDefaults that is passed a schema with a cont property' , ( ) => {
107+ it ( 'test computeDefaults that is passed a schema with a const property' , ( ) => {
52108 const schema : RJSFSchema = {
53109 type : 'object' ,
54110 properties : {
@@ -885,6 +941,9 @@ export default function getDefaultFormStateTest(testValidator: TestValidatorType
885941 attr2 : true ,
886942 } ,
887943 } ,
944+ fromFormData : {
945+ type : 'string' ,
946+ } ,
888947 RootAndLocalConst : {
889948 type : 'string' ,
890949 const : 'FromLocal' ,
@@ -898,6 +957,9 @@ export default function getDefaultFormStateTest(testValidator: TestValidatorType
898957 getObjectDefaults ( testValidator , schema , {
899958 rootSchema : schema ,
900959 experimental_defaultFormStateBehavior : { emptyObjectFields : 'skipDefaults' } ,
960+ rawFormData : {
961+ fromFormData : 'fromFormData' ,
962+ } ,
901963 } )
902964 ) . toEqual ( {
903965 localConst : 'local' ,
0 commit comments