Merge branch 'master'
This commit is contained in:
@@ -25,3 +25,6 @@ You can run the tests with `npm test`.
|
|||||||
## Debugging
|
## Debugging
|
||||||
When running into an old version of the app try to run the following command first:
|
When running into an old version of the app try to run the following command first:
|
||||||
`react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res`
|
`react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res`
|
||||||
|
|
||||||
|
## NFP rules
|
||||||
|
More information about how the app calculates fertility status and bleeding predictions in the [wiki on Gitlab](https://gitlab.com/bloodyhealth/drip/wikis/home)
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ export default class DayColumn extends Component {
|
|||||||
temperatureExclude,
|
temperatureExclude,
|
||||||
bleeding,
|
bleeding,
|
||||||
mucus,
|
mucus,
|
||||||
|
cervix,
|
||||||
drawFhmLine,
|
drawFhmLine,
|
||||||
drawLtlAt,
|
drawLtlAt,
|
||||||
rightY,
|
rightY,
|
||||||
@@ -135,4 +136,4 @@ export default class DayColumn extends Component {
|
|||||||
</View>
|
</View>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,6 +61,11 @@ const styles = {
|
|||||||
'#a64ca6',
|
'#a64ca6',
|
||||||
'#993299'
|
'#993299'
|
||||||
],
|
],
|
||||||
|
cervixIcon: {
|
||||||
|
width: 12,
|
||||||
|
height: 12,
|
||||||
|
borderRadius: 50
|
||||||
|
},
|
||||||
yAxis: {
|
yAxis: {
|
||||||
width: config.columnWidth,
|
width: config.columnWidth,
|
||||||
borderRightWidth: 0.5,
|
borderRightWidth: 0.5,
|
||||||
|
|||||||
+10
-4
@@ -8,7 +8,7 @@ import {
|
|||||||
import { LocalDate, ChronoUnit } from 'js-joda'
|
import { LocalDate, ChronoUnit } from 'js-joda'
|
||||||
import styles from '../styles/index'
|
import styles from '../styles/index'
|
||||||
import cycleModule from '../lib/cycle'
|
import cycleModule from '../lib/cycle'
|
||||||
import { getOrCreateCycleDay, bleedingDaysSortedByDate, fillWithDummyData, deleteAll } from '../db'
|
import { getOrCreateCycleDay, bleedingDaysSortedByDate, fillWithMucusDummyData, fillWithCervixDummyData, deleteAll } from '../db'
|
||||||
import {bleedingPrediction as labels} from './labels'
|
import {bleedingPrediction as labels} from './labels'
|
||||||
|
|
||||||
const getCycleDayNumber = cycleModule().getCycleDayNumber
|
const getCycleDayNumber = cycleModule().getCycleDayNumber
|
||||||
@@ -62,8 +62,14 @@ export default class Home extends Component {
|
|||||||
</View>
|
</View>
|
||||||
<View style={styles.homeButton}>
|
<View style={styles.homeButton}>
|
||||||
<Button
|
<Button
|
||||||
onPress={() => fillWithDummyData()}
|
onPress={() => fillWithMucusDummyData()}
|
||||||
title="fill with example data">
|
title="fill with example data for mucus&temp">
|
||||||
|
</Button>
|
||||||
|
</View>
|
||||||
|
<View style={styles.homeButton}>
|
||||||
|
<Button
|
||||||
|
onPress={() => fillWithCervixDummyData()}
|
||||||
|
title="fill with example data for cervix&temp">
|
||||||
</Button>
|
</Button>
|
||||||
</View>
|
</View>
|
||||||
<View style={styles.homeButton}>
|
<View style={styles.homeButton}>
|
||||||
@@ -107,4 +113,4 @@ function determinePredictionText() {
|
|||||||
} else {
|
} else {
|
||||||
return labels.predictionStartedXDaysLeft(daysToEnd)
|
return labels.predictionStartedXDaysLeft(daysToEnd)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+26
-2
@@ -1,6 +1,9 @@
|
|||||||
function convertToSymptoFormat(val) {
|
function convertToSymptoFormat(val) {
|
||||||
const sympto = { date: val.date }
|
const sympto = { date: val.date }
|
||||||
if (val.temperature) sympto.temperature = { value: val.temperature, exclude: false }
|
if (val.temperature) sympto.temperature = {
|
||||||
|
value: val.temperature,
|
||||||
|
exclude: false
|
||||||
|
}
|
||||||
if (val.mucus) sympto.mucus = {
|
if (val.mucus) sympto.mucus = {
|
||||||
value: val.mucus,
|
value: val.mucus,
|
||||||
exclude: false,
|
exclude: false,
|
||||||
@@ -11,7 +14,7 @@ function convertToSymptoFormat(val) {
|
|||||||
return sympto
|
return sympto
|
||||||
}
|
}
|
||||||
|
|
||||||
export const cycleWithFhm = [
|
export const cycleWithFhmMucus = [
|
||||||
{ date: '2018-07-01', bleeding: 2 },
|
{ date: '2018-07-01', bleeding: 2 },
|
||||||
{ date: '2018-07-02', bleeding: 1 },
|
{ date: '2018-07-02', bleeding: 1 },
|
||||||
{ date: '2018-07-06', temperature: 36.2},
|
{ date: '2018-07-06', temperature: 36.2},
|
||||||
@@ -26,6 +29,27 @@ export const cycleWithFhm = [
|
|||||||
{ date: '2018-07-18', temperature: 36.9, mucus: 2 }
|
{ date: '2018-07-18', temperature: 36.9, mucus: 2 }
|
||||||
].map(convertToSymptoFormat).reverse()
|
].map(convertToSymptoFormat).reverse()
|
||||||
|
|
||||||
|
export const cycleWithFhmCervix = [
|
||||||
|
{ date: '2018-08-01', bleeding: 2 },
|
||||||
|
{ date: '2018-08-02', bleeding: 1 },
|
||||||
|
{ date: '2018-08-03', bleeding: 0 },
|
||||||
|
{ date: '2018-08-04', bleeding: 0 },
|
||||||
|
{ date: '2018-08-05', temperature: 36.07 },
|
||||||
|
{ date: '2018-08-06', temperature: 36.2 },
|
||||||
|
{ date: '2018-08-07', temperature: 36.35 },
|
||||||
|
{ date: '2018-08-08', temperature: 36.4 },
|
||||||
|
{ date: '2018-08-09', temperature: 36.3 },
|
||||||
|
{ date: '2018-08-10', temperature: 36.45 },
|
||||||
|
{ date: '2018-08-11', temperature: 36.45 },
|
||||||
|
{ date: '2018-08-12', temperature: 36.7, cervix: { isClosed: false, isHard: false } },
|
||||||
|
{ date: '2018-08-13', temperature: 36.8, cervix: { isClosed: true, isHard: true } },
|
||||||
|
{ date: '2018-08-14', temperature: 36.75, cervix: { isClosed: true, isHard: true } },
|
||||||
|
{ date: '2018-08-15', temperature: 36.9, cervix: { isClosed: true, isHard: true } },
|
||||||
|
{ date: '2018-08-16', temperature: 36.95, cervix: { isClosed: true, isHard: true } },
|
||||||
|
{ date: '2018-08-17', temperature: 36.9, cervix: { isClosed: true, isHard: true } },
|
||||||
|
{ date: '2018-08-18', temperature: 36.9, cervix: { isClosed: false, isHard: true } }
|
||||||
|
].map(convertToSymptoFormat).reverse()
|
||||||
|
|
||||||
export const longAndComplicatedCycle = [
|
export const longAndComplicatedCycle = [
|
||||||
{ date: '2018-06-01', temperature: 36.6, bleeding: 2 },
|
{ date: '2018-06-01', temperature: 36.6, bleeding: 2 },
|
||||||
{ date: '2018-06-02', temperature: 36.65 },
|
{ date: '2018-06-02', temperature: 36.65 },
|
||||||
|
|||||||
+30
-4
@@ -2,7 +2,8 @@ import Realm from 'realm'
|
|||||||
import { LocalDate, ChronoUnit } from 'js-joda'
|
import { LocalDate, ChronoUnit } from 'js-joda'
|
||||||
import {
|
import {
|
||||||
cycleWithTempAndNoMucusShift,
|
cycleWithTempAndNoMucusShift,
|
||||||
cycleWithFhm,
|
cycleWithFhmMucus,
|
||||||
|
cycleWithFhmCervix,
|
||||||
longAndComplicatedCycle
|
longAndComplicatedCycle
|
||||||
} from './fixtures'
|
} from './fixtures'
|
||||||
|
|
||||||
@@ -179,9 +180,9 @@ function getCycleDay(localDate) {
|
|||||||
return db.objectForPrimaryKey('CycleDay', localDate)
|
return db.objectForPrimaryKey('CycleDay', localDate)
|
||||||
}
|
}
|
||||||
|
|
||||||
function fillWithDummyData() {
|
function fillWithMucusDummyData() {
|
||||||
const dummyCycles = [
|
const dummyCycles = [
|
||||||
cycleWithFhm,
|
cycleWithFhmMucus,
|
||||||
longAndComplicatedCycle,
|
longAndComplicatedCycle,
|
||||||
cycleWithTempAndNoMucusShift
|
cycleWithTempAndNoMucusShift
|
||||||
]
|
]
|
||||||
@@ -204,6 +205,30 @@ function fillWithDummyData() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function fillWithCervixDummyData() {
|
||||||
|
const dummyCycles = [
|
||||||
|
cycleWithFhmCervix
|
||||||
|
]
|
||||||
|
|
||||||
|
db.write(() => {
|
||||||
|
db.deleteAll()
|
||||||
|
dummyCycles.forEach(cycle => {
|
||||||
|
cycle.forEach(day => {
|
||||||
|
const existing = getCycleDay(day.date)
|
||||||
|
if (existing) {
|
||||||
|
Object.keys(day).forEach(key => {
|
||||||
|
if (key === 'date') return
|
||||||
|
existing[key] = day[key]
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
db.create('CycleDay', day)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function deleteAll() {
|
function deleteAll() {
|
||||||
db.write(() => {
|
db.write(() => {
|
||||||
db.deleteAll()
|
db.deleteAll()
|
||||||
@@ -266,7 +291,8 @@ export {
|
|||||||
bleedingDaysSortedByDate,
|
bleedingDaysSortedByDate,
|
||||||
temperatureDaysSortedByDate,
|
temperatureDaysSortedByDate,
|
||||||
cycleDaysSortedByDate,
|
cycleDaysSortedByDate,
|
||||||
fillWithDummyData,
|
fillWithMucusDummyData,
|
||||||
|
fillWithCervixDummyData,
|
||||||
deleteAll,
|
deleteAll,
|
||||||
getPreviousTemperature,
|
getPreviousTemperature,
|
||||||
getCycleDay,
|
getCycleDay,
|
||||||
|
|||||||
@@ -0,0 +1,41 @@
|
|||||||
|
export default function (cycleDays, tempEvalEndIndex) {
|
||||||
|
const cervixDays = cycleDays.filter(day => day.cervix && !day.cervix.exclude)
|
||||||
|
|
||||||
|
for (let i = 0; i < cervixDays.length; i++) {
|
||||||
|
const day = cervixDays[i]
|
||||||
|
if (isClosedAndHard(day.cervix)) continue
|
||||||
|
// the three following days must be with closed and hard cervix
|
||||||
|
// AND no other cervix value may occur until temperature evaluation has
|
||||||
|
// been completed
|
||||||
|
const threeFollowingDays = cervixDays.slice(i + 1, i + 4)
|
||||||
|
if (threeFollowingDays.length < 3) continue
|
||||||
|
|
||||||
|
const fertileCervixOccursIn3FollowingDays = threeFollowingDays.some(day => {
|
||||||
|
return !isClosedAndHard(day.cervix)
|
||||||
|
})
|
||||||
|
if (fertileCervixOccursIn3FollowingDays) continue
|
||||||
|
|
||||||
|
const cycleDayIndex = cycleDays.indexOf(day)
|
||||||
|
const relevantDays = cycleDays
|
||||||
|
.slice(cycleDayIndex + 1, tempEvalEndIndex + 1)
|
||||||
|
.filter(day => day.cervix && !day.cervix.exclude)
|
||||||
|
|
||||||
|
const onlyClosedAndHardUntilEndOfTempEval = relevantDays.every(day => {
|
||||||
|
return isClosedAndHard(day.cervix)
|
||||||
|
})
|
||||||
|
|
||||||
|
if (onlyClosedAndHardUntilEndOfTempEval) {
|
||||||
|
return {
|
||||||
|
detected: true,
|
||||||
|
cervixPeak: day,
|
||||||
|
evaluationCompleteDay: threeFollowingDays[threeFollowingDays.length - 1]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return { detected: false }
|
||||||
|
}
|
||||||
|
|
||||||
|
function isClosedAndHard (cervixValue) {
|
||||||
|
return cervixValue.isClosed && cervixValue.isHard
|
||||||
|
}
|
||||||
+27
-11
@@ -1,11 +1,12 @@
|
|||||||
import getTemperatureShift from './temperature'
|
import getTemperatureShift from './temperature'
|
||||||
import getMucusShift from './mucus'
|
import getMucusShift from './mucus'
|
||||||
|
import getCervixShift from './cervix'
|
||||||
import getPreOvulatoryPhase from './pre-ovulatory'
|
import getPreOvulatoryPhase from './pre-ovulatory'
|
||||||
import { LocalDate } from 'js-joda'
|
import { LocalDate } from 'js-joda'
|
||||||
import assert from 'assert'
|
import assert from 'assert'
|
||||||
|
|
||||||
export default function getSymptoThermalStatus(cycles) {
|
export default function getSymptoThermalStatus(cycleInfo) {
|
||||||
const { cycle, previousCycle, earlierCycles = [] } = cycles
|
const { cycle, previousCycle, earlierCycles = [], secondarySymptom = 'mucus' } = cycleInfo
|
||||||
throwIfArgsAreNotInRequiredFormat([cycle, ...earlierCycles])
|
throwIfArgsAreNotInRequiredFormat([cycle, ...earlierCycles])
|
||||||
|
|
||||||
const status = {
|
const status = {
|
||||||
@@ -48,20 +49,28 @@ export default function getSymptoThermalStatus(cycles) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const temperatureShift = getTemperatureShift(cycle)
|
const temperatureShift = getTemperatureShift(cycle)
|
||||||
|
|
||||||
if (!temperatureShift.detected) return status
|
if (!temperatureShift.detected) return status
|
||||||
|
|
||||||
const tempEvalEndIndex = cycle.indexOf(temperatureShift.evaluationCompleteDay)
|
const tempEvalEndIndex = cycle.indexOf(temperatureShift.evaluationCompleteDay)
|
||||||
const mucusShift = getMucusShift(cycle, tempEvalEndIndex)
|
|
||||||
if (!mucusShift.detected) return status
|
let secondaryShift
|
||||||
|
if (secondarySymptom === 'mucus') {
|
||||||
|
secondaryShift = getMucusShift(cycle, tempEvalEndIndex)
|
||||||
|
} else if (secondarySymptom === 'cervix') {
|
||||||
|
secondaryShift = getCervixShift(cycle, tempEvalEndIndex)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!secondaryShift.detected) return status
|
||||||
|
|
||||||
let periOvulatoryEnd
|
let periOvulatoryEnd
|
||||||
const tempOver = temperatureShift.evaluationCompleteDay.date
|
const tempOver = temperatureShift.evaluationCompleteDay.date
|
||||||
const mucusOver = mucusShift.evaluationCompleteDay.date
|
const secondarySymptomOver = secondaryShift.evaluationCompleteDay.date
|
||||||
|
|
||||||
if (tempOver > mucusOver) {
|
if (tempOver > secondarySymptomOver) {
|
||||||
periOvulatoryEnd = temperatureShift.evaluationCompleteDay
|
periOvulatoryEnd = temperatureShift.evaluationCompleteDay
|
||||||
} else {
|
} else {
|
||||||
periOvulatoryEnd = mucusShift.evaluationCompleteDay
|
periOvulatoryEnd = secondaryShift.evaluationCompleteDay
|
||||||
}
|
}
|
||||||
|
|
||||||
const previousPeriDays = periPhase.cycleDays
|
const previousPeriDays = periPhase.cycleDays
|
||||||
@@ -78,7 +87,12 @@ export default function getSymptoThermalStatus(cycles) {
|
|||||||
periPhase.cycleDays = previousPeriDays.slice(0, previousPeriEndIndex + 1)
|
periPhase.cycleDays = previousPeriDays.slice(0, previousPeriEndIndex + 1)
|
||||||
periPhase.end = status.phases.postOvulatory.start
|
periPhase.end = status.phases.postOvulatory.start
|
||||||
|
|
||||||
status.mucusShift = mucusShift
|
if (secondarySymptom === 'mucus') {
|
||||||
|
status.mucusShift = secondaryShift
|
||||||
|
} else if (secondarySymptom === 'cervix') {
|
||||||
|
status.cervixShift = secondaryShift
|
||||||
|
}
|
||||||
|
|
||||||
status.temperatureShift = temperatureShift
|
status.temperatureShift = temperatureShift
|
||||||
|
|
||||||
return status
|
return status
|
||||||
@@ -87,9 +101,9 @@ export default function getSymptoThermalStatus(cycles) {
|
|||||||
function throwIfArgsAreNotInRequiredFormat(cycles) {
|
function throwIfArgsAreNotInRequiredFormat(cycles) {
|
||||||
cycles.forEach(cycle => {
|
cycles.forEach(cycle => {
|
||||||
assert.ok(Array.isArray(cycle))
|
assert.ok(Array.isArray(cycle))
|
||||||
assert.ok(cycle.length > 0)
|
assert.ok(cycle.length > 0) //what about 2 cycles of 1 day each?!
|
||||||
assert.ok(cycle[0].bleeding !== null)
|
assert.ok(cycle[0].bleeding !== null)
|
||||||
assert.equal(typeof cycle[0].bleeding, 'object')
|
assert.equal(typeof cycle[0].bleeding, 'object', "First cycle day must contain bleeding value")
|
||||||
assert.equal(typeof cycle[0].bleeding.value, 'number')
|
assert.equal(typeof cycle[0].bleeding.value, 'number')
|
||||||
cycle.forEach(day => {
|
cycle.forEach(day => {
|
||||||
assert.equal(typeof day.date, 'string')
|
assert.equal(typeof day.date, 'string')
|
||||||
@@ -98,6 +112,8 @@ function throwIfArgsAreNotInRequiredFormat(cycles) {
|
|||||||
if (day.mucus) assert.equal(typeof day.mucus.value, 'number')
|
if (day.mucus) assert.equal(typeof day.mucus.value, 'number')
|
||||||
if (day.mucus) assert.ok(day.mucus.value >= 0)
|
if (day.mucus) assert.ok(day.mucus.value >= 0)
|
||||||
if (day.mucus) assert.ok(day.mucus.value < 5)
|
if (day.mucus) assert.ok(day.mucus.value < 5)
|
||||||
|
if (day.cervix) assert.equal(typeof day.cervix.isClosed, 'boolean')
|
||||||
|
if (day.cervix) assert.equal(typeof day.cervix.isHard, 'boolean')
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,215 @@
|
|||||||
|
|
||||||
|
function convertToSymptoFormat(val) {
|
||||||
|
const sympto = { date: val.date }
|
||||||
|
if (val.temperature) sympto.temperature = {
|
||||||
|
value: val.temperature,
|
||||||
|
exclude: false
|
||||||
|
}
|
||||||
|
if (val.cervix) sympto.cervix = {
|
||||||
|
value: val.cervix,
|
||||||
|
exclude: false
|
||||||
|
}
|
||||||
|
if (val.bleeding) sympto.bleeding = {
|
||||||
|
value: val.bleeding,
|
||||||
|
exclude: false
|
||||||
|
}
|
||||||
|
return sympto
|
||||||
|
}
|
||||||
|
|
||||||
|
export const idealCycle = [
|
||||||
|
{ date: '2018-08-01', bleeding: 1, cervix: { isClosed: false, isHard: false } },
|
||||||
|
{ date: '2018-08-02', bleeding: 2, cervix: { isClosed: false, isHard: false } },
|
||||||
|
{ date: '2018-08-03', temperature: 36.6, bleeding: 2, cervix: { isClosed: false, isHard: false } },
|
||||||
|
{ date: '2018-08-04', temperature: 36.55, bleeding: 1, cervix: { isClosed: false, isHard: true } },
|
||||||
|
{ date: '2018-08-05', temperature: 36.6, bleeding: null, cervix: { isClosed: true, isHard: false } },
|
||||||
|
{ date: '2018-08-06', temperature: 36.65, bleeding: null, cervix: { isClosed: true, isHard: false } },
|
||||||
|
{ date: '2018-08-07', temperature: 36.7, bleeding: null, cervix: { isClosed: false, isHard: true } },
|
||||||
|
{ date: '2018-08-08', temperature: 36.6, bleeding: null, cervix: { isClosed: true, isHard: false } },
|
||||||
|
{ date: '2018-08-09', temperature: 36.8, bleeding: null, cervix: { isClosed: true, isHard: true } },
|
||||||
|
{ date: '2018-08-10', temperature: 36.75, bleeding: null, cervix: { isClosed: true, isHard: true } },
|
||||||
|
{ date: '2018-08-11', temperature: 36.9, bleeding: null, cervix: { isClosed: true, isHard: true } },
|
||||||
|
{ date: '2018-08-12', temperature: 36.95, bleeding: null, cervix: { isClosed: true, isHard: true } },
|
||||||
|
{ date: '2018-08-13', temperature: 36.95, bleeding: null, cervix: { isClosed: true, isHard: true } }
|
||||||
|
].map(convertToSymptoFormat)
|
||||||
|
|
||||||
|
export const cycleWithFhmNoCervixShift = [
|
||||||
|
{ date: '2018-06-01', temperature: 36.6, bleeding: 2 },
|
||||||
|
{ date: '2018-06-02', temperature: 36.65 },
|
||||||
|
{ date: '2018-06-04', temperature: 36.6 },
|
||||||
|
{ date: '2018-06-05', temperature: 36.55 },
|
||||||
|
{ date: '2018-06-06', temperature: 36.7 },
|
||||||
|
{ date: '2018-06-08', temperature: 36.7 },
|
||||||
|
{ date: '2018-06-09', temperature: 36.7 },
|
||||||
|
{ date: '2018-06-10', temperature: 36.7 },
|
||||||
|
{ date: '2018-06-11', temperature: 36.7 },
|
||||||
|
{ date: '2018-06-12', temperature: 36.7 },
|
||||||
|
{ date: '2018-06-13', temperature: 36.8 },
|
||||||
|
{ date: '2018-06-15', temperature: 36.9 },
|
||||||
|
{ date: '2018-06-16', temperature: 36.9 },
|
||||||
|
{ date: '2018-06-17', temperature: 36.9 },
|
||||||
|
{ date: '2018-06-18', temperature: 36.9 }
|
||||||
|
].map(convertToSymptoFormat)
|
||||||
|
|
||||||
|
export const cycleWithoutFhm = [
|
||||||
|
{ date: '2018-06-02', temperature: 36.6, bleeding: 2 },
|
||||||
|
{ date: '2018-06-03', temperature: 36.65 },
|
||||||
|
{ date: '2018-06-04', temperature: 36.6 },
|
||||||
|
{ date: '2018-06-05', temperature: 36.55 },
|
||||||
|
{ date: '2018-06-06', temperature: 36.7, cervix: { isClosed: true, isHard: true } },
|
||||||
|
{ date: '2018-06-09', temperature: 36.8, cervix: { isClosed: true, isHard: false } },
|
||||||
|
{ date: '2018-06-10', temperature: 36.9, cervix: { isClosed: false, isHard: true } },
|
||||||
|
{ date: '2018-06-13', temperature: 36.9, cervix: { isClosed: false, isHard: false } }
|
||||||
|
].map(convertToSymptoFormat)
|
||||||
|
|
||||||
|
export const cycleWithoutAnyShifts = [
|
||||||
|
{ date: '2018-07-01', temperature: 36.65, bleeding: 2, cervix: { isClosed: false, isHard: false } },
|
||||||
|
{ date: '2018-07-02', temperature: 36.45, cervix: { isClosed: false, isHard: false } },
|
||||||
|
{ date: '2018-07-03', temperature: 36.65, cervix: { isClosed: false, isHard: false } },
|
||||||
|
{ date: '2018-07-04', temperature: 36.65, cervix: { isClosed: false, isHard: false } },
|
||||||
|
{ date: '2018-07-05', temperature: 36.65, cervix: { isClosed: false, isHard: false } },
|
||||||
|
{ date: '2018-07-06', temperature: 36.85, cervix: { isClosed: true, isHard: false } },
|
||||||
|
{ date: '2018-07-07', temperature: 36.65, cervix: { isClosed: false, isHard: false } },
|
||||||
|
{ date: '2018-07-08', temperature: 36.65, cervix: { isClosed: false, isHard: false } },
|
||||||
|
{ date: '2018-07-09', temperature: 36.65, cervix: { isClosed: false, isHard: false } },
|
||||||
|
{ date: '2018-07-10', temperature: 36.65, cervix: { isClosed: false, isHard: false } },
|
||||||
|
{ date: '2018-07-11', temperature: 36.35, cervix: { isClosed: true, isHard: true } },
|
||||||
|
{ date: '2018-07-12', temperature: 36.65, cervix: { isClosed: true, isHard: true } },
|
||||||
|
{ date: '2018-07-13', temperature: 36.25, cervix: { isClosed: false, isHard: false } },
|
||||||
|
{ date: '2018-07-14', temperature: 36.65, cervix: { isClosed: false, isHard: false } },
|
||||||
|
{ date: '2018-07-15', temperature: 36.65, cervix: { isClosed: false, isHard: true } },
|
||||||
|
{ date: '2018-07-16', temperature: 36.15, cervix: { isClosed: false, isHard: false } },
|
||||||
|
{ date: '2018-07-17', temperature: 36.65, cervix: { isClosed: true, isHard: false } },
|
||||||
|
{ date: '2018-07-18', temperature: 36.25, cervix: { isClosed: false, isHard: false } },
|
||||||
|
{ date: '2018-07-19', temperature: 36.65, cervix: { isClosed: false, isHard: false } },
|
||||||
|
{ date: '2018-07-20', temperature: 36.45, cervix: { isClosed: false, isHard: false } },
|
||||||
|
{ date: '2018-07-21', temperature: 36.5, cervix: { isClosed: true, isHard: true } },
|
||||||
|
{ date: '2018-07-22', temperature: 36.65, cervix: { isClosed: false, isHard: false } },
|
||||||
|
{ date: '2018-07-23', temperature: 36.75, cervix: { isClosed: false, isHard: false } },
|
||||||
|
{ date: '2018-07-24', temperature: 36.65, cervix: { isClosed: false, isHard: false } },
|
||||||
|
{ date: '2018-07-25', temperature: 36.65, cervix: { isClosed: true, isHard: false } },
|
||||||
|
{ date: '2018-07-26', temperature: 36.65, cervix: { isClosed: false, isHard: false } },
|
||||||
|
].map(convertToSymptoFormat)
|
||||||
|
|
||||||
|
export const longAndComplicatedCycle = [
|
||||||
|
{ date: '2018-06-01', temperature: 36.6, bleeding: 2 },
|
||||||
|
{ date: '2018-06-02', temperature: 36.65 },
|
||||||
|
{ date: '2018-06-04', temperature: 36.6 },
|
||||||
|
{ date: '2018-06-05', temperature: 36.55 },
|
||||||
|
{ date: '2018-06-06', temperature: 36.7, cervix: { isClosed: true, isHard: true } },
|
||||||
|
{ date: '2018-06-09', temperature: 36.5, cervix: { isClosed: false, isHard: false } },
|
||||||
|
{ date: '2018-06-10', temperature: 36.4, cervix: { isClosed: false, isHard: false } },
|
||||||
|
{ date: '2018-06-13', temperature: 36.45, cervix: { isClosed: false, isHard: false } },
|
||||||
|
{ date: '2018-06-14', temperature: 36.5, cervix: { isClosed: false, isHard: false } },
|
||||||
|
{ date: '2018-06-15', temperature: 36.55, cervix: { isClosed: false, isHard: false } },
|
||||||
|
{ date: '2018-06-16', temperature: 36.7, cervix: { isClosed: false, isHard: false } },
|
||||||
|
{ date: '2018-06-17', temperature: 36.65, cervix: { isClosed: false, isHard: false } },
|
||||||
|
{ date: '2018-06-18', temperature: 36.75, cervix: { isClosed: false, isHard: false } },
|
||||||
|
{ date: '2018-06-19', temperature: 36.8, cervix: { isClosed: true, isHard: true } },
|
||||||
|
{ date: '2018-06-20', temperature: 36.85, cervix: { isClosed: false, isHard: false } },
|
||||||
|
{ date: '2018-06-21', temperature: 36.8, cervix: { isClosed: false, isHard: false } },
|
||||||
|
{ date: '2018-06-22', temperature: 36.9, cervix: { isClosed: false, isHard: false } },
|
||||||
|
{ date: '2018-06-25', temperature: 36.9, cervix: { isClosed: true, isHard: true } },
|
||||||
|
{ date: '2018-06-26', temperature: 36.8, cervix: { isClosed: true, isHard: true } },
|
||||||
|
{ date: '2018-06-27', temperature: 36.9, cervix: { isClosed: true, isHard: true } }
|
||||||
|
].map(convertToSymptoFormat)
|
||||||
|
|
||||||
|
export const tempAndCervixEvalEndOnSameDay = [
|
||||||
|
{ date: '2018-06-01', bleeding: 2 },
|
||||||
|
{ date: '2018-06-02', bleeding: 1 },
|
||||||
|
{ date: '2018-06-03', bleeding: 1 },
|
||||||
|
{ date: '2018-06-04', bleeding: 2 },
|
||||||
|
{ date: '2018-06-05', bleeding: 1 },
|
||||||
|
{ date: '2018-06-06', bleeding: 1 },
|
||||||
|
{ date: '2018-06-07', cervix: { isClosed: false, isHard: true } },
|
||||||
|
{ date: '2018-06-08', temperature: 36.45, cervix: { isClosed: true, isHard: false } },
|
||||||
|
{ date: '2018-06-09', temperature: 36.5, cervix: { isClosed: true, isHard: true } },
|
||||||
|
{ date: '2018-06-10', temperature: 36.30, cervix: { isClosed: true, isHard: false } },
|
||||||
|
{ date: '2018-06-11', temperature: 36.30, cervix: { isClosed: false, isHard: true } },
|
||||||
|
{ date: '2018-06-12', temperature: 36.4, cervix: { isClosed: false, isHard: false } },
|
||||||
|
{ date: '2018-06-13', temperature: 36.3, cervix: { isClosed: false, isHard: false } },
|
||||||
|
{ date: '2018-06-14', temperature: 36.4, cervix: { isClosed: false, isHard: false } },
|
||||||
|
{ date: '2018-06-15', temperature: 36.8, cervix: { isClosed: true, isHard: true } },
|
||||||
|
{ date: '2018-06-16', temperature: 36.8, cervix: { isClosed: true, isHard: true } },
|
||||||
|
{ date: '2018-06-17', temperature: 36.9, cervix: { isClosed: true, isHard: true } },
|
||||||
|
{ date: '2018-06-18', temperature: 36.9, cervix: { isClosed: true, isHard: true } },
|
||||||
|
{ date: '2018-06-19', temperature: 36.95, cervix: { isClosed: true, isHard: true } },
|
||||||
|
{ date: '2018-06-20', temperature: 37.0, cervix: { isClosed: true, isHard: true } },
|
||||||
|
{ date: '2018-06-21', temperature: 37.0, cervix: { isClosed: true, isHard: true } },
|
||||||
|
{ date: '2018-06-22', temperature: 37.0, cervix: { isClosed: true, isHard: true } },
|
||||||
|
{ date: '2018-06-23', cervix: { isClosed: true, isHard: true } },
|
||||||
|
{ date: '2018-06-24', cervix: { isClosed: true, isHard: true }},
|
||||||
|
{ date: '2018-06-25', cervix: { isClosed: false, isHard: false } }
|
||||||
|
].map(convertToSymptoFormat)
|
||||||
|
|
||||||
|
export const cervixShiftWaitsForTempShift = [
|
||||||
|
{ date: '2018-05-08', bleeding: 3 },
|
||||||
|
{ date: '2018-05-09', bleeding: 2 },
|
||||||
|
{ date: '2018-05-10', bleeding: 2 },
|
||||||
|
{ date: '2018-05-11', bleeding: 1 },
|
||||||
|
{ date: '2018-05-12', temperature: 36.3, cervix: { isClosed: false, isHard: false } },
|
||||||
|
{ date: '2018-05-13', temperature: 36.4, cervix: { isClosed: false, isHard: false } },
|
||||||
|
{ date: '2018-05-14', temperature: 36.3, cervix: { isClosed: false, isHard: false } },
|
||||||
|
{ date: '2018-05-15', temperature: 36.2, cervix: { isClosed: false, isHard: false } },
|
||||||
|
{ date: '2018-05-16', temperature: 36.3, cervix: { isClosed: true, isHard: true } },
|
||||||
|
{ date: '2018-05-17', temperature: 36.3, cervix: { isClosed: true, isHard: true } },
|
||||||
|
{ date: '2018-05-18', temperature: 36.55, cervix: { isClosed: true, isHard: true } },
|
||||||
|
{ date: '2018-05-19', temperature: 36.65, cervix: { isClosed: true, isHard: true } },
|
||||||
|
{ date: '2018-05-20', temperature: 36.7, cervix: { isClosed: true, isHard: true } },
|
||||||
|
{ date: '2018-05-21', temperature: 36.6, cervix: { isClosed: true, isHard: true } },
|
||||||
|
{ date: '2018-05-22', temperature: 36.85, cervix: { isClosed: true, isHard: true } },
|
||||||
|
{ date: '2018-05-23', temperature: 36.8, cervix: { isClosed: true, isHard: true } },
|
||||||
|
{ date: '2018-05-24', temperature: 36.85, cervix: { isClosed: true, isHard: true } },
|
||||||
|
{ date: '2018-05-25', temperature: 36.95, cervix: { isClosed: true, isHard: true } },
|
||||||
|
{ date: '2018-05-26', temperature: 36.85, cervix: { isClosed: true, isHard: false } },
|
||||||
|
{ date: '2018-05-27', temperature: 36.8, cervix: { isClosed: false, isHard: true } },
|
||||||
|
{ date: '2018-05-28', temperature: 36.6, cervix: { isClosed: false, isHard: true } },
|
||||||
|
{ date: '2018-05-29', bleeding: 2 }
|
||||||
|
].map(convertToSymptoFormat)
|
||||||
|
|
||||||
|
export const tempShiftWaitsForCervixShift = [
|
||||||
|
{ date: '2018-04-05', bleeding: 3 },
|
||||||
|
{ date: '2018-04-06', bleeding: 2 },
|
||||||
|
{ date: '2018-04-07', bleeding: 2 },
|
||||||
|
{ date: '2018-04-08', bleeding: 1 },
|
||||||
|
{ date: '2018-04-09', temperature: 36.5, cervix: { isClosed: false, isHard: false } },
|
||||||
|
{ date: '2018-04-10', temperature: 36.5, cervix: { isClosed: false, isHard: false } },
|
||||||
|
{ date: '2018-04-11', temperature: 36.55, cervix: { isClosed: false, isHard: false } },
|
||||||
|
{ date: '2018-04-12', temperature: 36.5, cervix: { isClosed: false, isHard: false } },
|
||||||
|
{ date: '2018-04-13', temperature: 36.35, cervix: { isClosed: false, isHard: false } },
|
||||||
|
{ date: '2018-04-14', temperature: 36.35, cervix: { isClosed: false, isHard: false } },
|
||||||
|
{ date: '2018-04-15', temperature: 36.6, cervix: { isClosed: false, isHard: false } },
|
||||||
|
{ date: '2018-04-16', temperature: 36.8, cervix: { isClosed: false, isHard: false } },
|
||||||
|
{ date: '2018-04-17', cervix: { isClosed: false, isHard: false } },
|
||||||
|
{ date: '2018-04-18', temperature: 36.8, cervix: { isClosed: false, isHard: true } },
|
||||||
|
{ date: '2018-04-19', temperature: 36.85, cervix: { isClosed: true, isHard: true } },
|
||||||
|
{ date: '2018-04-20', temperature: 37.0, cervix: { isClosed: true, isHard: true } },
|
||||||
|
{ date: '2018-04-21', temperature: 36.9, cervix: { isClosed: true, isHard: true } },
|
||||||
|
{ date: '2018-04-22', temperature: 36.9, cervix: { isClosed: true, isHard: true } },
|
||||||
|
{ date: '2018-04-23', temperature: 37.1, cervix: { isClosed: true, isHard: true } },
|
||||||
|
{ date: '2018-04-24', temperature: 36.75, cervix: { isClosed: false, isHard: false } }
|
||||||
|
].map(convertToSymptoFormat)
|
||||||
|
|
||||||
|
export const noInfertilePhaseDetected = [
|
||||||
|
{ date: '2018-03-08', bleeding: 3 },
|
||||||
|
{ date: '2018-03-09', bleeding: 3 },
|
||||||
|
{ date: '2018-03-10', bleeding: 3 },
|
||||||
|
{ date: '2018-03-11', bleeding: 3 },
|
||||||
|
{ date: '2018-03-12', temperature: 36.3, cervix: { isClosed: true, isHard: false } },
|
||||||
|
{ date: '2018-03-13', temperature: 36.5, cervix: { isClosed: false, isHard: false } },
|
||||||
|
{ date: '2018-03-14', temperature: 36.45, cervix: { isClosed: false, isHard: false } },
|
||||||
|
{ date: '2018-03-15', temperature: 36.4, cervix: { isClosed: false, isHard: false } },
|
||||||
|
{ date: '2018-03-16', temperature: 36.2, cervix: { isClosed: false, isHard: false } },
|
||||||
|
{ date: '2018-03-17', temperature: 36.5, cervix: { isClosed: false, isHard: false } },
|
||||||
|
{ date: '2018-03-18', temperature: 36.6, cervix: { isClosed: false, isHard: false } },
|
||||||
|
{ date: '2018-03-19', temperature: 36.35, cervix: { isClosed: false, isHard: true } },
|
||||||
|
{ date: '2018-03-20', temperature: 36.8, cervix: { isClosed: true, isHard: true } },
|
||||||
|
{ date: '2018-03-21', temperature: 36.7, cervix: { isClosed: true, isHard: true } },
|
||||||
|
{ date: '2018-03-22', temperature: 36.7, cervix: { isClosed: true, isHard: false } },
|
||||||
|
{ date: '2018-03-23', temperature: 36.7, cervix: { isClosed: true, isHard: true } }
|
||||||
|
].map(convertToSymptoFormat)
|
||||||
|
|
||||||
|
export const fiveDayCycle = [
|
||||||
|
{ date: '2018-08-01', bleeding: 2 },
|
||||||
|
{ date: '2018-08-03', bleeding: 3 },
|
||||||
|
{ date: '2018-08-05', bleeding: 0 }
|
||||||
|
].map(convertToSymptoFormat)
|
||||||
@@ -0,0 +1,199 @@
|
|||||||
|
import chai from 'chai'
|
||||||
|
import getSensiplanStatus from '../../lib/sympto'
|
||||||
|
import {
|
||||||
|
idealCycle,
|
||||||
|
cycleWithFhmNoCervixShift,
|
||||||
|
cycleWithoutFhm,
|
||||||
|
cycleWithoutAnyShifts,
|
||||||
|
tempAndCervixEvalEndOnSameDay,
|
||||||
|
cervixShiftWaitsForTempShift,
|
||||||
|
tempShiftWaitsForCervixShift,
|
||||||
|
noInfertilePhaseDetected,
|
||||||
|
fiveDayCycle
|
||||||
|
} from './cervix-temp-fixtures'
|
||||||
|
|
||||||
|
const expect = chai.expect
|
||||||
|
|
||||||
|
describe('sympto', () => {
|
||||||
|
describe('combining temperature and cervix tracking', () => {
|
||||||
|
describe('with no previous higher temp measurement', () => {
|
||||||
|
|
||||||
|
it('with no temp or cervix shifts detects only peri-ovulatory', function () {
|
||||||
|
const status = getSensiplanStatus({
|
||||||
|
cycle: cycleWithoutAnyShifts,
|
||||||
|
previousCycle: cycleWithoutFhm,
|
||||||
|
secondarySymptom: 'cervix'
|
||||||
|
})
|
||||||
|
expect(Object.keys(status.phases).length).to.eql(1)
|
||||||
|
expect(status).to.eql({
|
||||||
|
phases: {
|
||||||
|
periOvulatory: {
|
||||||
|
start: { date: '2018-07-01' },
|
||||||
|
cycleDays: cycleWithoutAnyShifts
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it('with temp but no cervix shift detects only peri-ovulatory', function () {
|
||||||
|
const status = getSensiplanStatus({
|
||||||
|
cycle: cycleWithFhmNoCervixShift,
|
||||||
|
previousCycle: cycleWithoutFhm,
|
||||||
|
secondarySymptom: 'cervix'
|
||||||
|
})
|
||||||
|
expect(Object.keys(status.phases).length).to.eql(1)
|
||||||
|
expect(status).to.eql({
|
||||||
|
phases: {
|
||||||
|
periOvulatory: {
|
||||||
|
start: { date: '2018-06-01' },
|
||||||
|
cycleDays: cycleWithFhmNoCervixShift
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it('with temp and cervix shifts detects only peri- and post-ovulatory phases', function () {
|
||||||
|
const status = getSensiplanStatus({
|
||||||
|
cycle: idealCycle,
|
||||||
|
previousCycle: cycleWithoutFhm,
|
||||||
|
secondarySymptom: 'cervix'
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(status.temperatureShift).to.be.an('object')
|
||||||
|
expect(status.cervixShift).to.be.an('object')
|
||||||
|
|
||||||
|
expect(Object.keys(status.phases).length).to.eql(2)
|
||||||
|
expect(status.phases.periOvulatory).to.eql({
|
||||||
|
start: { date: '2018-08-01' },
|
||||||
|
end: { date: '2018-08-11', time: '18:00' },
|
||||||
|
cycleDays: idealCycle
|
||||||
|
.filter(({date}) => date <= '2018-08-11')
|
||||||
|
})
|
||||||
|
expect(status.phases.postOvulatory).to.eql({
|
||||||
|
start: { date: '2018-08-11', time: '18:00' },
|
||||||
|
cycleDays: idealCycle
|
||||||
|
.filter(({date}) => date >= '2018-08-11')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
})
|
||||||
|
describe('with previous higher temp measurement', () => {
|
||||||
|
|
||||||
|
describe('with no shifts detects only peri-ovulatory', function () {
|
||||||
|
it.skip('according to 5-day rule', function () {
|
||||||
|
const status = getSensiplanStatus({
|
||||||
|
cycle: fiveDayCycle,
|
||||||
|
previousCycle: cycleWithFhmNoCervixShift
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(Object.keys(status.phases).length).to.eql(1)
|
||||||
|
expect(status.phases.preOvulatory).to.eql({
|
||||||
|
cycleDays: fiveDayCycle,
|
||||||
|
start: { date: '2018-08-01' },
|
||||||
|
end: { date: '2018-08-05' }
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('with no shifts detects pre- and peri-ovulatory phase', () => {
|
||||||
|
it.skip('according to 5-day-rule', function () {
|
||||||
|
const status = getSensiplanStatus({
|
||||||
|
cycle: cycleWithoutAnyShifts,
|
||||||
|
previousCycle: cycleWithFhmNoCervixShift
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(Object.keys(status.phases).length).to.eql(2)
|
||||||
|
expect(status.phases.preOvulatory).to.eql({
|
||||||
|
cycleDays: cycleWithoutAnyShifts
|
||||||
|
.filter(({date}) => date <= '2018-07-05'),
|
||||||
|
start: { date: '2018-07-01' },
|
||||||
|
end: { date: '2018-07-05' }
|
||||||
|
})
|
||||||
|
expect(status.phases.periOvulatory).to.eql({
|
||||||
|
cycleDays: cycleWithoutAnyShifts
|
||||||
|
.filter(({date}) => date > '2018-07-05'),
|
||||||
|
start: { date: '2018-07-06' }
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it('with evaluation of temperature and cervix end on same day', () => {
|
||||||
|
const status = getSensiplanStatus({
|
||||||
|
cycle: tempAndCervixEvalEndOnSameDay,
|
||||||
|
previousCycle: cycleWithFhmNoCervixShift,
|
||||||
|
secondarySymptom: 'cervix'
|
||||||
|
})
|
||||||
|
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: tempAndCervixEvalEndOnSameDay
|
||||||
|
.filter(({date}) => date <= '2018-06-05')
|
||||||
|
})
|
||||||
|
expect(status.phases.periOvulatory).to.eql({
|
||||||
|
start: { date: '2018-06-06' },
|
||||||
|
end: { date: '2018-06-17', time: '18:00' },
|
||||||
|
cycleDays: tempAndCervixEvalEndOnSameDay
|
||||||
|
.filter(({date}) => {
|
||||||
|
return date > '2018-06-05' && date <= '2018-06-17'
|
||||||
|
})
|
||||||
|
})
|
||||||
|
expect(status.phases.postOvulatory).to.eql({
|
||||||
|
start: { date: '2018-06-17', time: '18:00' },
|
||||||
|
cycleDays: tempAndCervixEvalEndOnSameDay
|
||||||
|
.filter(({date}) => date >= '2018-06-17')
|
||||||
|
})
|
||||||
|
expect(status.cervixShift.detected).to.be.true()
|
||||||
|
expect(status.cervixShift.cervixPeak.date).to.eql('2018-06-14')
|
||||||
|
expect(status.cervixShift.evaluationCompleteDay.date).to.eql('2018-06-17')
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
it('when cervix shift waits for temperature shift', () => {
|
||||||
|
const status = getSensiplanStatus({
|
||||||
|
cycle: cervixShiftWaitsForTempShift,
|
||||||
|
previousCycle: cycleWithFhmNoCervixShift,
|
||||||
|
secondarySymptom: 'cervix'
|
||||||
|
})
|
||||||
|
expect(Object.keys(status.phases).length).to.eql(3)
|
||||||
|
expect(status.cervixShift.detected).to.be.true()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('when temperature shift waits for cervix shift', () => {
|
||||||
|
const status = getSensiplanStatus({
|
||||||
|
cycle: tempShiftWaitsForCervixShift,
|
||||||
|
previousCycle: cycleWithFhmNoCervixShift,
|
||||||
|
secondarySymptom: 'cervix'
|
||||||
|
})
|
||||||
|
expect(Object.keys(status.phases).length).to.eql(3)
|
||||||
|
expect(status.cervixShift.detected).to.be.true()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('when no infertile phase can be detected', () => {
|
||||||
|
const status = getSensiplanStatus({
|
||||||
|
cycle: noInfertilePhaseDetected,
|
||||||
|
previousCycle: cycleWithFhmNoCervixShift,
|
||||||
|
secondarySymptom: 'cervix'
|
||||||
|
})
|
||||||
|
expect(Object.keys(status.phases).length).to.eql(2)
|
||||||
|
})
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
it('', function () {
|
||||||
|
const status = getSensiplanStatus({
|
||||||
|
cycle: idealCycle,
|
||||||
|
previousCycle: idealCycle,
|
||||||
|
secondarySymptom: 'cervix'
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(Object.keys(status.phases).length).to.eql()
|
||||||
|
expect(status).to.eql({
|
||||||
|
phases: {
|
||||||
|
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -0,0 +1,114 @@
|
|||||||
|
import chai from 'chai'
|
||||||
|
import getCervixStatus from '../../lib/sympto/cervix'
|
||||||
|
|
||||||
|
const expect = chai.expect
|
||||||
|
|
||||||
|
function turnIntoCycleDayObject(value, fakeDate) {
|
||||||
|
const hardAndClosed = {
|
||||||
|
isHard: true,
|
||||||
|
isClosed: true
|
||||||
|
}
|
||||||
|
const hardAndOpen = {
|
||||||
|
isHard: true,
|
||||||
|
isClosed: false
|
||||||
|
}
|
||||||
|
const softAndClosed = {
|
||||||
|
isHard: false,
|
||||||
|
isClosed: true
|
||||||
|
}
|
||||||
|
const softAndOpen = {
|
||||||
|
isHard: false,
|
||||||
|
isClosed: false
|
||||||
|
}
|
||||||
|
const cervixStates = [hardAndClosed, hardAndOpen, softAndClosed, softAndOpen]
|
||||||
|
return {
|
||||||
|
cervix : cervixStates[value],
|
||||||
|
date: fakeDate
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
describe('sympto', () => {
|
||||||
|
describe('detects cervix shift', () => {
|
||||||
|
it('when an ideal cycle happens', function () {
|
||||||
|
const values = [0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 3, 1, 3, 1, 0, 0, 0, 0]
|
||||||
|
.map(turnIntoCycleDayObject)
|
||||||
|
const status = getCervixStatus(values)
|
||||||
|
expect(status).to.eql({
|
||||||
|
detected: true,
|
||||||
|
cervixPeak: {
|
||||||
|
date: 13,
|
||||||
|
cervix: {
|
||||||
|
isHard: true,
|
||||||
|
isClosed: false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
evaluationCompleteDay: {
|
||||||
|
date: 16,
|
||||||
|
cervix: {
|
||||||
|
isHard: true,
|
||||||
|
isClosed: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it('at the very first day of cycle days even if later shift happens again', function () {
|
||||||
|
const values = [2, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
|
||||||
|
.map(turnIntoCycleDayObject)
|
||||||
|
const status = getCervixStatus(values)
|
||||||
|
expect(status).to.eql({
|
||||||
|
detected: true,
|
||||||
|
cervixPeak: {
|
||||||
|
date: 0,
|
||||||
|
cervix: {
|
||||||
|
isHard: false,
|
||||||
|
isClosed: true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
evaluationCompleteDay: {
|
||||||
|
date: 3,
|
||||||
|
cervix: {
|
||||||
|
isHard: true,
|
||||||
|
isClosed: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('detects no cervix shift', () => {
|
||||||
|
it('if there are less than 3 days closed and hard cervix', function () {
|
||||||
|
const values = [0, 0, 0, 1, 1, 1, 2, 2, 3, 3, 3, 1, 1, 1, 0, 0, 2, 0]
|
||||||
|
.map(turnIntoCycleDayObject)
|
||||||
|
const status = getCervixStatus(values)
|
||||||
|
expect(status).to.eql({ detected: false })
|
||||||
|
})
|
||||||
|
|
||||||
|
it('if there are no cervix values', function () {
|
||||||
|
const values = [].map(turnIntoCycleDayObject)
|
||||||
|
const status = getCervixStatus(values)
|
||||||
|
expect(status).to.eql({ detected: false })
|
||||||
|
})
|
||||||
|
|
||||||
|
it('when the cervix values are all the same', function () {
|
||||||
|
const values = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
|
||||||
|
.map(turnIntoCycleDayObject)
|
||||||
|
const status = getCervixStatus(values)
|
||||||
|
expect(status).to.eql({ detected: false })
|
||||||
|
})
|
||||||
|
|
||||||
|
it('if no days of hard and closed cervix are tracked', function () {
|
||||||
|
const values = [1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1]
|
||||||
|
.map(turnIntoCycleDayObject)
|
||||||
|
const status = getCervixStatus(values)
|
||||||
|
expect(status).to.eql({ detected: false })
|
||||||
|
})
|
||||||
|
|
||||||
|
it('if days of hard and closed cervix are fewer than 3', function () {
|
||||||
|
const values = [1, 3, 2, 1, 0, 2, 1, 3, 2, 0, 0, 2, 1, 3, 2, 1]
|
||||||
|
.map(turnIntoCycleDayObject)
|
||||||
|
const status = getCervixStatus(values)
|
||||||
|
expect(status).to.eql({ detected: false })
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -1,660 +0,0 @@
|
|||||||
import chai from 'chai'
|
|
||||||
import getSensiplanStatus from '../../lib/sympto'
|
|
||||||
import { AssertionError } from 'assert'
|
|
||||||
import {
|
|
||||||
cycleWithoutFhm,
|
|
||||||
longAndComplicatedCycle,
|
|
||||||
cycleWithTempAndNoMucusShift,
|
|
||||||
cycleWithFhm,
|
|
||||||
cycleWithoutAnyShifts,
|
|
||||||
fiveDayCycle,
|
|
||||||
cycleWithEarlyMucus,
|
|
||||||
cycleWithMucusOnFirstDay,
|
|
||||||
mucusPeakAndFhmOnSameDay,
|
|
||||||
fhmTwoDaysBeforeMucusPeak,
|
|
||||||
fhm5DaysAfterMucusPeak,
|
|
||||||
mucusPeak5DaysAfterFhm,
|
|
||||||
mucusPeakTwoDaysBeforeFhm,
|
|
||||||
fhmOnDay12,
|
|
||||||
fhmOnDay15,
|
|
||||||
mucusPeakSlightlyBeforeTempShift,
|
|
||||||
highestMucusQualityAfterEndOfEval
|
|
||||||
} from './fixtures'
|
|
||||||
|
|
||||||
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,
|
|
||||||
previousCycle: cycleWithoutFhm
|
|
||||||
})
|
|
||||||
|
|
||||||
expect(status).to.eql({
|
|
||||||
|
|
||||||
phases: {
|
|
||||||
periOvulatory: {
|
|
||||||
start: { date: '2018-06-01' },
|
|
||||||
cycleDays: cycleWithoutAnyShifts
|
|
||||||
}
|
|
||||||
},
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
it('with shifts detects only peri-ovulatory and post-ovulatory', () => {
|
|
||||||
const status = getSensiplanStatus({
|
|
||||||
cycle: longAndComplicatedCycle,
|
|
||||||
previousCycle: cycleWithoutFhm
|
|
||||||
})
|
|
||||||
|
|
||||||
expect(status.temperatureShift).to.be.an('object')
|
|
||||||
expect(status.mucusShift).to.be.an('object')
|
|
||||||
|
|
||||||
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: longAndComplicatedCycle
|
|
||||||
.filter(({date}) => date <= '2018-06-21')
|
|
||||||
})
|
|
||||||
expect(status.phases.postOvulatory).to.eql({
|
|
||||||
start: {
|
|
||||||
date: '2018-06-21',
|
|
||||||
time: '18:00'
|
|
||||||
},
|
|
||||||
cycleDays: longAndComplicatedCycle
|
|
||||||
.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,
|
|
||||||
previousCycle: cycleWithFhm
|
|
||||||
})
|
|
||||||
|
|
||||||
expect(Object.keys(status.phases).length).to.eql(1)
|
|
||||||
|
|
||||||
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', () => {
|
|
||||||
it('according to 5-day-rule', function () {
|
|
||||||
const status = getSensiplanStatus({
|
|
||||||
cycle: cycleWithTempAndNoMucusShift,
|
|
||||||
previousCycle: cycleWithFhm
|
|
||||||
})
|
|
||||||
|
|
||||||
expect(Object.keys(status.phases).length).to.eql(2)
|
|
||||||
|
|
||||||
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'),
|
|
||||||
start: { date: '2018-06-06' }
|
|
||||||
})
|
|
||||||
})
|
|
||||||
it('according to 5-day-rule with shortened pre-phase', function () {
|
|
||||||
const status = getSensiplanStatus({
|
|
||||||
cycle: cycleWithEarlyMucus,
|
|
||||||
previousCycle: cycleWithFhm
|
|
||||||
})
|
|
||||||
|
|
||||||
expect(Object.keys(status.phases).length).to.eql(2)
|
|
||||||
|
|
||||||
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: longAndComplicatedCycle,
|
|
||||||
previousCycle: cycleWithFhm
|
|
||||||
})
|
|
||||||
|
|
||||||
expect(Object.keys(status.phases).length).to.eql(3)
|
|
||||||
|
|
||||||
expect(status.phases.preOvulatory).to.eql({
|
|
||||||
cycleDays: longAndComplicatedCycle
|
|
||||||
.filter(({date}) => date <= '2018-06-05'),
|
|
||||||
start: { date: '2018-06-01' },
|
|
||||||
end: { date: '2018-06-05' }
|
|
||||||
})
|
|
||||||
expect(status.phases.periOvulatory).to.eql({
|
|
||||||
cycleDays: longAndComplicatedCycle
|
|
||||||
.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: longAndComplicatedCycle
|
|
||||||
.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 start of postovu phase', () => {
|
|
||||||
const status = getSensiplanStatus({
|
|
||||||
cycle: mucusPeakAndFhmOnSameDay,
|
|
||||||
previousCycle: cycleWithFhm
|
|
||||||
})
|
|
||||||
|
|
||||||
expect(status.temperatureShift).to.be.an('object')
|
|
||||||
expect(status.mucusShift).to.be.an('object')
|
|
||||||
|
|
||||||
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,
|
|
||||||
previousCycle: cycleWithFhm
|
|
||||||
})
|
|
||||||
|
|
||||||
expect(status.temperatureShift).to.be.an('object')
|
|
||||||
expect(status.mucusShift).to.be.an('object')
|
|
||||||
|
|
||||||
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('another example for mucus peak before temp shift', () => {
|
|
||||||
const status = getSensiplanStatus({
|
|
||||||
cycle: mucusPeakSlightlyBeforeTempShift,
|
|
||||||
previousCycle: cycleWithFhm
|
|
||||||
})
|
|
||||||
|
|
||||||
expect(status.temperatureShift).to.be.an('object')
|
|
||||||
expect(status.mucusShift).to.be.an('object')
|
|
||||||
|
|
||||||
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: mucusPeakSlightlyBeforeTempShift
|
|
||||||
.filter(({date}) => date <= '2018-06-05')
|
|
||||||
})
|
|
||||||
expect(status.phases.periOvulatory).to.eql({
|
|
||||||
start: { date: '2018-06-06' },
|
|
||||||
end: { date: '2018-06-17', time: '18:00' },
|
|
||||||
cycleDays: mucusPeakSlightlyBeforeTempShift
|
|
||||||
.filter(({date}) => {
|
|
||||||
return date > '2018-06-05' && date <= '2018-06-17'
|
|
||||||
})
|
|
||||||
})
|
|
||||||
expect(status.phases.postOvulatory).to.eql({
|
|
||||||
start: {
|
|
||||||
date: '2018-06-17',
|
|
||||||
time: '18:00'
|
|
||||||
},
|
|
||||||
cycleDays: mucusPeakSlightlyBeforeTempShift
|
|
||||||
.filter(({date}) => date >= '2018-06-17')
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
it('with another mucus peak 5 days after fHM ignores it', () => {
|
|
||||||
const status = getSensiplanStatus({
|
|
||||||
cycle: mucusPeak5DaysAfterFhm,
|
|
||||||
previousCycle: cycleWithFhm
|
|
||||||
})
|
|
||||||
|
|
||||||
expect(status.temperatureShift).to.be.an('object')
|
|
||||||
expect(status.mucusShift).to.be.an('object')
|
|
||||||
|
|
||||||
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,
|
|
||||||
previousCycle: cycleWithFhm
|
|
||||||
})
|
|
||||||
|
|
||||||
expect(status.temperatureShift).to.be.an('object')
|
|
||||||
expect(status.mucusShift).to.be.an('object')
|
|
||||||
|
|
||||||
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,
|
|
||||||
previousCycle: cycleWithFhm
|
|
||||||
})
|
|
||||||
|
|
||||||
expect(status.temperatureShift).to.be.an('object')
|
|
||||||
expect(status.mucusShift).to.be.an('object')
|
|
||||||
|
|
||||||
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')
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
it('with highest quality after end of eval', () => {
|
|
||||||
const status = getSensiplanStatus({
|
|
||||||
cycle: highestMucusQualityAfterEndOfEval,
|
|
||||||
previousCycle: cycleWithFhm
|
|
||||||
})
|
|
||||||
|
|
||||||
expect(status.temperatureShift).to.be.an('object')
|
|
||||||
expect(status.mucusShift).to.be.an('object')
|
|
||||||
|
|
||||||
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: highestMucusQualityAfterEndOfEval
|
|
||||||
.filter(({date}) => date <= '2018-06-05')
|
|
||||||
})
|
|
||||||
expect(status.phases.periOvulatory).to.eql({
|
|
||||||
start: { date: '2018-06-06' },
|
|
||||||
end: { date: '2018-06-17', time: '18:00' },
|
|
||||||
cycleDays: highestMucusQualityAfterEndOfEval
|
|
||||||
.filter(({date}) => {
|
|
||||||
return date > '2018-06-05' && date <= '2018-06-17'
|
|
||||||
})
|
|
||||||
})
|
|
||||||
expect(status.phases.postOvulatory).to.eql({
|
|
||||||
start: {
|
|
||||||
date: '2018-06-17',
|
|
||||||
time: '18:00'
|
|
||||||
},
|
|
||||||
cycleDays: highestMucusQualityAfterEndOfEval
|
|
||||||
.filter(({date}) => date >= '2018-06-17')
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
describe('applying the minus-8 rule', () => {
|
|
||||||
it('shortens the pre-ovu phase if there is a previous <13 fhm', () => {
|
|
||||||
const status = getSensiplanStatus({
|
|
||||||
cycle: longAndComplicatedCycle,
|
|
||||||
previousCycle: fhmOnDay15,
|
|
||||||
earlierCycles: [fhmOnDay12, ...Array(10).fill(fhmOnDay15)]
|
|
||||||
})
|
|
||||||
|
|
||||||
expect(status.temperatureShift).to.be.an('object')
|
|
||||||
expect(status.mucusShift).to.be.an('object')
|
|
||||||
|
|
||||||
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: longAndComplicatedCycle
|
|
||||||
.filter(({date}) => date <= '2018-06-04')
|
|
||||||
})
|
|
||||||
expect(status.phases.periOvulatory).to.eql({
|
|
||||||
start: { date: '2018-06-05' },
|
|
||||||
end: { date: '2018-06-21', time: '18:00' },
|
|
||||||
cycleDays: longAndComplicatedCycle
|
|
||||||
.filter(({date}) => {
|
|
||||||
return date > '2018-06-04' && date <= '2018-06-21'
|
|
||||||
})
|
|
||||||
})
|
|
||||||
expect(status.phases.postOvulatory).to.eql({
|
|
||||||
start: {
|
|
||||||
date: '2018-06-21',
|
|
||||||
time: '18:00'
|
|
||||||
},
|
|
||||||
cycleDays: longAndComplicatedCycle
|
|
||||||
.filter(({date}) => date >= '2018-06-21')
|
|
||||||
})
|
|
||||||
})
|
|
||||||
it('shortens pre-ovu phase with prev <13 fhm even with <12 cycles', () => {
|
|
||||||
const status = getSensiplanStatus({
|
|
||||||
cycle: longAndComplicatedCycle,
|
|
||||||
previousCycle: fhmOnDay12,
|
|
||||||
earlierCycles: Array(10).fill(fhmOnDay12)
|
|
||||||
})
|
|
||||||
|
|
||||||
expect(status.temperatureShift).to.be.an('object')
|
|
||||||
expect(status.mucusShift).to.be.an('object')
|
|
||||||
|
|
||||||
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: longAndComplicatedCycle
|
|
||||||
.filter(({date}) => date <= '2018-06-04')
|
|
||||||
})
|
|
||||||
expect(status.phases.periOvulatory).to.eql({
|
|
||||||
start: { date: '2018-06-05' },
|
|
||||||
end: { date: '2018-06-21', time: '18:00' },
|
|
||||||
cycleDays: longAndComplicatedCycle
|
|
||||||
.filter(({date}) => {
|
|
||||||
return date > '2018-06-04' && date <= '2018-06-21'
|
|
||||||
})
|
|
||||||
})
|
|
||||||
expect(status.phases.postOvulatory).to.eql({
|
|
||||||
start: {
|
|
||||||
date: '2018-06-21',
|
|
||||||
time: '18:00'
|
|
||||||
},
|
|
||||||
cycleDays: longAndComplicatedCycle
|
|
||||||
.filter(({date}) => date >= '2018-06-21')
|
|
||||||
})
|
|
||||||
})
|
|
||||||
it('shortens the pre-ovu phase if mucus occurs', () => {
|
|
||||||
const status = getSensiplanStatus({
|
|
||||||
cycle: cycleWithEarlyMucus,
|
|
||||||
previousCycle: fhmOnDay12,
|
|
||||||
earlierCycles: Array(10).fill(fhmOnDay12)
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
expect(Object.keys(status.phases).length).to.eql(2)
|
|
||||||
expect(status.phases.preOvulatory).to.eql({
|
|
||||||
start: { date: '2018-06-01' },
|
|
||||||
end: { date: '2018-06-01' },
|
|
||||||
cycleDays: cycleWithEarlyMucus
|
|
||||||
.filter(({date}) => date <= '2018-06-01')
|
|
||||||
})
|
|
||||||
expect(status.phases.periOvulatory).to.eql({
|
|
||||||
start: { date: '2018-06-02' },
|
|
||||||
cycleDays: cycleWithEarlyMucus
|
|
||||||
.filter(({date}) => {
|
|
||||||
return date > '2018-06-01'
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
it('shortens the pre-ovu phase if mucus occurs even on the first day', () => {
|
|
||||||
const status = getSensiplanStatus({
|
|
||||||
cycle: cycleWithMucusOnFirstDay,
|
|
||||||
previousCycle: fhmOnDay12,
|
|
||||||
earlierCycles: Array(10).fill(fhmOnDay12)
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
expect(Object.keys(status.phases).length).to.eql(1)
|
|
||||||
|
|
||||||
expect(status.phases.periOvulatory).to.eql({
|
|
||||||
start: { date: '2018-06-01' },
|
|
||||||
cycleDays: cycleWithMucusOnFirstDay
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
it('lengthens the pre-ovu phase if >= 12 cycles with fhm > 13', () => {
|
|
||||||
const status = getSensiplanStatus({
|
|
||||||
cycle: longAndComplicatedCycle,
|
|
||||||
previousCycle: fhmOnDay15,
|
|
||||||
earlierCycles: Array(11).fill(fhmOnDay15)
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
expect(Object.keys(status.phases).length).to.eql(3)
|
|
||||||
expect(status.phases.preOvulatory).to.eql({
|
|
||||||
start: { date: '2018-06-01' },
|
|
||||||
end: { date: '2018-06-07' },
|
|
||||||
cycleDays: longAndComplicatedCycle
|
|
||||||
.filter(({date}) => date <= '2018-06-07')
|
|
||||||
})
|
|
||||||
expect(status.phases.periOvulatory).to.eql({
|
|
||||||
start: { date: '2018-06-08' },
|
|
||||||
end: { date: '2018-06-21', time: '18:00' },
|
|
||||||
cycleDays: longAndComplicatedCycle
|
|
||||||
.filter(({date}) => {
|
|
||||||
return date > '2018-06-07' && date <= '2018-06-21'
|
|
||||||
})
|
|
||||||
})
|
|
||||||
expect(status.phases.postOvulatory).to.eql({
|
|
||||||
start: {
|
|
||||||
date: '2018-06-21',
|
|
||||||
time: '18:00'
|
|
||||||
},
|
|
||||||
cycleDays: longAndComplicatedCycle
|
|
||||||
.filter(({date}) => date >= '2018-06-21')
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
it('does not lengthen the pre-ovu phase if < 12 cycles', () => {
|
|
||||||
const status = getSensiplanStatus({
|
|
||||||
cycle: longAndComplicatedCycle,
|
|
||||||
previousCycle: fhmOnDay15,
|
|
||||||
earlierCycles: Array(10).fill(fhmOnDay15)
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
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: longAndComplicatedCycle
|
|
||||||
.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: longAndComplicatedCycle
|
|
||||||
.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: longAndComplicatedCycle
|
|
||||||
.filter(({date}) => date >= '2018-06-21')
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
it('does not detect any pre-ovu phase if prev cycle had no fhm', () => {
|
|
||||||
const status = getSensiplanStatus({
|
|
||||||
cycle: longAndComplicatedCycle,
|
|
||||||
previousCycle: cycleWithoutFhm,
|
|
||||||
earlierCycles: [...Array(12).fill(fhmOnDay15)]
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
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: longAndComplicatedCycle
|
|
||||||
.filter(({date}) => {
|
|
||||||
return date >= '2018-06-01' && date <= '2018-06-21'
|
|
||||||
})
|
|
||||||
})
|
|
||||||
expect(status.phases.postOvulatory).to.eql({
|
|
||||||
start: {
|
|
||||||
date: '2018-06-21',
|
|
||||||
time: '18:00'
|
|
||||||
},
|
|
||||||
cycleDays: longAndComplicatedCycle
|
|
||||||
.filter(({date}) => date >= '2018-06-21')
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
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 }
|
|
||||||
}],
|
|
||||||
earlierCycles: [[{
|
|
||||||
date: '1992-09-09',
|
|
||||||
bleeding: { value: 0 }
|
|
||||||
}]]
|
|
||||||
})).to.throw(AssertionError)
|
|
||||||
expect(() => getSensiplanStatus({
|
|
||||||
cycle: [{
|
|
||||||
date: '2018-04-13',
|
|
||||||
temperature: {value: '35'},
|
|
||||||
bleeding: { value: 0 }
|
|
||||||
}],
|
|
||||||
earlierCycles: [[{
|
|
||||||
date: '1992-09-09',
|
|
||||||
bleeding: { value: 0 }
|
|
||||||
}]]
|
|
||||||
})).to.throw(AssertionError)
|
|
||||||
expect(() => getSensiplanStatus({
|
|
||||||
cycle: [{
|
|
||||||
date: '09-14-2017',
|
|
||||||
bleeding: { value: 0 }
|
|
||||||
}],
|
|
||||||
earlierCycles: [[{
|
|
||||||
date: '1992-09-09',
|
|
||||||
bleeding: { value: 0 }
|
|
||||||
}]]
|
|
||||||
})).to.throw(AssertionError)
|
|
||||||
})
|
|
||||||
it('throws if first cycle day does not have bleeding value', () => {
|
|
||||||
expect(() => getSensiplanStatus({
|
|
||||||
cycle: [{
|
|
||||||
date: '2017-01-01',
|
|
||||||
bleeding: {
|
|
||||||
value: 'medium'
|
|
||||||
}
|
|
||||||
}],
|
|
||||||
earlierCycles: [[
|
|
||||||
{
|
|
||||||
date: '2017-09-23',
|
|
||||||
}
|
|
||||||
]]
|
|
||||||
})).to.throw(AssertionError)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
@@ -15,7 +15,7 @@ export const cycleWithFhm = [
|
|||||||
{ date: '2018-06-06', temperature: 36.7, mucus: 0 },
|
{ date: '2018-06-06', temperature: 36.7, mucus: 0 },
|
||||||
{ date: '2018-06-13', temperature: 36.8, mucus: 4 },
|
{ date: '2018-06-13', temperature: 36.8, mucus: 4 },
|
||||||
{ date: '2018-06-15', temperature: 36.9, mucus: 2 },
|
{ date: '2018-06-15', temperature: 36.9, mucus: 2 },
|
||||||
{ date: '2018-06-17', temperature: 36.9, mucus: 2 },
|
{ date: '2018-06-16', temperature: 36.9, mucus: 2 },
|
||||||
{ date: '2018-06-17', temperature: 36.9, mucus: 2 },
|
{ date: '2018-06-17', temperature: 36.9, mucus: 2 },
|
||||||
{ date: '2018-06-18', temperature: 36.9, mucus: 2 }
|
{ date: '2018-06-18', temperature: 36.9, mucus: 2 }
|
||||||
].map(convertToSymptoFormat)
|
].map(convertToSymptoFormat)
|
||||||
@@ -227,6 +227,31 @@ export const mucusPeak5DaysAfterFhm = [
|
|||||||
{ date: '2018-07-02', temperature: 36.9, mucus: 1 }
|
{ date: '2018-07-02', temperature: 36.9, mucus: 1 }
|
||||||
].map(convertToSymptoFormat)
|
].map(convertToSymptoFormat)
|
||||||
|
|
||||||
|
export const highestMucusQualityAfterEndOfEval = [
|
||||||
|
{ date: '2018-06-01', temperature: 36.6, bleeding: 2 },
|
||||||
|
{ date: '2018-06-02', temperature: 36.65, mucus: 2 },
|
||||||
|
{ date: '2018-06-04', temperature: 36.6 },
|
||||||
|
{ date: '2018-06-05', temperature: 36.55 },
|
||||||
|
{ date: '2018-06-06', temperature: 36.7, mucus: 0 },
|
||||||
|
{ date: '2018-06-09', temperature: 36.5, mucus: 1 },
|
||||||
|
{ date: '2018-06-10', temperature: 36.4, mucus: 2 },
|
||||||
|
{ date: '2018-06-13', temperature: 36.45, mucus: 3 },
|
||||||
|
{ date: '2018-06-14', temperature: 36.5, mucus: 3 },
|
||||||
|
{ date: '2018-06-15', temperature: 36.55, mucus: 3 },
|
||||||
|
{ date: '2018-06-16', temperature: 36.7, mucus: 3 },
|
||||||
|
{ date: '2018-06-17', temperature: 36.65, mucus: 3 },
|
||||||
|
{ date: '2018-06-18', temperature: 36.60, mucus: 2 },
|
||||||
|
{ date: '2018-06-19', temperature: 36.8, mucus: 3 },
|
||||||
|
{ date: '2018-06-20', temperature: 36.85, mucus: 3 },
|
||||||
|
{ date: '2018-06-21', temperature: 36.8, mucus: 3 },
|
||||||
|
{ date: '2018-06-22', temperature: 36.9, mucus: 1 },
|
||||||
|
{ date: '2018-06-25', temperature: 36.9, mucus: 1 },
|
||||||
|
{ date: '2018-06-26', temperature: 36.8, mucus: 1 },
|
||||||
|
{ date: '2018-06-30', temperature: 36.9, mucus: 1 },
|
||||||
|
{ date: '2018-07-01', temperature: 36.9, mucus: 4 },
|
||||||
|
{ date: '2018-07-02', temperature: 36.9, mucus: 1 }
|
||||||
|
].map(convertToSymptoFormat)
|
||||||
|
|
||||||
export const fhm5DaysAfterMucusPeak = [
|
export const fhm5DaysAfterMucusPeak = [
|
||||||
{ date: '2018-06-01', temperature: 36.6, bleeding: 2 },
|
{ date: '2018-06-01', temperature: 36.6, bleeding: 2 },
|
||||||
{ date: '2018-06-02', temperature: 36.65 },
|
{ date: '2018-06-02', temperature: 36.65 },
|
||||||
@@ -299,26 +324,3 @@ export const mucusPeakSlightlyBeforeTempShift = [
|
|||||||
{ date: '2018-06-21', temperature: 36.8, mucus: 1},
|
{ date: '2018-06-21', temperature: 36.8, mucus: 1},
|
||||||
{ date: '2018-06-22', temperature: 36.8, mucus: 1}
|
{ date: '2018-06-22', temperature: 36.8, mucus: 1}
|
||||||
].map(convertToSymptoFormat)
|
].map(convertToSymptoFormat)
|
||||||
|
|
||||||
|
|
||||||
export const highestMucusQualityAfterEndOfEval = [
|
|
||||||
{ date: '2018-06-01', temperature: 36.6, bleeding: 2 },
|
|
||||||
{ date: '2018-06-02', temperature: 36.65 },
|
|
||||||
{ date: '2018-06-04', temperature: 36.6 },
|
|
||||||
{ date: '2018-06-07', temperature: 36.4, mucus: 1 },
|
|
||||||
{ date: '2018-06-08', temperature: 36.35, mucus: 2},
|
|
||||||
{ date: '2018-06-09', temperature: 36.4, mucus: 2},
|
|
||||||
{ date: '2018-06-10', temperature: 36.45, mucus: 2},
|
|
||||||
{ date: '2018-06-11', temperature: 36.4, mucus: 2},
|
|
||||||
{ date: '2018-06-12', temperature: 36.45, mucus: 2},
|
|
||||||
{ date: '2018-06-13', temperature: 36.45, mucus: 3},
|
|
||||||
{ date: '2018-06-14', temperature: 36.55, mucus: 2},
|
|
||||||
{ date: '2018-06-15', temperature: 36.6, mucus: 2},
|
|
||||||
{ date: '2018-06-16', temperature: 36.6, mucus: 2},
|
|
||||||
{ date: '2018-06-17', temperature: 36.55, mucus: 2},
|
|
||||||
{ date: '2018-06-18', temperature: 36.6, mucus: 1},
|
|
||||||
{ date: '2018-06-19', temperature: 36.7, mucus: 4},
|
|
||||||
{ date: '2018-06-20', temperature: 36.75, mucus: 1},
|
|
||||||
{ date: '2018-06-21', temperature: 36.8, mucus: 1},
|
|
||||||
{ date: '2018-06-22', temperature: 36.8, mucus: 1}
|
|
||||||
].map(convertToSymptoFormat)
|
|
||||||
@@ -0,0 +1,661 @@
|
|||||||
|
import chai from 'chai'
|
||||||
|
import getSensiplanStatus from '../../lib/sympto'
|
||||||
|
import { AssertionError } from 'assert'
|
||||||
|
import {
|
||||||
|
cycleWithoutFhm,
|
||||||
|
longAndComplicatedCycle,
|
||||||
|
cycleWithTempAndNoMucusShift,
|
||||||
|
cycleWithFhm,
|
||||||
|
cycleWithoutAnyShifts,
|
||||||
|
fiveDayCycle,
|
||||||
|
cycleWithEarlyMucus,
|
||||||
|
cycleWithMucusOnFirstDay,
|
||||||
|
mucusPeakAndFhmOnSameDay,
|
||||||
|
fhmTwoDaysBeforeMucusPeak,
|
||||||
|
fhm5DaysAfterMucusPeak,
|
||||||
|
mucusPeak5DaysAfterFhm,
|
||||||
|
mucusPeakTwoDaysBeforeFhm,
|
||||||
|
fhmOnDay12,
|
||||||
|
fhmOnDay15,
|
||||||
|
mucusPeakSlightlyBeforeTempShift,
|
||||||
|
highestMucusQualityAfterEndOfEval
|
||||||
|
} from './mucus-temp-fixtures'
|
||||||
|
|
||||||
|
const expect = chai.expect
|
||||||
|
|
||||||
|
describe('sympto', () => {
|
||||||
|
describe('combining temperature and mucus tracking', () => {
|
||||||
|
describe('with no previous higher temp measurement', () => {
|
||||||
|
|
||||||
|
it('with no shifts detects only peri-ovulatory', function () {
|
||||||
|
const status = getSensiplanStatus({
|
||||||
|
cycle: cycleWithoutAnyShifts,
|
||||||
|
previousCycle: cycleWithoutFhm
|
||||||
|
})
|
||||||
|
expect(status.phases.periOvulatory).to.eql({
|
||||||
|
start: { date: '2018-06-01' },
|
||||||
|
cycleDays: cycleWithoutAnyShifts
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it('with temp and mucus shifts detects only peri-ovulatory and post-ovulatory', () => {
|
||||||
|
const status = getSensiplanStatus({
|
||||||
|
cycle: longAndComplicatedCycle,
|
||||||
|
previousCycle: cycleWithoutFhm
|
||||||
|
})
|
||||||
|
expect(status.temperatureShift).to.be.an('object')
|
||||||
|
expect(status.mucusShift).to.be.an('object')
|
||||||
|
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: longAndComplicatedCycle
|
||||||
|
.filter(({date}) => date <= '2018-06-21')
|
||||||
|
})
|
||||||
|
expect(status.phases.postOvulatory).to.eql({
|
||||||
|
start: {
|
||||||
|
date: '2018-06-21',
|
||||||
|
time: '18:00'
|
||||||
|
},
|
||||||
|
cycleDays: longAndComplicatedCycle
|
||||||
|
.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,
|
||||||
|
previousCycle: cycleWithFhm
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(Object.keys(status.phases).length).to.eql(1)
|
||||||
|
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', () => {
|
||||||
|
it('according to 5-day-rule', function () {
|
||||||
|
const status = getSensiplanStatus({
|
||||||
|
cycle: cycleWithTempAndNoMucusShift,
|
||||||
|
previousCycle: cycleWithFhm
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(Object.keys(status.phases).length).to.eql(2)
|
||||||
|
|
||||||
|
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'),
|
||||||
|
start: { date: '2018-06-06' }
|
||||||
|
})
|
||||||
|
})
|
||||||
|
it('according to 5-day-rule with shortened pre-phase', function () {
|
||||||
|
const status = getSensiplanStatus({
|
||||||
|
cycle: cycleWithEarlyMucus,
|
||||||
|
previousCycle: cycleWithFhm
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(Object.keys(status.phases).length).to.eql(2)
|
||||||
|
|
||||||
|
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: longAndComplicatedCycle,
|
||||||
|
previousCycle: cycleWithFhm
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(Object.keys(status.phases).length).to.eql(3)
|
||||||
|
|
||||||
|
expect(status.phases.preOvulatory).to.eql({
|
||||||
|
cycleDays: longAndComplicatedCycle
|
||||||
|
.filter(({date}) => date <= '2018-06-05'),
|
||||||
|
start: { date: '2018-06-01' },
|
||||||
|
end: { date: '2018-06-05' }
|
||||||
|
})
|
||||||
|
expect(status.phases.periOvulatory).to.eql({
|
||||||
|
cycleDays: longAndComplicatedCycle
|
||||||
|
.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: longAndComplicatedCycle
|
||||||
|
.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 start of postovu phase', () => {
|
||||||
|
const status = getSensiplanStatus({
|
||||||
|
cycle: mucusPeakAndFhmOnSameDay,
|
||||||
|
previousCycle: cycleWithFhm
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(status.temperatureShift).to.be.an('object')
|
||||||
|
expect(status.mucusShift).to.be.an('object')
|
||||||
|
|
||||||
|
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,
|
||||||
|
previousCycle: cycleWithFhm
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(status.temperatureShift).to.be.an('object')
|
||||||
|
expect(status.mucusShift).to.be.an('object')
|
||||||
|
|
||||||
|
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('another example for mucus peak before temp shift', () => {
|
||||||
|
const status = getSensiplanStatus({
|
||||||
|
cycle: mucusPeakSlightlyBeforeTempShift,
|
||||||
|
previousCycle: cycleWithFhm
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(status.temperatureShift).to.be.an('object')
|
||||||
|
expect(status.mucusShift).to.be.an('object')
|
||||||
|
|
||||||
|
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: mucusPeakSlightlyBeforeTempShift
|
||||||
|
.filter(({date}) => date <= '2018-06-05')
|
||||||
|
})
|
||||||
|
expect(status.phases.periOvulatory).to.eql({
|
||||||
|
start: { date: '2018-06-06' },
|
||||||
|
end: { date: '2018-06-17', time: '18:00' },
|
||||||
|
cycleDays: mucusPeakSlightlyBeforeTempShift
|
||||||
|
.filter(({date}) => {
|
||||||
|
return date > '2018-06-05' && date <= '2018-06-17'
|
||||||
|
})
|
||||||
|
})
|
||||||
|
expect(status.phases.postOvulatory).to.eql({
|
||||||
|
start: {
|
||||||
|
date: '2018-06-17',
|
||||||
|
time: '18:00'
|
||||||
|
},
|
||||||
|
cycleDays: mucusPeakSlightlyBeforeTempShift
|
||||||
|
.filter(({date}) => date >= '2018-06-17')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it('with another mucus peak 5 days after fHM ignores it', () => {
|
||||||
|
const status = getSensiplanStatus({
|
||||||
|
cycle: mucusPeak5DaysAfterFhm,
|
||||||
|
previousCycle: cycleWithFhm
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(status.temperatureShift).to.be.an('object')
|
||||||
|
expect(status.mucusShift).to.be.an('object')
|
||||||
|
|
||||||
|
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,
|
||||||
|
previousCycle: cycleWithFhm
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(status.temperatureShift).to.be.an('object')
|
||||||
|
expect(status.mucusShift).to.be.an('object')
|
||||||
|
|
||||||
|
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,
|
||||||
|
previousCycle: cycleWithFhm
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(status.temperatureShift).to.be.an('object')
|
||||||
|
expect(status.mucusShift).to.be.an('object')
|
||||||
|
|
||||||
|
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', () => {
|
||||||
|
const status = getSensiplanStatus({
|
||||||
|
cycle: longAndComplicatedCycle,
|
||||||
|
previousCycle: fhmOnDay15,
|
||||||
|
earlierCycles: [fhmOnDay12, ...Array(10).fill(fhmOnDay15)]
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(status.temperatureShift).to.be.an('object')
|
||||||
|
expect(status.mucusShift).to.be.an('object')
|
||||||
|
|
||||||
|
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: longAndComplicatedCycle
|
||||||
|
.filter(({date}) => date <= '2018-06-04')
|
||||||
|
})
|
||||||
|
expect(status.phases.periOvulatory).to.eql({
|
||||||
|
start: { date: '2018-06-05' },
|
||||||
|
end: { date: '2018-06-21', time: '18:00' },
|
||||||
|
cycleDays: longAndComplicatedCycle
|
||||||
|
.filter(({date}) => {
|
||||||
|
return date > '2018-06-04' && date <= '2018-06-21'
|
||||||
|
})
|
||||||
|
})
|
||||||
|
expect(status.phases.postOvulatory).to.eql({
|
||||||
|
start: {
|
||||||
|
date: '2018-06-21',
|
||||||
|
time: '18:00'
|
||||||
|
},
|
||||||
|
cycleDays: longAndComplicatedCycle
|
||||||
|
.filter(({date}) => date >= '2018-06-21')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
// #TODO
|
||||||
|
it.only('shortens pre-ovu phase with prev <13 fhm even with <12 cycles', () => {
|
||||||
|
const status = getSensiplanStatus({
|
||||||
|
cycle: longAndComplicatedCycle,
|
||||||
|
previousCycle: fhmOnDay12,
|
||||||
|
earlierCycles: Array(10).fill(fhmOnDay12)
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(status.temperatureShift).to.be.an('object')
|
||||||
|
expect(status.mucusShift).to.be.an('object')
|
||||||
|
|
||||||
|
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')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
// #TODO
|
||||||
|
it('with highest quality after end of eval', () => {
|
||||||
|
const status = getSensiplanStatus({
|
||||||
|
cycle: highestMucusQualityAfterEndOfEval,
|
||||||
|
previousCycle: cycleWithFhm
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(status.temperatureShift).to.be.an('object')
|
||||||
|
expect(status.mucusShift).to.be.an('object')
|
||||||
|
|
||||||
|
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: highestMucusQualityAfterEndOfEval
|
||||||
|
.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: highestMucusQualityAfterEndOfEval
|
||||||
|
.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: highestMucusQualityAfterEndOfEval
|
||||||
|
.filter(({date}) => date >= '2018-06-26')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('something', () => {
|
||||||
|
|
||||||
|
it('shortens the pre-ovu phase if mucus occurs', () => {
|
||||||
|
const status = getSensiplanStatus({
|
||||||
|
cycle: cycleWithEarlyMucus,
|
||||||
|
previousCycle: fhmOnDay12,
|
||||||
|
earlierCycles: Array(10).fill(fhmOnDay12)
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
expect(Object.keys(status.phases).length).to.eql(2)
|
||||||
|
expect(status.phases.preOvulatory).to.eql({
|
||||||
|
start: { date: '2018-06-01' },
|
||||||
|
end: { date: '2018-06-01' },
|
||||||
|
cycleDays: cycleWithEarlyMucus
|
||||||
|
.filter(({date}) => date <= '2018-06-01')
|
||||||
|
})
|
||||||
|
expect(status.phases.periOvulatory).to.eql({
|
||||||
|
start: { date: '2018-06-02' },
|
||||||
|
cycleDays: cycleWithEarlyMucus
|
||||||
|
.filter(({date}) => {
|
||||||
|
return date > '2018-06-01'
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it('shortens the pre-ovu phase if mucus occurs even on the first day', () => {
|
||||||
|
const status = getSensiplanStatus({
|
||||||
|
cycle: cycleWithMucusOnFirstDay,
|
||||||
|
previousCycle: fhmOnDay12,
|
||||||
|
earlierCycles: Array(10).fill(fhmOnDay12)
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
expect(Object.keys(status.phases).length).to.eql(1)
|
||||||
|
|
||||||
|
expect(status.phases.periOvulatory).to.eql({
|
||||||
|
start: { date: '2018-06-01' },
|
||||||
|
cycleDays: cycleWithMucusOnFirstDay
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it('lengthens the pre-ovu phase if >= 12 cycles with fhm > 13', () => {
|
||||||
|
const status = getSensiplanStatus({
|
||||||
|
cycle: longAndComplicatedCycle,
|
||||||
|
previousCycle: fhmOnDay15,
|
||||||
|
earlierCycles: Array(11).fill(fhmOnDay15)
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
expect(Object.keys(status.phases).length).to.eql(3)
|
||||||
|
expect(status.phases.preOvulatory).to.eql({
|
||||||
|
start: { date: '2018-06-01' },
|
||||||
|
end: { date: '2018-06-07' },
|
||||||
|
cycleDays: longAndComplicatedCycle
|
||||||
|
.filter(({date}) => date <= '2018-06-07')
|
||||||
|
})
|
||||||
|
expect(status.phases.periOvulatory).to.eql({
|
||||||
|
start: { date: '2018-06-08' },
|
||||||
|
end: { date: '2018-06-21', time: '18:00' },
|
||||||
|
cycleDays: longAndComplicatedCycle
|
||||||
|
.filter(({date}) => {
|
||||||
|
return date > '2018-06-07' && date <= '2018-06-21'
|
||||||
|
})
|
||||||
|
})
|
||||||
|
expect(status.phases.postOvulatory).to.eql({
|
||||||
|
start: {
|
||||||
|
date: '2018-06-21',
|
||||||
|
time: '18:00'
|
||||||
|
},
|
||||||
|
cycleDays: longAndComplicatedCycle
|
||||||
|
.filter(({date}) => date >= '2018-06-21')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it('does not lengthen the pre-ovu phase if < 12 cycles', () => {
|
||||||
|
const status = getSensiplanStatus({
|
||||||
|
cycle: longAndComplicatedCycle,
|
||||||
|
previousCycle: fhmOnDay15,
|
||||||
|
earlierCycles: Array(10).fill(fhmOnDay15)
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
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: longAndComplicatedCycle
|
||||||
|
.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: longAndComplicatedCycle
|
||||||
|
.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: longAndComplicatedCycle
|
||||||
|
.filter(({date}) => date >= '2018-06-21')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it('does not detect any pre-ovu phase if prev cycle had no fhm', () => {
|
||||||
|
const status = getSensiplanStatus({
|
||||||
|
cycle: longAndComplicatedCycle,
|
||||||
|
previousCycle: cycleWithoutFhm,
|
||||||
|
earlierCycles: [...Array(12).fill(fhmOnDay15)]
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
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: longAndComplicatedCycle
|
||||||
|
.filter(({date}) => {
|
||||||
|
return date >= '2018-06-01' && date <= '2018-06-21'
|
||||||
|
})
|
||||||
|
})
|
||||||
|
expect(status.phases.postOvulatory).to.eql({
|
||||||
|
start: {
|
||||||
|
date: '2018-06-21',
|
||||||
|
time: '18:00'
|
||||||
|
},
|
||||||
|
cycleDays: longAndComplicatedCycle
|
||||||
|
.filter(({date}) => date >= '2018-06-21')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
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 }
|
||||||
|
}],
|
||||||
|
earlierCycles: [[{
|
||||||
|
date: '1992-09-09',
|
||||||
|
bleeding: { value: 0 }
|
||||||
|
}]]
|
||||||
|
})).to.throw(AssertionError)
|
||||||
|
expect(() => getSensiplanStatus({
|
||||||
|
cycle: [{
|
||||||
|
date: '2018-04-13',
|
||||||
|
temperature: {value: '35'},
|
||||||
|
bleeding: { value: 0 }
|
||||||
|
}],
|
||||||
|
earlierCycles: [[{
|
||||||
|
date: '1992-09-09',
|
||||||
|
bleeding: { value: 0 }
|
||||||
|
}]]
|
||||||
|
})).to.throw(AssertionError)
|
||||||
|
expect(() => getSensiplanStatus({
|
||||||
|
cycle: [{
|
||||||
|
date: '09-14-2017',
|
||||||
|
bleeding: { value: 0 }
|
||||||
|
}],
|
||||||
|
earlierCycles: [[{
|
||||||
|
date: '1992-09-09',
|
||||||
|
bleeding: { value: 0 }
|
||||||
|
}]]
|
||||||
|
})).to.throw(AssertionError)
|
||||||
|
})
|
||||||
|
it('throws if first cycle day does not have bleeding value', () => {
|
||||||
|
expect(() => getSensiplanStatus({
|
||||||
|
cycle: [{
|
||||||
|
date: '2017-01-01',
|
||||||
|
bleeding: {
|
||||||
|
value: 'medium'
|
||||||
|
}
|
||||||
|
}],
|
||||||
|
earlierCycles: [[
|
||||||
|
{
|
||||||
|
date: '2017-09-23',
|
||||||
|
}
|
||||||
|
]]
|
||||||
|
})).to.throw(AssertionError)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
Reference in New Issue
Block a user