From 7e0456c10fa3b7bfe6e07ed984d5dbec06aa4e6a Mon Sep 17 00:00:00 2001 From: emelko <ml.kochsiek@mailbox.org> Date: Wed, 4 Jul 2018 22:54:06 +0200 Subject: [PATCH] Adding unit tests to all possible mucus feeling/texture combinations --- components/mucus.js | 3 +- lib/sensiplan-mucus.js | 16 ++++++++ test/sensiplan-mucus.spec.js | 80 ++++++++++++++++++++++++++++++++++++ 3 files changed, 98 insertions(+), 1 deletion(-) create mode 100644 lib/sensiplan-mucus.js create mode 100644 test/sensiplan-mucus.spec.js diff --git a/components/mucus.js b/components/mucus.js index f2d643d8..4c75148f 100644 --- a/components/mucus.js +++ b/components/mucus.js @@ -12,6 +12,7 @@ import { mucusFeeling as feelingLabels, mucusTexture as textureLabels } from '../labels/labels' +import computeSensiplanValue from '../lib/sensiplan-mucus' export default class Mucus extends Component { constructor(props) { @@ -137,11 +138,11 @@ export default class Mucus extends Component { saveMucus(this.cycleDay, { feeling: this.state.currentFeelingValue, texture: this.state.currentTextureValue, + computedValue: computeSensiplanValue(this.state.currentFeelingValue, this.state.currentTextureValue), exclude: this.state.exclude }) this.showView('dayView') }} - // FIXME: find out how disabled works when 2 values need to be checked disabled={ this.state.currentFeelingValue === -1 || this.state.currentTextureValue === -1 } title="Save"> </Button> diff --git a/lib/sensiplan-mucus.js b/lib/sensiplan-mucus.js new file mode 100644 index 00000000..27e1590e --- /dev/null +++ b/lib/sensiplan-mucus.js @@ -0,0 +1,16 @@ +export default function (feeling, texture) { + const feelingMapping = { + 0: 0, + 1: 1, + 2: 2, + 3: 4 + } + const textureMapping = { + 0: 0, + 1: 3, + 2: 4 + } + const nfpFeelingValue = feelingMapping[feeling] + const nfpTextureValue = textureMapping[texture] + return Math.max(nfpFeelingValue, nfpTextureValue) +} diff --git a/test/sensiplan-mucus.spec.js b/test/sensiplan-mucus.spec.js new file mode 100644 index 00000000..feb4e93d --- /dev/null +++ b/test/sensiplan-mucus.spec.js @@ -0,0 +1,80 @@ +import chai from 'chai' +import dirtyChai from 'dirty-chai' + +const expect = chai.expect +chai.use(dirtyChai) + +import getSensiplanMucus from '../lib/sensiplan-mucus' + +describe.only('getSensiplanMucus', () => { + + describe('results in t for:', () => { + it('dry feeling and no texture', function () { + const sensiplanValue = getSensiplanMucus(0, 0) + expect(sensiplanValue).to.eql(0) + }) + }) + + describe('results in Ø for:', () => { + it('no feeling and no texture', function () { + const sensiplanValue = getSensiplanMucus(1, 0) + expect(sensiplanValue).to.eql(1) + }) + }) + + describe('results in f for:', () => { + it('wet feeling and no texture', function () { + const sensiplanValue = getSensiplanMucus(2, 0) + expect(sensiplanValue).to.eql(2) + }) + }) + + describe('results in S for:', () => { + it('dry feeling and creamy texture', function () { + const sensiplanValue = getSensiplanMucus(0, 1) + expect(sensiplanValue).to.eql(3) + }) + + it('no feeling and creamy texture', function () { + const sensiplanValue = getSensiplanMucus(1, 1) + expect(sensiplanValue).to.eql(3) + }) + + it('wet feeling and creamy texture', function () { + const sensiplanValue = getSensiplanMucus(2, 1) + expect(sensiplanValue).to.eql(3) + }) + }) + + describe('results in +S for:', () => { + it('dry feeling and egg white texture', function () { + const sensiplanValue = getSensiplanMucus(0, 2) + expect(sensiplanValue).to.eql(4) + }) + + it('no feeling and egg white texture', function () { + const sensiplanValue = getSensiplanMucus(1, 2) + expect(sensiplanValue).to.eql(4) + }) + + it('wet feeling and egg white texture', function () { + const sensiplanValue = getSensiplanMucus(2, 2) + expect(sensiplanValue).to.eql(4) + }) + + it('slippery feeling and egg white texture', function () { + const sensiplanValue = getSensiplanMucus(3, 2) + expect(sensiplanValue).to.eql(4) + }) + + it('slippery feeling and creamy texture', function () { + const sensiplanValue = getSensiplanMucus(3, 1) + expect(sensiplanValue).to.eql(4) + }) + + it('slippery feeling and no texture', function () { + const sensiplanValue = getSensiplanMucus(3, 0) + expect(sensiplanValue).to.eql(4) + }) + }) +}) -- GitLab