Chore/jest
This commit is contained in:
+1
-1
@@ -3,7 +3,7 @@ module.exports = {
|
|||||||
extends: ['eslint:recommended', 'plugin:react/recommended'],
|
extends: ['eslint:recommended', 'plugin:react/recommended'],
|
||||||
env: {
|
env: {
|
||||||
node: true,
|
node: true,
|
||||||
mocha: true,
|
jest: true,
|
||||||
es6: true,
|
es6: true,
|
||||||
},
|
},
|
||||||
parser: '@babel/eslint-parser',
|
parser: '@babel/eslint-parser',
|
||||||
|
|||||||
Generated
+6738
-662
File diff suppressed because it is too large
Load Diff
+3
-6
@@ -14,8 +14,8 @@
|
|||||||
"android": "react-native run-android",
|
"android": "react-native run-android",
|
||||||
"ios": "react-native run-ios --simulator=\"iPhone 8 Plus\"",
|
"ios": "react-native run-ios --simulator=\"iPhone 8 Plus\"",
|
||||||
"log": "react-native log-android",
|
"log": "react-native log-android",
|
||||||
"test": "mocha --recursive --require @babel/register test && npm run lint",
|
"test": "jest test && npm run lint",
|
||||||
"test-watch": "mocha --recursive --require @babel/register --watch test",
|
"test-watch": "jest --watch test",
|
||||||
"lint": "eslint components lib test styles slices db",
|
"lint": "eslint components lib test styles slices db",
|
||||||
"devtool": "adb shell input keyevent 82",
|
"devtool": "adb shell input keyevent 82",
|
||||||
"build-android-release": "cd android && ./gradlew clean && ./gradlew assembleRelease && cd ..",
|
"build-android-release": "cd android && ./gradlew clean && ./gradlew assembleRelease && cd ..",
|
||||||
@@ -66,21 +66,18 @@
|
|||||||
"@babel/core": "^7.6.2",
|
"@babel/core": "^7.6.2",
|
||||||
"@babel/eslint-parser": "^7.16.3",
|
"@babel/eslint-parser": "^7.16.3",
|
||||||
"@babel/preset-react": "^7.16.0",
|
"@babel/preset-react": "^7.16.0",
|
||||||
"@babel/register": "^7.0.0",
|
|
||||||
"@babel/runtime": "^7.6.2",
|
"@babel/runtime": "^7.6.2",
|
||||||
"basic-changelog": "gitlab:bloodyhealth/basic-changelog",
|
"basic-changelog": "gitlab:bloodyhealth/basic-changelog",
|
||||||
"chai": "^4.1.2",
|
|
||||||
"eslint": "^6.5.1",
|
"eslint": "^6.5.1",
|
||||||
"eslint-plugin-react": "^7.8.2",
|
"eslint-plugin-react": "^7.8.2",
|
||||||
"husky": "^8.0.0",
|
"husky": "^8.0.0",
|
||||||
|
"jest": "^28.1.3",
|
||||||
"jetifier": "^1.6.6",
|
"jetifier": "^1.6.6",
|
||||||
"left-pad": "^1.3.0",
|
"left-pad": "^1.3.0",
|
||||||
"metro-react-native-babel-preset": "^0.58.0",
|
"metro-react-native-babel-preset": "^0.58.0",
|
||||||
"mocha": "^5.2.0",
|
|
||||||
"prettier": "2.4.0",
|
"prettier": "2.4.0",
|
||||||
"pretty-quick": "^3.1.1",
|
"pretty-quick": "^3.1.1",
|
||||||
"react-native-version": "^3.1.0",
|
"react-native-version": "^3.1.0",
|
||||||
"react-test-renderer": "16.11.0",
|
|
||||||
"readline": "^1.3.0"
|
"readline": "^1.3.0"
|
||||||
},
|
},
|
||||||
"description": "A menstrual cycle tracking app that's open-source and leaves your data on your phone. Use it to track your menstrual cycle or for fertility awareness!",
|
"description": "A menstrual cycle tracking app that's open-source and leaves your data on your phone. Use it to track your menstrual cycle or for fertility awareness!",
|
||||||
|
|||||||
+46
-42
@@ -1,11 +1,7 @@
|
|||||||
import chai from 'chai'
|
|
||||||
|
|
||||||
import { getCycleLengthStats as cycleInfo } from '../lib/cycle-length'
|
import { getCycleLengthStats as cycleInfo } from '../lib/cycle-length'
|
||||||
|
|
||||||
const expect = chai.expect
|
|
||||||
|
|
||||||
describe('getCycleLengthStats', () => {
|
describe('getCycleLengthStats', () => {
|
||||||
it('works for a simple odd-numbered array', () => {
|
test('works for a simple odd-numbered array', () => {
|
||||||
const cycleLengths = [99, 5, 1, 2, 100]
|
const cycleLengths = [99, 5, 1, 2, 100]
|
||||||
const result = cycleInfo(cycleLengths)
|
const result = cycleInfo(cycleLengths)
|
||||||
const expectedResult = {
|
const expectedResult = {
|
||||||
@@ -15,9 +11,10 @@ describe('getCycleLengthStats', () => {
|
|||||||
median: 5,
|
median: 5,
|
||||||
stdDeviation: 53.06,
|
stdDeviation: 53.06,
|
||||||
}
|
}
|
||||||
expect(result).to.eql(expectedResult)
|
expect(result).toEqual(expectedResult)
|
||||||
}),
|
})
|
||||||
it('works for a simple even-numbered array', () => {
|
|
||||||
|
test('works for a simple even-numbered array', () => {
|
||||||
const cycleLengths = [4, 1, 15, 2, 20, 5]
|
const cycleLengths = [4, 1, 15, 2, 20, 5]
|
||||||
const result = cycleInfo(cycleLengths)
|
const result = cycleInfo(cycleLengths)
|
||||||
const expectedResult = {
|
const expectedResult = {
|
||||||
@@ -27,9 +24,10 @@ describe('getCycleLengthStats', () => {
|
|||||||
median: 4.5,
|
median: 4.5,
|
||||||
stdDeviation: 7.78,
|
stdDeviation: 7.78,
|
||||||
}
|
}
|
||||||
expect(result).to.eql(expectedResult)
|
expect(result).toEqual(expectedResult)
|
||||||
}),
|
})
|
||||||
it('works for an one-element array', () => {
|
|
||||||
|
test('works for an one-element array', () => {
|
||||||
const cycleLengths = [42]
|
const cycleLengths = [42]
|
||||||
const result = cycleInfo(cycleLengths)
|
const result = cycleInfo(cycleLengths)
|
||||||
const expectedResult = {
|
const expectedResult = {
|
||||||
@@ -39,10 +37,12 @@ describe('getCycleLengthStats', () => {
|
|||||||
median: 42,
|
median: 42,
|
||||||
stdDeviation: null,
|
stdDeviation: null,
|
||||||
}
|
}
|
||||||
expect(result).to.eql(expectedResult)
|
expect(result).toEqual(expectedResult)
|
||||||
}),
|
})
|
||||||
describe('works for more realistic examples', () => {
|
})
|
||||||
it('1 day difference between shortest and longest period', () => {
|
|
||||||
|
describe('works for more realistic examples', () => {
|
||||||
|
test('1 day difference between shortest and longest period', () => {
|
||||||
const cycleLengths = [28, 29, 28, 28, 28, 29, 28, 28, 28, 29, 29, 28]
|
const cycleLengths = [28, 29, 28, 28, 28, 29, 28, 28, 28, 29, 29, 28]
|
||||||
const result = cycleInfo(cycleLengths)
|
const result = cycleInfo(cycleLengths)
|
||||||
const expectedResult = {
|
const expectedResult = {
|
||||||
@@ -52,9 +52,10 @@ describe('getCycleLengthStats', () => {
|
|||||||
median: 28,
|
median: 28,
|
||||||
stdDeviation: 0.49,
|
stdDeviation: 0.49,
|
||||||
}
|
}
|
||||||
expect(result).to.eql(expectedResult)
|
expect(result).toEqual(expectedResult)
|
||||||
}),
|
})
|
||||||
it('3 days difference between shortest and longest period', () => {
|
|
||||||
|
test('3 days difference between shortest and longest period', () => {
|
||||||
const cycleLengths = [28, 29, 28, 28, 27, 30, 28, 27, 28, 28, 29, 27]
|
const cycleLengths = [28, 29, 28, 28, 27, 30, 28, 27, 28, 28, 29, 27]
|
||||||
const result = cycleInfo(cycleLengths)
|
const result = cycleInfo(cycleLengths)
|
||||||
const expectedResult = {
|
const expectedResult = {
|
||||||
@@ -64,9 +65,10 @@ describe('getCycleLengthStats', () => {
|
|||||||
median: 28,
|
median: 28,
|
||||||
stdDeviation: 0.9,
|
stdDeviation: 0.9,
|
||||||
}
|
}
|
||||||
expect(result).to.eql(expectedResult)
|
expect(result).toEqual(expectedResult)
|
||||||
}),
|
})
|
||||||
it('8 days difference between shortest and longest period', () => {
|
|
||||||
|
test('8 days difference between shortest and longest period', () => {
|
||||||
const cycleLengths = [28, 32, 29, 27, 28, 26, 33, 28, 29, 34, 27, 29]
|
const cycleLengths = [28, 32, 29, 27, 28, 26, 33, 28, 29, 34, 27, 29]
|
||||||
const result = cycleInfo(cycleLengths)
|
const result = cycleInfo(cycleLengths)
|
||||||
const expectedResult = {
|
const expectedResult = {
|
||||||
@@ -76,26 +78,28 @@ describe('getCycleLengthStats', () => {
|
|||||||
median: 28.5,
|
median: 28.5,
|
||||||
stdDeviation: 2.52,
|
stdDeviation: 2.52,
|
||||||
}
|
}
|
||||||
expect(result).to.eql(expectedResult)
|
expect(result).toEqual(expectedResult)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('when args are wrong', () => {
|
describe('when args are wrong', () => {
|
||||||
it('throws when arg object is an empty array', () => {
|
test('throws when arg object is an empty array', () => {
|
||||||
const cycleLengths = []
|
const cycleLengths = []
|
||||||
expect(() => cycleInfo(cycleLengths)).to.throw(Error)
|
expect(() => cycleInfo(cycleLengths)).toThrow(Error)
|
||||||
}),
|
})
|
||||||
it('throws when arg object is not in right format', () => {
|
|
||||||
const wrongObject = { hello: 'world' }
|
test('throws when arg object is not in right format', () => {
|
||||||
expect(() => cycleInfo(wrongObject)).to.throw(Error)
|
const wrongObject = { hello: 'world' }
|
||||||
}),
|
expect(() => cycleInfo(wrongObject)).toThrow(Error)
|
||||||
it('throws when arg array contains a string', () => {
|
})
|
||||||
const wrongElement = [4, 1, 15, '2', 20, 5]
|
|
||||||
expect(() => cycleInfo(wrongElement)).to.throw(Error)
|
test('throws when arg array contains a string', () => {
|
||||||
}),
|
const wrongElement = [4, 1, 15, '2', 20, 5]
|
||||||
it('throws when arg array contains a NaN', () => {
|
expect(() => cycleInfo(wrongElement)).toThrow(Error)
|
||||||
const wrongElement = [4, 1, 15, NaN, 20, 5]
|
})
|
||||||
expect(() => cycleInfo(wrongElement)).to.throw(Error)
|
|
||||||
})
|
test('throws when arg array contains a NaN', () => {
|
||||||
|
const wrongElement = [4, 1, 15, NaN, 20, 5]
|
||||||
|
expect(() => cycleInfo(wrongElement)).toThrow(Error)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import { expect } from 'chai'
|
|
||||||
import cycleModule from '../lib/cycle'
|
import cycleModule from '../lib/cycle'
|
||||||
|
|
||||||
const cycleStartDay = { date: '2018-05-03' }
|
const cycleStartDay = { date: '2018-05-03' }
|
||||||
@@ -23,12 +22,12 @@ const cycleStartsSortedByDate = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
describe('getCycleByStartDay', () => {
|
describe('getCycleByStartDay', () => {
|
||||||
it('gets cycle by cycle start day', () => {
|
test('gets cycle by cycle start day', () => {
|
||||||
const { getCycleByStartDay } = cycleModule({
|
const { getCycleByStartDay } = cycleModule({
|
||||||
cycleDaysSortedByDate,
|
cycleDaysSortedByDate,
|
||||||
cycleStartsSortedByDate,
|
cycleStartsSortedByDate,
|
||||||
})
|
})
|
||||||
|
|
||||||
expect(getCycleByStartDay(cycleStartDay)).to.eql(cycle)
|
expect(getCycleByStartDay(cycleStartDay)).toEqual(cycle)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,18 +1,17 @@
|
|||||||
import { expect } from 'chai'
|
|
||||||
import cycleModule from '../lib/cycle'
|
import cycleModule from '../lib/cycle'
|
||||||
|
|
||||||
const simpleCycleStarts = [{ date: '2018-05-09' }, { date: '2018-05-03' }]
|
const simpleCycleStarts = [{ date: '2018-05-09' }, { date: '2018-05-03' }]
|
||||||
|
|
||||||
describe('getCycleDayNumber', () => {
|
describe('getCycleDayNumber', () => {
|
||||||
it('works for a date in the current cycle', () => {
|
test('works for a date in the current cycle', () => {
|
||||||
const cycleStartsSortedByDate = simpleCycleStarts
|
const cycleStartsSortedByDate = simpleCycleStarts
|
||||||
const date = '2018-05-17'
|
const date = '2018-05-17'
|
||||||
const { getCycleDayNumber } = cycleModule({ cycleStartsSortedByDate })
|
const { getCycleDayNumber } = cycleModule({ cycleStartsSortedByDate })
|
||||||
|
|
||||||
expect(getCycleDayNumber(date)).to.eql(9)
|
expect(getCycleDayNumber(date)).toEqual(9)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('works for a date which is not in the current cycle', () => {
|
test('works for a date which is not in the current cycle', () => {
|
||||||
const cycleStartsSortedByDate = [
|
const cycleStartsSortedByDate = [
|
||||||
{ date: '2018-05-13' },
|
{ date: '2018-05-13' },
|
||||||
{ date: '2018-04-10' },
|
{ date: '2018-04-10' },
|
||||||
@@ -20,31 +19,31 @@ describe('getCycleDayNumber', () => {
|
|||||||
const date = '2018-04-27'
|
const date = '2018-04-27'
|
||||||
const { getCycleDayNumber } = cycleModule({ cycleStartsSortedByDate })
|
const { getCycleDayNumber } = cycleModule({ cycleStartsSortedByDate })
|
||||||
|
|
||||||
expect(getCycleDayNumber(date)).to.eql(18)
|
expect(getCycleDayNumber(date)).toEqual(18)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('works for a date which is the first and only day in cycle', () => {
|
test('works for a date which is the first and only day in cycle', () => {
|
||||||
const cycleStartsSortedByDate = [{ date: '2018-05-13' }]
|
const cycleStartsSortedByDate = [{ date: '2018-05-13' }]
|
||||||
const date = '2018-05-13'
|
const date = '2018-05-13'
|
||||||
const { getCycleDayNumber } = cycleModule({ cycleStartsSortedByDate })
|
const { getCycleDayNumber } = cycleModule({ cycleStartsSortedByDate })
|
||||||
|
|
||||||
expect(getCycleDayNumber(date)).to.eql(1)
|
expect(getCycleDayNumber(date)).toEqual(1)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('returns null if there are no cycle starts', function () {
|
test('returns null if there are no cycle starts', function () {
|
||||||
const cycleStartsSortedByDate = []
|
const cycleStartsSortedByDate = []
|
||||||
const date = '2018-05-17'
|
const date = '2018-05-17'
|
||||||
const { getCycleDayNumber } = cycleModule({ cycleStartsSortedByDate })
|
const { getCycleDayNumber } = cycleModule({ cycleStartsSortedByDate })
|
||||||
|
|
||||||
expect(getCycleDayNumber(date)).to.be.null
|
expect(getCycleDayNumber(date)).toBeNull()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('returns null if the cycle is longer than the max', function () {
|
test('returns null if the cycle is longer than the max', function () {
|
||||||
const cycleStartsSortedByDate = simpleCycleStarts
|
const cycleStartsSortedByDate = simpleCycleStarts
|
||||||
// we use the default 99 days max length
|
// we use the default 99 days max length
|
||||||
const date = '2018-08-16'
|
const date = '2018-08-16'
|
||||||
const { getCycleDayNumber } = cycleModule({ cycleStartsSortedByDate })
|
const { getCycleDayNumber } = cycleModule({ cycleStartsSortedByDate })
|
||||||
|
|
||||||
expect(getCycleDayNumber(date)).to.be.null
|
expect(getCycleDayNumber(date)).toBeNull()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import { expect } from 'chai'
|
|
||||||
import cycleModule from '../lib/cycle'
|
import cycleModule from '../lib/cycle'
|
||||||
|
|
||||||
describe('getCycleForDay', () => {
|
describe('getCycleForDay', () => {
|
||||||
@@ -49,18 +48,18 @@ describe('getCycleForDay', () => {
|
|||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
|
|
||||||
it('gets cycle that has only one day', () => {
|
test('gets cycle that has only one day', () => {
|
||||||
const result = getCycleForDay('2018-07-05', '2018-08-01')
|
const result = getCycleForDay('2018-07-05', '2018-08-01')
|
||||||
expect(result.length).to.eql(1)
|
expect(result.length).toEqual(1)
|
||||||
expect(result).to.eql([
|
expect(result).toEqual([
|
||||||
{
|
{
|
||||||
date: '2018-07-05',
|
date: '2018-07-05',
|
||||||
bleeding: { value: 2 },
|
bleeding: { value: 2 },
|
||||||
},
|
},
|
||||||
])
|
])
|
||||||
const result2 = getCycleForDay('2018-06-05')
|
const result2 = getCycleForDay('2018-06-05')
|
||||||
expect(result2.length).to.eql(1)
|
expect(result2.length).toEqual(1)
|
||||||
expect(result2).to.eql([
|
expect(result2).toEqual([
|
||||||
{
|
{
|
||||||
date: '2018-06-05',
|
date: '2018-06-05',
|
||||||
bleeding: { value: 2 },
|
bleeding: { value: 2 },
|
||||||
@@ -68,10 +67,10 @@ describe('getCycleForDay', () => {
|
|||||||
])
|
])
|
||||||
})
|
})
|
||||||
|
|
||||||
it('for later date gets cycle that has only one day', () => {
|
test('for later date gets cycle that has only one day', () => {
|
||||||
const result = getCycleForDay('2018-06-20')
|
const result = getCycleForDay('2018-06-20')
|
||||||
expect(result.length).to.eql(1)
|
expect(result.length).toEqual(1)
|
||||||
expect(result).to.eql([
|
expect(result).toEqual([
|
||||||
{
|
{
|
||||||
date: '2018-06-05',
|
date: '2018-06-05',
|
||||||
bleeding: { value: 2 },
|
bleeding: { value: 2 },
|
||||||
@@ -79,12 +78,12 @@ describe('getCycleForDay', () => {
|
|||||||
])
|
])
|
||||||
})
|
})
|
||||||
|
|
||||||
it('returns null if there is no cycle start for that date', () => {
|
test('returns null if there is no cycle start for that date', () => {
|
||||||
const result = getCycleForDay('2018-04-01')
|
const result = getCycleForDay('2018-04-01')
|
||||||
expect(result).to.eql(null)
|
expect(result).toBeNull()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('returns null if the cycle is longer than the max', () => {
|
test('returns null if the cycle is longer than the max', () => {
|
||||||
const { getCycleForDay } = cycleModule({
|
const { getCycleForDay } = cycleModule({
|
||||||
cycleDaysSortedByDate,
|
cycleDaysSortedByDate,
|
||||||
cycleStartsSortedByDate: cycleDaysSortedByDate.filter((d) => {
|
cycleStartsSortedByDate: cycleDaysSortedByDate.filter((d) => {
|
||||||
@@ -93,13 +92,13 @@ describe('getCycleForDay', () => {
|
|||||||
maxCycleLength: 3,
|
maxCycleLength: 3,
|
||||||
})
|
})
|
||||||
const result = getCycleForDay('2018-04-04')
|
const result = getCycleForDay('2018-04-04')
|
||||||
expect(result).to.eql(null)
|
expect(result).toBeNull()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('gets cycle for day', () => {
|
test('gets cycle for day', () => {
|
||||||
const result = getCycleForDay('2018-04-04')
|
const result = getCycleForDay('2018-04-04')
|
||||||
expect(result.length).to.eql(4)
|
expect(result.length).toEqual(4)
|
||||||
expect(result).to.eql([
|
expect(result).toEqual([
|
||||||
{
|
{
|
||||||
date: '2018-04-05',
|
date: '2018-04-05',
|
||||||
mucus: { value: 2 },
|
mucus: { value: 2 },
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import { expect } from 'chai'
|
|
||||||
import cycleModule from '../lib/cycle'
|
import cycleModule from '../lib/cycle'
|
||||||
|
|
||||||
const julyCycle = [{ date: '2018-07-05' }]
|
const julyCycle = [{ date: '2018-07-05' }]
|
||||||
@@ -30,18 +29,18 @@ const cycleStartsSortedByDate = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
describe('getCyclesBefore', () => {
|
describe('getCyclesBefore', () => {
|
||||||
it('gets previous cycles', () => {
|
test('gets previous cycles', () => {
|
||||||
const { getCyclesBefore } = cycleModule({
|
const { getCyclesBefore } = cycleModule({
|
||||||
cycleDaysSortedByDate,
|
cycleDaysSortedByDate,
|
||||||
cycleStartsSortedByDate,
|
cycleStartsSortedByDate,
|
||||||
})
|
})
|
||||||
const cyclesBeforeJuly = getCyclesBefore(...julyCycle)
|
const cyclesBeforeJuly = getCyclesBefore(...julyCycle)
|
||||||
|
|
||||||
expect(cyclesBeforeJuly.length).to.eql(3)
|
expect(cyclesBeforeJuly.length).toEqual(3)
|
||||||
expect(cyclesBeforeJuly).to.eql([juneCycle, mayCycle, aprilCycle])
|
expect(cyclesBeforeJuly).toEqual([juneCycle, mayCycle, aprilCycle])
|
||||||
})
|
})
|
||||||
|
|
||||||
it('skips cycles that are longer than max', () => {
|
test('skips cycles that are longer than max', () => {
|
||||||
const { getCyclesBefore } = cycleModule({
|
const { getCyclesBefore } = cycleModule({
|
||||||
cycleDaysSortedByDate,
|
cycleDaysSortedByDate,
|
||||||
cycleStartsSortedByDate,
|
cycleStartsSortedByDate,
|
||||||
@@ -49,7 +48,7 @@ describe('getCyclesBefore', () => {
|
|||||||
})
|
})
|
||||||
const cyclesBeforeJuly = getCyclesBefore(...julyCycle)
|
const cyclesBeforeJuly = getCyclesBefore(...julyCycle)
|
||||||
|
|
||||||
expect(cyclesBeforeJuly.length).to.eql(1)
|
expect(cyclesBeforeJuly.length).toEqual(1)
|
||||||
expect(cyclesBeforeJuly).to.eql([juneCycle])
|
expect(cyclesBeforeJuly).toEqual([juneCycle])
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
import { expect } from 'chai'
|
|
||||||
import cycleModule from '../lib/cycle'
|
import cycleModule from '../lib/cycle'
|
||||||
|
|
||||||
describe('getMensesDaysRightAfter', () => {
|
describe('getMensesDaysRightAfter', () => {
|
||||||
it('works for simple menses start', () => {
|
test('works for simple menses start', () => {
|
||||||
const cycleDaysSortedByDate = [
|
const cycleDaysSortedByDate = [
|
||||||
{
|
{
|
||||||
date: '2018-05-04',
|
date: '2018-05-04',
|
||||||
@@ -29,7 +28,7 @@ describe('getMensesDaysRightAfter', () => {
|
|||||||
bleedingDaysSortedByDate: cycleDaysSortedByDate.filter((d) => d.bleeding),
|
bleedingDaysSortedByDate: cycleDaysSortedByDate.filter((d) => d.bleeding),
|
||||||
})
|
})
|
||||||
const days = getMensesDaysRightAfter(cycleDaysSortedByDate[3])
|
const days = getMensesDaysRightAfter(cycleDaysSortedByDate[3])
|
||||||
expect(days).to.eql([
|
expect(days).toEqual([
|
||||||
{
|
{
|
||||||
date: '2018-05-03',
|
date: '2018-05-03',
|
||||||
bleeding: { value: 1 },
|
bleeding: { value: 1 },
|
||||||
@@ -41,7 +40,7 @@ describe('getMensesDaysRightAfter', () => {
|
|||||||
])
|
])
|
||||||
})
|
})
|
||||||
|
|
||||||
it('works when the day is not a bleeding day', () => {
|
test('works when the day is not a bleeding day', () => {
|
||||||
const cycleDaysSortedByDate = [
|
const cycleDaysSortedByDate = [
|
||||||
{
|
{
|
||||||
date: '2018-05-04',
|
date: '2018-05-04',
|
||||||
@@ -69,7 +68,7 @@ describe('getMensesDaysRightAfter', () => {
|
|||||||
bleedingDaysSortedByDate: cycleDaysSortedByDate.filter((d) => d.bleeding),
|
bleedingDaysSortedByDate: cycleDaysSortedByDate.filter((d) => d.bleeding),
|
||||||
})
|
})
|
||||||
const days = getMensesDaysRightAfter(cycleDaysSortedByDate[4])
|
const days = getMensesDaysRightAfter(cycleDaysSortedByDate[4])
|
||||||
expect(days).to.eql([
|
expect(days).toEqual([
|
||||||
{
|
{
|
||||||
date: '2018-05-03',
|
date: '2018-05-03',
|
||||||
bleeding: { value: 1 },
|
bleeding: { value: 1 },
|
||||||
@@ -85,7 +84,7 @@ describe('getMensesDaysRightAfter', () => {
|
|||||||
])
|
])
|
||||||
})
|
})
|
||||||
|
|
||||||
it('ignores excluded values', () => {
|
test('ignores excluded values', () => {
|
||||||
const cycleDaysSortedByDate = [
|
const cycleDaysSortedByDate = [
|
||||||
{
|
{
|
||||||
date: '2018-05-04',
|
date: '2018-05-04',
|
||||||
@@ -112,7 +111,7 @@ describe('getMensesDaysRightAfter', () => {
|
|||||||
bleedingDaysSortedByDate: cycleDaysSortedByDate.filter((d) => d.bleeding),
|
bleedingDaysSortedByDate: cycleDaysSortedByDate.filter((d) => d.bleeding),
|
||||||
})
|
})
|
||||||
const days = getMensesDaysRightAfter(cycleDaysSortedByDate[3])
|
const days = getMensesDaysRightAfter(cycleDaysSortedByDate[3])
|
||||||
expect(days).to.eql([
|
expect(days).toEqual([
|
||||||
{
|
{
|
||||||
date: '2018-05-03',
|
date: '2018-05-03',
|
||||||
bleeding: { value: 1 },
|
bleeding: { value: 1 },
|
||||||
@@ -120,7 +119,7 @@ describe('getMensesDaysRightAfter', () => {
|
|||||||
])
|
])
|
||||||
})
|
})
|
||||||
|
|
||||||
it('returns empty when there are no bleeding days after', () => {
|
test('returns empty when there are no bleeding days after', () => {
|
||||||
const cycleDaysSortedByDate = [
|
const cycleDaysSortedByDate = [
|
||||||
{
|
{
|
||||||
date: '2018-05-04',
|
date: '2018-05-04',
|
||||||
@@ -145,10 +144,10 @@ describe('getMensesDaysRightAfter', () => {
|
|||||||
bleedingDaysSortedByDate: cycleDaysSortedByDate.filter((d) => d.bleeding),
|
bleedingDaysSortedByDate: cycleDaysSortedByDate.filter((d) => d.bleeding),
|
||||||
})
|
})
|
||||||
const days = getMensesDaysRightAfter(cycleDaysSortedByDate[3])
|
const days = getMensesDaysRightAfter(cycleDaysSortedByDate[3])
|
||||||
expect(days).to.eql([])
|
expect(days).toEqual([])
|
||||||
})
|
})
|
||||||
|
|
||||||
it('returns empty when there are no bleeding days within threshold', () => {
|
test('returns empty when there are no bleeding days within threshold', () => {
|
||||||
const cycleDaysSortedByDate = [
|
const cycleDaysSortedByDate = [
|
||||||
{
|
{
|
||||||
date: '2018-05-04',
|
date: '2018-05-04',
|
||||||
@@ -174,10 +173,10 @@ describe('getMensesDaysRightAfter', () => {
|
|||||||
bleedingDaysSortedByDate: cycleDaysSortedByDate.filter((d) => d.bleeding),
|
bleedingDaysSortedByDate: cycleDaysSortedByDate.filter((d) => d.bleeding),
|
||||||
})
|
})
|
||||||
const days = getMensesDaysRightAfter(cycleDaysSortedByDate[3])
|
const days = getMensesDaysRightAfter(cycleDaysSortedByDate[3])
|
||||||
expect(days).to.eql([])
|
expect(days).toEqual([])
|
||||||
})
|
})
|
||||||
|
|
||||||
it('includes days within the treshold', () => {
|
test('includes days within the treshold', () => {
|
||||||
const cycleDaysSortedByDate = [
|
const cycleDaysSortedByDate = [
|
||||||
{
|
{
|
||||||
date: '2018-05-04',
|
date: '2018-05-04',
|
||||||
@@ -204,7 +203,7 @@ describe('getMensesDaysRightAfter', () => {
|
|||||||
bleedingDaysSortedByDate: cycleDaysSortedByDate.filter((d) => d.bleeding),
|
bleedingDaysSortedByDate: cycleDaysSortedByDate.filter((d) => d.bleeding),
|
||||||
})
|
})
|
||||||
const days = getMensesDaysRightAfter(cycleDaysSortedByDate[3])
|
const days = getMensesDaysRightAfter(cycleDaysSortedByDate[3])
|
||||||
expect(days).to.eql([
|
expect(days).toEqual([
|
||||||
{
|
{
|
||||||
date: '2018-05-05',
|
date: '2018-05-05',
|
||||||
bleeding: { value: 1 },
|
bleeding: { value: 1 },
|
||||||
@@ -215,10 +214,11 @@ describe('getMensesDaysRightAfter', () => {
|
|||||||
},
|
},
|
||||||
])
|
])
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('with cycle thresholds', () => {
|
describe('with cycle thresholds', () => {
|
||||||
const maxBreakInBleeding = 3
|
const maxBreakInBleeding = 3
|
||||||
|
|
||||||
it('disregards bleeding breaks shorter than maxAllowedBleedingBreak in a bleeding period', () => {
|
test('disregards bleeding breaks shorter than maxAllowedBleedingBreak in a bleeding period', () => {
|
||||||
const bleedingDays = [
|
const bleedingDays = [
|
||||||
{
|
{
|
||||||
date: '2018-05-14',
|
date: '2018-05-14',
|
||||||
@@ -239,10 +239,10 @@ describe('getMensesDaysRightAfter', () => {
|
|||||||
maxBreakInBleeding,
|
maxBreakInBleeding,
|
||||||
}).getMensesDaysRightAfter
|
}).getMensesDaysRightAfter
|
||||||
const result = getMensesDaysRightAfter(bleedingDays[1])
|
const result = getMensesDaysRightAfter(bleedingDays[1])
|
||||||
expect(result).to.eql([bleedingDays[0]])
|
expect(result).toEqual([bleedingDays[0]])
|
||||||
})
|
})
|
||||||
|
|
||||||
it('counts bleeding breaks longer than maxAllowedBleedingBreak in a bleeding period', () => {
|
test('counts bleeding breaks longer than maxAllowedBleedingBreak in a bleeding period', () => {
|
||||||
const bleedingDays = [
|
const bleedingDays = [
|
||||||
{
|
{
|
||||||
date: '2018-05-14',
|
date: '2018-05-14',
|
||||||
@@ -263,7 +263,7 @@ describe('getMensesDaysRightAfter', () => {
|
|||||||
maxBreakInBleeding,
|
maxBreakInBleeding,
|
||||||
}).getMensesDaysRightAfter
|
}).getMensesDaysRightAfter
|
||||||
const result = getMensesDaysRightAfter(bleedingDays[1])
|
const result = getMensesDaysRightAfter(bleedingDays[1])
|
||||||
expect(result).to.eql([])
|
expect(result).toEqual([])
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
import { expect } from 'chai'
|
|
||||||
import cycleModule from '../lib/cycle'
|
import cycleModule from '../lib/cycle'
|
||||||
|
|
||||||
describe('getPredictedMenses', () => {
|
describe('getPredictedMenses', () => {
|
||||||
describe('cannot predict next menses', () => {
|
describe('cannot predict next menses', () => {
|
||||||
it('if no bleeding is documented', () => {
|
test('if no bleeding is documented', () => {
|
||||||
const cycleDaysSortedByDate = [{}]
|
const cycleDaysSortedByDate = [{}]
|
||||||
const cycleStarts = []
|
const cycleStarts = []
|
||||||
|
|
||||||
@@ -19,10 +18,10 @@ describe('getPredictedMenses', () => {
|
|||||||
minCyclesForPrediction: 1,
|
minCyclesForPrediction: 1,
|
||||||
})
|
})
|
||||||
const result = getPredictedMenses()
|
const result = getPredictedMenses()
|
||||||
expect(result).to.eql([])
|
expect(result).toEqual([])
|
||||||
})
|
})
|
||||||
|
|
||||||
it('if one bleeding is documented (no completed cycle)', () => {
|
test('if one bleeding is documented (no completed cycle)', () => {
|
||||||
const cycleDaysSortedByDate = [
|
const cycleDaysSortedByDate = [
|
||||||
{
|
{
|
||||||
date: '2018-06-02',
|
date: '2018-06-02',
|
||||||
@@ -43,10 +42,10 @@ describe('getPredictedMenses', () => {
|
|||||||
minCyclesForPrediction: 1,
|
minCyclesForPrediction: 1,
|
||||||
})
|
})
|
||||||
const result = getPredictedMenses()
|
const result = getPredictedMenses()
|
||||||
expect(result).to.eql([])
|
expect(result).toEqual([])
|
||||||
})
|
})
|
||||||
|
|
||||||
it('if number of cycles is below minCyclesForPrediction', () => {
|
test('if number of cycles is below minCyclesForPrediction', () => {
|
||||||
const cycleDaysSortedByDate = [
|
const cycleDaysSortedByDate = [
|
||||||
{
|
{
|
||||||
date: '2018-06-02',
|
date: '2018-06-02',
|
||||||
@@ -73,10 +72,10 @@ describe('getPredictedMenses', () => {
|
|||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
const result = getPredictedMenses()
|
const result = getPredictedMenses()
|
||||||
expect(result).to.eql([])
|
expect(result).toEqual([])
|
||||||
})
|
})
|
||||||
|
|
||||||
it('if number of cycles is below minCyclesForPrediction because one of them is too long', () => {
|
test('if number of cycles is below minCyclesForPrediction because one of them is too long', () => {
|
||||||
const cycleDaysSortedByDate = [
|
const cycleDaysSortedByDate = [
|
||||||
{
|
{
|
||||||
date: '2018-06-02',
|
date: '2018-06-02',
|
||||||
@@ -116,11 +115,12 @@ describe('getPredictedMenses', () => {
|
|||||||
maxCycleLength: 2,
|
maxCycleLength: 2,
|
||||||
})
|
})
|
||||||
const result = getPredictedMenses()
|
const result = getPredictedMenses()
|
||||||
expect(result).to.eql([])
|
expect(result).toEqual([])
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('works', () => {
|
describe('works', () => {
|
||||||
it('for one completed cycle with minCyclesForPrediction = 1', () => {
|
test('for one completed cycle with minCyclesForPrediction = 1', () => {
|
||||||
const cycleDaysSortedByDate = [
|
const cycleDaysSortedByDate = [
|
||||||
{
|
{
|
||||||
date: '2018-07-15',
|
date: '2018-07-15',
|
||||||
@@ -145,10 +145,10 @@ describe('getPredictedMenses', () => {
|
|||||||
['2018-08-10', '2018-08-11', '2018-08-12', '2018-08-13', '2018-08-14'],
|
['2018-08-10', '2018-08-11', '2018-08-12', '2018-08-13', '2018-08-14'],
|
||||||
['2018-08-24', '2018-08-25', '2018-08-26', '2018-08-27', '2018-08-28'],
|
['2018-08-24', '2018-08-25', '2018-08-26', '2018-08-27', '2018-08-28'],
|
||||||
]
|
]
|
||||||
expect(result).to.eql(expectedResult)
|
expect(result).toEqual(expectedResult)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('if number of cycles is above minCyclesForPrediction', () => {
|
test('if number of cycles is above minCyclesForPrediction', () => {
|
||||||
const cycleDaysSortedByDate = [
|
const cycleDaysSortedByDate = [
|
||||||
{
|
{
|
||||||
date: '2018-08-02',
|
date: '2018-08-02',
|
||||||
@@ -179,10 +179,10 @@ describe('getPredictedMenses', () => {
|
|||||||
['2018-10-02', '2018-10-03', '2018-10-04'],
|
['2018-10-02', '2018-10-03', '2018-10-04'],
|
||||||
['2018-11-02', '2018-11-03', '2018-11-04'],
|
['2018-11-02', '2018-11-03', '2018-11-04'],
|
||||||
]
|
]
|
||||||
expect(result).to.eql(expectedResult)
|
expect(result).toEqual(expectedResult)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('3 cycles with little standard deviation', () => {
|
test('3 cycles with little standard deviation', () => {
|
||||||
const cycleDaysSortedByDate = [
|
const cycleDaysSortedByDate = [
|
||||||
{
|
{
|
||||||
date: '2018-08-01',
|
date: '2018-08-01',
|
||||||
@@ -212,10 +212,10 @@ describe('getPredictedMenses', () => {
|
|||||||
['2018-08-28', '2018-08-29', '2018-08-30'],
|
['2018-08-28', '2018-08-29', '2018-08-30'],
|
||||||
['2018-09-11', '2018-09-12', '2018-09-13'],
|
['2018-09-11', '2018-09-12', '2018-09-13'],
|
||||||
]
|
]
|
||||||
expect(result).to.eql(expectedResult)
|
expect(result).toEqual(expectedResult)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('3 cycles with bigger standard deviation', () => {
|
test('3 cycles with bigger standard deviation', () => {
|
||||||
const cycleDaysSortedByDate = [
|
const cycleDaysSortedByDate = [
|
||||||
{
|
{
|
||||||
date: '2018-08-01',
|
date: '2018-08-01',
|
||||||
@@ -245,10 +245,10 @@ describe('getPredictedMenses', () => {
|
|||||||
['2018-08-27', '2018-08-28', '2018-08-29', '2018-08-30', '2018-08-31'],
|
['2018-08-27', '2018-08-28', '2018-08-29', '2018-08-30', '2018-08-31'],
|
||||||
['2018-09-10', '2018-09-11', '2018-09-12', '2018-09-13', '2018-09-14'],
|
['2018-09-10', '2018-09-11', '2018-09-12', '2018-09-13', '2018-09-14'],
|
||||||
]
|
]
|
||||||
expect(result).to.eql(expectedResult)
|
expect(result).toEqual(expectedResult)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('does not count cycles longer than max', () => {
|
test('does not count cycles longer than max', () => {
|
||||||
const cycleDaysSortedByDate = [
|
const cycleDaysSortedByDate = [
|
||||||
{
|
{
|
||||||
date: '2018-08-01',
|
date: '2018-08-01',
|
||||||
@@ -283,7 +283,7 @@ describe('getPredictedMenses', () => {
|
|||||||
['2018-08-27', '2018-08-28', '2018-08-29', '2018-08-30', '2018-08-31'],
|
['2018-08-27', '2018-08-28', '2018-08-29', '2018-08-30', '2018-08-31'],
|
||||||
['2018-09-10', '2018-09-11', '2018-09-12', '2018-09-13', '2018-09-14'],
|
['2018-09-10', '2018-09-11', '2018-09-12', '2018-09-13', '2018-09-14'],
|
||||||
]
|
]
|
||||||
expect(result).to.eql(expectedResult)
|
expect(result).toEqual(expectedResult)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import { expect } from 'chai'
|
|
||||||
import cycleModule from '../lib/cycle'
|
import cycleModule from '../lib/cycle'
|
||||||
|
|
||||||
const mayCycle = [
|
const mayCycle = [
|
||||||
@@ -25,40 +24,40 @@ const cycleStartsSortedByDate = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
describe('getPreviousCycle', () => {
|
describe('getPreviousCycle', () => {
|
||||||
it('gets previous cycle', () => {
|
test('gets previous cycle', () => {
|
||||||
const { getPreviousCycle } = cycleModule({
|
const { getPreviousCycle } = cycleModule({
|
||||||
cycleDaysSortedByDate,
|
cycleDaysSortedByDate,
|
||||||
cycleStartsSortedByDate,
|
cycleStartsSortedByDate,
|
||||||
})
|
})
|
||||||
|
|
||||||
expect(getPreviousCycle('2018-06-08')).to.eql(mayCycle)
|
expect(getPreviousCycle('2018-06-08')).toEqual(mayCycle)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('returns null when target day is not in a cyle', () => {
|
test('returns null when target day is not in a cyle', () => {
|
||||||
const { getPreviousCycle } = cycleModule({
|
const { getPreviousCycle } = cycleModule({
|
||||||
cycleDaysSortedByDate,
|
cycleDaysSortedByDate,
|
||||||
cycleStartsSortedByDate: [],
|
cycleStartsSortedByDate: [],
|
||||||
})
|
})
|
||||||
|
|
||||||
expect(getPreviousCycle('2018-06-08')).to.eql(null)
|
expect(getPreviousCycle('2018-06-08')).toEqual(null)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('returns null when there is no previous cycle', () => {
|
test('returns null when there is no previous cycle', () => {
|
||||||
const { getPreviousCycle } = cycleModule({
|
const { getPreviousCycle } = cycleModule({
|
||||||
cycleDaysSortedByDate,
|
cycleDaysSortedByDate,
|
||||||
cycleStartsSortedByDate,
|
cycleStartsSortedByDate,
|
||||||
})
|
})
|
||||||
|
|
||||||
expect(getPreviousCycle('2018-04-18')).to.eql(null)
|
expect(getPreviousCycle('2018-04-18')).toEqual(null)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('returns null when the previous cycle > maxcyclelength', () => {
|
test('returns null when the previous cycle > maxcyclelength', () => {
|
||||||
const { getPreviousCycle } = cycleModule({
|
const { getPreviousCycle } = cycleModule({
|
||||||
cycleDaysSortedByDate,
|
cycleDaysSortedByDate,
|
||||||
cycleStartsSortedByDate,
|
cycleStartsSortedByDate,
|
||||||
maxCycleLength: 2,
|
maxCycleLength: 2,
|
||||||
})
|
})
|
||||||
|
|
||||||
expect(getPreviousCycle('2018-06-08')).to.eql(null)
|
expect(getPreviousCycle('2018-06-08')).toEqual(null)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
+11
-13
@@ -1,25 +1,23 @@
|
|||||||
import { expect } from 'chai'
|
import { getOrdinalSuffix } from '../components/helpers/home'
|
||||||
|
|
||||||
import {getOrdinalSuffix } from '../components/helpers/home'
|
|
||||||
|
|
||||||
describe('Home helper: getOrdinalSuffix', () => {
|
describe('Home helper: getOrdinalSuffix', () => {
|
||||||
it('For 1, it returns suffix \'st\'', () => {
|
test("For 1, it returns suffix 'st'", () => {
|
||||||
expect(getOrdinalSuffix(1)).to.eql('st')
|
expect(getOrdinalSuffix(1)).toEqual('st')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('For 2, it returns suffix \'nd\'', () => {
|
test("For 2, it returns suffix 'nd'", () => {
|
||||||
expect(getOrdinalSuffix(2)).to.eql('nd')
|
expect(getOrdinalSuffix(2)).toEqual('nd')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('For 3, it returns suffix \'rd\'', () => {
|
test("For 3, it returns suffix 'rd'", () => {
|
||||||
expect(getOrdinalSuffix(3)).to.eql('rd')
|
expect(getOrdinalSuffix(3)).toEqual('rd')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('For 11, it returns suffix \'th\'', () => {
|
test("For 11, it returns suffix 'th'", () => {
|
||||||
expect(getOrdinalSuffix(11)).to.eql('th')
|
expect(getOrdinalSuffix(11)).toEqual('th')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('For 23, it returns suffix \'rd\'', () => {
|
test("For 23, it returns suffix 'rd'", () => {
|
||||||
expect(getOrdinalSuffix(23)).to.eql('rd')
|
expect(getOrdinalSuffix(23)).toEqual('rd')
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
import { expect } from 'chai'
|
|
||||||
import cycleModule from '../lib/cycle'
|
import cycleModule from '../lib/cycle'
|
||||||
|
|
||||||
describe('isMensesStart', () => {
|
describe('isMensesStart', () => {
|
||||||
it('works for simple menses start', () => {
|
test('works for simple menses start', () => {
|
||||||
const cycleDaysSortedByDate = [
|
const cycleDaysSortedByDate = [
|
||||||
{
|
{
|
||||||
date: '2018-05-04',
|
date: '2018-05-04',
|
||||||
@@ -29,14 +28,14 @@ describe('isMensesStart', () => {
|
|||||||
bleedingDaysSortedByDate: cycleDaysSortedByDate.filter((d) => d.bleeding),
|
bleedingDaysSortedByDate: cycleDaysSortedByDate.filter((d) => d.bleeding),
|
||||||
})
|
})
|
||||||
const start = isMensesStart(cycleDaysSortedByDate[3])
|
const start = isMensesStart(cycleDaysSortedByDate[3])
|
||||||
expect(start).to.be.true
|
expect(start).toBeTruthy()
|
||||||
expect(isMensesStart(cycleDaysSortedByDate[0])).to.be.false
|
expect(isMensesStart(cycleDaysSortedByDate[0])).toBeFalsy()
|
||||||
expect(isMensesStart(cycleDaysSortedByDate[1])).to.be.false
|
expect(isMensesStart(cycleDaysSortedByDate[1])).toBeFalsy()
|
||||||
expect(isMensesStart(cycleDaysSortedByDate[2])).to.be.false
|
expect(isMensesStart(cycleDaysSortedByDate[2])).toBeFalsy()
|
||||||
expect(isMensesStart(cycleDaysSortedByDate[4])).to.be.false
|
expect(isMensesStart(cycleDaysSortedByDate[4])).toBeFalsy()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('works with previous excluded value', () => {
|
test('works with previous excluded value', () => {
|
||||||
const cycleDaysSortedByDate = [
|
const cycleDaysSortedByDate = [
|
||||||
{
|
{
|
||||||
date: '2018-06-01',
|
date: '2018-06-01',
|
||||||
@@ -57,12 +56,12 @@ describe('isMensesStart', () => {
|
|||||||
bleedingDaysSortedByDate: cycleDaysSortedByDate.filter((d) => d.bleeding),
|
bleedingDaysSortedByDate: cycleDaysSortedByDate.filter((d) => d.bleeding),
|
||||||
})
|
})
|
||||||
const start = isMensesStart(cycleDaysSortedByDate[1])
|
const start = isMensesStart(cycleDaysSortedByDate[1])
|
||||||
expect(start).to.be.true
|
expect(start).toBeTruthy()
|
||||||
const notStart = isMensesStart(cycleDaysSortedByDate[2])
|
const notStart = isMensesStart(cycleDaysSortedByDate[2])
|
||||||
expect(notStart).to.be.false
|
expect(notStart).toBeFalsy()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('returns false when day has no bleeding', () => {
|
test('returns false when day has no bleeding', () => {
|
||||||
const cycleDaysSortedByDate = [
|
const cycleDaysSortedByDate = [
|
||||||
{
|
{
|
||||||
date: '2018-06-01',
|
date: '2018-06-01',
|
||||||
@@ -81,10 +80,10 @@ describe('isMensesStart', () => {
|
|||||||
bleedingDaysSortedByDate: cycleDaysSortedByDate.filter((d) => d.bleeding),
|
bleedingDaysSortedByDate: cycleDaysSortedByDate.filter((d) => d.bleeding),
|
||||||
})
|
})
|
||||||
const start = isMensesStart(cycleDaysSortedByDate[0])
|
const start = isMensesStart(cycleDaysSortedByDate[0])
|
||||||
expect(start).to.be.false
|
expect(start).toBeFalsy()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('returns false when there is a previous bleeding day within the threshold', () => {
|
test('returns false when there is a previous bleeding day within the threshold', () => {
|
||||||
const cycleDaysSortedByDate = [
|
const cycleDaysSortedByDate = [
|
||||||
{
|
{
|
||||||
date: '2018-06-01',
|
date: '2018-06-01',
|
||||||
@@ -110,10 +109,10 @@ describe('isMensesStart', () => {
|
|||||||
bleedingDaysSortedByDate: cycleDaysSortedByDate.filter((d) => d.bleeding),
|
bleedingDaysSortedByDate: cycleDaysSortedByDate.filter((d) => d.bleeding),
|
||||||
})
|
})
|
||||||
const start = isMensesStart(cycleDaysSortedByDate[2])
|
const start = isMensesStart(cycleDaysSortedByDate[2])
|
||||||
expect(start).to.be.false
|
expect(start).toBeFalsy()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('returns true when there is a previous excluded bleeding day within the threshold', () => {
|
test('returns true when there is a previous excluded bleeding day within the threshold', () => {
|
||||||
const cycleDaysSortedByDate = [
|
const cycleDaysSortedByDate = [
|
||||||
{
|
{
|
||||||
date: '2018-06-01',
|
date: '2018-06-01',
|
||||||
@@ -139,12 +138,13 @@ describe('isMensesStart', () => {
|
|||||||
bleedingDaysSortedByDate: cycleDaysSortedByDate.filter((d) => d.bleeding),
|
bleedingDaysSortedByDate: cycleDaysSortedByDate.filter((d) => d.bleeding),
|
||||||
})
|
})
|
||||||
const start = isMensesStart(cycleDaysSortedByDate[2])
|
const start = isMensesStart(cycleDaysSortedByDate[2])
|
||||||
expect(start).to.be.true
|
expect(start).toBeTruthy()
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('with cycle thresholds', () => {
|
describe('with cycle thresholds', () => {
|
||||||
const maxBreakInBleeding = 3
|
const maxBreakInBleeding = 3
|
||||||
|
|
||||||
it('disregards bleeding breaks equal to maxAllowedBleedingBreak in a bleeding period', () => {
|
test('disregards bleeding breaks equal to maxAllowedBleedingBreak in a bleeding period', () => {
|
||||||
const bleedingDays = [
|
const bleedingDays = [
|
||||||
{
|
{
|
||||||
date: '2018-05-14',
|
date: '2018-05-14',
|
||||||
@@ -165,10 +165,10 @@ describe('isMensesStart', () => {
|
|||||||
maxBreakInBleeding,
|
maxBreakInBleeding,
|
||||||
}).isMensesStart
|
}).isMensesStart
|
||||||
const result = isMensesStart(bleedingDays[0])
|
const result = isMensesStart(bleedingDays[0])
|
||||||
expect(result).to.be.false
|
expect(result).toBeFalsy()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('counts bleeding breaks longer than maxAllowedBleedingBreak in a bleeding period', () => {
|
test('counts bleeding breaks longer than maxAllowedBleedingBreak in a bleeding period', () => {
|
||||||
const bleedingDays = [
|
const bleedingDays = [
|
||||||
{
|
{
|
||||||
date: '2018-05-14',
|
date: '2018-05-14',
|
||||||
@@ -189,7 +189,7 @@ describe('isMensesStart', () => {
|
|||||||
maxBreakInBleeding,
|
maxBreakInBleeding,
|
||||||
}).isMensesStart
|
}).isMensesStart
|
||||||
const result = isMensesStart(bleedingDays[0])
|
const result = isMensesStart(bleedingDays[0])
|
||||||
expect(result).to.be.true
|
expect(result).toBeTruthy()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,7 +1,4 @@
|
|||||||
import replaceWithNullIfAllPropertiesAreNull from '../lib/import-export/replace-with-null'
|
import replaceWithNullIfAllPropertiesAreNull from '../lib/import-export/replace-with-null'
|
||||||
import chai from 'chai'
|
|
||||||
|
|
||||||
const expect = chai.expect
|
|
||||||
|
|
||||||
describe('replaceWithNullIfAllPropertiesAreNull', () => {
|
describe('replaceWithNullIfAllPropertiesAreNull', () => {
|
||||||
it('when data object has no null values, data object remains unchanged', () => {
|
it('when data object has no null values, data object remains unchanged', () => {
|
||||||
@@ -12,7 +9,7 @@ describe('replaceWithNullIfAllPropertiesAreNull', () => {
|
|||||||
const obj = { ...initialData }
|
const obj = { ...initialData }
|
||||||
replaceWithNullIfAllPropertiesAreNull(obj)
|
replaceWithNullIfAllPropertiesAreNull(obj)
|
||||||
|
|
||||||
expect(obj).to.deep.equal(initialData)
|
expect(obj).toEqual(initialData)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('when data object has nested object with all values null, nested object is replaced with null', () => {
|
it('when data object has nested object with all values null, nested object is replaced with null', () => {
|
||||||
@@ -24,13 +21,13 @@ describe('replaceWithNullIfAllPropertiesAreNull', () => {
|
|||||||
const expectedData = { bleeding: null, date: '2021-10-08' }
|
const expectedData = { bleeding: null, date: '2021-10-08' }
|
||||||
replaceWithNullIfAllPropertiesAreNull(obj)
|
replaceWithNullIfAllPropertiesAreNull(obj)
|
||||||
|
|
||||||
expect(obj).to.deep.equal(expectedData)
|
expect(obj).toEqual(expectedData)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('when data object is empty, data object remains unchanged', () => {
|
it('when data object is empty, data object remains unchanged', () => {
|
||||||
const obj = {}
|
const obj = {}
|
||||||
replaceWithNullIfAllPropertiesAreNull(obj)
|
replaceWithNullIfAllPropertiesAreNull(obj)
|
||||||
|
|
||||||
expect(obj).to.deep.equal({})
|
expect(obj).toEqual({})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,81 +1,79 @@
|
|||||||
import { expect } from 'chai'
|
|
||||||
|
|
||||||
import getSensiplanMucus from '../lib/nfp-mucus'
|
import getSensiplanMucus from '../lib/nfp-mucus'
|
||||||
|
|
||||||
describe('getSensiplanMucus', () => {
|
describe('getSensiplanMucus', () => {
|
||||||
it('returns null if there is no value for feeling or texture', () => {
|
test('returns null if there is no value for feeling or texture', () => {
|
||||||
expect(getSensiplanMucus()).to.be.null
|
expect(getSensiplanMucus()).toBeNull()
|
||||||
expect(getSensiplanMucus(undefined, 3)).to.be.null
|
expect(getSensiplanMucus(undefined, 3)).toBeNull()
|
||||||
expect(getSensiplanMucus(2, undefined)).to.be.null
|
expect(getSensiplanMucus(2, undefined)).toBeNull()
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('results in t for:', () => {
|
describe('results in t for:', () => {
|
||||||
it('dry feeling and no texture', function () {
|
test('dry feeling and no texture', function () {
|
||||||
const sensiplanValue = getSensiplanMucus(0, 0)
|
const sensiplanValue = getSensiplanMucus(0, 0)
|
||||||
expect(sensiplanValue).to.eql(0)
|
expect(sensiplanValue).toEqual(0)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('results in Ø for:', () => {
|
describe('results in Ø for:', () => {
|
||||||
it('no feeling and no texture', function () {
|
test('no feeling and no texture', function () {
|
||||||
const sensiplanValue = getSensiplanMucus(1, 0)
|
const sensiplanValue = getSensiplanMucus(1, 0)
|
||||||
expect(sensiplanValue).to.eql(1)
|
expect(sensiplanValue).toEqual(1)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('results in f for:', () => {
|
describe('results in f for:', () => {
|
||||||
it('wet feeling and no texture', function () {
|
test('wet feeling and no texture', function () {
|
||||||
const sensiplanValue = getSensiplanMucus(2, 0)
|
const sensiplanValue = getSensiplanMucus(2, 0)
|
||||||
expect(sensiplanValue).to.eql(2)
|
expect(sensiplanValue).toEqual(2)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('results in S for:', () => {
|
describe('results in S for:', () => {
|
||||||
it('dry feeling and creamy texture', function () {
|
test('dry feeling and creamy texture', function () {
|
||||||
const sensiplanValue = getSensiplanMucus(0, 1)
|
const sensiplanValue = getSensiplanMucus(0, 1)
|
||||||
expect(sensiplanValue).to.eql(3)
|
expect(sensiplanValue).toEqual(3)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('no feeling and creamy texture', function () {
|
test('no feeling and creamy texture', function () {
|
||||||
const sensiplanValue = getSensiplanMucus(1, 1)
|
const sensiplanValue = getSensiplanMucus(1, 1)
|
||||||
expect(sensiplanValue).to.eql(3)
|
expect(sensiplanValue).toEqual(3)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('wet feeling and creamy texture', function () {
|
test('wet feeling and creamy texture', function () {
|
||||||
const sensiplanValue = getSensiplanMucus(2, 1)
|
const sensiplanValue = getSensiplanMucus(2, 1)
|
||||||
expect(sensiplanValue).to.eql(3)
|
expect(sensiplanValue).toEqual(3)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('results in +S for:', () => {
|
describe('results in +S for:', () => {
|
||||||
it('dry feeling and egg white texture', function () {
|
test('dry feeling and egg white texture', function () {
|
||||||
const sensiplanValue = getSensiplanMucus(0, 2)
|
const sensiplanValue = getSensiplanMucus(0, 2)
|
||||||
expect(sensiplanValue).to.eql(4)
|
expect(sensiplanValue).toEqual(4)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('no feeling and egg white texture', function () {
|
test('no feeling and egg white texture', function () {
|
||||||
const sensiplanValue = getSensiplanMucus(1, 2)
|
const sensiplanValue = getSensiplanMucus(1, 2)
|
||||||
expect(sensiplanValue).to.eql(4)
|
expect(sensiplanValue).toEqual(4)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('wet feeling and egg white texture', function () {
|
test('wet feeling and egg white texture', function () {
|
||||||
const sensiplanValue = getSensiplanMucus(2, 2)
|
const sensiplanValue = getSensiplanMucus(2, 2)
|
||||||
expect(sensiplanValue).to.eql(4)
|
expect(sensiplanValue).toEqual(4)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('slippery feeling and egg white texture', function () {
|
test('slippery feeling and egg white texture', function () {
|
||||||
const sensiplanValue = getSensiplanMucus(3, 2)
|
const sensiplanValue = getSensiplanMucus(3, 2)
|
||||||
expect(sensiplanValue).to.eql(4)
|
expect(sensiplanValue).toEqual(4)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('slippery feeling and creamy texture', function () {
|
test('slippery feeling and creamy texture', function () {
|
||||||
const sensiplanValue = getSensiplanMucus(3, 1)
|
const sensiplanValue = getSensiplanMucus(3, 1)
|
||||||
expect(sensiplanValue).to.eql(4)
|
expect(sensiplanValue).toEqual(4)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('slippery feeling and no texture', function () {
|
test('slippery feeling and no texture', function () {
|
||||||
const sensiplanValue = getSensiplanMucus(3, 0)
|
const sensiplanValue = getSensiplanMucus(3, 0)
|
||||||
expect(sensiplanValue).to.eql(4)
|
expect(sensiplanValue).toEqual(4)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import { expect } from 'chai'
|
|
||||||
import maybeSetNewCycleStart from '../lib/set-new-cycle-start'
|
import maybeSetNewCycleStart from '../lib/set-new-cycle-start'
|
||||||
|
|
||||||
describe('maybeSetNewCycleStart', () => {
|
describe('maybeSetNewCycleStart', () => {
|
||||||
@@ -68,7 +67,7 @@ describe('maybeSetNewCycleStart', () => {
|
|||||||
if (cycleDay.date === '2020-01-02') return true
|
if (cycleDay.date === '2020-01-02') return true
|
||||||
}
|
}
|
||||||
|
|
||||||
it('sets new cycle start when first day of period deleted', () => {
|
test('sets new cycle start when first day of period deleted', () => {
|
||||||
const [cycleStartDay, mensesDaysAfter] = getFixtures()
|
const [cycleStartDay, mensesDaysAfter] = getFixtures()
|
||||||
|
|
||||||
maybeSetNewCycleStart({
|
maybeSetNewCycleStart({
|
||||||
@@ -77,12 +76,12 @@ describe('maybeSetNewCycleStart', () => {
|
|||||||
mensesDaysAfter,
|
mensesDaysAfter,
|
||||||
checkIsMensesStart,
|
checkIsMensesStart,
|
||||||
})
|
})
|
||||||
expect(cycleStartDay.isCycleStart).to.be.false
|
expect(cycleStartDay.isCycleStart).toBeFalsy()
|
||||||
expect(cycleStartDay.bleeding).to.be.null
|
expect(cycleStartDay.bleeding).toBeNull()
|
||||||
expect(mensesDaysAfter[2].isCycleStart).to.be.true
|
expect(mensesDaysAfter[2].isCycleStart).toBeTruthy()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('sets new cycle start when first day of period excluded', () => {
|
test('sets new cycle start when first day of period excluded', () => {
|
||||||
const [cycleStartDay, mensesDaysAfter] = getFixtures()
|
const [cycleStartDay, mensesDaysAfter] = getFixtures()
|
||||||
|
|
||||||
maybeSetNewCycleStart({
|
maybeSetNewCycleStart({
|
||||||
@@ -92,12 +91,12 @@ describe('maybeSetNewCycleStart', () => {
|
|||||||
checkIsMensesStart,
|
checkIsMensesStart,
|
||||||
})
|
})
|
||||||
|
|
||||||
expect(cycleStartDay.isCycleStart).to.be.false
|
expect(cycleStartDay.isCycleStart).toBeFalsy()
|
||||||
expect(cycleStartDay.bleeding).to.equal(excludedBleedingValue)
|
expect(cycleStartDay.bleeding).toEqual(excludedBleedingValue)
|
||||||
expect(mensesDaysAfter[2].isCycleStart).to.be.true
|
expect(mensesDaysAfter[2].isCycleStart).toBeTruthy()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('does not set new cycle start when other day of period deleted', () => {
|
test('does not set new cycle start when other day of period deleted', () => {
|
||||||
const [cycleStartDay, mensesDaysAfter, notCycleStartDay] = getFixtures()
|
const [cycleStartDay, mensesDaysAfter, notCycleStartDay] = getFixtures()
|
||||||
|
|
||||||
maybeSetNewCycleStart({
|
maybeSetNewCycleStart({
|
||||||
@@ -107,11 +106,12 @@ describe('maybeSetNewCycleStart', () => {
|
|||||||
checkIsMensesStart,
|
checkIsMensesStart,
|
||||||
})
|
})
|
||||||
|
|
||||||
expect(cycleStartDay.isCycleStart).to.be.true
|
expect(cycleStartDay.isCycleStart).toBeTruthy()
|
||||||
expect(notCycleStartDay.isCycleStart).to.be.false
|
expect(notCycleStartDay.isCycleStart).toBeFalsy()
|
||||||
expect(notCycleStartDay.bleeding).to.equal(deletedBleedingValue)
|
expect(notCycleStartDay.bleeding).toEqual(deletedBleedingValue)
|
||||||
})
|
})
|
||||||
it('does not set new cycle start when other day of period excluded', () => {
|
|
||||||
|
test('does not set new cycle start when other day of period excluded', () => {
|
||||||
const excludedBleedingValue = {
|
const excludedBleedingValue = {
|
||||||
value: 2,
|
value: 2,
|
||||||
exclude: true,
|
exclude: true,
|
||||||
@@ -126,11 +126,12 @@ describe('maybeSetNewCycleStart', () => {
|
|||||||
checkIsMensesStart,
|
checkIsMensesStart,
|
||||||
})
|
})
|
||||||
|
|
||||||
expect(cycleStartDay.isCycleStart).to.be.true
|
expect(cycleStartDay.isCycleStart).toBeTruthy()
|
||||||
expect(notCycleStartDay.isCycleStart).to.be.false
|
expect(notCycleStartDay.isCycleStart).toBeFalsy()
|
||||||
expect(notCycleStartDay.bleeding).to.equal(excludedBleedingValue)
|
expect(notCycleStartDay.bleeding).toEqual(excludedBleedingValue)
|
||||||
})
|
})
|
||||||
it('works when there are no following bleeding days', () => {
|
|
||||||
|
test('works when there are no following bleeding days', () => {
|
||||||
const [cycleStartDay] = getFixtures()
|
const [cycleStartDay] = getFixtures()
|
||||||
|
|
||||||
maybeSetNewCycleStart({
|
maybeSetNewCycleStart({
|
||||||
@@ -140,7 +141,7 @@ describe('maybeSetNewCycleStart', () => {
|
|||||||
checkIsMensesStart,
|
checkIsMensesStart,
|
||||||
})
|
})
|
||||||
|
|
||||||
expect(cycleStartDay.isCycleStart).to.be.false
|
expect(cycleStartDay.isCycleStart).toBeFalsy()
|
||||||
expect(cycleStartDay.bleeding).to.equal(deletedBleedingValue)
|
expect(cycleStartDay.bleeding).toEqual(deletedBleedingValue)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user