aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-web/test/medium/custom-measures.spec.js
blob: d43274febfa983c6d783ee07fa75441bef93ef86 (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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
define(function (require) {
  var bdd = require('intern!bdd');
  require('../helpers/test-page');

  bdd.describe('Custom Measures Page', function () {
    var projectId = 'uuid';

    bdd.it('should show list', function () {
      return this.remote
          .open()
          .mockFromFile('/api/custom_measures/search', 'custom-measures-spec/search.json',
          { data: { projectId: projectId } })
          .startApp('custom-measures/app')
          .checkElementCount('#custom-measures-list li[data-id]', 4)
          .checkElementInclude('#custom-measures-list .js-custom-measure-value', '35')
          .checkElementInclude('#custom-measures-list .js-custom-measure-metric-name', 'Distribution')
          .checkElementInclude('#custom-measures-list .js-custom-measure-domain', 'Management')
          .checkElementInclude('#custom-measures-list .js-custom-measure-description', 'Description...')
          .checkElementInclude('#custom-measures-list .js-custom-measure-created-at', '2015')
          .checkElementInclude('#custom-measures-list .js-custom-measure-user', 'Administrator')
          .checkElementCount('#custom-measures-list .js-custom-measure-pending', 4)
          .checkElementCount('#custom-measures-list .js-custom-measure-update', 4)
          .checkElementCount('#custom-measures-list .js-custom-measure-delete', 4)
          .checkElementInclude('#custom-measures-list-footer', '4/4');
    });

    bdd.it('should show more', function () {
      return this.remote
          .open()
          .mockFromFile('/api/custom_measures/search', 'custom-measures-spec/search-big-1.json',
          { data: { projectId: projectId } })
          .startApp('custom-measures/app')
          .checkElementCount('#custom-measures-list li[data-id]', 2)
          .checkElementNotExist('[data-id="3"]')
          .clearMocks()
          .mockFromFile('/api/custom_measures/search', 'custom-measures-spec/search-big-2.json',
          { data: { projectId: projectId, p: 2 } })
          .clickElement('#custom-measures-fetch-more')
          .checkElementExist('[data-id="3"]')
          .checkElementCount('#custom-measures-list li[data-id]', 4);
    });

    bdd.it('should create a new custom measure', function () {
      return this.remote
          .open()
          .mockFromFile('/api/custom_measures/search', 'custom-measures-spec/search.json',
          { data: { projectId: projectId } })
          .mockFromFile('/api/metrics/search', 'custom-measures-spec/metrics.json', { data: { isCustom: true } })
          .startApp('custom-measures/app')
          .checkElementCount('#custom-measures-list li[data-id]', 4)
          .clickElement('#custom-measures-create')
          .checkElementExist('#create-custom-measure-form')
          .clearMocks()
          .mockFromFile('/api/custom_measures/search', 'custom-measures-spec/search-created.json',
          { data: { projectId: projectId } })
          .mockFromString('/api/custom_measures/create', '{}', { data: {
            metricId: '156',
            value: '17',
            description: 'example',
            projectId: projectId
          } })
          .fillElement('#create-custom-measure-metric', '156')
          .fillElement('#create-custom-measure-value', '17')
          .fillElement('#create-custom-measure-description', 'example')
          .clickElement('#create-custom-measure-submit')
          .checkElementExist('[data-id="6"]')
          .checkElementCount('#custom-measures-list li[data-id]', 5)
          .checkElementInclude('[data-id="6"] .js-custom-measure-value', '17');
    });

    bdd.it('should filter available metrics', function () {
      return this.remote
          .open()
          .mockFromFile('/api/custom_measures/search', 'custom-measures-spec/search.json',
          { data: { projectId: projectId } })
          .mockFromFile('/api/metrics/search', 'custom-measures-spec/metrics.json', { data: { isCustom: true } })
          .startApp('custom-measures/app')
          .clickElement('#custom-measures-create')
          .checkElementExist('#create-custom-measure-form')
          .checkElementCount('#create-custom-measure-metric option', 1)
          .checkElementExist('#create-custom-measure-metric option[value="156"]');
    });

    bdd.it('should show warning when there are no available metrics', function () {
      return this.remote
          .open()
          .mockFromFile('/api/custom_measures/search', 'custom-measures-spec/search.json',
          { data: { projectId: projectId } })
          .mockFromFile('/api/metrics/search', 'custom-measures-spec/metrics-limited.json',
          { data: { isCustom: true } })
          .startApp('custom-measures/app')
          .clickElement('#custom-measures-create')
          .checkElementExist('#create-custom-measure-form')
          .checkElementNotExist('#create-custom-measure-metric')
          .checkElementExist('#create-custom-measure-form .alert-warning')
          .checkElementExist('#create-custom-measure-submit[disabled]');
    });

    bdd.it('should update a custom measure', function () {
      return this.remote
          .open()
          .mockFromFile('/api/custom_measures/search', 'custom-measures-spec/search.json',
          { data: { projectId: projectId } })
          .mockFromFile('/api/metrics/search', 'custom-measures-spec/metrics.json', { data: { isCustom: true } })
          .startApp('custom-measures/app')
          .clickElement('[data-id="5"] .js-custom-measure-update')
          .checkElementExist('#create-custom-measure-form')
          .clearMocks()
          .mockFromFile('/api/custom_measures/search', 'custom-measures-spec/search-updated.json',
          { data: { projectId: projectId } })
          .mockFromString('/api/custom_measures/update', '{}', { data: {
            id: '5',
            value: '2',
            description: 'new!'
          } })
          .fillElement('#create-custom-measure-value', '2')
          .fillElement('#create-custom-measure-description', 'new!')
          .clickElement('#create-custom-measure-submit')
          .checkElementExist('[data-id="5"]')
          .checkElementInclude('[data-id="5"] .js-custom-measure-value', 'B')
          .checkElementInclude('[data-id="5"] .js-custom-measure-description', 'new!');
    });

    bdd.it('should delete a custom measure', function () {
      return this.remote
          .open()
          .mockFromFile('/api/custom_measures/search', 'custom-measures-spec/search.json',
          { data: { projectId: projectId } })
          .startApp('custom-measures/app')
          .clickElement('[data-id="5"] .js-custom-measure-delete')
          .checkElementExist('#delete-custom-measure-form', 1)
          .clearMocks()
          .mockFromFile('/api/custom_measures/search', 'custom-measures-spec/search-deleted.json',
          { data: { projectId: projectId } })
          .mockFromString('/api/custom_measures/delete', '{}', { data: { id: '5' } })
          .clickElement('#delete-custom-measure-submit')
          .checkElementNotExist('[data-id="5"]');
    });
  });

});