Skip to content

Commit 66d11fd

Browse files
mattwr18joaopapereira
authored andcommitted
Refactor tests
1 parent 8c29a06 commit 66d11fd

File tree

2 files changed

+48
-40
lines changed

2 files changed

+48
-40
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import React from 'react'
2+
import { mount } from 'enzyme'
3+
import EventForm from '../../components/EventForm'
4+
import { StaticRouter } from 'react-router'
5+
6+
describe('EventForm', () => {
7+
let wrapper
8+
const context = {}
9+
beforeEach(() => {
10+
wrapper = mount(
11+
<StaticRouter context={context}>
12+
<EventForm />
13+
</StaticRouter>
14+
)
15+
})
16+
17+
it('shows a DaysOfTheWeekSelect if the event is repeating', () => {
18+
wrapper = mount(
19+
<StaticRouter context={context}>
20+
<EventForm repeats={'weekly'} />
21+
</StaticRouter>
22+
)
23+
24+
expect(wrapper.find('DaysOfTheWeekSelect')).toHaveLength(1)
25+
})
26+
27+
it('shows the endDate select if the recurring event ends', () => {
28+
wrapper = mount(
29+
<StaticRouter context={context}>
30+
<EventForm repeats={'weekly'} repeatEnds={'on'} />
31+
</StaticRouter>
32+
)
33+
34+
const endDateSelect = wrapper.find('DatePicker').filterWhere(item => {
35+
return item.prop('name') === 'endDate'
36+
})
37+
38+
expect(endDateSelect).toHaveLength(1)
39+
})
40+
})
Lines changed: 8 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import React from 'react'
22
import { shallow, mount } from 'enzyme'
3-
import { EventForm } from '../../containers/EventForm'
3+
import { CreateEventPage } from '../../containers/CreateEventPage'
44
import { 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

Comments
 (0)