aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-web/tests/apps/permission-templates-test.js
blob: be99e6f54fd60d6cd2edefe8c604c64a836dcd2d (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
85
86
87
88
89
90
91
92
93
94
95
96
/* eslint no-unused-expressions: 0 */
import React from 'react';
import TestUtils from 'react-addons-test-utils';

import Defaults from '../../src/main/js/apps/permission-templates/permission-template-defaults';
import SetDefaults from '../../src/main/js/apps/permission-templates/permission-template-set-defaults';

let expect = require('chai').expect;
let sinon = require('sinon');

describe('Permission Templates', function () {
  describe('Defaults', () => {
    it('should display one qualifier', () => {
      let permissionTemplate = { defaultFor: ['VW'] },
          topQualifiers = ['TRK', 'VW'];
      let result = TestUtils.renderIntoDocument(
          <Defaults permissionTemplate={permissionTemplate} topQualifiers={topQualifiers}/>
      );
      expect(TestUtils.scryRenderedDOMComponentsWithClass(result, 'icon-qualifier-trk')).to.be.empty;
      expect(TestUtils.scryRenderedDOMComponentsWithClass(result, 'icon-qualifier-vw')).to.have.length(1);
    });

    it('should display two qualifiers', () => {
      let permissionTemplate = { defaultFor: ['TRK', 'VW'] },
          topQualifiers = ['TRK', 'VW'];
      let result = TestUtils.renderIntoDocument(
          <Defaults permissionTemplate={permissionTemplate} topQualifiers={topQualifiers}/>
      );
      expect(TestUtils.scryRenderedDOMComponentsWithClass(result, 'icon-qualifier-trk')).to.have.length(1);
      expect(TestUtils.scryRenderedDOMComponentsWithClass(result, 'icon-qualifier-vw')).to.have.length(1);
    });

    it('should not display qualifiers', () => {
      let permissionTemplate = { defaultFor: [] },
          topQualifiers = ['TRK', 'VW'];
      let result = TestUtils.renderIntoDocument(
          <Defaults permissionTemplate={permissionTemplate} topQualifiers={topQualifiers}/>
      );
      expect(TestUtils.scryRenderedDOMComponentsWithClass(result, 'icon-qualifier-trk')).to.be.empty;
      expect(TestUtils.scryRenderedDOMComponentsWithClass(result, 'icon-qualifier-vw')).to.be.empty;
    });

    it('should omit "project" if there is only one qualifier', () => {
      let permissionTemplate = { defaultFor: ['TRK'] },
          topQualifiers = ['TRK'];
      let result = TestUtils.renderIntoDocument(
          <Defaults permissionTemplate={permissionTemplate} topQualifiers={topQualifiers}/>
      );
      expect(TestUtils.scryRenderedDOMComponentsWithClass(result, 'icon-qualifier-trk')).to.be.empty;
    });
  });

  describe('SetDefaults', () => {
    var refresh = sinon.spy();

    it('should display a dropdown with one option', () => {
      let permissionTemplate = { defaultFor: ['VW'] },
          topQualifiers = ['TRK', 'VW'];
      let result = TestUtils.renderIntoDocument(
          <SetDefaults permissionTemplate={permissionTemplate} topQualifiers={topQualifiers} refresh={refresh}/>
      );
      expect(TestUtils.scryRenderedDOMComponentsWithClass(result, 'dropdown')).to.have.length(1);
      expect(TestUtils.scryRenderedDOMComponentsWithTag(result, 'a')).to.have.length(1);
    });

    it('should display a dropdown with two options', () => {
      let permissionTemplate = { defaultFor: [] },
          topQualifiers = ['TRK', 'VW'];
      let result = TestUtils.renderIntoDocument(
          <SetDefaults permissionTemplate={permissionTemplate} topQualifiers={topQualifiers} refresh={refresh}/>
      );
      expect(TestUtils.scryRenderedDOMComponentsWithClass(result, 'dropdown')).to.have.length(1);
      expect(TestUtils.scryRenderedDOMComponentsWithTag(result, 'a')).to.have.length(2);
    });

    it('should not display a dropdown', () => {
      let permissionTemplate = { defaultFor: ['TRK', 'VW'] },
          topQualifiers = ['TRK', 'VW'];
      let result = TestUtils.renderIntoDocument(
          <SetDefaults permissionTemplate={permissionTemplate} topQualifiers={topQualifiers} refresh={refresh}/>
      );
      expect(TestUtils.scryRenderedDOMComponentsWithClass(result, 'dropdown')).to.be.empty;
      expect(TestUtils.scryRenderedDOMComponentsWithTag(result, 'a')).to.be.empty;
    });

    it('should omit dropdown if there is only one qualifier', () => {
      let permissionTemplate = { defaultFor: [] },
          topQualifiers = ['TRK'];
      let result = TestUtils.renderIntoDocument(
          <SetDefaults permissionTemplate={permissionTemplate} topQualifiers={topQualifiers} refresh={refresh}/>
      );
      expect(TestUtils.scryRenderedDOMComponentsWithClass(result, 'dropdown')).to.be.empty;
      expect(TestUtils.scryRenderedDOMComponentsWithTag(result, 'a')).to.have.length(1);
    });
  });
});