aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-web/tests/apps/overview/helpers/periods-test.js
blob: 6dcd1ff3f961314099aa77d4666b4f90b8745d9e (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
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
import chai from 'chai';
import { expect } from 'chai';
chai.use(require('chai-datetime'));

import { getPeriodDate, getPeriodLabel } from '../../../../src/main/js/apps/overview/helpers/periods';


const PERIOD = {
  date: '2015-09-09T00:00:00+0200',
  index: '1',
  mode: 'previous_version',
  modeParam: '1.7'
};

const PERIOD_WITHOUT_VERSION = {
  date: '2015-09-09T00:00:00+0200',
  index: '1',
  mode: 'previous_version',
  modeParam: ''
};


describe('Overview Helpers', function () {
  describe('Periods', function () {

    describe('#getPeriodDate', function () {
      it('should return date', function () {
        let result = getPeriodDate([PERIOD], PERIOD.index);
        expect(result).to.equalDate(new Date(2015, 8, 9));
      });

      it('should return null', function () {
        let result = getPeriodDate([], '1');
        expect(result).to.be.null;
      });
    });


    describe('#getPeriodLabel', function () {
      it('should return label', function () {
        let result = getPeriodLabel([PERIOD], PERIOD.index);
        expect(result).to.equal('overview.period.previous_version.1.7');
      });

      it('should return "since previous version"', function () {
        let result = getPeriodLabel([PERIOD_WITHOUT_VERSION], PERIOD_WITHOUT_VERSION.index);
        expect(result).to.equal('overview.period.previous_version_only_date');
      });

      it('should return null', function () {
        let result = getPeriodLabel([], '1');
        expect(result).to.be.null;
      });
    });

  });
});