11import React from 'react'
22import { shallow , mount } from 'enzyme'
3- import { EventForm } from '../../containers/EventForm '
3+ import { CreateEventPage } from '../../containers/CreateEventPage '
44import { StaticRouter } from 'react-router'
55
6- describe ( 'EventForm ' , ( ) => {
6+ describe ( 'CreateEventPage ' , ( ) => {
77 let wrapper
88 const props = {
99 location : { pathname : '/events/new' } ,
@@ -13,10 +13,11 @@ describe('EventForm', () => {
1313 projects : [ ] ,
1414 fetchActiveProjects : jest . fn ( ) ,
1515 loggedInUser : { } ,
16- createEvent : jest . fn ( )
16+ createEvent : jest . fn ( ) ,
17+ handleStartDateChange : jest . fn ( )
1718 }
1819 beforeEach ( ( ) => {
19- wrapper = shallow ( < EventForm { ...props } /> )
20+ wrapper = shallow ( < CreateEventPage { ...props } /> )
2021 } )
2122
2223 it ( 'setsLastLocation with path' , ( ) => {
@@ -31,22 +32,22 @@ describe('EventForm', () => {
3132 it ( 'sets state with projects if received from props' , ( ) => {
3233 const expected = [ { id : 3 , name : 'Project1' } ]
3334 props . projects = expected
34- wrapper = shallow ( < EventForm { ...props } /> )
35+ wrapper = shallow ( < CreateEventPage { ...props } /> )
3536 expect ( wrapper . state ( ) . projects ) . toEqual ( expected )
3637 } )
3738
3839 it ( 'sets state when props are updated' , ( ) => {
3940 const expected = [ { id : 3 , name : 'Project1' } ]
4041 wrapper . setProps ( { projects : expected } )
41- wrapper = shallow ( < EventForm { ...props } /> )
42+ wrapper = shallow ( < CreateEventPage { ...props } /> )
4243 expect ( wrapper . state ( ) . projects ) . toEqual ( expected )
4344 } )
4445
4546 it ( 'calls createEvent when the form in submitted' , ( ) => {
4647 const context = { }
4748 wrapper = mount (
4849 < StaticRouter context = { context } >
49- < EventForm { ...props } />
50+ < CreateEventPage { ...props } />
5051 </ StaticRouter >
5152 )
5253
@@ -63,37 +64,4 @@ describe('EventForm', () => {
6364
6465 expect ( props . createEvent ) . toHaveBeenCalledTimes ( 1 )
6566 } )
66-
67- it ( 'sets state when startDate is changed' , ( ) => {
68- const startDateSelect = wrapper . find ( 'DatePicker' ) . filterWhere ( item => {
69- return item . prop ( 'name' ) === 'startDate'
70- } )
71-
72- startDateSelect . simulate ( 'change' , new Date ( '04/05/2019' ) )
73-
74- expect ( wrapper . state ( ) . startDate ) . toEqual ( new Date ( '04/05/2019' ) )
75- } )
76-
77- it ( 'sets state when endDate is changed' , ( ) => {
78- const context = { }
79- wrapper = mount (
80- < StaticRouter context = { context } >
81- < EventForm { ...props } />
82- </ StaticRouter >
83- )
84- const eventForm = wrapper . find ( 'EventForm' )
85- eventForm . setState ( { repeats : 'weekly' , repeatEnds : 'on' } )
86-
87- const weekdaysSelect = wrapper . find ( 'Select' ) . filterWhere ( item => {
88- return item . prop ( 'name' ) === 'weekdays'
89- } )
90-
91- weekdaysSelect . simulate ( 'change' , [ 'Monday' ] )
92- const endDateSelect = wrapper . find ( 'DatePicker' ) . filterWhere ( item => {
93- return item . prop ( 'name' ) === 'endDate'
94- } )
95- endDateSelect . props ( ) . onChange ( new Date ( '2019-05-26' ) )
96-
97- expect ( eventForm . state ( ) . endDate ) . toEqual ( new Date ( '2019-05-26' ) )
98- } )
9967} )
0 commit comments