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)
})
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
it('gets the correct number if the target day is not in the current cycle', () => {
const cycleDays = [{
date: moment([2018, 5, 14]),
}, {
date: moment([2018, 5, 13]),
bleeding: {
value: 2
}
}, {
date: moment([2018, 4, 12]),
}, {
date: moment([2018, 4, 11]),
bleeding: {
value: 2
}
}, {
date: moment([2018, 4, 10]),
bleeding: {
value: 2
}
}, {
date: moment([2018, 4, 9]),
}]
const targetDate = moment([2018, 4, 27])
const result = getCycleDayNumber(cycleDays, targetDate)
expect(result).to.eql(18)
})
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)
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
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)