diff --git a/test/sympto/cervix-temp-fixtures.js b/test/sympto/cervix-temp-fixtures.js index d5b85a5f64c539c6cd40be5479629f0901bcd507..0c8ae85683cb722ebe817f7f2ab1c459032999aa 100644 --- a/test/sympto/cervix-temp-fixtures.js +++ b/test/sympto/cervix-temp-fixtures.js @@ -1,4 +1,3 @@ - function convertToSymptoFormat(val) { const sympto = { date: val.date } if (val.temperature) sympto.temperature = { @@ -37,11 +36,11 @@ export const idealCycle = [ ].map(convertToSymptoFormat) export const cycleWithFhmNoCervixShift = [ - { date: '2018-08-01', bleeding: 1, cervix: { opening: 1, firmness: 1 } }, - { date: '2018-08-02', bleeding: 2, cervix: { opening: 1, firmness: 1 } }, - { date: '2018-08-03', temperature: 36.6, bleeding: 2, cervix: { opening: 2, firmness: 1 } }, - { date: '2018-08-04', temperature: 36.55, bleeding: 1, cervix: { opening: 2, firmness: 0 } }, - { date: '2018-08-05', temperature: 36.6, cervix: { opening: 0, firmness: 1 } }, + { date: '2018-08-01', bleeding: 1 }, + { date: '2018-08-02', bleeding: 2 }, + { date: '2018-08-03', temperature: 36.6, bleeding: 2 }, + { date: '2018-08-04', temperature: 36.55, bleeding: 1 }, + { date: '2018-08-05', temperature: 36.6 }, { date: '2018-08-06', temperature: 36.65, cervix: { opening: 0, firmness: 1 } }, { date: '2018-08-07', temperature: 36.7, cervix: { opening: 1, firmness: 0 } }, { date: '2018-08-08', temperature: 36.6, cervix: { opening: 0, firmness: 1 } }, @@ -64,11 +63,11 @@ export const cycleWithoutFhmNoCervixShift = [ ].map(convertToSymptoFormat) export const cycleWithoutAnyShifts = [ - { date: '2018-07-01', temperature: 36.65, bleeding: -1, cervix: { opening: 1, firmness: 1 } }, - { date: '2018-07-02', temperature: 36.45, cervix: { opening: 1, firmness: 1 } }, - { date: '2018-07-03', temperature: 36.65, cervix: { opening: 2, firmness: 1 } }, - { date: '2018-07-04', temperature: 36.65, cervix: { opening: 2, firmness: 1 } }, - { date: '2018-07-05', temperature: 36.65, cervix: { opening: 1, firmness: 1 } }, + { date: '2018-07-01', temperature: 36.65, bleeding: 1 }, + { date: '2018-07-02', temperature: 36.45 }, + { date: '2018-07-03', temperature: 36.65 }, + { date: '2018-07-04', temperature: 36.65 }, + { date: '2018-07-05', temperature: 36.65, cervix: { opening: 0, firmness: 0 } }, { date: '2018-07-06', temperature: 36.85, cervix: { opening: 0, firmness: 1 } }, { date: '2018-07-07', temperature: 36.65, cervix: { opening: 1, firmness: 1 } }, { date: '2018-07-08', temperature: 36.65, cervix: { opening: 2, firmness: 1 } }, @@ -84,7 +83,7 @@ export const cycleWithoutAnyShifts = [ { date: '2018-07-18', temperature: 36.25, cervix: { opening: 2, firmness: 1 } }, { date: '2018-07-19', temperature: 36.65, cervix: { opening: 1, firmness: 1 } }, { date: '2018-07-20', temperature: 36.45, cervix: { opening: 1, firmness: 1 } }, - { date: '2018-07-21', temperature: 36.5, cervix: { opening: 0, firmness: 0 } }, + { date: '2018-07-21', temperature: 36.52, cervix: { opening: 0, firmness: 0 } }, { date: '2018-07-22', temperature: 36.65, cervix: { opening: 1, firmness: 1 } }, { date: '2018-07-23', temperature: 36.75, cervix: { opening: 1, firmness: 1 } }, { date: '2018-07-24', temperature: 36.65, cervix: { opening: 1, firmness: 1 } }, @@ -127,7 +126,7 @@ export const tempAndCervixEvalEndOnSameDay = [ { date: '2018-06-09', temperature: 36.5, cervix: { opening: 0, firmness: 0 } }, { date: '2018-06-10', temperature: 36.30, cervix: { opening: 0, firmness: 1 } }, { date: '2018-06-11', temperature: 36.30, cervix: { opening: 1, firmness: 0 } }, - { date: '2018-06-12', temperature: 36.4, cervix: { opening: 1, firmness: 1 } }, + { date: '2018-06-12', temperature: 36.4, cervix: { opening: 2, firmness: 1 } }, { date: '2018-06-13', temperature: 36.3, cervix: { opening: 1, firmness: 1 } }, { date: '2018-06-14', temperature: 36.4, cervix: { opening: 1, firmness: 1 } }, { date: '2018-06-15', temperature: 36.8, cervix: { opening: 0, firmness: 0 } }, @@ -143,18 +142,18 @@ export const tempAndCervixEvalEndOnSameDay = [ { date: '2018-06-25', cervix: { opening: 1, firmness: 1 } } ].map(convertToSymptoFormat) -export const cervixShiftWaitsForTempShift = [ +export const tempShift3DaysAfterCervixShift = [ { 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: { opening: 1, firmness: 1 } }, + { date: '2018-05-12', temperature: 36.3 }, { date: '2018-05-13', temperature: 36.4, cervix: { opening: 1, firmness: 1 } }, { date: '2018-05-14', temperature: 36.3, cervix: { opening: 1, firmness: 1 } }, { date: '2018-05-15', temperature: 36.2, cervix: { opening: 1, firmness: 1 } }, { date: '2018-05-16', temperature: 36.3, cervix: { opening: 0, firmness: 0 } }, { date: '2018-05-17', temperature: 36.3, cervix: { opening: 0, firmness: 0 } }, - { date: '2018-05-18', temperature: 36.55, cervix: { opening: 0, firmness: 0 } }, + { date: '2018-05-18', temperature: 36.35, cervix: { opening: 0, firmness: 0 } }, { date: '2018-05-19', temperature: 36.65, cervix: { opening: 0, firmness: 0 } }, { date: '2018-05-20', temperature: 36.7, cervix: { opening: 0, firmness: 0 } }, { date: '2018-05-21', temperature: 36.6, cervix: { opening: 0, firmness: 0 } }, @@ -168,12 +167,12 @@ export const cervixShiftWaitsForTempShift = [ { date: '2018-05-29', bleeding: 2 } ].map(convertToSymptoFormat) -export const tempShiftWaitsForCervixShift = [ +export const cervixShift2DaysAfterTempShift = [ { 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: { opening: 1, firmness: 1 } }, + { date: '2018-04-09', temperature: 36.5 }, { date: '2018-04-10', temperature: 36.5, cervix: { opening: 1, firmness: 1 } }, { date: '2018-04-11', temperature: 36.55, cervix: { opening: 1, firmness: 1 } }, { date: '2018-04-12', temperature: 36.5, cervix: { opening: 1, firmness: 1 } }, @@ -181,14 +180,13 @@ export const tempShiftWaitsForCervixShift = [ { date: '2018-04-14', temperature: 36.35, cervix: { opening: 1, firmness: 1 } }, { date: '2018-04-15', temperature: 36.6, cervix: { opening: 1, firmness: 1 } }, { date: '2018-04-16', temperature: 36.8, cervix: { opening: 1, firmness: 1 } }, - { date: '2018-04-17', cervix: { opening: 1, firmness: 1 } }, - { date: '2018-04-18', temperature: 36.8, cervix: { opening: 1, firmness: 0 } }, + { date: '2018-04-17', temperature: 36.8, cervix: { opening: 0, firmness: 0 } }, + { date: '2018-04-18', temperature: 36.8, cervix: { opening: 0, firmness: 0 } }, { date: '2018-04-19', temperature: 36.85, cervix: { opening: 0, firmness: 0 } }, { date: '2018-04-20', temperature: 37.0, cervix: { opening: 0, firmness: 0 } }, - { date: '2018-04-21', temperature: 36.9, cervix: { opening: 0, firmness: 0 } }, { date: '2018-04-22', temperature: 36.9, cervix: { opening: 0, firmness: 0 } }, { date: '2018-04-23', temperature: 37.1, cervix: { opening: 0, firmness: 0 } }, - { date: '2018-04-24', temperature: 36.75, cervix: { opening: 1, firmness: 1 } } + { date: '2018-04-24', temperature: 36.75, cervix: { opening: 0, firmness: 0 } } ].map(convertToSymptoFormat) export const noInfertilePhaseDetected = [ @@ -196,7 +194,7 @@ export const noInfertilePhaseDetected = [ { 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: { opening: 0, firmness: 1 } }, + { date: '2018-03-12', temperature: 36.3, cervix: { opening: 0, firmness: 0 } }, { date: '2018-03-13', temperature: 36.5, cervix: { opening: 1, firmness: 1 } }, { date: '2018-03-14', temperature: 36.45, cervix: { opening: 1, firmness: 1 } }, { date: '2018-03-15', temperature: 36.4, cervix: { opening: 1, firmness: 1 } }, @@ -212,6 +210,5 @@ export const noInfertilePhaseDetected = [ export const fiveDayCycle = [ { date: '2018-08-01', bleeding: 2 }, - { date: '2018-08-03', bleeding: 3 }, - { date: '2018-08-05', bleeding: 0 } + { date: '2018-08-03', bleeding: 3 } ].map(convertToSymptoFormat) diff --git a/test/sympto/cervix-temp.spec.js b/test/sympto/cervix-temp.spec.js index 17e20898abebcc57b71d48b9dd79ea89bc82c8de..6b06ddd080854ab94715819f6590a2a222dc093e 100644 --- a/test/sympto/cervix-temp.spec.js +++ b/test/sympto/cervix-temp.spec.js @@ -6,8 +6,8 @@ import { cycleWithoutFhm, cycleWithoutAnyShifts, tempAndCervixEvalEndOnSameDay, - cervixShiftWaitsForTempShift, - tempShiftWaitsForCervixShift, + tempShift3DaysAfterCervixShift, + cervixShift2DaysAfterTempShift, noInfertilePhaseDetected, fiveDayCycle } from './cervix-temp-fixtures' @@ -17,8 +17,7 @@ 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 () { + it('with no temp or cervix shifts detects only peri-ovulatory', () => { const status = getSensiplanStatus({ cycle: cycleWithoutAnyShifts, previousCycle: cycleWithoutFhm, @@ -34,8 +33,7 @@ describe('sympto', () => { } }) }) - - it('with temp but no cervix shift detects only peri-ovulatory', function () { + it('with temp but no cervix shift detects only peri-ovulatory', () => { const status = getSensiplanStatus({ cycle: cycleWithFhmNoCervixShift, previousCycle: cycleWithoutFhm, @@ -45,85 +43,79 @@ describe('sympto', () => { expect(status).to.eql({ phases: { periOvulatory: { - start: { date: '2018-06-01' }, + start: { date: '2018-08-01' }, cycleDays: cycleWithFhmNoCervixShift } } }) }) - - it('with temp and cervix shifts detects only peri- and post-ovulatory phases', function () { + it('with temp and cervix shifts detects only peri- and post-ovulatory phases', () => { 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.temperatureShift.evaluationCompleteDay.date).to.eql('2018-08-15') + expect(status.cervixShift.evaluationCompleteDay.date).to.eql('2018-08-15') + expect(status.temperatureShift.rule).to.eql(0) expect(status.phases.periOvulatory).to.eql({ start: { date: '2018-08-01' }, - end: { date: '2018-08-11', time: '18:00' }, + end: { date: '2018-08-15', time: '18:00' }, cycleDays: idealCycle - .filter(({date}) => date <= '2018-08-11') + .filter(({date}) => date <= '2018-08-15') }) expect(status.phases.postOvulatory).to.eql({ - start: { date: '2018-08-11', time: '18:00' }, + start: { date: '2018-08-15', time: '18:00' }, cycleDays: idealCycle - .filter(({date}) => date >= '2018-08-11') + .filter(({date}) => date >= '2018-08-15') }) }) - }) 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' } - }) + it('with no shifts detects only peri-ovulatory in 3-day long cycle according to 5-day rule', () => { + const status = getSensiplanStatus({ + cycle: fiveDayCycle, + previousCycle: idealCycle, + secondarySymptom: 'cervix' + }) + 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' } }) }) + it('with no shifts detects pre- and peri-ovulatory phase according to 5-day-rule', () => { + const status = getSensiplanStatus({ + cycle: cycleWithoutAnyShifts, + previousCycle: idealCycle, + secondarySymptom: 'cervix' + }) - 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' } - }) + 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-06'), + start: { date: '2018-07-06' } }) }) - it('with evaluation of temperature and cervix end on same day', () => { const status = getSensiplanStatus({ cycle: tempAndCervixEvalEndOnSameDay, - previousCycle: cycleWithFhmNoCervixShift, + previousCycle: idealCycle, secondarySymptom: 'cervix' }) expect(Object.keys(status.phases).length).to.eql(3) + expect(status.temperatureShift.evaluationCompleteDay.date).to.eql('2018-06-17') + expect(status.cervixShift.evaluationCompleteDay.date).to.eql('2018-06-17') + expect(status.phases.preOvulatory).to.eql({ start: { date: '2018-06-01' }, end: { date: '2018-06-05' }, @@ -142,58 +134,90 @@ describe('sympto', () => { start: { date: '2018-06-17', time: '18:00' }, cycleDays: tempAndCervixEvalEndOnSameDay .filter(({date}) => date >= '2018-06-17') - expect(status.cervixShift.cervixPeakBeforeShift.date).to.eql('2018-06-14') }) - expect(status.cervixShift.detected).to.be.true() - expect(status.cervixShift.evaluationCompleteDay.date).to.eql('2018-06-17') }) - - - it('when cervix shift waits for temperature shift', () => { + it('when temperature shift happens 3 days after cervix shift', () => { const status = getSensiplanStatus({ - cycle: cervixShiftWaitsForTempShift, - previousCycle: cycleWithFhmNoCervixShift, + cycle: tempShift3DaysAfterCervixShift, + previousCycle: idealCycle, secondarySymptom: 'cervix' }) expect(Object.keys(status.phases).length).to.eql(3) - expect(status.cervixShift.detected).to.be.true() - }) + expect(status.cervixShift).to.be.an('object') + expect(status.temperatureShift).to.be.an('object') + expect(status.cervixShift.evaluationCompleteDay.date).to.eql('2018-05-18') + expect(status.temperatureShift.evaluationCompleteDay.date).to.eql('2018-05-21') - it('when temperature shift waits for cervix shift', () => { + expect(status.phases.preOvulatory).to.eql({ + start: { date: '2018-05-08' }, + end: { date: '2018-05-12' }, + cycleDays: tempShift3DaysAfterCervixShift + .filter(({date}) => date <= '2018-05-12') + }) + expect(status.phases.periOvulatory).to.eql({ + start: { date:'2018-05-13'}, + end: { date: '2018-05-21', time: '18:00' }, + cycleDays: tempShift3DaysAfterCervixShift + .filter(({date}) => { + return date >= '2018-05-13' && date <= '2018-05-21' + }) + }) + expect(status.phases.postOvulatory).to.eql({ + start: { date: '2018-05-21', time: '18:00' }, + cycleDays: tempShift3DaysAfterCervixShift + .filter(({date}) => date >= '2018-05-21') + }) + }) + it('when cervix shift happens 2 days after temperature shift', () => { const status = getSensiplanStatus({ - cycle: tempShiftWaitsForCervixShift, - previousCycle: cycleWithFhmNoCervixShift, + cycle: cervixShift2DaysAfterTempShift, + previousCycle: idealCycle, secondarySymptom: 'cervix' }) expect(Object.keys(status.phases).length).to.eql(3) - expect(status.cervixShift.detected).to.be.true() - }) + expect(status.temperatureShift.rule).to.eql(0) + expect(status.temperatureShift.evaluationCompleteDay.date).to.eql('2018-04-17') + expect(status.cervixShift.evaluationCompleteDay.date).to.eql('2018-04-19') + expect(status.phases.preOvulatory).to.eql({ + cycleDays: cervixShift2DaysAfterTempShift + .filter(({date}) => date <= '2018-04-09'), + start: { date: '2018-04-05' }, + end: { date: '2018-04-09' } + }) + expect(status.phases.periOvulatory).to.eql({ + cycleDays: cervixShift2DaysAfterTempShift + .filter(({date}) => { + return date >= '2018-04-10' && date <= '2018-04-19' + }), + start: { date: '2018-04-10' }, + end: { date: '2018-04-19', time: '18:00' } + }) + expect(status.phases.postOvulatory).to.eql({ + cycleDays: cervixShift2DaysAfterTempShift + .filter(({date}) => date >= '2018-04-19'), + start: { date: '2018-04-19', time: '18:00' } + }) + }) it('when no infertile phase can be detected', () => { const status = getSensiplanStatus({ cycle: noInfertilePhaseDetected, - previousCycle: cycleWithFhmNoCervixShift, + previousCycle: idealCycle, 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: { - - } + expect(status.phases.preOvulatory).to.eql({ + cycleDays: noInfertilePhaseDetected + .filter(({date}) => date <= '2018-03-12'), + start: { date: '2018-03-08' }, + end: { date: '2018-03-12' } + }) + expect(status.phases.periOvulatory).to.eql({ + cycleDays: noInfertilePhaseDetected + .filter(({date}) => date > '2018-03-12'), + start: { date: '2018-03-13' } + }) }) }) - }) })