Chore/retire dirty chai

This commit is contained in:
Sofiya Tepikin
2022-08-01 12:34:26 +00:00
parent 6a6de1d5ea
commit f78d2c480d
12 changed files with 282 additions and 409 deletions
-6
View File
@@ -3045,12 +3045,6 @@
"integrity": "sha512-Dj6Wk3tWyTE+Fo1rW8v0Xhwk80um6yFYKbuAxc9c3EZxIHFDYwbi34Uk42u1CdnIiVorvt4RmlSDjIPyzGC2ew==",
"dev": true
},
"dirty-chai": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/dirty-chai/-/dirty-chai-2.0.1.tgz",
"integrity": "sha512-ys79pWKvDMowIDEPC6Fig8d5THiC0DJ2gmTeGzVAoEH18J8OzLud0Jh7I9IWg3NSk8x2UocznUuFmfHCXYZx9w==",
"dev": true
},
"doctrine": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/doctrine/-/doctrine-2.1.0.tgz",
-1
View File
@@ -70,7 +70,6 @@
"babel-jest": "^24.9.0",
"basic-changelog": "gitlab:bloodyhealth/basic-changelog",
"chai": "^4.1.2",
"dirty-chai": "^2.0.1",
"eslint": "^6.4.0",
"eslint-plugin-react": "^7.8.2",
"husky": "^8.0.0",
+2 -11
View File
@@ -1,17 +1,9 @@
import chai from 'chai'
import dirtyChai from 'dirty-chai'
import { expect } from 'chai'
import cycleModule from '../lib/cycle'
const { expect } = chai
chai.use(dirtyChai)
const cycleStartDay = { date: '2018-05-03' }
const cycle = [
{ date: '2018-05-05' },
{ date: '2018-05-04' },
cycleStartDay,
]
const cycle = [{ date: '2018-05-05' }, { date: '2018-05-04' }, cycleStartDay]
const cycleDaysSortedByDate = [
{ date: '2018-07-05' },
@@ -32,7 +24,6 @@ const cycleStartsSortedByDate = [
describe('getCycleByStartDay', () => {
it('gets cycle by cycle start day', () => {
const { getCycleByStartDay } = cycleModule({
cycleDaysSortedByDate,
cycleStartsSortedByDate,
+6 -15
View File
@@ -1,14 +1,7 @@
import chai from 'chai'
import dirtyChai from 'dirty-chai'
import { expect } from 'chai'
import cycleModule from '../lib/cycle'
const { expect } = chai
chai.use(dirtyChai)
const simpleCycleStarts = [
{ date: '2018-05-09' },
{ date: '2018-05-03'},
]
const simpleCycleStarts = [{ date: '2018-05-09' }, { date: '2018-05-03' }]
describe('getCycleDayNumber', () => {
it('works for a date in the current cycle', () => {
@@ -22,7 +15,7 @@ describe('getCycleDayNumber', () => {
it('works for a date which is not in the current cycle', () => {
const cycleStartsSortedByDate = [
{ date: '2018-05-13' },
{ date: '2018-04-10'}
{ date: '2018-04-10' },
]
const date = '2018-04-27'
const { getCycleDayNumber } = cycleModule({ cycleStartsSortedByDate })
@@ -31,9 +24,7 @@ describe('getCycleDayNumber', () => {
})
it('works for a date which is the first and only day in cycle', () => {
const cycleStartsSortedByDate = [
{ date: '2018-05-13' }
]
const cycleStartsSortedByDate = [{ date: '2018-05-13' }]
const date = '2018-05-13'
const { getCycleDayNumber } = cycleModule({ cycleStartsSortedByDate })
@@ -45,7 +36,7 @@ describe('getCycleDayNumber', () => {
const date = '2018-05-17'
const { getCycleDayNumber } = cycleModule({ cycleStartsSortedByDate })
expect(getCycleDayNumber(date)).to.be.null()
expect(getCycleDayNumber(date)).to.be.null
})
it('returns null if the cycle is longer than the max', function () {
@@ -54,6 +45,6 @@ describe('getCycleDayNumber', () => {
const date = '2018-08-16'
const { getCycleDayNumber } = cycleModule({ cycleStartsSortedByDate })
expect(getCycleDayNumber(date)).to.be.null()
expect(getCycleDayNumber(date)).to.be.null
})
})
+25 -34
View File
@@ -1,61 +1,52 @@
import chai from 'chai'
import dirtyChai from 'dirty-chai'
import { expect } from 'chai'
import cycleModule from '../lib/cycle'
const { expect } = chai
chai.use(dirtyChai)
describe('getCycleForDay', () => {
const cycleDaysSortedByDate = [
{
date: '2018-07-05',
bleeding: { value: 2 }
bleeding: { value: 2 },
},
{
date: '2018-06-05',
bleeding: { value: 2 }
bleeding: { value: 2 },
},
{
date: '2018-05-05',
mucus: { value: 2 }
mucus: { value: 2 },
},
{
date: '2018-05-04',
bleeding: { value: 2 }
bleeding: { value: 2 },
},
{
date: '2018-05-03',
bleeding: { value: 2 }
bleeding: { value: 2 },
},
{
date: '2018-04-05',
mucus: { value: 2 }
mucus: { value: 2 },
},
{
date: '2018-04-04',
mucus: { value: 2 }
mucus: { value: 2 },
},
{
date: '2018-04-03',
mucus: { value: 2 }
mucus: { value: 2 },
},
{
date: '2018-04-02',
bleeding: { value: 2 }
bleeding: { value: 2 },
},
]
const cycleStarts = [
'2018-07-05',
'2018-06-05',
'2018-05-03',
'2018-04-02'
]
const cycleStarts = ['2018-07-05', '2018-06-05', '2018-05-03', '2018-04-02']
const { getCycleForDay } = cycleModule({
cycleDaysSortedByDate,
cycleStartsSortedByDate: cycleDaysSortedByDate.filter(d => {
cycleStartsSortedByDate: cycleDaysSortedByDate.filter((d) => {
return cycleStarts.includes(d.date)
})
}),
})
it('gets cycle that has only one day', () => {
@@ -64,16 +55,16 @@ describe('getCycleForDay', () => {
expect(result).to.eql([
{
date: '2018-07-05',
bleeding: { value: 2 }
}
bleeding: { value: 2 },
},
])
const result2 = getCycleForDay('2018-06-05')
expect(result2.length).to.eql(1)
expect(result2).to.eql([
{
date: '2018-06-05',
bleeding: { value: 2 }
}
bleeding: { value: 2 },
},
])
})
@@ -83,8 +74,8 @@ describe('getCycleForDay', () => {
expect(result).to.eql([
{
date: '2018-06-05',
bleeding: { value: 2 }
}
bleeding: { value: 2 },
},
])
})
@@ -96,10 +87,10 @@ describe('getCycleForDay', () => {
it('returns null if the cycle is longer than the max', () => {
const { getCycleForDay } = cycleModule({
cycleDaysSortedByDate,
cycleStartsSortedByDate: cycleDaysSortedByDate.filter(d => {
cycleStartsSortedByDate: cycleDaysSortedByDate.filter((d) => {
return cycleStarts.includes(d.date)
}),
maxCycleLength: 3
maxCycleLength: 3,
})
const result = getCycleForDay('2018-04-04')
expect(result).to.eql(null)
@@ -111,19 +102,19 @@ describe('getCycleForDay', () => {
expect(result).to.eql([
{
date: '2018-04-05',
mucus: { value: 2 }
mucus: { value: 2 },
},
{
date: '2018-04-04',
mucus: { value: 2 }
mucus: { value: 2 },
},
{
date: '2018-04-03',
mucus: { value: 2 }
mucus: { value: 2 },
},
{
date: '2018-04-02',
bleeding: { value: 2 }
bleeding: { value: 2 },
},
])
})
+4 -10
View File
@@ -1,10 +1,6 @@
import chai from 'chai'
import dirtyChai from 'dirty-chai'
import { expect } from '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 = [
@@ -35,7 +31,6 @@ const cycleStartsSortedByDate = [
describe('getCyclesBefore', () => {
it('gets previous cycles', () => {
const { getCyclesBefore } = cycleModule({
cycleDaysSortedByDate,
cycleStartsSortedByDate,
@@ -43,19 +38,18 @@ describe('getCyclesBefore', () => {
const cyclesBeforeJuly = getCyclesBefore(...julyCycle)
expect(cyclesBeforeJuly.length).to.eql(3)
expect(cyclesBeforeJuly).to.eql([ juneCycle, mayCycle, aprilCycle ])
expect(cyclesBeforeJuly).to.eql([juneCycle, mayCycle, aprilCycle])
})
it('skips cycles that are longer than max', () => {
const { getCyclesBefore } = cycleModule({
cycleDaysSortedByDate,
cycleStartsSortedByDate,
maxCycleLength: 30
maxCycleLength: 30,
})
const cyclesBeforeJuly = getCyclesBefore(...julyCycle)
expect(cyclesBeforeJuly.length).to.eql(1)
expect(cyclesBeforeJuly).to.eql([ juneCycle ])
expect(cyclesBeforeJuly).to.eql([juneCycle])
})
})
+71 -69
View File
@@ -1,10 +1,6 @@
import chai from 'chai'
import dirtyChai from 'dirty-chai'
import { expect } from 'chai'
import cycleModule from '../lib/cycle'
const expect = chai.expect
chai.use(dirtyChai)
describe('getMensesDaysRightAfter', () => {
it('works for simple menses start', () => {
const cycleDaysSortedByDate = [
@@ -13,35 +9,35 @@ describe('getMensesDaysRightAfter', () => {
},
{
date: '2018-05-03',
bleeding: { value: 1 }
bleeding: { value: 1 },
},
{
date: '2018-05-02',
bleeding: { value: 1 }
bleeding: { value: 1 },
},
{
date: '2018-05-01',
bleeding: { value: 1 }
bleeding: { value: 1 },
},
{
date: '2018-04-30',
}
},
]
const { getMensesDaysRightAfter } = cycleModule({
cycleDaysSortedByDate,
bleedingDaysSortedByDate: cycleDaysSortedByDate.filter(d => d.bleeding)
bleedingDaysSortedByDate: cycleDaysSortedByDate.filter((d) => d.bleeding),
})
const days = getMensesDaysRightAfter(cycleDaysSortedByDate[3])
expect(days).to.eql([
{
date: '2018-05-03',
bleeding: { value: 1 }
bleeding: { value: 1 },
},
{
date: '2018-05-02',
bleeding: { value: 1 }
}
bleeding: { value: 1 },
},
])
})
@@ -52,40 +48,40 @@ describe('getMensesDaysRightAfter', () => {
},
{
date: '2018-05-03',
bleeding: { value: 1 }
bleeding: { value: 1 },
},
{
date: '2018-05-02',
bleeding: { value: 1 }
bleeding: { value: 1 },
},
{
date: '2018-05-01',
bleeding: { value: 1 }
bleeding: { value: 1 },
},
{
date: '2018-04-30',
bleeding: null
}
bleeding: null,
},
]
const { getMensesDaysRightAfter } = cycleModule({
cycleDaysSortedByDate,
bleedingDaysSortedByDate: cycleDaysSortedByDate.filter(d => d.bleeding)
bleedingDaysSortedByDate: cycleDaysSortedByDate.filter((d) => d.bleeding),
})
const days = getMensesDaysRightAfter(cycleDaysSortedByDate[4])
expect(days).to.eql([
{
date: '2018-05-03',
bleeding: { value: 1 }
bleeding: { value: 1 },
},
{
date: '2018-05-02',
bleeding: { value: 1 }
bleeding: { value: 1 },
},
{
date: '2018-05-01',
bleeding: { value: 1 }
}
bleeding: { value: 1 },
},
])
})
@@ -96,31 +92,31 @@ describe('getMensesDaysRightAfter', () => {
},
{
date: '2018-05-03',
bleeding: { value: 1 }
bleeding: { value: 1 },
},
{
date: '2018-05-02',
bleeding: { value: 1, exclude: true }
bleeding: { value: 1, exclude: true },
},
{
date: '2018-05-01',
bleeding: { value: 1 }
bleeding: { value: 1 },
},
{
date: '2018-04-30',
}
},
]
const { getMensesDaysRightAfter } = cycleModule({
cycleDaysSortedByDate,
bleedingDaysSortedByDate: cycleDaysSortedByDate.filter(d => d.bleeding)
bleedingDaysSortedByDate: cycleDaysSortedByDate.filter((d) => d.bleeding),
})
const days = getMensesDaysRightAfter(cycleDaysSortedByDate[3])
expect(days).to.eql([
{
date: '2018-05-03',
bleeding: { value: 1 }
}
bleeding: { value: 1 },
},
])
})
@@ -137,16 +133,16 @@ describe('getMensesDaysRightAfter', () => {
},
{
date: '2018-05-01',
bleeding: { value: 1 }
bleeding: { value: 1 },
},
{
date: '2018-04-30',
}
},
]
const { getMensesDaysRightAfter } = cycleModule({
cycleDaysSortedByDate,
bleedingDaysSortedByDate: cycleDaysSortedByDate.filter(d => d.bleeding)
bleedingDaysSortedByDate: cycleDaysSortedByDate.filter((d) => d.bleeding),
})
const days = getMensesDaysRightAfter(cycleDaysSortedByDate[3])
expect(days).to.eql([])
@@ -156,7 +152,7 @@ describe('getMensesDaysRightAfter', () => {
const cycleDaysSortedByDate = [
{
date: '2018-05-04',
bleeding: { value: 1 }
bleeding: { value: 1 },
},
{
date: '2018-05-03',
@@ -166,16 +162,16 @@ describe('getMensesDaysRightAfter', () => {
},
{
date: '2018-05-01',
bleeding: { value: 1 }
bleeding: { value: 1 },
},
{
date: '2018-04-30',
}
},
]
const { getMensesDaysRightAfter } = cycleModule({
cycleDaysSortedByDate,
bleedingDaysSortedByDate: cycleDaysSortedByDate.filter(d => d.bleeding)
bleedingDaysSortedByDate: cycleDaysSortedByDate.filter((d) => d.bleeding),
})
const days = getMensesDaysRightAfter(cycleDaysSortedByDate[3])
expect(days).to.eql([])
@@ -188,77 +184,83 @@ describe('getMensesDaysRightAfter', () => {
},
{
date: '2018-05-05',
bleeding: { value: 1 }
bleeding: { value: 1 },
},
{
date: '2018-05-03',
bleeding: { value: 1 }
bleeding: { value: 1 },
},
{
date: '2018-05-01',
bleeding: { value: 1 }
bleeding: { value: 1 },
},
{
date: '2018-04-30',
}
},
]
const { getMensesDaysRightAfter } = cycleModule({
cycleDaysSortedByDate,
bleedingDaysSortedByDate: cycleDaysSortedByDate.filter(d => d.bleeding)
bleedingDaysSortedByDate: cycleDaysSortedByDate.filter((d) => d.bleeding),
})
const days = getMensesDaysRightAfter(cycleDaysSortedByDate[3])
expect(days).to.eql([
{
date: '2018-05-05',
bleeding: { value: 1 }
bleeding: { value: 1 },
},
{
date: '2018-05-03',
bleeding: { value: 1 }
}
bleeding: { value: 1 },
},
])
})
describe('with cycle thresholds', () => {
const maxBreakInBleeding = 3
it('disregards bleeding breaks shorter than maxAllowedBleedingBreak in a bleeding period', () => {
const bleedingDays = [{
date: '2018-05-14',
bleeding: {
value: 2
}
}, {
date: '2018-05-10',
bleeding: {
value: 2
}
}]
const bleedingDays = [
{
date: '2018-05-14',
bleeding: {
value: 2,
},
},
{
date: '2018-05-10',
bleeding: {
value: 2,
},
},
]
const getMensesDaysRightAfter = cycleModule({
bleedingDaysSortedByDate: bleedingDays,
maxBreakInBleeding
maxBreakInBleeding,
}).getMensesDaysRightAfter
const result = getMensesDaysRightAfter(bleedingDays[1])
expect(result).to.eql([bleedingDays[0]])
})
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 bleedingDays = [
{
date: '2018-05-14',
bleeding: {
value: 2,
},
},
{
date: '2018-05-09',
bleeding: {
value: 2,
},
},
]
const getMensesDaysRightAfter = cycleModule({
bleedingDaysSortedByDate: bleedingDays,
maxBreakInBleeding
maxBreakInBleeding,
}).getMensesDaysRightAfter
const result = getMensesDaysRightAfter(bleedingDays[1])
expect(result).to.eql([])
+73 -147
View File
@@ -1,24 +1,22 @@
import chai from 'chai'
import dirtyChai from 'dirty-chai'
import { expect } from 'chai'
import cycleModule from '../lib/cycle'
const { expect } = chai
chai.use(dirtyChai)
describe('getPredictedMenses', () => {
describe('cannot predict next menses', () => {
it('if no bleeding is documented', () => {
const cycleDaysSortedByDate = [ {} ]
const cycleDaysSortedByDate = [{}]
const cycleStarts = []
const { getPredictedMenses } = cycleModule({
cycleDaysSortedByDate,
bleedingDaysSortedByDate: cycleDaysSortedByDate.filter(d => d.bleeding),
cycleStartsSortedByDate: cycleDaysSortedByDate.filter(d => {
bleedingDaysSortedByDate: cycleDaysSortedByDate.filter(
(d) => d.bleeding
),
cycleStartsSortedByDate: cycleDaysSortedByDate.filter((d) => {
return cycleStarts.includes(d.date)
}),
maxCycleLength: 99,
minCyclesForPrediction: 1
minCyclesForPrediction: 1,
})
const result = getPredictedMenses()
expect(result).to.eql([])
@@ -28,19 +26,21 @@ describe('getPredictedMenses', () => {
const cycleDaysSortedByDate = [
{
date: '2018-06-02',
bleeding: { value: 2 }
}
bleeding: { value: 2 },
},
]
const cycleStarts = ['2018-06-02']
const { getPredictedMenses } = cycleModule({
cycleDaysSortedByDate,
bleedingDaysSortedByDate: cycleDaysSortedByDate.filter(d => d.bleeding),
cycleStartsSortedByDate: cycleDaysSortedByDate.filter(d => {
bleedingDaysSortedByDate: cycleDaysSortedByDate.filter(
(d) => d.bleeding
),
cycleStartsSortedByDate: cycleDaysSortedByDate.filter((d) => {
return cycleStarts.includes(d.date)
}),
maxCycleLength: 99,
minCyclesForPrediction: 1
minCyclesForPrediction: 1,
})
const result = getPredictedMenses()
expect(result).to.eql([])
@@ -50,23 +50,25 @@ describe('getPredictedMenses', () => {
const cycleDaysSortedByDate = [
{
date: '2018-06-02',
bleeding: { value: 2 }
bleeding: { value: 2 },
},
{
date: '2018-06-01',
bleeding: { value: 2 }
bleeding: { value: 2 },
},
{
date: '2018-05-01',
bleeding: { value: 2 }
bleeding: { value: 2 },
},
]
const cycleStarts = ['2018-06-01', '2018-05-01']
const { getPredictedMenses } = cycleModule({
cycleDaysSortedByDate,
bleedingDaysSortedByDate: cycleDaysSortedByDate.filter(d => d.bleeding),
cycleStartsSortedByDate: cycleDaysSortedByDate.filter(d => {
bleedingDaysSortedByDate: cycleDaysSortedByDate.filter(
(d) => d.bleeding
),
cycleStartsSortedByDate: cycleDaysSortedByDate.filter((d) => {
return cycleStarts.includes(d.date)
}),
})
@@ -78,38 +80,40 @@ describe('getPredictedMenses', () => {
const cycleDaysSortedByDate = [
{
date: '2018-06-02',
bleeding: { value: 2 }
bleeding: { value: 2 },
},
{
date: '2018-06-01',
bleeding: { value: 2 }
bleeding: { value: 2 },
},
{
date: '2018-05-01',
bleeding: { value: 2 }
bleeding: { value: 2 },
},
{
date: '2018-04-03',
bleeding: { value: 2 }
bleeding: { value: 2 },
},
{
date: '2018-04-02',
bleeding: { value: 2 }
bleeding: { value: 2 },
},
{
date: '2018-04-01',
bleeding: { value: 2 }
bleeding: { value: 2 },
},
]
const cycleStarts = ['2018-06-01', '2018-05-01', '2018-04-01']
const { getPredictedMenses } = cycleModule({
cycleDaysSortedByDate,
bleedingDaysSortedByDate: cycleDaysSortedByDate.filter(d => d.bleeding),
cycleStartsSortedByDate: cycleDaysSortedByDate.filter(d => {
bleedingDaysSortedByDate: cycleDaysSortedByDate.filter(
(d) => d.bleeding
),
cycleStartsSortedByDate: cycleDaysSortedByDate.filter((d) => {
return cycleStarts.includes(d.date)
}),
maxCycleLength: 2
maxCycleLength: 2,
})
const result = getPredictedMenses()
expect(result).to.eql([])
@@ -120,44 +124,26 @@ describe('getPredictedMenses', () => {
const cycleDaysSortedByDate = [
{
date: '2018-07-15',
bleeding: { value: 2 }
bleeding: { value: 2 },
},
{
date: '2018-07-01',
bleeding: { value: 2 }
}
bleeding: { value: 2 },
},
]
const cycleStarts = ['2018-07-15', '2018-07-01']
const { getPredictedMenses } = cycleModule({
cycleDaysSortedByDate,
cycleStartsSortedByDate: cycleDaysSortedByDate.filter(d => {
cycleStartsSortedByDate: cycleDaysSortedByDate.filter((d) => {
return cycleStarts.includes(d.date)
}),
minCyclesForPrediction: 1
minCyclesForPrediction: 1,
})
const result = getPredictedMenses()
const expectedResult = [
[
'2018-07-27',
'2018-07-28',
'2018-07-29',
'2018-07-30',
'2018-07-31'
],
[
'2018-08-10',
'2018-08-11',
'2018-08-12',
'2018-08-13',
'2018-08-14',
],
[
'2018-08-24',
'2018-08-25',
'2018-08-26',
'2018-08-27',
'2018-08-28',
]
['2018-07-27', '2018-07-28', '2018-07-29', '2018-07-30', '2018-07-31'],
['2018-08-10', '2018-08-11', '2018-08-12', '2018-08-13', '2018-08-14'],
['2018-08-24', '2018-08-25', '2018-08-26', '2018-08-27', '2018-08-28'],
]
expect(result).to.eql(expectedResult)
})
@@ -166,44 +152,32 @@ describe('getPredictedMenses', () => {
const cycleDaysSortedByDate = [
{
date: '2018-08-02',
bleeding: { value: 2 }
bleeding: { value: 2 },
},
{
date: '2018-07-02',
bleeding: { value: 2 }
bleeding: { value: 2 },
},
{
date: '2018-06-01',
bleeding: { value: 2 }
bleeding: { value: 2 },
},
{
date: '2018-05-01',
bleeding: { value: 2 }
bleeding: { value: 2 },
},
]
const { getPredictedMenses } = cycleModule({
cycleDaysSortedByDate,
cycleStartsSortedByDate: cycleDaysSortedByDate,
minCyclesForPrediction: 1
minCyclesForPrediction: 1,
})
const result = getPredictedMenses()
const expectedResult = [
[
'2018-09-01',
'2018-09-02',
'2018-09-03'
],
[
'2018-10-02',
'2018-10-03',
'2018-10-04'
],
[
'2018-11-02',
'2018-11-03',
'2018-11-04'
]
['2018-09-01', '2018-09-02', '2018-09-03'],
['2018-10-02', '2018-10-03', '2018-10-04'],
['2018-11-02', '2018-11-03', '2018-11-04'],
]
expect(result).to.eql(expectedResult)
})
@@ -212,43 +186,31 @@ describe('getPredictedMenses', () => {
const cycleDaysSortedByDate = [
{
date: '2018-08-01',
bleeding: { value: 2 }
bleeding: { value: 2 },
},
{
date: '2018-07-18',
bleeding: { value: 2 }
bleeding: { value: 2 },
},
{
date: '2018-07-05',
bleeding: { value: 2 }
bleeding: { value: 2 },
},
{
date: '2018-06-20',
bleeding: { value: 2 }
bleeding: { value: 2 },
},
]
const { getPredictedMenses } = cycleModule({
cycleDaysSortedByDate,
cycleStartsSortedByDate: cycleDaysSortedByDate
cycleStartsSortedByDate: cycleDaysSortedByDate,
})
const result = getPredictedMenses()
const expectedResult = [
[
'2018-08-14',
'2018-08-15',
'2018-08-16'
],
[
'2018-08-28',
'2018-08-29',
'2018-08-30'
],
[
'2018-09-11',
'2018-09-12',
'2018-09-13'
]
['2018-08-14', '2018-08-15', '2018-08-16'],
['2018-08-28', '2018-08-29', '2018-08-30'],
['2018-09-11', '2018-09-12', '2018-09-13'],
]
expect(result).to.eql(expectedResult)
})
@@ -257,49 +219,31 @@ describe('getPredictedMenses', () => {
const cycleDaysSortedByDate = [
{
date: '2018-08-01',
bleeding: { value: 2 }
bleeding: { value: 2 },
},
{
date: '2018-07-14',
bleeding: { value: 2 }
bleeding: { value: 2 },
},
{
date: '2018-07-04',
bleeding: { value: 2 }
bleeding: { value: 2 },
},
{
date: '2018-06-20',
bleeding: { value: 2 }
bleeding: { value: 2 },
},
]
const { getPredictedMenses } = cycleModule({
cycleDaysSortedByDate,
cycleStartsSortedByDate: cycleDaysSortedByDate
cycleStartsSortedByDate: cycleDaysSortedByDate,
})
const result = getPredictedMenses()
const expectedResult = [
[
'2018-08-13',
'2018-08-14',
'2018-08-15',
'2018-08-16',
'2018-08-17',
],
[
'2018-08-27',
'2018-08-28',
'2018-08-29',
'2018-08-30',
'2018-08-31',
],
[
'2018-09-10',
'2018-09-11',
'2018-09-12',
'2018-09-13',
'2018-09-14',
]
['2018-08-13', '2018-08-14', '2018-08-15', '2018-08-16', '2018-08-17'],
['2018-08-27', '2018-08-28', '2018-08-29', '2018-08-30', '2018-08-31'],
['2018-09-10', '2018-09-11', '2018-09-12', '2018-09-13', '2018-09-14'],
]
expect(result).to.eql(expectedResult)
})
@@ -308,54 +252,36 @@ describe('getPredictedMenses', () => {
const cycleDaysSortedByDate = [
{
date: '2018-08-01',
bleeding: { value: 2 }
bleeding: { value: 2 },
},
{
date: '2018-07-14',
bleeding: { value: 2 }
bleeding: { value: 2 },
},
{
date: '2018-07-04',
bleeding: { value: 2 }
bleeding: { value: 2 },
},
{
date: '2018-06-20',
bleeding: { value: 2 }
bleeding: { value: 2 },
},
{
date: '2018-04-20',
bleeding: { value: 2 }
bleeding: { value: 2 },
},
]
const { getPredictedMenses } = cycleModule({
cycleDaysSortedByDate,
cycleStartsSortedByDate: cycleDaysSortedByDate,
maxCycleLength: 50
maxCycleLength: 50,
})
const result = getPredictedMenses()
const expectedResult = [
[
'2018-08-13',
'2018-08-14',
'2018-08-15',
'2018-08-16',
'2018-08-17',
],
[
'2018-08-27',
'2018-08-28',
'2018-08-29',
'2018-08-30',
'2018-08-31',
],
[
'2018-09-10',
'2018-09-11',
'2018-09-12',
'2018-09-13',
'2018-09-14',
]
['2018-08-13', '2018-08-14', '2018-08-15', '2018-08-16', '2018-08-17'],
['2018-08-27', '2018-08-28', '2018-08-29', '2018-08-30', '2018-08-31'],
['2018-09-10', '2018-09-11', '2018-09-12', '2018-09-13', '2018-09-14'],
]
expect(result).to.eql(expectedResult)
})
+1 -9
View File
@@ -1,10 +1,6 @@
import chai from 'chai'
import dirtyChai from 'dirty-chai'
import { expect } from 'chai'
import cycleModule from '../lib/cycle'
const { expect } = chai
chai.use(dirtyChai)
const mayCycle = [
{ date: '2018-05-05' },
{ date: '2018-05-04' },
@@ -30,7 +26,6 @@ const cycleStartsSortedByDate = [
describe('getPreviousCycle', () => {
it('gets previous cycle', () => {
const { getPreviousCycle } = cycleModule({
cycleDaysSortedByDate,
cycleStartsSortedByDate,
@@ -40,7 +35,6 @@ describe('getPreviousCycle', () => {
})
it('returns null when target day is not in a cyle', () => {
const { getPreviousCycle } = cycleModule({
cycleDaysSortedByDate,
cycleStartsSortedByDate: [],
@@ -50,7 +44,6 @@ describe('getPreviousCycle', () => {
})
it('returns null when there is no previous cycle', () => {
const { getPreviousCycle } = cycleModule({
cycleDaysSortedByDate,
cycleStartsSortedByDate,
@@ -60,7 +53,6 @@ describe('getPreviousCycle', () => {
})
it('returns null when the previous cycle > maxcyclelength', () => {
const { getPreviousCycle } = cycleModule({
cycleDaysSortedByDate,
cycleStartsSortedByDate,
+62 -60
View File
@@ -1,10 +1,6 @@
import chai from 'chai'
import dirtyChai from 'dirty-chai'
import { expect } from 'chai'
import cycleModule from '../lib/cycle'
const { expect } = chai
chai.use(dirtyChai)
describe('isMensesStart', () => {
it('works for simple menses start', () => {
const cycleDaysSortedByDate = [
@@ -13,57 +9,57 @@ describe('isMensesStart', () => {
},
{
date: '2018-05-03',
bleeding: { value: 1 }
bleeding: { value: 1 },
},
{
date: '2018-05-02',
bleeding: { value: 1 }
bleeding: { value: 1 },
},
{
date: '2018-05-01',
bleeding: { value: 1 }
bleeding: { value: 1 },
},
{
date: '2018-04-30',
}
},
]
const { isMensesStart } = cycleModule({
cycleDaysSortedByDate,
bleedingDaysSortedByDate: cycleDaysSortedByDate.filter(d => d.bleeding)
bleedingDaysSortedByDate: cycleDaysSortedByDate.filter((d) => d.bleeding),
})
const start = isMensesStart(cycleDaysSortedByDate[3])
expect(start).to.be.true()
expect(isMensesStart(cycleDaysSortedByDate[0])).to.be.false()
expect(isMensesStart(cycleDaysSortedByDate[1])).to.be.false()
expect(isMensesStart(cycleDaysSortedByDate[2])).to.be.false()
expect(isMensesStart(cycleDaysSortedByDate[4])).to.be.false()
expect(start).to.be.true
expect(isMensesStart(cycleDaysSortedByDate[0])).to.be.false
expect(isMensesStart(cycleDaysSortedByDate[1])).to.be.false
expect(isMensesStart(cycleDaysSortedByDate[2])).to.be.false
expect(isMensesStart(cycleDaysSortedByDate[4])).to.be.false
})
it('works with previous excluded value', () => {
const cycleDaysSortedByDate = [
{
date: '2018-06-01',
bleeding: { value: 2 }
bleeding: { value: 2 },
},
{
date: '2018-05-01',
bleeding: { value: 2 }
bleeding: { value: 2 },
},
{
date: '2018-04-30',
bleeding: { value: 2 , exclude: true}
bleeding: { value: 2, exclude: true },
},
]
const { isMensesStart } = cycleModule({
cycleDaysSortedByDate,
bleedingDaysSortedByDate: cycleDaysSortedByDate.filter(d => d.bleeding)
bleedingDaysSortedByDate: cycleDaysSortedByDate.filter((d) => d.bleeding),
})
const start = isMensesStart(cycleDaysSortedByDate[1])
expect(start).to.be.true()
expect(start).to.be.true
const notStart = isMensesStart(cycleDaysSortedByDate[2])
expect(notStart).to.be.false()
expect(notStart).to.be.false
})
it('returns false when day has no bleeding', () => {
@@ -76,16 +72,16 @@ describe('isMensesStart', () => {
},
{
date: '2018-04-30',
bleeding: { value: 2 , exclude: true}
bleeding: { value: 2, exclude: true },
},
]
const { isMensesStart } = cycleModule({
cycleDaysSortedByDate,
bleedingDaysSortedByDate: cycleDaysSortedByDate.filter(d => d.bleeding)
bleedingDaysSortedByDate: cycleDaysSortedByDate.filter((d) => d.bleeding),
})
const start = isMensesStart(cycleDaysSortedByDate[0])
expect(start).to.be.false()
expect(start).to.be.false
})
it('returns false when there is a previous bleeding day within the threshold', () => {
@@ -98,23 +94,23 @@ describe('isMensesStart', () => {
},
{
date: '2018-04-30',
bleeding: { value: 2 }
bleeding: { value: 2 },
},
{
date: '2018-04-29'
date: '2018-04-29',
},
{
date: '2018-04-28',
bleeding: { value: 2 }
bleeding: { value: 2 },
},
]
const { isMensesStart } = cycleModule({
cycleDaysSortedByDate,
bleedingDaysSortedByDate: cycleDaysSortedByDate.filter(d => d.bleeding)
bleedingDaysSortedByDate: cycleDaysSortedByDate.filter((d) => d.bleeding),
})
const start = isMensesStart(cycleDaysSortedByDate[2])
expect(start).to.be.false()
expect(start).to.be.false
})
it('returns true when there is a previous excluded bleeding day within the threshold', () => {
@@ -127,67 +123,73 @@ describe('isMensesStart', () => {
},
{
date: '2018-04-30',
bleeding: { value: 2 }
bleeding: { value: 2 },
},
{
date: '2018-04-29'
date: '2018-04-29',
},
{
date: '2018-04-28',
bleeding: { value: 2 , exclude: true}
bleeding: { value: 2, exclude: true },
},
]
const { isMensesStart } = cycleModule({
cycleDaysSortedByDate,
bleedingDaysSortedByDate: cycleDaysSortedByDate.filter(d => d.bleeding)
bleedingDaysSortedByDate: cycleDaysSortedByDate.filter((d) => d.bleeding),
})
const start = isMensesStart(cycleDaysSortedByDate[2])
expect(start).to.be.true()
expect(start).to.be.true
})
describe('with cycle thresholds', () => {
const maxBreakInBleeding = 3
it('disregards bleeding breaks equal to maxAllowedBleedingBreak in a bleeding period', () => {
const bleedingDays = [{
date: '2018-05-14',
bleeding: {
value: 2
}
}, {
date: '2018-05-10',
bleeding: {
value: 2
}
}]
const bleedingDays = [
{
date: '2018-05-14',
bleeding: {
value: 2,
},
},
{
date: '2018-05-10',
bleeding: {
value: 2,
},
},
]
const isMensesStart = cycleModule({
bleedingDaysSortedByDate: bleedingDays,
maxBreakInBleeding
maxBreakInBleeding,
}).isMensesStart
const result = isMensesStart(bleedingDays[0])
expect(result).to.be.false()
expect(result).to.be.false
})
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 bleedingDays = [
{
date: '2018-05-14',
bleeding: {
value: 2,
},
},
{
date: '2018-05-09',
bleeding: {
value: 2,
},
},
]
const isMensesStart = cycleModule({
bleedingDaysSortedByDate: bleedingDays,
maxBreakInBleeding
maxBreakInBleeding,
}).isMensesStart
const result = isMensesStart(bleedingDays[0])
expect(result).to.be.true()
expect(result).to.be.true
})
})
})
+4 -8
View File
@@ -1,16 +1,12 @@
import chai from 'chai'
import dirtyChai from 'dirty-chai'
const expect = chai.expect
chai.use(dirtyChai)
import { expect } from 'chai'
import getSensiplanMucus from '../lib/nfp-mucus'
describe('getSensiplanMucus', () => {
it('returns null if there is no value for feeling or texture', () => {
expect(getSensiplanMucus()).to.be.null()
expect(getSensiplanMucus(undefined, 3)).to.be.null()
expect(getSensiplanMucus(2, undefined)).to.be.null()
expect(getSensiplanMucus()).to.be.null
expect(getSensiplanMucus(undefined, 3)).to.be.null
expect(getSensiplanMucus(2, undefined)).to.be.null
})
describe('results in t for:', () => {
+33 -38
View File
@@ -1,27 +1,22 @@
import chai from 'chai'
import dirtyChai from 'dirty-chai'
import { expect } from 'chai'
import maybeSetNewCycleStart from '../lib/set-new-cycle-start'
const expect = chai.expect
chai.use(dirtyChai)
describe('maybeSetNewCycleStart', () => {
const deletedBleedingValue = null
const excludedBleedingValue = {
value: 2,
exclude: true
exclude: true,
}
function getFixtures() {
const cycleStartDay = {
date: '2020-01-01',
isCycleStart: true,
bleeding: {
value: 2,
exclude: false
}
exclude: false,
},
}
const mensesDaysAfter = [
@@ -31,9 +26,9 @@ describe('maybeSetNewCycleStart', () => {
value: {
bleeding: {
value: 2,
exclude: false
}
}
exclude: false,
},
},
},
{
date: '2020-01-03',
@@ -41,9 +36,9 @@ describe('maybeSetNewCycleStart', () => {
value: {
bleeding: {
value: 2,
exclude: false
}
}
exclude: false,
},
},
},
{
date: '2020-01-02',
@@ -51,10 +46,10 @@ describe('maybeSetNewCycleStart', () => {
value: {
bleeding: {
value: 2,
exclude: false
}
}
}
exclude: false,
},
},
},
]
const notCycleStartDay = {
@@ -62,14 +57,14 @@ describe('maybeSetNewCycleStart', () => {
isCycleStart: false,
bleeding: {
value: 2,
exclude: false
}
exclude: false,
},
}
return [cycleStartDay, mensesDaysAfter, notCycleStartDay]
}
const checkIsMensesStart = cycleDay => {
const checkIsMensesStart = (cycleDay) => {
if (cycleDay.date === '2020-01-02') return true
}
@@ -80,11 +75,11 @@ describe('maybeSetNewCycleStart', () => {
val: deletedBleedingValue,
cycleDay: cycleStartDay,
mensesDaysAfter,
checkIsMensesStart
checkIsMensesStart,
})
expect(cycleStartDay.isCycleStart).to.be.false()
expect(cycleStartDay.bleeding).to.be.null()
expect(mensesDaysAfter[2].isCycleStart).to.be.true()
expect(cycleStartDay.isCycleStart).to.be.false
expect(cycleStartDay.bleeding).to.be.null
expect(mensesDaysAfter[2].isCycleStart).to.be.true
})
it('sets new cycle start when first day of period excluded', () => {
@@ -94,12 +89,12 @@ describe('maybeSetNewCycleStart', () => {
val: excludedBleedingValue,
cycleDay: cycleStartDay,
mensesDaysAfter,
checkIsMensesStart
checkIsMensesStart,
})
expect(cycleStartDay.isCycleStart).to.be.false()
expect(cycleStartDay.isCycleStart).to.be.false
expect(cycleStartDay.bleeding).to.equal(excludedBleedingValue)
expect(mensesDaysAfter[2].isCycleStart).to.be.true()
expect(mensesDaysAfter[2].isCycleStart).to.be.true
})
it('does not set new cycle start when other day of period deleted', () => {
@@ -109,17 +104,17 @@ describe('maybeSetNewCycleStart', () => {
val: deletedBleedingValue,
cycleDay: notCycleStartDay,
mensesDaysAfter,
checkIsMensesStart
checkIsMensesStart,
})
expect(cycleStartDay.isCycleStart).to.be.true()
expect(notCycleStartDay.isCycleStart).to.be.false()
expect(cycleStartDay.isCycleStart).to.be.true
expect(notCycleStartDay.isCycleStart).to.be.false
expect(notCycleStartDay.bleeding).to.equal(deletedBleedingValue)
})
it('does not set new cycle start when other day of period excluded', () => {
const excludedBleedingValue = {
value: 2,
exclude: true
exclude: true,
}
const [cycleStartDay, mensesDaysAfter, notCycleStartDay] = getFixtures()
@@ -128,11 +123,11 @@ describe('maybeSetNewCycleStart', () => {
val: excludedBleedingValue,
cycleDay: notCycleStartDay,
mensesDaysAfter,
checkIsMensesStart
checkIsMensesStart,
})
expect(cycleStartDay.isCycleStart).to.be.true()
expect(notCycleStartDay.isCycleStart).to.be.false()
expect(cycleStartDay.isCycleStart).to.be.true
expect(notCycleStartDay.isCycleStart).to.be.false
expect(notCycleStartDay.bleeding).to.equal(excludedBleedingValue)
})
it('works when there are no following bleeding days', () => {
@@ -142,10 +137,10 @@ describe('maybeSetNewCycleStart', () => {
val: deletedBleedingValue,
cycleDay: cycleStartDay,
mensesDaysAfter: [],
checkIsMensesStart
checkIsMensesStart,
})
expect(cycleStartDay.isCycleStart).to.be.false()
expect(cycleStartDay.isCycleStart).to.be.false
expect(cycleStartDay.bleeding).to.equal(deletedBleedingValue)
})
})