Fixing cervix unit tests

This commit is contained in:
emelko
2018-09-08 14:47:31 +02:00
parent ab2dd76bf4
commit 1b0d04dfc0
+16 -38
View File
@@ -5,53 +5,45 @@ const expect = chai.expect
function turnIntoCycleDayObject(value, fakeDate) { function turnIntoCycleDayObject(value, fakeDate) {
const hardAndClosed = { const hardAndClosed = {
isHard: true, value: { opening: 0, firmness: 0 }
isClosed: true
} }
const hardAndOpen = { const hardAndOpen = {
isHard: true, value: { opening: 1, firmness: 0 }
isClosed: false
} }
const softAndClosed = { const softAndClosed = {
isHard: false, value: { opening: 0, firmness: 1 }
isClosed: true
} }
const softAndOpen = { const softAndOpen = {
isHard: false, value: { opening: 1, firmness: 1 }
isClosed: false
} }
const cervixStates = [hardAndClosed, hardAndOpen, softAndClosed, softAndOpen] const cervixStates = [hardAndClosed, hardAndOpen, softAndClosed, softAndOpen]
return { return {
date: fakeDate,
cervix: cervixStates[value], cervix: cervixStates[value],
date: fakeDate exclude: false
} }
} }
describe('sympto', () => { describe('sympto', () => {
describe('detects cervix shift', () => { describe('detects cervix shift', () => {
it('when an ideal cycle happens', function () { it('when shift happens at day 15 with consistent following days', function () {
const values = [0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 3, 1, 3, 1, 0, 0, 0, 0] const values = [0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 3, 1, 3, 1, 0, 0, 0, 0]
.map(turnIntoCycleDayObject) .map(turnIntoCycleDayObject)
const status = getCervixStatus(values) const status = getCervixStatus(values)
expect(status).to.eql({ expect(status).to.eql({
detected: true, detected: true,
cervixPeakBeforeShift: { cervixPeakBeforeShift: {
date: 13, date: 13,
cervix: { cervix: {value: { opening: 1, firmness: 0 }},
isHard: true, exclude: false
isClosed: false
}
}, },
evaluationCompleteDay: { evaluationCompleteDay: {
date: 16, date: 16,
cervix: { cervix: { value: { opening: 0, firmness: 0 }},
isHard: true, exclude: false
isClosed: true
}
} }
}) })
}) })
it('at the very first day of cycle days even if later shift happens again', function () { 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] const values = [2, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
.map(turnIntoCycleDayObject) .map(turnIntoCycleDayObject)
@@ -60,17 +52,13 @@ describe('sympto', () => {
detected: true, detected: true,
cervixPeakBeforeShift: { cervixPeakBeforeShift: {
date: 0, date: 0,
cervix: { cervix: { value: { opening: 0, firmness: 1 } },
isHard: false, exclude: false
isClosed: true
}
}, },
evaluationCompleteDay: { evaluationCompleteDay: {
date: 3, date: 3,
cervix: { cervix: { value: { opening: 0, firmness: 0 } },
isHard: true, exclude: false
isClosed: true
}
} }
}) })
}) })
@@ -83,32 +71,22 @@ describe('sympto', () => {
const status = getCervixStatus(values) const status = getCervixStatus(values)
expect(status).to.eql({ detected: false }) expect(status).to.eql({ detected: false })
}) })
it('if there are no cervix values', function () { it('if there are no cervix values', function () {
const values = [].map(turnIntoCycleDayObject) const values = [].map(turnIntoCycleDayObject)
const status = getCervixStatus(values) const status = getCervixStatus(values)
expect(status).to.eql({ detected: false }) expect(status).to.eql({ detected: false })
}) })
it('when the cervix values are all the same', function () { 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] const values = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
.map(turnIntoCycleDayObject) .map(turnIntoCycleDayObject)
const status = getCervixStatus(values) const status = getCervixStatus(values)
expect(status).to.eql({ detected: false }) expect(status).to.eql({ detected: false })
}) })
it('if no days of hard and closed cervix are tracked', function () { 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] const values = [1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1]
.map(turnIntoCycleDayObject) .map(turnIntoCycleDayObject)
const status = getCervixStatus(values) const status = getCervixStatus(values)
expect(status).to.eql({ detected: false }) 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 })
})
}) })
}) })