From 64a4c8c455373e92bea2b147d421e554bb77986d Mon Sep 17 00:00:00 2001 From: Sofiya Tepikin <sofiya.tepikin@gmail.com> Date: Sat, 14 Mar 2020 11:40:04 +0000 Subject: [PATCH] Moves out the test for getPReviousCycle method of cycle module --- test/cycle.spec.js | 233 +------------------------------- test/get-previous-cycle.spec.js | 72 ++++++++++ 2 files changed, 73 insertions(+), 232 deletions(-) create mode 100644 test/get-previous-cycle.spec.js diff --git a/test/cycle.spec.js b/test/cycle.spec.js index 0ad8d3c3..a4486479 100644 --- a/test/cycle.spec.js +++ b/test/cycle.spec.js @@ -5,237 +5,6 @@ import cycleModule from '../lib/cycle' const expect = chai.expect chai.use(dirtyChai) -describe('getPreviousCycle', () => { - it('gets previous cycle', () => { - const cycleDaysSortedByDate = [ - { - date: '2018-07-05', - bleeding: { value: 2 } - }, - { - date: '2018-06-05', - bleeding: { value: 2 } - }, - { - date: '2018-05-05', - mucus: { value: 2 } - }, - { - date: '2018-05-04', - bleeding: { value: 2 } - }, - { - date: '2018-05-03', - bleeding: { value: 2 } - }, - { - date: '2018-04-05', - mucus: { value: 2 } - }, - { - date: '2018-04-04', - mucus: { value: 2 } - }, - { - date: '2018-04-03', - mucus: { value: 2 } - }, - { - date: '2018-04-02', - bleeding: { value: 2 } - }, - ] - - const cycleStarts = [ - '2018-07-05', - '2018-06-05', - '2018-05-03', - '2018-04-02' - ] - - const { getPreviousCycle } = cycleModule({ - cycleDaysSortedByDate, - cycleStartsSortedByDate: cycleDaysSortedByDate.filter(d => { - return cycleStarts.includes(d.date) - }) - }) - const result = getPreviousCycle('2018-06-08') - expect(result).to.eql([ - { - date: '2018-05-05', - mucus: { value: 2 } - }, - { - date: '2018-05-04', - bleeding: { value: 2 } - }, - { - date: '2018-05-03', - bleeding: { value: 2 } - } - ]) - }) - - it('returns null when target day is not in a cyle', () => { - const cycleDaysSortedByDate = [ - { - date: '2018-07-05', - }, - { - date: '2018-06-05', - }, - { - date: '2018-05-05', - }, - { - date: '2018-05-04', - }, - { - date: '2018-05-03', - }, - { - date: '2018-04-05', - }, - { - date: '2018-04-04', - mucus: { value: 2 } - }, - { - date: '2018-04-03', - }, - { - date: '2018-04-02', - }, - ] - - const cycleStarts = [] - - const { getPreviousCycle } = cycleModule({ - cycleDaysSortedByDate, - cycleStartsSortedByDate: cycleDaysSortedByDate.filter(d => { - return cycleStarts.includes(d.date) - }) - }) - const result = getPreviousCycle('2018-06-08') - expect(result).to.eql(null) - }) - - it('returns null when there is no previous cycle', () => { - const cycleDaysSortedByDate = [ - { - date: '2018-07-05', - bleeding: { value: 2 } - }, - { - date: '2018-06-05', - bleeding: { value: 2 } - }, - { - date: '2018-05-05', - mucus: { value: 2 } - }, - { - date: '2018-05-04', - bleeding: { value: 2 } - }, - { - date: '2018-05-03', - bleeding: { value: 2 } - }, - { - date: '2018-04-05', - mucus: { value: 2 } - }, - { - date: '2018-04-04', - mucus: { value: 2 } - }, - { - date: '2018-04-03', - mucus: { value: 2 } - }, - { - date: '2018-04-02', - bleeding: { value: 2 } - }, - ] - - const cycleStarts = [ - '2018-07-05', - '2018-06-05', - '2018-05-03', - '2018-04-02' - ] - - const { getPreviousCycle } = cycleModule({ - cycleDaysSortedByDate, - cycleStartsSortedByDate: cycleDaysSortedByDate.filter(d => { - return cycleStarts.includes(d.date) - }) - }) - const result = getPreviousCycle('2018-04-18') - expect(result).to.eql(null) - }) - - it('returns null when the previous cycle > maxcyclelength', () => { - const cycleDaysSortedByDate = [ - { - date: '2018-07-05', - bleeding: { value: 2 } - }, - { - date: '2018-06-05', - bleeding: { value: 2 } - }, - { - date: '2018-05-05', - mucus: { value: 2 } - }, - { - date: '2018-05-04', - bleeding: { value: 2 } - }, - { - date: '2018-05-03', - bleeding: { value: 2 } - }, - { - date: '2018-04-05', - mucus: { value: 2 } - }, - { - date: '2018-04-04', - mucus: { value: 2 } - }, - { - date: '2018-04-03', - mucus: { value: 2 } - }, - { - date: '2018-04-02', - bleeding: { value: 2 } - }, - ] - - const cycleStarts = [ - '2018-07-05', - '2018-06-05', - '2018-05-03', - '2018-04-02' - ] - - const { getPreviousCycle } = cycleModule({ - cycleDaysSortedByDate, - cycleStartsSortedByDate: cycleDaysSortedByDate.filter(d => { - return cycleStarts.includes(d.date) - }), - maxCycleLength: 2 - }) - const result = getPreviousCycle('2018-06-08') - expect(result).to.eql(null) - }) -}) - describe('getCyclesBefore', () => { it('gets previous cycles', () => { const cycleDaysSortedByDate = [ @@ -1322,4 +1091,4 @@ describe('getMensesDaysRightAfter', () => { expect(result).to.eql([]) }) }) -}) \ No newline at end of file +}) diff --git a/test/get-previous-cycle.spec.js b/test/get-previous-cycle.spec.js new file mode 100644 index 00000000..d67546fa --- /dev/null +++ b/test/get-previous-cycle.spec.js @@ -0,0 +1,72 @@ +import chai from 'chai' +import dirtyChai from 'dirty-chai' +import cycleModule from '../lib/cycle' + +const { expect } = chai +chai.use(dirtyChai) + +const mayCycle = [ + { date: '2018-05-05' }, + { date: '2018-05-04' }, + { date: '2018-05-03' }, +] + +const cycleDaysSortedByDate = [ + { date: '2018-07-05' }, + { date: '2018-06-05' }, + ...mayCycle, + { date: '2018-04-05' }, + { date: '2018-04-04' }, + { date: '2018-04-03' }, + { date: '2018-04-02' }, +] + +const cycleStartsSortedByDate = [ + { date: '2018-07-05' }, + { date: '2018-06-05' }, + { date: '2018-05-03' }, + { date: '2018-04-02' }, +] + +describe('getPreviousCycle', () => { + it('gets previous cycle', () => { + + const { getPreviousCycle } = cycleModule({ + cycleDaysSortedByDate, + cycleStartsSortedByDate, + }) + + expect(getPreviousCycle('2018-06-08')).to.eql(mayCycle) + }) + + it('returns null when target day is not in a cyle', () => { + + const { getPreviousCycle } = cycleModule({ + cycleDaysSortedByDate, + cycleStartsSortedByDate: [], + }) + + expect(getPreviousCycle('2018-06-08')).to.eql(null) + }) + + it('returns null when there is no previous cycle', () => { + + const { getPreviousCycle } = cycleModule({ + cycleDaysSortedByDate, + cycleStartsSortedByDate, + }) + + expect(getPreviousCycle('2018-04-18')).to.eql(null) + }) + + it('returns null when the previous cycle > maxcyclelength', () => { + + const { getPreviousCycle } = cycleModule({ + cycleDaysSortedByDate, + cycleStartsSortedByDate, + maxCycleLength: 2, + }) + + expect(getPreviousCycle('2018-06-08')).to.eql(null) + }) +}) -- GitLab