@@ -2,13 +2,14 @@ import React from 'react';
22import Enzyme , { mount } from 'enzyme' ;
33import Adapter from 'enzyme-adapter-react-16' ;
44import {
5+ CellProps ,
56 ControlProps ,
67 OwnPropsOfEnum ,
78 rankWith
89} from '@jsonforms/core' ;
910
1011import { JsonForms } from '../src/JsonForms' ;
11- import { withJsonFormsEnumProps } from '../src/JsonFormsContext' ;
12+ import { withJsonFormsEnumCellProps , withJsonFormsEnumProps } from '../src/JsonFormsContext' ;
1213
1314Enzyme . configure ( { adapter : new Adapter ( ) } ) ;
1415
@@ -110,3 +111,86 @@ test('withJsonFormsEnumProps - enum: should supply control and enum props', () =
110111 null
111112 ] ) ;
112113} ) ;
114+
115+ test ( 'withJsonFormsEnumCellProps - constant: should supply control and enum props' , ( ) => {
116+ const MockEnumCellUnwrapped = ( _ : CellProps & OwnPropsOfEnum ) => {
117+ return < > </ > ;
118+ } ;
119+
120+ const MockEnumControl = withJsonFormsEnumCellProps ( MockEnumCellUnwrapped ) ;
121+
122+ const schema = {
123+ const : 'Cambodia'
124+ } ;
125+
126+ const renderers = [
127+ {
128+ tester : rankWith ( 1 , ( ) => true ) ,
129+ renderer : MockEnumControl
130+ }
131+ ] ;
132+
133+ const uischema = {
134+ type : 'Control' ,
135+ scope : '#/properties/name'
136+ } ;
137+
138+ const wrapper = mount (
139+ < JsonForms
140+ data = { { } }
141+ schema = { schema }
142+ uischema = { uischema }
143+ renderers = { renderers }
144+ />
145+ ) ;
146+ const mockEnumControlUnwrappedProps = wrapper
147+ . find ( MockEnumCellUnwrapped )
148+ . props ( ) ;
149+
150+ expect ( mockEnumControlUnwrappedProps . uischema ) . toEqual ( uischema ) ;
151+ expect ( mockEnumControlUnwrappedProps . schema ) . toEqual ( schema ) ;
152+ expect ( mockEnumControlUnwrappedProps . options ) . toEqual ( [ 'Cambodia' ] ) ;
153+ } ) ;
154+
155+ test ( 'withJsonFormsEnumCellProps - enum: should supply control and enum props' , ( ) => {
156+ const MockEnumCellUnwrapped = ( _ : CellProps & OwnPropsOfEnum ) => {
157+ return < > </ > ;
158+ } ;
159+
160+ const MockEnumControl = withJsonFormsEnumCellProps ( MockEnumCellUnwrapped ) ;
161+
162+ const schema = {
163+ type : 'string' ,
164+ enum : [ 'red' , 'amber' , 'green' , null ]
165+ } ;
166+
167+ const renderers = [
168+ {
169+ tester : rankWith ( 1 , ( ) => true ) ,
170+ renderer : MockEnumControl
171+ }
172+ ] ;
173+
174+ const uischema = {
175+ type : 'Control' ,
176+ scope : '#/properties/color'
177+ } ;
178+
179+ const wrapper = mount (
180+ < JsonForms
181+ data = { { } }
182+ schema = { schema }
183+ uischema = { uischema }
184+ renderers = { renderers }
185+ />
186+ ) ;
187+ const mockEnumControlUnwrappedProps = wrapper . find ( MockEnumCellUnwrapped ) . props ( ) ;
188+ expect ( mockEnumControlUnwrappedProps . uischema ) . toEqual ( uischema ) ;
189+ expect ( mockEnumControlUnwrappedProps . schema ) . toEqual ( schema ) ;
190+ expect ( mockEnumControlUnwrappedProps . options ) . toEqual ( [
191+ 'red' ,
192+ 'amber' ,
193+ 'green' ,
194+ null
195+ ] ) ;
196+ } ) ;
0 commit comments