Merge branch 'get-cycle-day-number-test' into 'master'
Moves out the tests for getCycleDayNumber and organises them See merge request bloodyhealth/drip!268
This commit is contained in:
@@ -5,95 +5,6 @@ import cycleModule from '../lib/cycle'
|
||||
const expect = chai.expect
|
||||
chai.use(dirtyChai)
|
||||
|
||||
describe('getCycleDayNumber', () => {
|
||||
it('works for a simple example', () => {
|
||||
const cycleStarts = [{
|
||||
date: '2018-05-09',
|
||||
isCycleStart: true,
|
||||
bleeding: {
|
||||
value: 2
|
||||
}
|
||||
}, {
|
||||
date: '2018-05-03',
|
||||
isCycleStart: true,
|
||||
bleeding: { value: 2 }
|
||||
}]
|
||||
const getCycleDayNumber = cycleModule({
|
||||
cycleStartsSortedByDate: cycleStarts
|
||||
}).getCycleDayNumber
|
||||
const targetDate = '2018-05-17'
|
||||
const result = getCycleDayNumber(targetDate)
|
||||
expect(result).to.eql(9)
|
||||
})
|
||||
|
||||
it('gets the correct number if the target day is not in the current cycle', () => {
|
||||
const cycleStarts = [{
|
||||
date: '2018-05-13',
|
||||
isCycleStart: true,
|
||||
bleeding: {
|
||||
value: 2
|
||||
}
|
||||
}, {
|
||||
date: '2018-04-10',
|
||||
isCycleStart: true,
|
||||
bleeding: { value: 2 }
|
||||
}]
|
||||
|
||||
const targetDate = '2018-04-27'
|
||||
const getCycleDayNumber = cycleModule({
|
||||
cycleStartsSortedByDate: cycleStarts
|
||||
}).getCycleDayNumber
|
||||
const result = getCycleDayNumber(targetDate)
|
||||
expect(result).to.eql(18)
|
||||
})
|
||||
|
||||
it('gets the correct number if the target day is the only bleeding day', () => {
|
||||
const cycleStarts = [{
|
||||
date: '2018-05-13',
|
||||
isCycleStart: true,
|
||||
bleeding: { value: 2 }
|
||||
}]
|
||||
|
||||
const targetDate = '2018-05-13'
|
||||
const getCycleDayNumber = cycleModule({
|
||||
cycleStartsSortedByDate: cycleStarts
|
||||
}).getCycleDayNumber
|
||||
const result = getCycleDayNumber(targetDate)
|
||||
expect(result).to.eql(1)
|
||||
})
|
||||
|
||||
it('returns null if there are no bleeding days', function () {
|
||||
const cycleStarts = []
|
||||
const targetDate = '2018-05-17'
|
||||
const getCycleDayNumber = cycleModule({
|
||||
cycleStartsSortedByDate: cycleStarts
|
||||
}).getCycleDayNumber
|
||||
const result = getCycleDayNumber(targetDate)
|
||||
expect(result).to.be.null()
|
||||
})
|
||||
|
||||
it('returns null if the cycle is longer than the max', function () {
|
||||
const cycleStarts = [{
|
||||
date: '2018-05-09',
|
||||
isCycleStart: true,
|
||||
bleeding: {
|
||||
value: 2
|
||||
}
|
||||
}, {
|
||||
date: '2018-05-03',
|
||||
isCycleStart: true,
|
||||
bleeding: { value: 2 }
|
||||
}]
|
||||
// we use the default 99 days max length
|
||||
const getCycleDayNumber = cycleModule({
|
||||
cycleStartsSortedByDate: cycleStarts
|
||||
}).getCycleDayNumber
|
||||
const targetDate = '2018-08-16'
|
||||
const result = getCycleDayNumber(targetDate)
|
||||
expect(result).to.be.null()
|
||||
})
|
||||
})
|
||||
|
||||
describe('getPreviousCycle', () => {
|
||||
it('gets previous cycle', () => {
|
||||
const cycleDaysSortedByDate = [
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
import chai from 'chai'
|
||||
import dirtyChai from 'dirty-chai'
|
||||
import cycleModule from '../lib/cycle'
|
||||
|
||||
const { expect } = chai
|
||||
chai.use(dirtyChai)
|
||||
|
||||
const simpleCycleStarts = [
|
||||
{ date: '2018-05-09' },
|
||||
{ date: '2018-05-03'},
|
||||
]
|
||||
|
||||
describe('getCycleDayNumber', () => {
|
||||
it('works for a date in the current cycle', () => {
|
||||
const cycleStartsSortedByDate = simpleCycleStarts
|
||||
const date = '2018-05-17'
|
||||
const { getCycleDayNumber } = cycleModule({ cycleStartsSortedByDate })
|
||||
|
||||
expect(getCycleDayNumber(date)).to.eql(9)
|
||||
})
|
||||
|
||||
it('works for a date which is not in the current cycle', () => {
|
||||
const cycleStartsSortedByDate = [
|
||||
{ date: '2018-05-13' },
|
||||
{ date: '2018-04-10'}
|
||||
]
|
||||
const date = '2018-04-27'
|
||||
const { getCycleDayNumber } = cycleModule({ cycleStartsSortedByDate })
|
||||
|
||||
expect(getCycleDayNumber(date)).to.eql(18)
|
||||
})
|
||||
|
||||
it('works for a date which is the first and only day in cycle', () => {
|
||||
const cycleStartsSortedByDate = [
|
||||
{ date: '2018-05-13' }
|
||||
]
|
||||
const date = '2018-05-13'
|
||||
const { getCycleDayNumber } = cycleModule({ cycleStartsSortedByDate })
|
||||
|
||||
expect(getCycleDayNumber(date)).to.eql(1)
|
||||
})
|
||||
|
||||
it('returns null if there are no cycle starts', function () {
|
||||
const cycleStartsSortedByDate = []
|
||||
const date = '2018-05-17'
|
||||
const { getCycleDayNumber } = cycleModule({ cycleStartsSortedByDate })
|
||||
|
||||
expect(getCycleDayNumber(date)).to.be.null()
|
||||
})
|
||||
|
||||
it('returns null if the cycle is longer than the max', function () {
|
||||
const cycleStartsSortedByDate = simpleCycleStarts
|
||||
// we use the default 99 days max length
|
||||
const date = '2018-08-16'
|
||||
const { getCycleDayNumber } = cycleModule({ cycleStartsSortedByDate })
|
||||
|
||||
expect(getCycleDayNumber(date)).to.be.null()
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user