This repository has been archived by the owner on Aug 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
tests.spec.ts
71 lines (56 loc) · 1.93 KB
/
tests.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import { Epiweek, MMWRDate } from './index'
import { expect } from 'chai'
import 'mocha'
import * as moment from 'moment'
describe('MMWRDate', () => {
it('should initialize correctly', () => {
let mdate = new MMWRDate(2016, 48)
expect(mdate.year).to.equal(2016)
expect(mdate.week).to.equal(48)
expect(mdate.day).to.equal(undefined)
})
it('should return correct first day of season', () => {
let mdate = new MMWRDate(2016, 48)
expect(mdate.startMomentDate.isSame(moment('2016-01-03T00:00:00.000'))).to.be.true
})
it('should return correct moment date', () => {
let mdate = new MMWRDate(2016, 48)
expect(mdate.toMomentDate().isSame(moment('2016-11-27T00:00:00.000'))).to.be.true
})
it('should read correctly from moment date', () => {
let mdate = new MMWRDate(2016)
mdate.fromMomentDate(moment('2016-12-27'))
expect(mdate.year).to.equal(2016)
expect(mdate.week).to.equal(52)
expect(mdate.day).to.equal(3)
})
it('should return correct epiweek', () => {
let mdate = new MMWRDate(2016, 52)
expect(mdate.toEpiweek()).to.equal(201652)
})
it('should read correctly from epiweek', () => {
let mdate = new MMWRDate(2016)
mdate.fromEpiweek(201732)
expect(mdate.year).to.equal(2017)
expect(mdate.week).to.equal(32)
expect(mdate.day).to.equal(1)
})
it('should return correct number of weeks', () => {
let mdate = new MMWRDate(2016)
expect(mdate.nWeeks).to.equal(52)
mdate = new MMWRDate(2014)
expect(mdate.nWeeks).to.equal(53)
})
it('should return correct week difference', () => {
let mdate = new MMWRDate(2016, 52)
let odate = new MMWRDate(2016, 3)
expect(mdate.diffWeek(odate)).to.equal(49)
})
it('should apply correct week difference', () => {
let mdate = new MMWRDate(2016, 52, 3)
mdate.applyWeekDiff(56)
expect(mdate.year).to.equal(2018)
expect(mdate.week).to.equal(4)
expect(mdate.day).to.equal(3)
})
})