summaryrefslogtreecommitdiff
path: root/spec/javascripts/lib/utils/datefix_spec.js
blob: 0b9fde2be674004cb51d10ea63fb35629ef2e5a7 (plain)
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
import { pad, parsePikadayDate, pikadayToString } from '~/lib/utils/datefix';

describe('datefix', () => {
  describe('pad', () => {
    it('should add a 0 when length is smaller than 2', () => {
      expect(pad(2)).toEqual('02');
    });

    it('should not add a zero when lenght matches the default', () => {
      expect(pad(12)).toEqual('12');
    });

    it('should add a 0 when lenght is smaller than the provided', () => {
      expect(pad(12, 3)).toEqual('012');
    });
  });

  describe('parsePikadayDate', () => {
    it('should return a UTC date', () => {
      expect(parsePikadayDate('2020-01-29')).toEqual(new Date('2020-01-29'));
    });
  });

  describe('pikadayToString', () => {
    it('should format a UTC date into yyyy-mm-dd format', () => {
      expect(pikadayToString(new Date('2020-01-29'))).toEqual('2020-01-29');
    });
  });
});