summaryrefslogtreecommitdiffstats
path: root/server/sonar-web/tests/apps/overview/main/coverage-test.js
blob: 3883c69a8e676a78cce5bad91ae8d5f2072e45c7 (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
58
59
60
61
62
63
64
65
66
import _ from 'underscore';
import { expect } from 'chai';
import React from 'react';
import TestUtils from 'react-addons-test-utils';

import { GeneralCoverage } from '../../../../src/main/js/apps/overview/main/coverage';


const COMPONENT = { key: 'component-key' };

const DATE = new Date(2015, 0, 1);

const MEASURES = {
  'overall_coverage': 73.5,
  'coverage': 69.7,
  'it_coverage': 54.0,
  'tests': 137
};
const LEAK = {
  'new_overall_coverage': 72.5,
  'new_coverage': 68.7,
  'new_it_coverage': 53.0
};
const MEASURES_FOR_UT = _.omit(MEASURES, 'overall_coverage');
const LEAK_FOR_UT = _.omit(LEAK, 'new_overall_coverage');
const MEASURES_FOR_IT = _.omit(MEASURES_FOR_UT, 'coverage');
const LEAK_FOR_IT = _.omit(LEAK_FOR_UT, 'new_coverage');


describe('Overview :: GeneralCoverage', function () {
  it('should display overall coverage', function () {
    let component = <GeneralCoverage measures={MEASURES} leak={LEAK} component={COMPONENT}
                                     leakPeriodDate={DATE}/>;
    let output = TestUtils.renderIntoDocument(component);

    let coverageElement = TestUtils.findRenderedDOMComponentWithClass(output, 'js-overview-main-coverage');
    expect(coverageElement.textContent).to.equal('73.5%');

    let newCoverageElement = TestUtils.findRenderedDOMComponentWithClass(output, 'js-overview-main-new-coverage');
    expect(newCoverageElement.textContent).to.equal('72.5%');
  });

  it('should fall back to UT coverage', function () {
    let component = <GeneralCoverage measures={MEASURES_FOR_UT} leak={LEAK_FOR_UT} component={COMPONENT}
                                     leakPeriodDate={DATE}/>;
    let output = TestUtils.renderIntoDocument(component);

    let coverageElement = TestUtils.findRenderedDOMComponentWithClass(output, 'js-overview-main-coverage');
    expect(coverageElement.textContent).to.equal('69.7%');

    let newCoverageElement = TestUtils.findRenderedDOMComponentWithClass(output, 'js-overview-main-new-coverage');
    expect(newCoverageElement.textContent).to.equal('68.7%');
  });

  it('should fall back to IT coverage', function () {
    let component = <GeneralCoverage measures={MEASURES_FOR_IT} leak={LEAK_FOR_IT} component={COMPONENT}
                                     leakPeriodDate={DATE}/>;
    let output = TestUtils.renderIntoDocument(component);

    let coverageElement = TestUtils.findRenderedDOMComponentWithClass(output, 'js-overview-main-coverage');
    expect(coverageElement.textContent).to.equal('54.0%');

    let newCoverageElement = TestUtils.findRenderedDOMComponentWithClass(output, 'js-overview-main-new-coverage');
    expect(newCoverageElement.textContent).to.equal('53.0%');
  });
});