11/*
22 The MIT License
33
4- Copyright (c) 2018 EclipseSource Munich
4+ Copyright (c) 2018-2019 EclipseSource Munich
55 https://github.com/eclipsesource/jsonforms
66
77 Permission is hereby granted, free of charge, to any person obtaining a copy
2222 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2323 THE SOFTWARE.
2424*/
25- import {
26- Actions ,
27- ControlElement ,
28- jsonformsReducer ,
29- JsonFormsState ,
30- JsonSchema
31- } from '@jsonforms/core' ;
25+ import { Actions , ControlElement , jsonformsReducer , JsonFormsState , JsonSchema } from '@jsonforms/core' ;
3226import * as React from 'react' ;
33- import * as _ from 'lodash' ;
3427import { Provider } from 'react-redux' ;
35- import * as TestUtils from 'react-dom/test-utils' ;
3628
3729import MaterialArrayControlRenderer from '../../src/complex/MaterialArrayControlRenderer' ;
3830import { combineReducers , createStore , Store } from 'redux' ;
3931import { materialFields , materialRenderers } from '../../src' ;
32+ import Enzyme , { mount , ReactWrapper } from 'enzyme' ;
33+ import Adapter from 'enzyme-adapter-react-16' ;
34+
35+ Enzyme . configure ( { adapter : new Adapter ( ) } ) ;
4036
4137export const initJsonFormsStore = ( customData ?: any ) : Store < JsonFormsState > => {
4238 const s : JsonFormsState = {
@@ -93,35 +89,38 @@ const fixture: {
9389
9490describe ( 'Material array control' , ( ) => {
9591
92+ let wrapper : ReactWrapper ;
93+
94+ afterEach ( ( ) => wrapper . unmount ( ) ) ;
95+
9696 it ( 'should render' , ( ) => {
9797 const store = initJsonFormsStore ( ) ;
98- const tree : React . Component < any > = TestUtils . renderIntoDocument (
98+ wrapper = mount (
9999 < Provider store = { store } >
100100 < MaterialArrayControlRenderer schema = { fixture . schema } uischema = { fixture . uischema } />
101101 </ Provider >
102- ) as React . Component < any > ;
102+ ) ;
103103
104- const rows = TestUtils . scryRenderedDOMComponentsWithTag ( tree , 'tr' ) ;
104+ const rows = wrapper . find ( 'tr' ) ;
105105 // 2 header rows + 2 data entries
106106 expect ( rows . length ) . toBe ( 4 ) ;
107107 } ) ;
108108
109109 it ( 'should render empty' , ( ) => {
110110 const store = initJsonFormsStore ( [ ] ) ;
111111
112- const tree : React . Component < any > = TestUtils . renderIntoDocument (
112+ wrapper = mount (
113113 < Provider store = { store } >
114114 < MaterialArrayControlRenderer schema = { fixture . schema } uischema = { fixture . uischema } />
115115 </ Provider >
116- ) as React . Component < any > ;
116+ ) ;
117117
118- const rows : HTMLTableRowElement [ ] =
119- TestUtils . scryRenderedDOMComponentsWithTag ( tree , 'tr' ) as HTMLTableRowElement [ ] ;
118+ const rows = wrapper . find ( 'tr' ) ;
120119 // two header rows + no data row
121120 expect ( rows . length ) . toBe ( 3 ) ;
122- const headerColumns = rows [ 1 ] . cells ;
123- // 3 columsn = message & done properties + column for delete button
124- expect ( headerColumns . length ) . toBe ( 3 ) ;
121+ const headerColumns = rows . at ( 1 ) . children ( ) ;
122+ // 3 columns: message & done properties + column for delete button
123+ expect ( headerColumns ) . toHaveLength ( 3 ) ;
125124 } ) ;
126125
127126 it ( 'should render empty primitives' , ( ) => {
@@ -143,20 +142,19 @@ describe('Material array control', () => {
143142 } ;
144143 store . dispatch ( Actions . init ( data , schema , uischema ) ) ;
145144
146- const tree : React . Component < any > = TestUtils . renderIntoDocument (
145+ wrapper = mount (
147146 < Provider store = { store } >
148147 < MaterialArrayControlRenderer schema = { schema } uischema = { uischema } />
149148 </ Provider >
150- ) as React . Component < any > ;
149+ ) ;
151150
152- const rows : HTMLTableRowElement [ ] =
153- TestUtils . scryRenderedDOMComponentsWithTag ( tree , 'tr' ) as HTMLTableRowElement [ ] ;
151+ const rows = wrapper . find ( 'tr' ) ;
154152 // header + no data row
155- expect ( rows . length ) . toBe ( 2 ) ;
156- const emptyDataCol = rows [ 1 ] . cells ;
157- expect ( emptyDataCol . length ) . toBe ( 1 ) ;
153+ expect ( rows ) . toHaveLength ( 2 ) ;
154+ const emptyDataCol = rows . at ( 1 ) . find ( 'td' ) ;
155+ expect ( emptyDataCol ) . toHaveLength ( 1 ) ;
158156 // selection column + 1 data column
159- expect ( emptyDataCol [ 0 ] . colSpan ) . toBe ( 2 ) ;
157+ expect ( emptyDataCol . first ( ) . props ( ) . colSpan ) . toBe ( 2 ) ;
160158 } ) ;
161159
162160 it ( 'should render primitives' , ( ) => {
@@ -178,39 +176,40 @@ describe('Material array control', () => {
178176 } ;
179177 store . dispatch ( Actions . init ( data , schema , uischema ) ) ;
180178
181- const tree : React . Component < any > = TestUtils . renderIntoDocument (
179+ wrapper = mount (
182180 < Provider store = { store } >
183181 < MaterialArrayControlRenderer schema = { schema } uischema = { uischema } />
184182 </ Provider >
185- ) as React . Component < any > ;
183+ ) ;
186184
187- const rows = TestUtils . scryRenderedDOMComponentsWithTag ( tree , 'tr' ) ;
185+ const rows = wrapper . find ( 'tr' ) ;
188186 // header + 2 data entries
189- expect ( rows . length ) . toBe ( 3 ) ;
187+ expect ( rows ) . toHaveLength ( 3 ) ;
190188 } ) ;
191189
192190 it ( 'should delete an item' , ( ) => {
193191 const store = initJsonFormsStore ( ) ;
194- const tree : React . Component < any > = TestUtils . renderIntoDocument (
192+ wrapper = mount (
195193 < Provider store = { store } >
196194 < MaterialArrayControlRenderer schema = { fixture . schema } uischema = { fixture . uischema } />
197195 </ Provider >
198- ) as React . Component < any > ;
196+ ) ;
199197
200- const buttons = TestUtils . scryRenderedDOMComponentsWithTag ( tree , 'button' ) ;
198+ const buttons = wrapper . find ( 'button' ) ;
201199 // 5 buttons
202200 // add row
203201 // delete row
204202 // delete row
205203 // two dialog buttons (no + yes)
206- const deleteButton = buttons [ 1 ] ;
207- const nrOfRowsBeforeDelete = TestUtils . scryRenderedDOMComponentsWithTag ( tree , 'tr' ) . length ;
204+ const nrOfRowsBeforeDelete = wrapper . find ( 'tr' ) . length ;
205+
206+ const deleteButton = buttons . at ( 1 ) ;
207+ deleteButton . simulate ( 'click' ) ;
208208
209- TestUtils . Simulate . click ( deleteButton ) ;
210- const confirmButton = buttons [ 4 ] ;
211- TestUtils . Simulate . click ( confirmButton ) ;
209+ const confirmButton = buttons . at ( 4 ) ;
210+ confirmButton . simulate ( 'click' ) ;
212211
213- const nrOfRowsAfterDelete = TestUtils . scryRenderedDOMComponentsWithTag ( tree , 'tr' ) . length ;
212+ const nrOfRowsAfterDelete = wrapper . find ( 'tr' ) . length ;
214213
215214 expect ( nrOfRowsBeforeDelete ) . toBe ( 4 ) ;
216215 expect ( nrOfRowsAfterDelete ) . toBe ( 3 ) ;
0 commit comments