Get previous cycles before detecting fertility status

This commit is contained in:
Julia Friesel
2018-07-13 11:30:54 +02:00
parent 8a8b131064
commit 85e2703b2f
4 changed files with 175 additions and 60 deletions
+137 -49
View File
@@ -23,7 +23,7 @@ describe('getCycleDay', () => {
value: 2
}
}]
const getCycleDayNumber = cycleModule({bleedingDaysSortedByDate: bleedingDays}).getCycleDayNumber
const getCycleDayNumber = cycleModule({ bleedingDaysSortedByDate: bleedingDays }).getCycleDayNumber
const targetDate = '2018-05-17'
const result = getCycleDayNumber(targetDate)
expect(result).to.eql(9)
@@ -49,7 +49,7 @@ describe('getCycleDay', () => {
}
}]
const targetDate = '2018-05-17'
const getCycleDayNumber = cycleModule({bleedingDaysSortedByDate: bleedingDays}).getCycleDayNumber
const getCycleDayNumber = cycleModule({ bleedingDaysSortedByDate: bleedingDays }).getCycleDayNumber
const result = getCycleDayNumber(targetDate)
expect(result).to.eql(15)
})
@@ -73,7 +73,7 @@ describe('getCycleDay', () => {
}]
const targetDate = '2018-04-27'
const getCycleDayNumber = cycleModule({bleedingDaysSortedByDate: bleedingDays}).getCycleDayNumber
const getCycleDayNumber = cycleModule({ bleedingDaysSortedByDate: bleedingDays }).getCycleDayNumber
const result = getCycleDayNumber(targetDate)
expect(result).to.eql(18)
})
@@ -87,59 +87,147 @@ describe('getCycleDay', () => {
}]
const targetDate = '2018-05-13'
const getCycleDayNumber = cycleModule({bleedingDaysSortedByDate: bleedingDays}).getCycleDayNumber
const getCycleDayNumber = cycleModule({ bleedingDaysSortedByDate: bleedingDays }).getCycleDayNumber
const result = getCycleDayNumber(targetDate)
expect(result).to.eql(1)
})
})
describe('getCycleDay returns null', () => {
it('if there are no bleeding days', function () {
const bleedingDays = []
const targetDate = '2018-05-17'
const getCycleDayNumber = cycleModule({bleedingDaysSortedByDate: bleedingDays}).getCycleDayNumber
const result = getCycleDayNumber(targetDate)
expect(result).to.be.null()
describe('getCycleDay returns null', () => {
it('if there are no bleeding days', function () {
const bleedingDays = []
const targetDate = '2018-05-17'
const getCycleDayNumber = cycleModule({ bleedingDaysSortedByDate: bleedingDays }).getCycleDayNumber
const result = getCycleDayNumber(targetDate)
expect(result).to.be.null()
})
})
describe('getCycleDay with cycle thresholds', () => {
const maxBreakInBleeding = 3
it('disregards bleeding breaks shorter than max allowed bleeding break in a bleeding period', () => {
const bleedingDays = [{
date: '2018-05-14',
bleeding: {
value: 2
}
}, {
date: '2018-05-10',
bleeding: {
value: 2
}
}]
const targetDate = '2018-05-17'
const getCycleDayNumber = cycleModule({ bleedingDaysSortedByDate: bleedingDays, maxBreakInBleeding }).getCycleDayNumber
const result = getCycleDayNumber(targetDate)
expect(result).to.eql(8)
})
it('counts bleeding breaks longer than maxAllowedBleedingBreak in a bleeding period', () => {
const bleedingDays = [{
date: '2018-05-14',
bleeding: {
value: 2
}
}, {
date: '2018-05-09',
bleeding: {
value: 2
}
}]
const targetDate = '2018-05-17'
const getCycleDayNumber = cycleModule({ bleedingDaysSortedByDate: bleedingDays, maxBreakInBleeding }).getCycleDayNumber
const result = getCycleDayNumber(targetDate)
expect(result).to.eql(4)
})
})
})
describe('getCycleDay with cycle thresholds', () => {
const maxBreakInBleeding = 3
describe('getPreviousCycles', () => {
it('gets previous cycles', () => {
const cycleDaysSortedByDate = [
{
date: '2018-07-05',
bleeding: { value: 2 }
},
{
date: '2018-06-05',
bleeding: { value: 2 }
},
{
date: '2018-05-05',
mucus: { value: 2 }
},
{
date: '2018-05-04',
bleeding: { value: 2 }
},
{
date: '2018-05-03',
bleeding: { value: 2 }
},
{
date: '2018-04-05',
mucus: { value: 2 }
},
{
date: '2018-04-04',
mucus: { value: 2 }
},
{
date: '2018-04-03',
mucus: { value: 2 }
},
{
date: '2018-04-02',
bleeding: { value: 2 }
},
]
it('disregards bleeding breaks shorter than max allowed bleeding break in a bleeding period', () => {
const bleedingDays = [{
date: '2018-05-14',
bleeding: {
value: 2
}
}, {
date: '2018-05-10',
bleeding: {
value: 2
}
}]
const targetDate = '2018-05-17'
const getCycleDayNumber = cycleModule({bleedingDaysSortedByDate: bleedingDays, maxBreakInBleeding }).getCycleDayNumber
const result = getCycleDayNumber(targetDate)
expect(result).to.eql(8)
})
it('counts bleeding breaks longer than maxAllowedBleedingBreak in a bleeding period', () => {
const bleedingDays = [{
date: '2018-05-14',
bleeding: {
value: 2
}
}, {
date: '2018-05-09',
bleeding: {
value: 2
}
}]
const targetDate = '2018-05-17'
const getCycleDayNumber = cycleModule({bleedingDaysSortedByDate: bleedingDays, maxBreakInBleeding }).getCycleDayNumber
const result = getCycleDayNumber(targetDate)
expect(result).to.eql(4)
const { getPreviousCycles } = cycleModule({
cycleDaysSortedByDate,
bleedingDaysSortedByDate: cycleDaysSortedByDate.filter(d => d.bleeding)
})
const result = getPreviousCycles(cycleDaysSortedByDate[0])
expect(result.length).to.eql(3)
expect(result).to.eql([
[
{
date: '2018-06-05',
bleeding: { value: 2 }
}
], [
{
date: '2018-05-05',
mucus: { value: 2 }
},
{
date: '2018-05-04',
bleeding: { value: 2 }
},
{
date: '2018-05-03',
bleeding: { value: 2 }
}
], [
{
date: '2018-04-05',
mucus: { value: 2 }
},
{
date: '2018-04-04',
mucus: { value: 2 }
},
{
date: '2018-04-03',
mucus: { value: 2 }
},
{
date: '2018-04-02',
bleeding: { value: 2 }
},
]
])
})
})