summaryrefslogtreecommitdiffstats
path: root/server/sonar-web/tests
diff options
context:
space:
mode:
authorStas Vilchik <vilchiks@gmail.com>2015-11-12 18:05:08 +0100
committerStas Vilchik <vilchiks@gmail.com>2015-11-13 14:25:00 +0100
commit27c49eda28940ca7600587b75fcbc9223268ee8b (patch)
treeb296526a4426370c20cff34aa55cc0097ee87d01 /server/sonar-web/tests
parent3348f196c986cfc9db1cfeb2a57ae847c2f4df63 (diff)
downloadsonarqube-27c49eda28940ca7600587b75fcbc9223268ee8b.tar.gz
sonarqube-27c49eda28940ca7600587b75fcbc9223268ee8b.zip
SONAR-6331 refactor overview code
Diffstat (limited to 'server/sonar-web/tests')
-rw-r--r--server/sonar-web/tests/apps/overview/components/complexity-distribution-test.js41
-rw-r--r--server/sonar-web/tests/apps/overview/components/issues-tags-test.js45
-rw-r--r--server/sonar-web/tests/apps/overview/components/language-distribution-test.js38
-rw-r--r--server/sonar-web/tests/apps/overview/components/legend-test.js26
-rw-r--r--server/sonar-web/tests/apps/overview/helpers/metrics-test.js110
-rw-r--r--server/sonar-web/tests/apps/overview/helpers/periods-test.js57
-rw-r--r--server/sonar-web/tests/apps/overview/overview-test.js (renamed from server/sonar-web/tests/apps/overview-test.js)13
7 files changed, 327 insertions, 3 deletions
diff --git a/server/sonar-web/tests/apps/overview/components/complexity-distribution-test.js b/server/sonar-web/tests/apps/overview/components/complexity-distribution-test.js
new file mode 100644
index 00000000000..a79cdbf34bc
--- /dev/null
+++ b/server/sonar-web/tests/apps/overview/components/complexity-distribution-test.js
@@ -0,0 +1,41 @@
+import { expect } from 'chai';
+import React from 'react';
+import TestUtils from 'react-addons-test-utils';
+
+import { ComplexityDistribution } from '../../../../src/main/js/apps/overview/components/complexity-distribution';
+
+
+const DISTRIBUTION = '1=11950;2=86;4=77;6=43;8=17;10=12;12=3';
+
+
+describe('ComplexityDistribution', function () {
+ let props;
+
+ beforeEach(function () {
+ let renderer = TestUtils.createRenderer();
+ renderer.render(<ComplexityDistribution distribution={DISTRIBUTION}/>);
+ let output = renderer.getRenderOutput();
+ let child = React.Children.only(output.props.children);
+ props = child.props;
+ });
+
+ it('should pass right data', function () {
+ expect(props.data).to.deep.equal([
+ { x: 0, y: 11950, value: 1 },
+ { x: 1, y: 86, value: 2 },
+ { x: 2, y: 77, value: 4 },
+ { x: 3, y: 43, value: 6 },
+ { x: 4, y: 17, value: 8 },
+ { x: 5, y: 12, value: 10 },
+ { x: 6, y: 3, value: 12 }
+ ]);
+ });
+
+ it('should pass right xTicks', function () {
+ expect(props.xTicks).to.deep.equal([1, 2, 4, 6, 8, 10, 12]);
+ });
+
+ it('should pass right xValues', function () {
+ expect(props.xValues).to.deep.equal(['11,950', '86', '77', '43', '17', '12', '3']);
+ });
+});
diff --git a/server/sonar-web/tests/apps/overview/components/issues-tags-test.js b/server/sonar-web/tests/apps/overview/components/issues-tags-test.js
new file mode 100644
index 00000000000..67d90c7c11f
--- /dev/null
+++ b/server/sonar-web/tests/apps/overview/components/issues-tags-test.js
@@ -0,0 +1,45 @@
+import { expect } from 'chai';
+import React from 'react';
+import TestUtils from 'react-addons-test-utils';
+
+import { IssuesTags } from '../../../../src/main/js/apps/overview/components/issues-tags';
+import { WordCloud } from '../../../../src/main/js/components/charts/word-cloud';
+
+
+const COMPONENT = { key: 'component-key' };
+
+const TAGS = [
+ { val: 'first', count: 3 },
+ { val: 'second', count: 7000 },
+ { val: 'third', count: 2 }
+];
+
+
+describe('IssuesTags', function () {
+ it('should pass right data', function () {
+ let renderer = TestUtils.createRenderer();
+ renderer.render(<IssuesTags tags={TAGS} component={COMPONENT}/>);
+ let output = renderer.getRenderOutput();
+ expect(output.type).to.equal(WordCloud);
+ expect(output.props.items).to.deep.equal([
+ {
+ "link": '/component_issues?id=component-key#resolved=false|tags=first',
+ "size": 3,
+ "text": 'first',
+ "tooltip": 'Issues: 3'
+ },
+ {
+ "link": '/component_issues?id=component-key#resolved=false|tags=second',
+ "size": 7000,
+ "text": 'second',
+ "tooltip": 'Issues: 7k'
+ },
+ {
+ "link": '/component_issues?id=component-key#resolved=false|tags=third',
+ "size": 2,
+ "text": 'third',
+ "tooltip": 'Issues: 2'
+ }
+ ]);
+ });
+});
diff --git a/server/sonar-web/tests/apps/overview/components/language-distribution-test.js b/server/sonar-web/tests/apps/overview/components/language-distribution-test.js
new file mode 100644
index 00000000000..a54ba2b1260
--- /dev/null
+++ b/server/sonar-web/tests/apps/overview/components/language-distribution-test.js
@@ -0,0 +1,38 @@
+import { expect } from 'chai';
+import React from 'react';
+import TestUtils from 'react-addons-test-utils';
+
+import { LanguageDistribution } from '../../../../src/main/js/apps/overview/components/language-distribution';
+
+
+const DISTRIBUTION = '<null>=17345;java=194342;js=20984';
+const LINES = 1000000;
+
+
+describe('LanguageDistribution', function () {
+ let props;
+
+ beforeEach(function () {
+ let renderer = TestUtils.createRenderer();
+ renderer.render(<LanguageDistribution distribution={DISTRIBUTION} lines={LINES}/>);
+ let output = renderer.getRenderOutput();
+ let child = React.Children.only(output.props.children);
+ props = child.props;
+ });
+
+ it('should pass right data', function () {
+ expect(props.data).to.deep.equal([
+ { x: 194342, y: 1, value: 'java' },
+ { x: 20984, y: 2, value: 'js' },
+ { x: 17345, y: 0, value: '<null>' }
+ ]);
+ });
+
+ it('should pass right yTicks', function () {
+ expect(props.yTicks).to.deep.equal(['java', 'js', '<null>']);
+ });
+
+ it('should pass right yValues', function () {
+ expect(props.yValues).to.deep.equal(['19.4%', '2.1%', '1.7%']);
+ });
+});
diff --git a/server/sonar-web/tests/apps/overview/components/legend-test.js b/server/sonar-web/tests/apps/overview/components/legend-test.js
new file mode 100644
index 00000000000..d4c877eafd5
--- /dev/null
+++ b/server/sonar-web/tests/apps/overview/components/legend-test.js
@@ -0,0 +1,26 @@
+import { expect } from 'chai';
+import React from 'react';
+import TestUtils from 'react-addons-test-utils';
+
+import { Legend } from '../../../../src/main/js/apps/overview/components/legend';
+
+
+const DATE = new Date(2015, 3, 7);
+const LABEL = 'since 1.0';
+
+
+describe('Legend', function () {
+ it('should not render', function () {
+ let renderer = TestUtils.createRenderer();
+ renderer.render(<Legend/>);
+ let output = renderer.getRenderOutput();
+ expect(output).to.be.null;
+ });
+
+ it('should render', function () {
+ let renderer = TestUtils.createRenderer();
+ renderer.render(<Legend leakPeriodDate={DATE} leakPeriodLabel={LABEL}/>);
+ let output = renderer.getRenderOutput();
+ expect(output).to.not.be.null;
+ });
+});
diff --git a/server/sonar-web/tests/apps/overview/helpers/metrics-test.js b/server/sonar-web/tests/apps/overview/helpers/metrics-test.js
new file mode 100644
index 00000000000..e090ea54ed3
--- /dev/null
+++ b/server/sonar-web/tests/apps/overview/helpers/metrics-test.js
@@ -0,0 +1,110 @@
+import { expect } from 'chai';
+
+import { filterMetrics, filterMetricsForDomains, getShortType, getMetricName } from
+ '../../../../src/main/js/apps/overview/helpers/metrics';
+
+
+const METRICS = [
+ { key: 'normal_metric', type: 'INT', hidden: false },
+ { key: 'hidden_metric', type: 'INT', hidden: true },
+ { key: 'DATA_metric', type: 'DATA', hidden: false },
+ { key: 'DISTRIB_metric', type: 'DISTRIB', hidden: false },
+ { key: 'new_metric', type: 'FLOAT', hidden: false }
+];
+
+
+describe('Overview Helpers', function () {
+ describe('Metrics', function () {
+
+ describe('#filterMetrics', function () {
+ it('should filter out hidden metrics', function () {
+ let metrics = [
+ { key: 'normal_metric', type: 'INT', hidden: false },
+ { key: 'hidden_metric', type: 'INT', hidden: true }
+ ];
+ expect(filterMetrics(metrics)).to.have.length(1);
+ });
+
+ it('should filter out DATA and DISTRIB metrics', function () {
+ let metrics = [
+ { key: 'normal_metric', type: 'INT', hidden: false },
+ { key: 'DATA_metric', type: 'DATA', hidden: false },
+ { key: 'DISTRIB_metric', type: 'DISTRIB', hidden: false }
+ ];
+ expect(filterMetrics(metrics)).to.have.length(1);
+ });
+
+ it('should filter out differential metrics', function () {
+ let metrics = [
+ { key: 'normal_metric', type: 'INT', hidden: false },
+ { key: 'new_metric', type: 'FLOAT', hidden: false }
+ ];
+ expect(filterMetrics(metrics)).to.have.length(1);
+ });
+ });
+
+ describe('#filterMetricsForDomains', function () {
+ it('should filter out hidden metrics', function () {
+ let metrics = [
+ { key: 'normal_metric', type: 'INT', hidden: false, domain: 'first' },
+ { key: 'hidden_metric', type: 'INT', hidden: true, domain: 'first' }
+ ];
+ expect(filterMetricsForDomains(metrics, ['first'])).to.have.length(1);
+ });
+
+ it('should filter out DATA and DISTRIB metrics', function () {
+ let metrics = [
+ { key: 'normal_metric', type: 'INT', hidden: false, domain: 'first' },
+ { key: 'DATA_metric', type: 'DATA', hidden: false, domain: 'first' },
+ { key: 'DISTRIB_metric', type: 'DISTRIB', hidden: false, domain: 'first' }
+ ];
+ expect(filterMetricsForDomains(metrics, ['first'])).to.have.length(1);
+ });
+
+ it('should filter out differential metrics', function () {
+ let metrics = [
+ { key: 'normal_metric', type: 'INT', hidden: false, domain: 'first' },
+ { key: 'new_metric', type: 'FLOAT', hidden: false, domain: 'first' }
+ ];
+ expect(filterMetricsForDomains(metrics, ['first'])).to.have.length(1);
+ });
+
+ it('should filter metrics by domains', function () {
+ let metrics = [
+ { key: 'normal_metric', type: 'INT', hidden: false, domain: 'first' },
+ { key: 'normal_metric1', type: 'INT', hidden: false, domain: 'second' },
+ { key: 'normal_metric2', type: 'INT', hidden: false, domain: 'third' },
+ { key: 'normal_metric3', type: 'INT', hidden: false, domain: 'second' }
+ ];
+ expect(filterMetricsForDomains(metrics, ['first', 'second'])).to.have.length(3);
+ });
+ });
+
+
+ describe('#getShortType', function () {
+ it('should shorten INT', function () {
+ expect(getShortType('INT')).to.equal('SHORT_INT');
+ });
+
+ it('should shorten WORK_DUR', function () {
+ expect(getShortType('WORK_DUR')).to.equal('SHORT_WORK_DUR');
+ });
+
+ it('should not shorten FLOAT', function () {
+ expect(getShortType('FLOAT')).to.equal('FLOAT');
+ });
+
+ it('should not shorten PERCENT', function () {
+ expect(getShortType('PERCENT')).to.equal('PERCENT');
+ });
+ });
+
+
+ describe('#getMetricName', function () {
+ it('should return metric name', function () {
+ expect(getMetricName('metric_name')).to.equal('overview.metric.metric_name');
+ });
+ });
+
+ });
+});
diff --git a/server/sonar-web/tests/apps/overview/helpers/periods-test.js b/server/sonar-web/tests/apps/overview/helpers/periods-test.js
new file mode 100644
index 00000000000..6dcd1ff3f96
--- /dev/null
+++ b/server/sonar-web/tests/apps/overview/helpers/periods-test.js
@@ -0,0 +1,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;
+ });
+ });
+
+ });
+});
diff --git a/server/sonar-web/tests/apps/overview-test.js b/server/sonar-web/tests/apps/overview/overview-test.js
index 2bfea7f419a..2b7ae01d8be 100644
--- a/server/sonar-web/tests/apps/overview-test.js
+++ b/server/sonar-web/tests/apps/overview/overview-test.js
@@ -3,9 +3,9 @@ import ReactDOM from 'react-dom';
import TestUtils from 'react-addons-test-utils';
import { expect } from 'chai';
-import Gate from '../../src/main/js/apps/overview/main/gate/gate';
-import GateConditions from '../../src/main/js/apps/overview/main/gate/gate-conditions';
-import GateCondition from '../../src/main/js/apps/overview/main/gate/gate-condition';
+import Gate from '../../../src/main/js/apps/overview/gate/gate';
+import GateConditions from '../../../src/main/js/apps/overview/gate/gate-conditions';
+import GateCondition from '../../../src/main/js/apps/overview/gate/gate-condition';
describe('Overview', function () {
@@ -41,4 +41,11 @@ describe('Overview', function () {
});
});
+
+ describe('Helpers', function () {
+ describe('Periods', function () {
+
+ });
+ });
+
});