Newer
Older
import chai from 'chai'
import getSensiplanStatus from '../../lib/sympto'
cycleWithoutTempShift,
cycleWithTempAndMucusShift,
cycleWithTempAndNoMucusShift,
cycleWithTempShift,
cycleWithoutAnyShifts,
fiveDayCycle,
cycleWithEarlyMucus,
mucusPeakAndFhmOnSameDay,
fhmTwoDaysBeforeMucusPeak,
fhm5DaysAfterMucusPeak,
mucusPeak5DaysAfterFhm,
mucusPeakTwoDaysBeforeFhm
const expect = chai.expect
describe('sympto', () => {
describe('with no previous higher measurement', () => {
it('with no shifts detects only peri-ovulatory', function () {
const status = getSensiplanStatus({
cycle: cycleWithoutAnyShifts,
expect(status).to.eql({
assumeFertility: true,
phases: {
periOvulatory: {
start: { date: '2018-06-01' },
cycleDays: cycleWithoutAnyShifts
}
},
})
it('with shifts detects only peri-ovulatory and post-ovulatory', function () {
const status = getSensiplanStatus({
cycle: cycleWithTempAndMucusShift,
expect(status.temperatureShift).to.be.an('object')
expect(status.mucusShift).to.be.an('object')
expect(status.assumeFertility).to.be.false()
expect(Object.keys(status.phases).length).to.eql(2)
expect(status.phases.periOvulatory).to.eql({
start: { date: '2018-06-01' },
end: { date: '2018-06-21', time: '18:00' },
cycleDays: cycleWithTempAndMucusShift.filter(({date}) => date <= '2018-06-21')
})
expect(status.phases.postOvulatory).to.eql({
start: {
date: '2018-06-21',
time: '18:00'
},
cycleDays: cycleWithTempAndMucusShift.filter(({date}) => date >= '2018-06-21')
})
})
})
describe('with previous higher measurement', () => {
describe('with no shifts detects pre-ovulatory phase', function () {
it('according to 5-day-rule', function () {
const status = getSensiplanStatus({
cycle: fiveDayCycle,
})
expect(Object.keys(status.phases).length).to.eql(1)
expect(status.assumeFertility).to.be.false()
expect(status.phases.preOvulatory).to.eql({
cycleDays: fiveDayCycle,
start: { date: '2018-06-01' },
end: { date: '2018-06-05' }
})
})
})
describe('with no shifts detects pre- and peri-ovulatory phase', function () {
it('according to 5-day-rule', function () {
const status = getSensiplanStatus({
cycle: cycleWithTempAndNoMucusShift,
expect(status.assumeFertility).to.be.true()
expect(status.phases.preOvulatory).to.eql({
cycleDays: cycleWithTempAndNoMucusShift.filter(({date}) => date <= '2018-06-05'),
start: { date: '2018-06-01' },
end: { date: '2018-06-05' }
})
expect(status.phases.periOvulatory).to.eql({
cycleDays: cycleWithTempAndNoMucusShift.filter(({date}) => date > '2018-06-05'),
it('according to 5-day-rule with shortened pre-phase', function () {
const status = getSensiplanStatus({
cycle: cycleWithEarlyMucus,
expect(Object.keys(status.phases).length).to.eql(2)
expect(status.assumeFertility).to.be.true()
expect(status.phases.preOvulatory).to.eql({
cycleDays: [cycleWithEarlyMucus[0]],
start: { date: '2018-06-01' },
end: { date: '2018-06-01' }
})
expect(status.phases.periOvulatory).to.eql({
cycleDays: cycleWithEarlyMucus.slice(1),
start: { date: '2018-06-02' }
})
})
describe('with shifts detects pre- and peri-ovulatory phase', function () {
it('according to 5-day-rule', function () {
const status = getSensiplanStatus({
cycle: cycleWithTempAndMucusShift,
})
expect(Object.keys(status.phases).length).to.eql(3)
expect(status.assumeFertility).to.be.false()
expect(status.phases.preOvulatory).to.eql({
cycleDays: cycleWithTempAndMucusShift.filter(({date}) => date <= '2018-06-05'),
start: { date: '2018-06-01' },
end: { date: '2018-06-05' }
})
expect(status.phases.periOvulatory).to.eql({
cycleDays: cycleWithTempAndMucusShift.filter(({date}) => date > '2018-06-05' && date <= '2018-06-21'),
start: { date: '2018-06-06' },
end: { date: '2018-06-21', time: '18:00'}
})
expect(status.phases.postOvulatory).to.eql({
cycleDays: cycleWithTempAndMucusShift.filter(({date}) => date >= '2018-06-21'),
start: { date: '2018-06-21', time: '18:00'}
})
})
})
describe('combining first higher measurment and mucus peak', () => {
it('with fhM + mucus peak on same day finds correct start of post-ovu phase', () => {
const status = getSensiplanStatus({
cycle: mucusPeakAndFhmOnSameDay,
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
})
expect(status.temperatureShift).to.be.an('object')
expect(status.mucusShift).to.be.an('object')
expect(status.assumeFertility).to.be.false()
expect(Object.keys(status.phases).length).to.eql(3)
expect(status.phases.preOvulatory).to.eql({
start: { date: '2018-06-01' },
end: { date: '2018-06-05' },
cycleDays: mucusPeakAndFhmOnSameDay.filter(({date}) => date <= '2018-06-05')
})
expect(status.phases.periOvulatory).to.eql({
start: { date: '2018-06-06' },
end: { date: '2018-06-21', time: '18:00' },
cycleDays: mucusPeakAndFhmOnSameDay.filter(({date}) => {
return date > '2018-06-05' && date <= '2018-06-21'
})
})
expect(status.phases.postOvulatory).to.eql({
start: {
date: '2018-06-21',
time: '18:00'
},
cycleDays: mucusPeakAndFhmOnSameDay.filter(({date}) => date >= '2018-06-21')
})
})
it('with fhM 2 days before mucus peak waits for end of mucus eval', () => {
const status = getSensiplanStatus({
cycle: fhmTwoDaysBeforeMucusPeak,
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
210
211
212
213
})
expect(status.temperatureShift).to.be.an('object')
expect(status.mucusShift).to.be.an('object')
expect(status.assumeFertility).to.be.false()
expect(Object.keys(status.phases).length).to.eql(3)
expect(status.phases.preOvulatory).to.eql({
start: { date: '2018-06-01' },
end: { date: '2018-06-05' },
cycleDays: fhmTwoDaysBeforeMucusPeak.filter(({date}) => date <= '2018-06-05')
})
expect(status.phases.periOvulatory).to.eql({
start: { date: '2018-06-06' },
end: { date: '2018-06-26', time: '18:00' },
cycleDays: fhmTwoDaysBeforeMucusPeak.filter(({date}) => {
return date > '2018-06-05' && date <= '2018-06-26'
})
})
expect(status.phases.postOvulatory).to.eql({
start: {
date: '2018-06-26',
time: '18:00'
},
cycleDays: fhmTwoDaysBeforeMucusPeak.filter(({date}) => date >= '2018-06-26')
})
})
it('with another mucus peak 5 days after fHM ignores it', () => {
const status = getSensiplanStatus({
cycle: mucusPeak5DaysAfterFhm,
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
})
expect(status.temperatureShift).to.be.an('object')
expect(status.mucusShift).to.be.an('object')
expect(status.assumeFertility).to.be.false()
expect(Object.keys(status.phases).length).to.eql(3)
expect(status.phases.preOvulatory).to.eql({
start: { date: '2018-06-01' },
end: { date: '2018-06-01' },
cycleDays: mucusPeak5DaysAfterFhm.filter(({date}) => date <= '2018-06-01')
})
expect(status.phases.periOvulatory).to.eql({
start: { date: '2018-06-02' },
end: { date: '2018-06-22', time: '18:00' },
cycleDays: mucusPeak5DaysAfterFhm.filter(({date}) => {
return date > '2018-06-01' && date <= '2018-06-22'
})
})
expect(status.phases.postOvulatory).to.eql({
start: {
date: '2018-06-22',
time: '18:00'
},
cycleDays: mucusPeak5DaysAfterFhm.filter(({date}) => date >= '2018-06-22')
})
})
it('with mucus peak 2 days before fhM waits for end of temp eval', () => {
const status = getSensiplanStatus({
cycle: mucusPeakTwoDaysBeforeFhm,
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
})
expect(status.temperatureShift).to.be.an('object')
expect(status.mucusShift).to.be.an('object')
expect(status.assumeFertility).to.be.false()
expect(Object.keys(status.phases).length).to.eql(3)
expect(status.phases.preOvulatory).to.eql({
start: { date: '2018-06-01' },
end: { date: '2018-06-04' },
cycleDays: mucusPeakTwoDaysBeforeFhm.filter(({date}) => date <= '2018-06-04')
})
expect(status.phases.periOvulatory).to.eql({
start: { date: '2018-06-05' },
end: { date: '2018-07-03', time: '18:00' },
cycleDays: mucusPeakTwoDaysBeforeFhm.filter(({date}) => {
return date > '2018-06-04' && date <= '2018-07-03'
})
})
expect(status.phases.postOvulatory).to.eql({
start: {
date: '2018-07-03',
time: '18:00'
},
cycleDays: mucusPeakTwoDaysBeforeFhm.filter(({date}) => date >= '2018-07-03')
})
})
it('with mucus peak 5 days before fhM waits for end of temp eval', () => {
const status = getSensiplanStatus({
cycle: fhm5DaysAfterMucusPeak,
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
})
expect(status.temperatureShift).to.be.an('object')
expect(status.mucusShift).to.be.an('object')
expect(status.assumeFertility).to.be.false()
expect(Object.keys(status.phases).length).to.eql(3)
expect(status.phases.preOvulatory).to.eql({
start: { date: '2018-06-01' },
end: { date: '2018-06-05' },
cycleDays: fhm5DaysAfterMucusPeak.filter(({date}) => date <= '2018-06-05')
})
expect(status.phases.periOvulatory).to.eql({
start: { date: '2018-06-06' },
end: { date: '2018-06-21', time: '18:00' },
cycleDays: fhm5DaysAfterMucusPeak.filter(({date}) => {
return date > '2018-06-05' && date <= '2018-06-21'
})
})
expect(status.phases.postOvulatory).to.eql({
start: {
date: '2018-06-21',
time: '18:00'
},
cycleDays: fhm5DaysAfterMucusPeak.filter(({date}) => date >= '2018-06-21')
})
})
})
describe('applying the minus-8 rule', () => {
it('shortens the pre-ovu phase if there is a previous <13 fhm')
it('shortens the pre-ovu phase if there is a previous <13 fhm with less than 12 cycles')
it('shortens the pre-ovu phase if mucus occurs')
it('lengthens the pre-ovu phase if >= 12 cycles')
it('does not lengthen the pre-ovu phase if < 12 cycles')
it('does not lengthen the pre-ovu phase if < 12 cycles')
})
describe('when args are wrong', () => {
it('throws when arg object is not in right format', () => {
const wrongObject = { hello: 'world' }
expect(() => getSensiplanStatus(wrongObject)).to.throw(AssertionError)
})
it('throws if cycle array is empty', () => {
expect(() => getSensiplanStatus({cycle: []})).to.throw(AssertionError)
})
it('throws if cycle days are not in right format', () => {
expect(() => getSensiplanStatus({
cycle: [{
hello: 'world',
bleeding: { value: 0 }
}],
expect(() => getSensiplanStatus({
cycle: [{
date: '2018-04-13',
temperature: {value: '35'},
bleeding: { value: 0 }
}],
expect(() => getSensiplanStatus({
cycle: [{
date: '09-14-2017',
bleeding: { value: 0 }
}],
})
it('throws if first cycle day does not have bleeding value', () => {
expect(() => getSensiplanStatus({
cycle: [{
date: '2017-01-01',
bleeding: {
value: 'medium'
}
}],