Chore/jest

This commit is contained in:
Sofiya Tepikin
2022-08-12 09:31:33 +00:00
parent 0cd2770996
commit a103949f7c
16 changed files with 6978 additions and 912 deletions
+90 -86
View File
@@ -1,11 +1,7 @@
import chai from 'chai'
import { getCycleLengthStats as cycleInfo } from '../lib/cycle-length'
const expect = chai.expect
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 result = cycleInfo(cycleLengths)
const expectedResult = {
@@ -15,87 +11,95 @@ describe('getCycleLengthStats', () => {
median: 5,
stdDeviation: 53.06,
}
expect(result).to.eql(expectedResult)
}),
it('works for a simple even-numbered array', () => {
const cycleLengths = [4, 1, 15, 2, 20, 5]
const result = cycleInfo(cycleLengths)
const expectedResult = {
minimum: 1,
maximum: 20,
mean: 7.83,
median: 4.5,
stdDeviation: 7.78,
}
expect(result).to.eql(expectedResult)
}),
it('works for an one-element array', () => {
const cycleLengths = [42]
const result = cycleInfo(cycleLengths)
const expectedResult = {
minimum: 42,
maximum: 42,
mean: 42,
median: 42,
stdDeviation: null,
}
expect(result).to.eql(expectedResult)
}),
describe('works for more realistic examples', () => {
it('1 day difference between shortest and longest period', () => {
const cycleLengths = [28, 29, 28, 28, 28, 29, 28, 28, 28, 29, 29, 28]
const result = cycleInfo(cycleLengths)
const expectedResult = {
minimum: 28,
maximum: 29,
mean: 28.33,
median: 28,
stdDeviation: 0.49,
}
expect(result).to.eql(expectedResult)
}),
it('3 days difference between shortest and longest period', () => {
const cycleLengths = [28, 29, 28, 28, 27, 30, 28, 27, 28, 28, 29, 27]
const result = cycleInfo(cycleLengths)
const expectedResult = {
minimum: 27,
maximum: 30,
mean: 28.08,
median: 28,
stdDeviation: 0.9,
}
expect(result).to.eql(expectedResult)
}),
it('8 days difference between shortest and longest period', () => {
const cycleLengths = [28, 32, 29, 27, 28, 26, 33, 28, 29, 34, 27, 29]
const result = cycleInfo(cycleLengths)
const expectedResult = {
minimum: 26,
maximum: 34,
mean: 29.17,
median: 28.5,
stdDeviation: 2.52,
}
expect(result).to.eql(expectedResult)
})
})
expect(result).toEqual(expectedResult)
})
describe('when args are wrong', () => {
it('throws when arg object is an empty array', () => {
const cycleLengths = []
expect(() => cycleInfo(cycleLengths)).to.throw(Error)
}),
it('throws when arg object is not in right format', () => {
const wrongObject = { hello: 'world' }
expect(() => cycleInfo(wrongObject)).to.throw(Error)
}),
it('throws when arg array contains a string', () => {
const wrongElement = [4, 1, 15, '2', 20, 5]
expect(() => cycleInfo(wrongElement)).to.throw(Error)
}),
it('throws when arg array contains a NaN', () => {
const wrongElement = [4, 1, 15, NaN, 20, 5]
expect(() => cycleInfo(wrongElement)).to.throw(Error)
})
test('works for a simple even-numbered array', () => {
const cycleLengths = [4, 1, 15, 2, 20, 5]
const result = cycleInfo(cycleLengths)
const expectedResult = {
minimum: 1,
maximum: 20,
mean: 7.83,
median: 4.5,
stdDeviation: 7.78,
}
expect(result).toEqual(expectedResult)
})
test('works for an one-element array', () => {
const cycleLengths = [42]
const result = cycleInfo(cycleLengths)
const expectedResult = {
minimum: 42,
maximum: 42,
mean: 42,
median: 42,
stdDeviation: null,
}
expect(result).toEqual(expectedResult)
})
})
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 result = cycleInfo(cycleLengths)
const expectedResult = {
minimum: 28,
maximum: 29,
mean: 28.33,
median: 28,
stdDeviation: 0.49,
}
expect(result).toEqual(expectedResult)
})
test('3 days difference between shortest and longest period', () => {
const cycleLengths = [28, 29, 28, 28, 27, 30, 28, 27, 28, 28, 29, 27]
const result = cycleInfo(cycleLengths)
const expectedResult = {
minimum: 27,
maximum: 30,
mean: 28.08,
median: 28,
stdDeviation: 0.9,
}
expect(result).toEqual(expectedResult)
})
test('8 days difference between shortest and longest period', () => {
const cycleLengths = [28, 32, 29, 27, 28, 26, 33, 28, 29, 34, 27, 29]
const result = cycleInfo(cycleLengths)
const expectedResult = {
minimum: 26,
maximum: 34,
mean: 29.17,
median: 28.5,
stdDeviation: 2.52,
}
expect(result).toEqual(expectedResult)
})
})
describe('when args are wrong', () => {
test('throws when arg object is an empty array', () => {
const cycleLengths = []
expect(() => cycleInfo(cycleLengths)).toThrow(Error)
})
test('throws when arg object is not in right format', () => {
const wrongObject = { hello: 'world' }
expect(() => cycleInfo(wrongObject)).toThrow(Error)
})
test('throws when arg array contains a string', () => {
const wrongElement = [4, 1, 15, '2', 20, 5]
expect(() => cycleInfo(wrongElement)).toThrow(Error)
})
test('throws when arg array contains a NaN', () => {
const wrongElement = [4, 1, 15, NaN, 20, 5]
expect(() => cycleInfo(wrongElement)).toThrow(Error)
})
})
+2 -3
View File
@@ -1,4 +1,3 @@
import { expect } from 'chai'
import cycleModule from '../lib/cycle'
const cycleStartDay = { date: '2018-05-03' }
@@ -23,12 +22,12 @@ const cycleStartsSortedByDate = [
]
describe('getCycleByStartDay', () => {
it('gets cycle by cycle start day', () => {
test('gets cycle by cycle start day', () => {
const { getCycleByStartDay } = cycleModule({
cycleDaysSortedByDate,
cycleStartsSortedByDate,
})
expect(getCycleByStartDay(cycleStartDay)).to.eql(cycle)
expect(getCycleByStartDay(cycleStartDay)).toEqual(cycle)
})
})
+10 -11
View File
@@ -1,18 +1,17 @@
import { expect } from 'chai'
import cycleModule from '../lib/cycle'
const simpleCycleStarts = [{ date: '2018-05-09' }, { date: '2018-05-03' }]
describe('getCycleDayNumber', () => {
it('works for a date in the current cycle', () => {
test('works for a date in the current cycle', () => {
const cycleStartsSortedByDate = simpleCycleStarts
const date = '2018-05-17'
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 = [
{ date: '2018-05-13' },
{ date: '2018-04-10' },
@@ -20,31 +19,31 @@ describe('getCycleDayNumber', () => {
const date = '2018-04-27'
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 date = '2018-05-13'
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 date = '2018-05-17'
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
// we use the default 99 days max length
const date = '2018-08-16'
const { getCycleDayNumber } = cycleModule({ cycleStartsSortedByDate })
expect(getCycleDayNumber(date)).to.be.null
expect(getCycleDayNumber(date)).toBeNull()
})
})
+15 -16
View File
@@ -1,4 +1,3 @@
import { expect } from 'chai'
import cycleModule from '../lib/cycle'
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')
expect(result.length).to.eql(1)
expect(result).to.eql([
expect(result.length).toEqual(1)
expect(result).toEqual([
{
date: '2018-07-05',
bleeding: { value: 2 },
},
])
const result2 = getCycleForDay('2018-06-05')
expect(result2.length).to.eql(1)
expect(result2).to.eql([
expect(result2.length).toEqual(1)
expect(result2).toEqual([
{
date: '2018-06-05',
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')
expect(result.length).to.eql(1)
expect(result).to.eql([
expect(result.length).toEqual(1)
expect(result).toEqual([
{
date: '2018-06-05',
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')
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({
cycleDaysSortedByDate,
cycleStartsSortedByDate: cycleDaysSortedByDate.filter((d) => {
@@ -93,13 +92,13 @@ describe('getCycleForDay', () => {
maxCycleLength: 3,
})
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')
expect(result.length).to.eql(4)
expect(result).to.eql([
expect(result.length).toEqual(4)
expect(result).toEqual([
{
date: '2018-04-05',
mucus: { value: 2 },
+6 -7
View File
@@ -1,4 +1,3 @@
import { expect } from 'chai'
import cycleModule from '../lib/cycle'
const julyCycle = [{ date: '2018-07-05' }]
@@ -30,18 +29,18 @@ const cycleStartsSortedByDate = [
]
describe('getCyclesBefore', () => {
it('gets previous cycles', () => {
test('gets previous cycles', () => {
const { getCyclesBefore } = cycleModule({
cycleDaysSortedByDate,
cycleStartsSortedByDate,
})
const cyclesBeforeJuly = getCyclesBefore(...julyCycle)
expect(cyclesBeforeJuly.length).to.eql(3)
expect(cyclesBeforeJuly).to.eql([juneCycle, mayCycle, aprilCycle])
expect(cyclesBeforeJuly.length).toEqual(3)
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({
cycleDaysSortedByDate,
cycleStartsSortedByDate,
@@ -49,7 +48,7 @@ describe('getCyclesBefore', () => {
})
const cyclesBeforeJuly = getCyclesBefore(...julyCycle)
expect(cyclesBeforeJuly.length).to.eql(1)
expect(cyclesBeforeJuly).to.eql([juneCycle])
expect(cyclesBeforeJuly.length).toEqual(1)
expect(cyclesBeforeJuly).toEqual([juneCycle])
})
})
+17 -17
View File
@@ -1,8 +1,7 @@
import { expect } from 'chai'
import cycleModule from '../lib/cycle'
describe('getMensesDaysRightAfter', () => {
it('works for simple menses start', () => {
test('works for simple menses start', () => {
const cycleDaysSortedByDate = [
{
date: '2018-05-04',
@@ -29,7 +28,7 @@ describe('getMensesDaysRightAfter', () => {
bleedingDaysSortedByDate: cycleDaysSortedByDate.filter((d) => d.bleeding),
})
const days = getMensesDaysRightAfter(cycleDaysSortedByDate[3])
expect(days).to.eql([
expect(days).toEqual([
{
date: '2018-05-03',
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 = [
{
date: '2018-05-04',
@@ -69,7 +68,7 @@ describe('getMensesDaysRightAfter', () => {
bleedingDaysSortedByDate: cycleDaysSortedByDate.filter((d) => d.bleeding),
})
const days = getMensesDaysRightAfter(cycleDaysSortedByDate[4])
expect(days).to.eql([
expect(days).toEqual([
{
date: '2018-05-03',
bleeding: { value: 1 },
@@ -85,7 +84,7 @@ describe('getMensesDaysRightAfter', () => {
])
})
it('ignores excluded values', () => {
test('ignores excluded values', () => {
const cycleDaysSortedByDate = [
{
date: '2018-05-04',
@@ -112,7 +111,7 @@ describe('getMensesDaysRightAfter', () => {
bleedingDaysSortedByDate: cycleDaysSortedByDate.filter((d) => d.bleeding),
})
const days = getMensesDaysRightAfter(cycleDaysSortedByDate[3])
expect(days).to.eql([
expect(days).toEqual([
{
date: '2018-05-03',
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 = [
{
date: '2018-05-04',
@@ -145,10 +144,10 @@ describe('getMensesDaysRightAfter', () => {
bleedingDaysSortedByDate: cycleDaysSortedByDate.filter((d) => d.bleeding),
})
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 = [
{
date: '2018-05-04',
@@ -174,10 +173,10 @@ describe('getMensesDaysRightAfter', () => {
bleedingDaysSortedByDate: cycleDaysSortedByDate.filter((d) => d.bleeding),
})
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 = [
{
date: '2018-05-04',
@@ -204,7 +203,7 @@ describe('getMensesDaysRightAfter', () => {
bleedingDaysSortedByDate: cycleDaysSortedByDate.filter((d) => d.bleeding),
})
const days = getMensesDaysRightAfter(cycleDaysSortedByDate[3])
expect(days).to.eql([
expect(days).toEqual([
{
date: '2018-05-05',
bleeding: { value: 1 },
@@ -215,10 +214,11 @@ describe('getMensesDaysRightAfter', () => {
},
])
})
describe('with cycle thresholds', () => {
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 = [
{
date: '2018-05-14',
@@ -239,10 +239,10 @@ describe('getMensesDaysRightAfter', () => {
maxBreakInBleeding,
}).getMensesDaysRightAfter
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 = [
{
date: '2018-05-14',
@@ -263,7 +263,7 @@ describe('getMensesDaysRightAfter', () => {
maxBreakInBleeding,
}).getMensesDaysRightAfter
const result = getMensesDaysRightAfter(bleedingDays[1])
expect(result).to.eql([])
expect(result).toEqual([])
})
})
})
+19 -19
View File
@@ -1,9 +1,8 @@
import { expect } from 'chai'
import cycleModule from '../lib/cycle'
describe('getPredictedMenses', () => {
describe('cannot predict next menses', () => {
it('if no bleeding is documented', () => {
test('if no bleeding is documented', () => {
const cycleDaysSortedByDate = [{}]
const cycleStarts = []
@@ -19,10 +18,10 @@ describe('getPredictedMenses', () => {
minCyclesForPrediction: 1,
})
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 = [
{
date: '2018-06-02',
@@ -43,10 +42,10 @@ describe('getPredictedMenses', () => {
minCyclesForPrediction: 1,
})
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 = [
{
date: '2018-06-02',
@@ -73,10 +72,10 @@ describe('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 = [
{
date: '2018-06-02',
@@ -116,11 +115,12 @@ describe('getPredictedMenses', () => {
maxCycleLength: 2,
})
const result = getPredictedMenses()
expect(result).to.eql([])
expect(result).toEqual([])
})
})
describe('works', () => {
it('for one completed cycle with minCyclesForPrediction = 1', () => {
test('for one completed cycle with minCyclesForPrediction = 1', () => {
const cycleDaysSortedByDate = [
{
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-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 = [
{
date: '2018-08-02',
@@ -179,10 +179,10 @@ describe('getPredictedMenses', () => {
['2018-10-02', '2018-10-03', '2018-10-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 = [
{
date: '2018-08-01',
@@ -212,10 +212,10 @@ describe('getPredictedMenses', () => {
['2018-08-28', '2018-08-29', '2018-08-30'],
['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 = [
{
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-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 = [
{
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-09-10', '2018-09-11', '2018-09-12', '2018-09-13', '2018-09-14'],
]
expect(result).to.eql(expectedResult)
expect(result).toEqual(expectedResult)
})
})
})
+8 -9
View File
@@ -1,4 +1,3 @@
import { expect } from 'chai'
import cycleModule from '../lib/cycle'
const mayCycle = [
@@ -25,40 +24,40 @@ const cycleStartsSortedByDate = [
]
describe('getPreviousCycle', () => {
it('gets previous cycle', () => {
test('gets previous cycle', () => {
const { getPreviousCycle } = cycleModule({
cycleDaysSortedByDate,
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({
cycleDaysSortedByDate,
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({
cycleDaysSortedByDate,
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({
cycleDaysSortedByDate,
cycleStartsSortedByDate,
maxCycleLength: 2,
})
expect(getPreviousCycle('2018-06-08')).to.eql(null)
expect(getPreviousCycle('2018-06-08')).toEqual(null)
})
})
+11 -13
View File
@@ -1,25 +1,23 @@
import { expect } from 'chai'
import {getOrdinalSuffix } from '../components/helpers/home'
import { getOrdinalSuffix } from '../components/helpers/home'
describe('Home helper: getOrdinalSuffix', () => {
it('For 1, it returns suffix \'st\'', () => {
expect(getOrdinalSuffix(1)).to.eql('st')
test("For 1, it returns suffix 'st'", () => {
expect(getOrdinalSuffix(1)).toEqual('st')
})
it('For 2, it returns suffix \'nd\'', () => {
expect(getOrdinalSuffix(2)).to.eql('nd')
test("For 2, it returns suffix 'nd'", () => {
expect(getOrdinalSuffix(2)).toEqual('nd')
})
it('For 3, it returns suffix \'rd\'', () => {
expect(getOrdinalSuffix(3)).to.eql('rd')
test("For 3, it returns suffix 'rd'", () => {
expect(getOrdinalSuffix(3)).toEqual('rd')
})
it('For 11, it returns suffix \'th\'', () => {
expect(getOrdinalSuffix(11)).to.eql('th')
test("For 11, it returns suffix 'th'", () => {
expect(getOrdinalSuffix(11)).toEqual('th')
})
it('For 23, it returns suffix \'rd\'', () => {
expect(getOrdinalSuffix(23)).to.eql('rd')
test("For 23, it returns suffix 'rd'", () => {
expect(getOrdinalSuffix(23)).toEqual('rd')
})
})
+20 -20
View File
@@ -1,8 +1,7 @@
import { expect } from 'chai'
import cycleModule from '../lib/cycle'
describe('isMensesStart', () => {
it('works for simple menses start', () => {
test('works for simple menses start', () => {
const cycleDaysSortedByDate = [
{
date: '2018-05-04',
@@ -29,14 +28,14 @@ describe('isMensesStart', () => {
bleedingDaysSortedByDate: cycleDaysSortedByDate.filter((d) => d.bleeding),
})
const start = isMensesStart(cycleDaysSortedByDate[3])
expect(start).to.be.true
expect(isMensesStart(cycleDaysSortedByDate[0])).to.be.false
expect(isMensesStart(cycleDaysSortedByDate[1])).to.be.false
expect(isMensesStart(cycleDaysSortedByDate[2])).to.be.false
expect(isMensesStart(cycleDaysSortedByDate[4])).to.be.false
expect(start).toBeTruthy()
expect(isMensesStart(cycleDaysSortedByDate[0])).toBeFalsy()
expect(isMensesStart(cycleDaysSortedByDate[1])).toBeFalsy()
expect(isMensesStart(cycleDaysSortedByDate[2])).toBeFalsy()
expect(isMensesStart(cycleDaysSortedByDate[4])).toBeFalsy()
})
it('works with previous excluded value', () => {
test('works with previous excluded value', () => {
const cycleDaysSortedByDate = [
{
date: '2018-06-01',
@@ -57,12 +56,12 @@ describe('isMensesStart', () => {
bleedingDaysSortedByDate: cycleDaysSortedByDate.filter((d) => d.bleeding),
})
const start = isMensesStart(cycleDaysSortedByDate[1])
expect(start).to.be.true
expect(start).toBeTruthy()
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 = [
{
date: '2018-06-01',
@@ -81,10 +80,10 @@ describe('isMensesStart', () => {
bleedingDaysSortedByDate: cycleDaysSortedByDate.filter((d) => d.bleeding),
})
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 = [
{
date: '2018-06-01',
@@ -110,10 +109,10 @@ describe('isMensesStart', () => {
bleedingDaysSortedByDate: cycleDaysSortedByDate.filter((d) => d.bleeding),
})
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 = [
{
date: '2018-06-01',
@@ -139,12 +138,13 @@ describe('isMensesStart', () => {
bleedingDaysSortedByDate: cycleDaysSortedByDate.filter((d) => d.bleeding),
})
const start = isMensesStart(cycleDaysSortedByDate[2])
expect(start).to.be.true
expect(start).toBeTruthy()
})
describe('with cycle thresholds', () => {
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 = [
{
date: '2018-05-14',
@@ -165,10 +165,10 @@ describe('isMensesStart', () => {
maxBreakInBleeding,
}).isMensesStart
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 = [
{
date: '2018-05-14',
@@ -189,7 +189,7 @@ describe('isMensesStart', () => {
maxBreakInBleeding,
}).isMensesStart
const result = isMensesStart(bleedingDays[0])
expect(result).to.be.true
expect(result).toBeTruthy()
})
})
})
+3 -6
View File
@@ -1,7 +1,4 @@
import replaceWithNullIfAllPropertiesAreNull from '../lib/import-export/replace-with-null'
import chai from 'chai'
const expect = chai.expect
describe('replaceWithNullIfAllPropertiesAreNull', () => {
it('when data object has no null values, data object remains unchanged', () => {
@@ -12,7 +9,7 @@ describe('replaceWithNullIfAllPropertiesAreNull', () => {
const obj = { ...initialData }
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', () => {
@@ -24,13 +21,13 @@ describe('replaceWithNullIfAllPropertiesAreNull', () => {
const expectedData = { bleeding: null, date: '2021-10-08' }
replaceWithNullIfAllPropertiesAreNull(obj)
expect(obj).to.deep.equal(expectedData)
expect(obj).toEqual(expectedData)
})
it('when data object is empty, data object remains unchanged', () => {
const obj = {}
replaceWithNullIfAllPropertiesAreNull(obj)
expect(obj).to.deep.equal({})
expect(obj).toEqual({})
})
})
+28 -30
View File
@@ -1,81 +1,79 @@
import { expect } from 'chai'
import getSensiplanMucus from '../lib/nfp-mucus'
describe('getSensiplanMucus', () => {
it('returns null if there is no value for feeling or texture', () => {
expect(getSensiplanMucus()).to.be.null
expect(getSensiplanMucus(undefined, 3)).to.be.null
expect(getSensiplanMucus(2, undefined)).to.be.null
test('returns null if there is no value for feeling or texture', () => {
expect(getSensiplanMucus()).toBeNull()
expect(getSensiplanMucus(undefined, 3)).toBeNull()
expect(getSensiplanMucus(2, undefined)).toBeNull()
})
describe('results in t for:', () => {
it('dry feeling and no texture', function () {
test('dry feeling and no texture', function () {
const sensiplanValue = getSensiplanMucus(0, 0)
expect(sensiplanValue).to.eql(0)
expect(sensiplanValue).toEqual(0)
})
})
describe('results in Ø for:', () => {
it('no feeling and no texture', function () {
test('no feeling and no texture', function () {
const sensiplanValue = getSensiplanMucus(1, 0)
expect(sensiplanValue).to.eql(1)
expect(sensiplanValue).toEqual(1)
})
})
describe('results in f for:', () => {
it('wet feeling and no texture', function () {
test('wet feeling and no texture', function () {
const sensiplanValue = getSensiplanMucus(2, 0)
expect(sensiplanValue).to.eql(2)
expect(sensiplanValue).toEqual(2)
})
})
describe('results in S for:', () => {
it('dry feeling and creamy texture', function () {
test('dry feeling and creamy texture', function () {
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)
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)
expect(sensiplanValue).to.eql(3)
expect(sensiplanValue).toEqual(3)
})
})
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)
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)
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)
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)
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)
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)
expect(sensiplanValue).to.eql(4)
expect(sensiplanValue).toEqual(4)
})
})
})
+21 -20
View File
@@ -1,4 +1,3 @@
import { expect } from 'chai'
import maybeSetNewCycleStart from '../lib/set-new-cycle-start'
describe('maybeSetNewCycleStart', () => {
@@ -68,7 +67,7 @@ describe('maybeSetNewCycleStart', () => {
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()
maybeSetNewCycleStart({
@@ -77,12 +76,12 @@ describe('maybeSetNewCycleStart', () => {
mensesDaysAfter,
checkIsMensesStart,
})
expect(cycleStartDay.isCycleStart).to.be.false
expect(cycleStartDay.bleeding).to.be.null
expect(mensesDaysAfter[2].isCycleStart).to.be.true
expect(cycleStartDay.isCycleStart).toBeFalsy()
expect(cycleStartDay.bleeding).toBeNull()
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()
maybeSetNewCycleStart({
@@ -92,12 +91,12 @@ describe('maybeSetNewCycleStart', () => {
checkIsMensesStart,
})
expect(cycleStartDay.isCycleStart).to.be.false
expect(cycleStartDay.bleeding).to.equal(excludedBleedingValue)
expect(mensesDaysAfter[2].isCycleStart).to.be.true
expect(cycleStartDay.isCycleStart).toBeFalsy()
expect(cycleStartDay.bleeding).toEqual(excludedBleedingValue)
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()
maybeSetNewCycleStart({
@@ -107,11 +106,12 @@ describe('maybeSetNewCycleStart', () => {
checkIsMensesStart,
})
expect(cycleStartDay.isCycleStart).to.be.true
expect(notCycleStartDay.isCycleStart).to.be.false
expect(notCycleStartDay.bleeding).to.equal(deletedBleedingValue)
expect(cycleStartDay.isCycleStart).toBeTruthy()
expect(notCycleStartDay.isCycleStart).toBeFalsy()
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 = {
value: 2,
exclude: true,
@@ -126,11 +126,12 @@ describe('maybeSetNewCycleStart', () => {
checkIsMensesStart,
})
expect(cycleStartDay.isCycleStart).to.be.true
expect(notCycleStartDay.isCycleStart).to.be.false
expect(notCycleStartDay.bleeding).to.equal(excludedBleedingValue)
expect(cycleStartDay.isCycleStart).toBeTruthy()
expect(notCycleStartDay.isCycleStart).toBeFalsy()
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()
maybeSetNewCycleStart({
@@ -140,7 +141,7 @@ describe('maybeSetNewCycleStart', () => {
checkIsMensesStart,
})
expect(cycleStartDay.isCycleStart).to.be.false
expect(cycleStartDay.bleeding).to.equal(deletedBleedingValue)
expect(cycleStartDay.isCycleStart).toBeFalsy()
expect(cycleStartDay.bleeding).toEqual(deletedBleedingValue)
})
})