2222 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2323 THE SOFTWARE.
2424*/
25- import { Provider } from 'react-redux' ;
2625import {
2726 Actions ,
2827 ControlElement ,
29- getData ,
3028 HorizontalLayout ,
3129 jsonformsReducer ,
3230 JsonFormsState ,
33- JsonSchema ,
3431 NOT_APPLICABLE
3532} from '@jsonforms/core' ;
36- import HorizontalLayoutRenderer from '../../src/layouts/MaterialHorizontalLayout' ;
37- import MaterialObjectRenderer , {
38- materialObjectControlTester
39- } from '../../src/complex/MaterialObjectRenderer' ;
4033import * as React from 'react' ;
41- import * as TestUtils from 'react-dom/test-utils' ;
4234import * as ReactDOM from 'react-dom' ;
35+ import * as TestUtils from 'react-dom/test-utils' ;
36+ import { Provider } from 'react-redux' ;
4337import { combineReducers , createStore , Store } from 'redux' ;
4438import { materialFields , materialRenderers } from '../../src' ;
39+ import MaterialObjectRenderer ,
40+ { materialObjectControlTester } from '../../src/complex/MaterialObjectRenderer' ;
41+ import HorizontalLayoutRenderer from '../../src/layouts/MaterialHorizontalLayout' ;
4542
4643const initJsonFormsStore = ( testData , testSchema , testUiSchema ) : Store < JsonFormsState > => {
4744 const store : Store < JsonFormsState > = createStore (
@@ -58,20 +55,20 @@ const initJsonFormsStore = (testData, testSchema, testUiSchema): Store<JsonForms
5855 return store ;
5956} ;
6057
61- const data = { foo : { foo_1 : 'foo' } , bar : { bar_1 : 'bar' } } ;
58+ const data = { foo : { foo_1 : 'foo' } , bar : { bar_1 : 'bar' } } ;
6259const schema = {
6360 type : 'object' ,
6461 properties : {
6562 foo : {
6663 type : 'object' ,
6764 properties : {
68- foo_1 : { type : 'string' }
65+ foo_1 : { type : 'string' }
6966 }
7067 } ,
7168 bar : {
7269 type : 'object' ,
7370 properties : {
74- bar_1 : { type : 'string' }
71+ bar_1 : { type : 'string' }
7572 }
7673 } ,
7774 } ,
@@ -90,15 +87,15 @@ describe('Material object renderer tester', () => {
9087 test ( 'should fail' , ( ) => {
9188 expect ( materialObjectControlTester ( undefined , undefined ) ) . toBe ( NOT_APPLICABLE ) ;
9289 expect ( materialObjectControlTester ( null , undefined ) ) . toBe ( NOT_APPLICABLE ) ;
93- expect ( materialObjectControlTester ( { type : 'Foo' } , undefined ) ) . toBe ( NOT_APPLICABLE ) ;
94- expect ( materialObjectControlTester ( { type : 'Control' } , undefined ) ) . toBe ( NOT_APPLICABLE ) ;
90+ expect ( materialObjectControlTester ( { type : 'Foo' } , undefined ) ) . toBe ( NOT_APPLICABLE ) ;
91+ expect ( materialObjectControlTester ( { type : 'Control' } , undefined ) ) . toBe ( NOT_APPLICABLE ) ;
9592 expect (
9693 materialObjectControlTester (
9794 uischema2 ,
9895 {
9996 type : 'object' ,
10097 properties : {
101- foo : { type : 'string' } ,
98+ foo : { type : 'string' } ,
10299 } ,
103100 } ,
104101 )
@@ -109,7 +106,7 @@ describe('Material object renderer tester', () => {
109106 {
110107 type : 'object' ,
111108 properties : {
112- foo : { type : 'string' } ,
109+ foo : { type : 'string' } ,
113110 bar : schema . properties . bar ,
114111 } ,
115112 } ,
@@ -141,99 +138,11 @@ describe('Material object control', () => {
141138 ReactDOM . unmountComponentAtNode ( container ) ;
142139 } ) ;
143140
144- it ( 'should autofocus first element' , ( ) => {
145- const firstControlElement : ControlElement = {
146- type : 'Control' ,
147- scope : '#/properties/foo' ,
148- options : {
149- focus : true
150- }
151- } ;
152- const secondControlElement : ControlElement = {
153- type : 'Control' ,
154- scope : '#/properties/bar' ,
155- options : {
156- focus : true
157- }
158- } ;
159- const layout : HorizontalLayout = {
160- type : 'HorizontalLayout' ,
161- elements : [
162- firstControlElement ,
163- secondControlElement
164- ]
165- } ;
166- const store = initJsonFormsStore (
167- data ,
168- schema ,
169- layout
170- ) ;
171- const tree = ReactDOM . render (
172- < Provider store = { store } >
173- < HorizontalLayoutRenderer schema = { schema } uischema = { layout } />
174- </ Provider > ,
175- container
176- ) ;
177- const inputs = TestUtils . scryRenderedDOMComponentsWithTag ( tree , 'input' ) ;
178- expect ( document . activeElement ) . not . toBe ( inputs [ 0 ] ) ;
179- expect ( document . activeElement ) . toBe ( inputs [ 1 ] ) ;
180- } ) ;
181-
182- it ( 'should autofocus via option' , ( ) => {
183- const control : ControlElement = {
184- type : 'Control' ,
185- scope : '#/properties/foo' ,
186- options : {
187- focus : true
188- }
189- } ;
190- const store = initJsonFormsStore ( data , schema , control ) ;
191- const tree = ReactDOM . render (
192- < Provider store = { store } >
193- < MaterialObjectRenderer schema = { schema } uischema = { control } />
194- </ Provider > ,
195- container
196- ) ;
197- const input = TestUtils . findRenderedDOMComponentWithTag ( tree , 'input' ) as HTMLInputElement ;
198- expect ( document . activeElement ) . toBe ( input ) ;
199- } ) ;
200-
201- it ( 'should not autofocus via option' , ( ) => {
202- const control : ControlElement = {
203- type : 'Control' ,
204- scope : '#/properties/foo' ,
205- options : {
206- focus : false
207- }
208- } ;
209- const store = initJsonFormsStore ( data , schema , control ) ;
210- const tree = ReactDOM . render (
211- < Provider store = { store } >
212- < MaterialObjectRenderer schema = { schema } uischema = { control } />
213- </ Provider > ,
214- container
215- ) ;
216- const input = TestUtils . findRenderedDOMComponentWithTag ( tree , 'input' ) as HTMLInputElement ;
217- expect ( input . autofocus ) . toBeFalsy ( ) ;
218- } ) ;
219-
220- it ( 'should not autofocus by default' , ( ) => {
221- const store = initJsonFormsStore ( data , schema , uischema2 ) ;
222- const tree = ReactDOM . render (
223- < Provider store = { store } >
224- < MaterialObjectRenderer schema = { schema } uischema = { uischema2 } />
225- </ Provider > ,
226- container
227- ) ;
228- const input = TestUtils . findRenderedDOMComponentWithTag ( tree , 'input' ) as HTMLInputElement ;
229- expect ( input . autofocus ) . toBeFalsy ( ) ;
230- } ) ;
231-
232141 it ( 'should render all children' , ( ) => {
233142 const store = initJsonFormsStore ( data , schema , uischema1 ) ;
234143 const tree = ReactDOM . render (
235144 < Provider store = { store } >
236- < MaterialObjectRenderer schema = { schema } uischema = { uischema1 } />
145+ < MaterialObjectRenderer schema = { schema } uischema = { uischema1 } />
237146 </ Provider > ,
238147 container
239148 ) ;
@@ -250,7 +159,7 @@ describe('Material object control', () => {
250159 const store = initJsonFormsStore ( data , schema , uischema1 ) ;
251160 const tree = ReactDOM . render (
252161 < Provider store = { store } >
253- < MaterialObjectRenderer schema = { schema } uischema = { uischema2 } />
162+ < MaterialObjectRenderer schema = { schema } uischema = { uischema2 } />
254163 </ Provider > ,
255164 container
256165 ) ;
@@ -261,23 +170,11 @@ describe('Material object control', () => {
261170 expect ( input [ 0 ] . value ) . toBe ( 'foo' ) ;
262171 } ) ;
263172
264- it ( 'can be disabled' , ( ) => {
265- const store = initJsonFormsStore ( data , schema , uischema2 ) ;
266- const tree = ReactDOM . render (
267- < Provider store = { store } >
268- < MaterialObjectRenderer schema = { schema } uischema = { uischema2 } enabled = { false } />
269- </ Provider > ,
270- container
271- ) ;
272- const input = TestUtils . findRenderedDOMComponentWithTag ( tree , 'input' ) as HTMLInputElement ;
273- expect ( input . disabled ) . toBeTruthy ( ) ;
274- } ) ;
275-
276173 it ( 'should be enabled by default' , ( ) => {
277174 const store = initJsonFormsStore ( data , schema , uischema2 ) ;
278175 const tree = ReactDOM . render (
279176 < Provider store = { store } >
280- < MaterialObjectRenderer schema = { schema } uischema = { uischema2 } />
177+ < MaterialObjectRenderer schema = { schema } uischema = { uischema2 } />
281178 </ Provider > ,
282179 container
283180 ) ;
@@ -289,7 +186,7 @@ describe('Material object control', () => {
289186 const store = initJsonFormsStore ( data , schema , uischema2 ) ;
290187 const tree = ReactDOM . render (
291188 < Provider store = { store } >
292- < MaterialObjectRenderer schema = { schema } uischema = { uischema2 } visible = { false } />
189+ < MaterialObjectRenderer schema = { schema } uischema = { uischema2 } visible = { false } />
293190 </ Provider > ,
294191 container
295192 ) ;
@@ -301,7 +198,7 @@ describe('Material object control', () => {
301198 const store = initJsonFormsStore ( data , schema , uischema2 ) ;
302199 const tree = ReactDOM . render (
303200 < Provider store = { store } >
304- < MaterialObjectRenderer schema = { schema } uischema = { uischema2 } />
201+ < MaterialObjectRenderer schema = { schema } uischema = { uischema2 } />
305202 </ Provider > ,
306203 container
307204 ) ;
0 commit comments