@@ -103,11 +103,13 @@ describe("DynamicJsonForm String Fields", () => {
103
103
expect ( options ) . toHaveLength ( 4 ) ;
104
104
} ) ;
105
105
106
- it ( "should use enumNames for option labels " , ( ) => {
106
+ it ( "should use oneOf with const and title for labeled options " , ( ) => {
107
107
const schema : JsonSchemaType = {
108
108
type : "string" ,
109
- enum : [ "val1" , "val2" ] ,
110
- enumNames : [ "Label 1" , "Label 2" ] ,
109
+ oneOf : [
110
+ { const : "val1" , title : "Label 1" } ,
111
+ { const : "val2" , title : "Label 2" } ,
112
+ ] ,
111
113
description : "Select with labels" ,
112
114
} ;
113
115
render ( < DynamicJsonForm schema = { schema } value = "" onChange = { jest . fn ( ) } /> ) ;
@@ -117,6 +119,24 @@ describe("DynamicJsonForm String Fields", () => {
117
119
expect ( options [ 2 ] ) . toHaveProperty ( "textContent" , "Label 2" ) ;
118
120
} ) ;
119
121
122
+ it ( "should call onChange with selected oneOf value" , ( ) => {
123
+ const onChange = jest . fn ( ) ;
124
+ const schema : JsonSchemaType = {
125
+ type : "string" ,
126
+ oneOf : [
127
+ { const : "option1" , title : "Option 1" } ,
128
+ { const : "option2" , title : "Option 2" } ,
129
+ ] ,
130
+ description : "Select an option" ,
131
+ } ;
132
+ render ( < DynamicJsonForm schema = { schema } value = "" onChange = { onChange } /> ) ;
133
+
134
+ const select = screen . getByRole ( "combobox" ) ;
135
+ fireEvent . change ( select , { target : { value : "option1" } } ) ;
136
+
137
+ expect ( onChange ) . toHaveBeenCalledWith ( "option1" ) ;
138
+ } ) ;
139
+
120
140
it ( "should call onChange with selected enum value" , ( ) => {
121
141
const onChange = jest . fn ( ) ;
122
142
const schema : JsonSchemaType = {
@@ -131,6 +151,44 @@ describe("DynamicJsonForm String Fields", () => {
131
151
132
152
expect ( onChange ) . toHaveBeenCalledWith ( "option1" ) ;
133
153
} ) ;
154
+
155
+ it ( "should render JSON Schema spec compliant oneOf with const for labeled enums" , ( ) => {
156
+ // Example from JSON Schema spec: labeled enums using oneOf with const
157
+ const onChange = jest . fn ( ) ;
158
+ const schema : JsonSchemaType = {
159
+ type : "string" ,
160
+ title : "Traffic Light" ,
161
+ description : "Select a traffic light color" ,
162
+ oneOf : [
163
+ { const : "red" , title : "Stop" } ,
164
+ { const : "amber" , title : "Caution" } ,
165
+ { const : "green" , title : "Go" } ,
166
+ ] ,
167
+ } ;
168
+ render ( < DynamicJsonForm schema = { schema } value = "" onChange = { onChange } /> ) ;
169
+
170
+ // Should render as a select dropdown
171
+ const select = screen . getByRole ( "combobox" ) ;
172
+ expect ( select . tagName ) . toBe ( "SELECT" ) ;
173
+
174
+ // Should have options with proper labels
175
+ const options = screen . getAllByRole ( "option" ) ;
176
+ expect ( options ) . toHaveLength ( 4 ) ; // 3 options + 1 default "Select an option..."
177
+
178
+ expect ( options [ 0 ] ) . toHaveProperty ( "textContent" , "Select an option..." ) ;
179
+ expect ( options [ 1 ] ) . toHaveProperty ( "textContent" , "Stop" ) ;
180
+ expect ( options [ 2 ] ) . toHaveProperty ( "textContent" , "Caution" ) ;
181
+ expect ( options [ 3 ] ) . toHaveProperty ( "textContent" , "Go" ) ;
182
+
183
+ // Should have proper values
184
+ expect ( options [ 1 ] ) . toHaveProperty ( "value" , "red" ) ;
185
+ expect ( options [ 2 ] ) . toHaveProperty ( "value" , "amber" ) ;
186
+ expect ( options [ 3 ] ) . toHaveProperty ( "value" , "green" ) ;
187
+
188
+ // Test onChange behavior
189
+ fireEvent . change ( select , { target : { value : "amber" } } ) ;
190
+ expect ( onChange ) . toHaveBeenCalledWith ( "amber" ) ;
191
+ } ) ;
134
192
} ) ;
135
193
136
194
describe ( "Validation Attributes" , ( ) => {
@@ -464,8 +522,8 @@ describe("DynamicJsonForm Object Fields", () => {
464
522
< DynamicJsonForm schema = { schema } value = { { } } onChange = { jest . fn ( ) } /> ,
465
523
) ;
466
524
467
- const nameLabel = screen . getByText ( "Name " ) ;
468
- const optionalLabel = screen . getByText ( "Optional " ) ;
525
+ const nameLabel = screen . getByText ( "name " ) ;
526
+ const optionalLabel = screen . getByText ( "optional " ) ;
469
527
470
528
const nameInput = nameLabel . closest ( "div" ) ?. querySelector ( "input" ) ;
471
529
const optionalInput = optionalLabel
0 commit comments