Skip to content
Snippets Groups Projects
Commit 06edde53 authored by Maria Zadnepryanets's avatar Maria Zadnepryanets
Browse files

Merge branch 'get-cycles-before-test' into 'master'

Moves out the test for getCyclesBefore method of cycle module

See merge request bloodyhealth/drip!273
parents 9b4da9bd 5b2dc822
No related branches found
No related tags found
No related merge requests found
......@@ -5,165 +5,6 @@ import cycleModule from '../lib/cycle'
const expect = chai.expect
chai.use(dirtyChai)
describe('getCyclesBefore', () => {
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 }
},
]
const cycleStarts = [
'2018-07-05',
'2018-06-05',
'2018-05-03',
'2018-04-02'
]
const { getCyclesBefore } = cycleModule({
cycleDaysSortedByDate,
cycleStartsSortedByDate: cycleDaysSortedByDate.filter(d => {
return cycleStarts.includes(d.date)
})
})
const result = getCyclesBefore(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 }
},
]
])
})
it('skips cycles that are longer than max', () => {
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 }
},
]
const cycleStarts = [
'2018-07-05',
'2018-06-05',
'2018-05-03',
'2018-04-02'
]
const { getCyclesBefore } = cycleModule({
cycleDaysSortedByDate,
cycleStartsSortedByDate: cycleDaysSortedByDate.filter(d => {
return cycleStarts.includes(d.date)
}),
maxCycleLength: 30
})
const result = getCyclesBefore(cycleDaysSortedByDate[0])
expect(result.length).to.eql(1)
expect(result).to.eql([[{
bleeding: { value: 2 },
date: "2018-06-05"
}]])
})
})
describe('getCycleForDay', () => {
const cycleDaysSortedByDate = [
{
......
import chai from 'chai'
import dirtyChai from 'dirty-chai'
import cycleModule from '../lib/cycle'
const { expect } = chai
chai.use(dirtyChai)
const julyCycle = [{ date: '2018-07-05' }]
const juneCycle = [{ date: '2018-06-05' }]
const mayCycle = [
{ date: '2018-05-05' },
{ date: '2018-05-04' },
{ date: '2018-05-03' },
]
const aprilCycle = [
{ date: '2018-04-05' },
{ date: '2018-04-04' },
{ date: '2018-04-03' },
{ date: '2018-04-02' },
]
const cycleDaysSortedByDate = [
...julyCycle,
...juneCycle,
...mayCycle,
...aprilCycle,
]
const cycleStartsSortedByDate = [
{ date: '2018-07-05' },
{ date: '2018-06-05' },
{ date: '2018-05-03' },
{ date: '2018-04-02' },
]
describe('getCyclesBefore', () => {
it('gets previous cycles', () => {
const { getCyclesBefore } = cycleModule({
cycleDaysSortedByDate,
cycleStartsSortedByDate,
})
const cyclesBeforeJuly = getCyclesBefore(...julyCycle)
expect(cyclesBeforeJuly.length).to.eql(3)
expect(cyclesBeforeJuly).to.eql([ juneCycle, mayCycle, aprilCycle ])
})
it('skips cycles that are longer than max', () => {
const { getCyclesBefore } = cycleModule({
cycleDaysSortedByDate,
cycleStartsSortedByDate,
maxCycleLength: 30
})
const cyclesBeforeJuly = getCyclesBefore(...julyCycle)
expect(cyclesBeforeJuly.length).to.eql(1)
expect(cyclesBeforeJuly).to.eql([ juneCycle ])
})
})
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment