File tree Expand file tree Collapse file tree 2 files changed +50
-1
lines changed
app/components/Area/Create Expand file tree Collapse file tree 2 files changed +50
-1
lines changed Original file line number Diff line number Diff line change @@ -21,9 +21,13 @@ class Area extends React.Component
2121 e . preventDefault ( ) ;
2222
2323 let form = e . target ;
24+ let parent = '' ;
25+ if ( form . querySelector ( '[name="parent"]' ) ) {
26+ parent = form . querySelector ( '[name="parent"]' ) . value ;
27+ }
2428 let formData = {
2529 _id : this . refs . area . value ,
26- parent : form . querySelector ( '[name=" parent"]' ) . value
30+ parent : parent
2731 } ;
2832
2933 this . setState ( { area : formData } ) ;
Original file line number Diff line number Diff line change @@ -256,5 +256,50 @@ describe('Test Create Area', () => {
256256 }
257257 } , 0 ) ;
258258 } ) ;
259+
260+ it ( 'Should return data on submit when first time using areas' , ( done ) => {
261+
262+ let areaInput ;
263+ let areaSelected ;
264+ let Area = require ( 'components/Area/Create/Area' ) . default ;
265+ let mockAdapter = new MockAdapter ( axios ) ;
266+ let component = mount (
267+ < Area /> ,
268+ { context }
269+ ) ;
270+ let expected = {
271+ _id : 'Test' ,
272+ parent : '' ,
273+ }
274+
275+ mockAdapter
276+ . onGet ( HOST + '/api/v1/area' ) . reply ( 404 , { error : "Not Found" } )
277+ . onPost ( HOST + '/api/v1/area' ) . reply ( 201 )
278+
279+ setTimeout ( ( ) => {
280+
281+ try {
282+
283+ let inputs = {
284+ area : component . find ( 'input' ) ,
285+ parent : component . find ( 'select' ) ,
286+ }
287+
288+ areaInput = component . find ( 'input' ) ;
289+ areaInput . node . value = 'Test' ;
290+ areaInput . simulate ( 'change' , areaInput ) ;
291+
292+ expect ( component . find ( '.is-danger' ) . text ( ) ) . toEqual ( 'Not Found' ) ;
293+
294+ component . find ( 'form' ) . simulate ( 'submit' , { target : component . find ( 'form' ) . get ( 0 ) } ) ;
295+
296+ expect ( component . state ( ) . area ) . toEqual ( expected ) ;
297+ expect ( component . state ( ) . error ) . toEqual ( '' ) ;
298+ done ( ) ;
299+ } catch ( e ) {
300+ console . log ( e ) ;
301+ }
302+ } , 25 ) ;
303+ } ) ;
259304} ) ;
260305
You can’t perform that action at this time.
0 commit comments