summaryrefslogtreecommitdiffstats
path: root/server/sonar-web/tests/helpers/urls-test.js
blob: 39b7c43b963c866b4ddc1f3c81792d7a9b761f58 (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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import { expect } from 'chai';

import { getComponentUrl, getComponentIssuesUrl, getComponentDrilldownUrl } from '../../src/main/js/helpers/urls';


const SIMPLE_COMPONENT_KEY = 'sonarqube';
const COMPLEX_COMPONENT_KEY = 'org.sonarsource.sonarqube:sonarqube';
const COMPLEX_COMPONENT_KEY_ENCODED = encodeURIComponent(COMPLEX_COMPONENT_KEY);
const METRIC = 'coverage';
const PERIOD = '3';


describe('URLs', function () {
  var oldBaseUrl;

  beforeEach(function () {
    oldBaseUrl = window.baseUrl;
  });

  afterEach(function () {
    window.baseUrl = oldBaseUrl;
  });

  describe('#getComponentUrl', function () {
    it('should return component url', function () {
      expect(getComponentUrl(SIMPLE_COMPONENT_KEY)).to.equal('/dashboard?id=' + SIMPLE_COMPONENT_KEY);
    });

    it('should encode component key', function () {
      expect(getComponentUrl(COMPLEX_COMPONENT_KEY)).to.equal('/dashboard?id=' + COMPLEX_COMPONENT_KEY_ENCODED);
    });

    it('should take baseUrl into account', function () {
      window.baseUrl = '/context';
      expect(getComponentUrl(COMPLEX_COMPONENT_KEY)).to.equal('/context/dashboard?id=' + COMPLEX_COMPONENT_KEY_ENCODED);
    });
  });

  describe('#getComponentIssuesUrl', function () {
    it('should work without parameters', function () {
      expect(getComponentIssuesUrl(SIMPLE_COMPONENT_KEY, {})).to.equal(
          '/component_issues?id=' + SIMPLE_COMPONENT_KEY + '#');
    });

    it('should encode component key', function () {
      expect(getComponentIssuesUrl(COMPLEX_COMPONENT_KEY, {})).to.equal(
          '/component_issues?id=' + COMPLEX_COMPONENT_KEY_ENCODED + '#');
    });

    it('should work with parameters', function () {
      expect(getComponentIssuesUrl(SIMPLE_COMPONENT_KEY, { resolved: 'false' })).to.equal(
          '/component_issues?id=' + SIMPLE_COMPONENT_KEY + '#resolved=false');
    });

    it('should encode parameters', function () {
      expect(getComponentIssuesUrl(SIMPLE_COMPONENT_KEY, { componentUuids: COMPLEX_COMPONENT_KEY })).to.equal(
          '/component_issues?id=' + SIMPLE_COMPONENT_KEY + '#componentUuids=' + COMPLEX_COMPONENT_KEY_ENCODED);
    });

    it('should take baseUrl into account', function () {
      window.baseUrl = '/context';
      expect(getComponentIssuesUrl(SIMPLE_COMPONENT_KEY, {})).to.equal(
          '/context/component_issues?id=' + SIMPLE_COMPONENT_KEY + '#');
    });
  });

  describe('#getComponentDrilldownUrl', function () {
    it('should return component drilldown url', function () {
      expect(getComponentDrilldownUrl(SIMPLE_COMPONENT_KEY, METRIC)).to.equal(
          '/component_measures/metric/' + METRIC + '?id=' + SIMPLE_COMPONENT_KEY);
    });

    it('should encode component key', function () {
      expect(getComponentDrilldownUrl(COMPLEX_COMPONENT_KEY, METRIC)).to.equal(
          '/component_measures/metric/' + METRIC + '?id=' + COMPLEX_COMPONENT_KEY_ENCODED);
    });

    it('should take baseUrl into account', function () {
      window.baseUrl = '/context';
      expect(getComponentDrilldownUrl(SIMPLE_COMPONENT_KEY, METRIC)).to.equal(
          '/context/component_measures/metric/' + METRIC + '?id=' + SIMPLE_COMPONENT_KEY);
    });
  });
});