diff --git a/components/mucus.js b/components/mucus.js index f2d643d855b51fd3bfe55cb0d3725a6e96b53816..4c75148f330085a82dc04918c8889f25c1c60a9f 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 0000000000000000000000000000000000000000..27e1590eb59f9799012f4a841973d90f0107d2a6 --- /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 0000000000000000000000000000000000000000..feb4e93df4b441dceaeed0a2e1505a7830bd183a --- /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) + }) + }) +})