/
DayContainer.test.js
81 lines (76 loc) · 1.91 KB
/
DayContainer.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import React from 'react'
import ReactDOM from 'react-dom'
import { Provider } from 'react-redux'
import { createStore } from 'redux'
import enhancer from './DayContainer'
const today = new Date()
const year = today.getFullYear()
const month = today.getMonth()
const day = today.getDate()
const todayReminders = [{
id: 3,
text: 'foo',
time: false
},{
id: 2,
text: 'test',
time: '23:00'
}, {
id: 14,
text: 'foo',
time: ''
}, {
id: 1,
text: 'test',
time: '01:00'
}]
const store = createStore(state => state, {
month: today,
reminders: {
[year]: {
[month]: {
[day]: todayReminders
}
}
}
})
describe('<Day/> connect() enhancer', () => {
it('should pass month, outOfMonth and reminders props', done => {
const Comp = enhancer(({ outOfMonth, reminders }) => {
expect(outOfMonth).toBe(false)
expect(reminders.length).toBe(todayReminders.length)
done()
return null
})
const div = document.createElement('div')
ReactDOM.render((<Provider store={store}>
<Comp date={new Date()} />
</Provider>), div)
})
it('should detect outOfMonth', done => {
const Comp = enhancer(({ outOfMonth }) => {
expect(outOfMonth).toBe(true)
done()
return null
})
const aDateNextMonth = new Date()
aDateNextMonth.setMonth(aDateNextMonth.getMonth() + 1)
const div = document.createElement('div')
ReactDOM.render((<Provider store={store}>
<Comp date={aDateNextMonth} />
</Provider>), div)
})
it('should sort reminders by time, push to the end those without', done => {
const Comp = enhancer(({ reminders }) => {
const [first, second] = reminders
expect(first.id).toBe(1)
expect(second.id).toBe(2)
done()
return null
})
const div = document.createElement('div')
ReactDOM.render((<Provider store={store}>
<Comp date={new Date()} />
</Provider>), div)
})
})