Newer
Older
import chai from 'chai'
import dirtyChai from 'dirty-chai'
import moment from 'moment'
const expect = chai.expect
chai.use(dirtyChai)
import getCycleDayNumberModule from '../get-cycle-day-number'
describe('getCycleDay', () => {
const getCycleDayNumber = getCycleDayNumberModule()
it('works if the last data entered is a bleeding day', function () {
const cycleDays = [{
date: moment([2018, 5, 2])
}, {
date: moment([2018, 5, 3]),
bleeding: {
value: 2
}
}, {
date: moment([2018, 5, 4])
}, {
date: moment([2018, 5, 9]),
bleeding: {
value: 2
}
}, {
date: moment([2018, 5, 10]),
bleeding: {
value: 2
}
}]
const targetDate = moment([2018, 5, 17])
const result = getCycleDayNumber(cycleDays, targetDate)
expect(result).to.eql(9)
})
it('works if the last data entered is a non-bleeding day', function () {
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
const cycleDays = [{
date: moment([2018, 5, 2])
}, {
date: moment([2018, 5, 3]),
bleeding: {
value: 2
}
}, {
date: moment([2018, 5, 4])
}, {
date: moment([2018, 5, 9]),
bleeding: {
value: 2
}
}, {
date: moment([2018, 5, 10]),
bleeding: {
value: 2
}
}, {
date: moment([2018, 5, 13])
}, {
date: moment([2018, 5, 14])
}]
const targetDate = moment([2018, 5, 17])
const result = getCycleDayNumber(cycleDays, targetDate)
expect(result).to.eql(9)
})
it('works if the cycle days are not sorted by date', function () {
const cycleDays = [{
date: moment([2018, 5, 13]),
bleeding: {
value: 2
}
}, {
date: moment([2018, 5, 9]),
bleeding: {
value: 2
}
}, {
date: moment([2018, 5, 3]),
bleeding: {
value: 2
}
}, {
date: moment([2018, 5, 4])
}, {
date: moment([2018, 5, 10]),
bleeding: {
value: 2
}
}, {
date: moment([2018, 5, 2])
}]
const targetDate = moment([2018, 5, 17])
const result = getCycleDayNumber(cycleDays, targetDate)
it('works when there are only bleeding days', function () {
const cycleDays = [{
date: moment([2018, 5, 9]),
bleeding: {
value: 2
}
}, {
date: moment([2018, 5, 10]),
bleeding: {
value: 2
}
}]
const targetDate = moment([2018, 5, 17])
const result = getCycleDayNumber(cycleDays, targetDate)
expect(result).to.eql(9)
})
it('works if some bleedings are exluded', function () {
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
const cycleDays = [{
date: moment([2018, 5, 2])
}, {
date: moment([2018, 5, 3]),
bleeding: {
value: 2
}
}, {
date: moment([2018, 5, 4])
}, {
date: moment([2018, 5, 9]),
bleeding: {
value: 2,
exclude: true
}
}, {
date: moment([2018, 5, 10]),
bleeding: {
value: 2,
exclude: true
}
}]
const targetDate = moment([2018, 5, 17])
const result = getCycleDayNumber(cycleDays, targetDate)
expect(result).to.eql(15)
})
describe('getCycleDay returns null', () => {
const getCycleDayNumber = getCycleDayNumberModule()
it('if there are no bleeding days', function () {
const cycleDays = [{
date: moment([2018, 5, 2])
}, {
date: moment([2018, 5, 4])
}, {
date: moment([2018, 5, 9]),
}, {
date: moment([2018, 5, 10]),
}]
const targetDate = moment([2018, 5, 17])
const result = getCycleDayNumber(cycleDays, targetDate)
})
it('if there are no cycle days', function () {
const cycleDays = []
const targetDate = moment([2018, 5, 17])
const result = getCycleDayNumber(cycleDays, targetDate)
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
expect(result).to.be.null()
})
})
describe('getCycleDay with cycle thresholds', () => {
const getCycleDayNumber = getCycleDayNumberModule({
minCycleLengthInDays: 5
})
it('disregards bleeding breaks shorter than the min cycle threshold in a bleeding period', () => {
const cycleDays = [{
date: moment([2018, 5, 10]),
bleeding: {
value: 2
}
}, {
date: moment([2018, 5, 14]),
bleeding: {
value: 2
}
}]
const targetDate = moment([2018, 5, 17])
const result = getCycleDayNumber(cycleDays, targetDate)
expect(result).to.eql(8)
})
it('counts bleeding breaks longer than the min cycle threshold in a bleeding period', () => {
const cycleDays = [{
date: moment([2018, 5, 9]),
bleeding: {
value: 2
}
}, {
date: moment([2018, 5, 14]),
bleeding: {
value: 2
}
}]
const targetDate = moment([2018, 5, 17])
const result = getCycleDayNumber(cycleDays, targetDate)
expect(result).to.eql(4)