11import  {  ComponentType  }  from  'react' ; 
22import  renderer  from  'react-test-renderer' ; 
3- import  {  RJSFSchema  }  from  '@rjsf/utils' ; 
3+ import  {  RJSFSchema ,   UiSchema  }  from  '@rjsf/utils' ; 
44import  validator  from  '@rjsf/validator-ajv8' ; 
55
66import  {  FormProps  }  from  '../src' ; 
77
8- // export type ObjectRenderCustomOptions = { 
9- // checkboxes?: TestRendererOptions; 
10- // } 
8+ const  titleAndDesc  =  { 
9+  title : 'Test field' , 
10+  description : 'a test description' 
11+ } ; 
12+ 
13+ const  uiTitleAndDesc : UiSchema  =  { 
14+  'ui:options' : { 
15+  title : 'My Field' , 
16+  description : 'a fancier description' 
17+  } , 
18+  a : { 
19+  'ui:options' : { 
20+  title : 'My Item A' , 
21+  description : 'a fancier item A description' 
22+  } 
23+  } , 
24+  b : { 
25+  'ui:options' : { 
26+  title : 'My Item B' , 
27+  description : 'a fancier item B description' 
28+  } 
29+  } 
30+ 
31+ } ; 
32+ 
33+ const  labelsOff : UiSchema  =  { 
34+  'ui:globalOptions' : {  label : false  } 
35+ } ; 
1136
1237export  default  function  arrayTests ( Form : ComponentType < FormProps > )  { 
1338 describe ( 'object fields' ,  ( )  =>  { 
@@ -30,5 +55,95 @@ export default function arrayTests(Form: ComponentType<FormProps>) {
3055 const  tree  =  renderer . create ( < Form  schema = { schema }  validator = { validator }  formData = { {  foo : 'foo'  } }  /> ) . toJSON ( ) ; 
3156 expect ( tree ) . toMatchSnapshot ( ) ; 
3257 } ) ; 
58+  describe ( 'with title and description' ,  ( )  =>  { 
59+  test ( 'object' ,  ( )  =>  { 
60+  const  schema : RJSFSchema  =  { 
61+  type : 'object' , 
62+  ...titleAndDesc , 
63+  properties : { 
64+  a : {  type : 'string' ,  title : 'A' ,  description : 'A description'  } , 
65+  b : {  type : 'number' ,  title : 'B' ,  description : 'B description'  } , 
66+  } , 
67+  } ; 
68+  const  tree  =  renderer . create ( < Form  schema = { schema }  validator = { validator }  /> ) . toJSON ( ) ; 
69+  expect ( tree ) . toMatchSnapshot ( ) ; 
70+  } ) ; 
71+  test ( 'additionalProperties' ,  ( )  =>  { 
72+  const  schema : RJSFSchema  =  { 
73+  type : 'object' , 
74+  ...titleAndDesc , 
75+  additionalProperties : true , 
76+  } ; 
77+  const  tree  =  renderer . create ( < Form  schema = { schema }  validator = { validator }  formData = { {  foo : 'foo'  } }  /> ) . toJSON ( ) ; 
78+  expect ( tree ) . toMatchSnapshot ( ) ; 
79+  } ) ; 
80+  } ) ; 
81+  describe ( 'with title and description from uiSchema' ,  ( )  =>  { 
82+  test ( 'object' ,  ( )  =>  { 
83+  const  schema : RJSFSchema  =  { 
84+  type : 'object' , 
85+  properties : { 
86+  a : {  type : 'string' ,  title : 'A'  } , 
87+  b : {  type : 'number' ,  title : 'B'  } , 
88+  } , 
89+  } ; 
90+  const  tree  =  renderer . create ( < Form  schema = { schema }  uiSchema = { uiTitleAndDesc }  validator = { validator }  /> ) . toJSON ( ) ; 
91+  expect ( tree ) . toMatchSnapshot ( ) ; 
92+  } ) ; 
93+  test ( 'additionalProperties' ,  ( )  =>  { 
94+  const  schema : RJSFSchema  =  { 
95+  type : 'object' , 
96+  additionalProperties : true , 
97+  } ; 
98+  const  tree  =  renderer . create ( < Form  schema = { schema }  uiSchema = { uiTitleAndDesc }  validator = { validator }  formData = { {  foo : 'foo'  } }  /> ) . toJSON ( ) ; 
99+  expect ( tree ) . toMatchSnapshot ( ) ; 
100+  } ) ; 
101+  } ) ; 
102+  describe ( 'with title and description from both' ,  ( )  =>  { 
103+  test ( 'object' ,  ( )  =>  { 
104+  const  schema : RJSFSchema  =  { 
105+  type : 'object' , 
106+  ...titleAndDesc , 
107+  properties : { 
108+  a : {  type : 'string' ,  title : 'A' ,  description : 'A description'  } , 
109+  b : {  type : 'number' ,  title : 'B' ,  description : 'B description'  } , 
110+  } , 
111+  } ; 
112+  const  tree  =  renderer . create ( < Form  schema = { schema }  uiSchema = { uiTitleAndDesc }  validator = { validator }  /> ) . toJSON ( ) ; 
113+  expect ( tree ) . toMatchSnapshot ( ) ; 
114+  } ) ; 
115+  test ( 'additionalProperties' ,  ( )  =>  { 
116+  const  schema : RJSFSchema  =  { 
117+  type : 'object' , 
118+  ...titleAndDesc , 
119+  additionalProperties : true , 
120+  } ; 
121+  const  tree  =  renderer . create ( < Form  schema = { schema }  uiSchema = { uiTitleAndDesc }  validator = { validator }  formData = { {  foo : 'foo'  } }  /> ) . toJSON ( ) ; 
122+  expect ( tree ) . toMatchSnapshot ( ) ; 
123+  } ) ; 
124+  } ) ; 
125+  describe ( 'with title and description with global label off' ,  ( )  =>  { 
126+  test ( 'object' ,  ( )  =>  { 
127+  const  schema : RJSFSchema  =  { 
128+  type : 'object' , 
129+  ...titleAndDesc , 
130+  properties : { 
131+  a : {  type : 'string' ,  title : 'A' ,  description : 'A description'  } , 
132+  b : {  type : 'number' ,  title : 'B' ,  description : 'B description'  } , 
133+  } , 
134+  } ; 
135+  const  tree  =  renderer . create ( < Form  schema = { schema }  uiSchema = { labelsOff }  validator = { validator }  /> ) . toJSON ( ) ; 
136+  expect ( tree ) . toMatchSnapshot ( ) ; 
137+  } ) ; 
138+  test ( 'additionalProperties' ,  ( )  =>  { 
139+  const  schema : RJSFSchema  =  { 
140+  type : 'object' , 
141+  ...titleAndDesc , 
142+  additionalProperties : true , 
143+  } ; 
144+  const  tree  =  renderer . create ( < Form  schema = { schema }  uiSchema = { labelsOff }  validator = { validator }  formData = { {  foo : 'foo'  } }  /> ) . toJSON ( ) ; 
145+  expect ( tree ) . toMatchSnapshot ( ) ; 
146+  } ) ; 
147+  } ) ; 
33148 } ) ; 
34149} 
0 commit comments