Browse Source

move tests

tags/6.0-RC1
Stas Vilchik 8 years ago
parent
commit
364cd42b9b
29 changed files with 815 additions and 484 deletions
  1. 1
    1
      server/sonar-web/package.json
  2. 3
    1
      server/sonar-web/pom.xml
  3. 60
    44
      server/sonar-web/src/main/js/apps/background-tasks/__tests__/background-tasks-test.js
  4. 3
    3
      server/sonar-web/src/main/js/apps/overview/components/__tests__/App-test.js
  5. 1
    1
      server/sonar-web/src/main/js/apps/overview/components/__tests__/EmptyOverview-test.js
  6. 2
    2
      server/sonar-web/src/main/js/apps/overview/qualityGate/__tests__/QualityGateCondition-test.js
  7. 48
    30
      server/sonar-web/src/main/js/apps/permission-templates/__tests__/permission-templates-test.js
  8. 54
    0
      server/sonar-web/src/main/js/apps/projects/__tests__/projects-test.js
  9. 39
    20
      server/sonar-web/src/main/js/apps/system/__tests__/system-test.js
  10. 59
    41
      server/sonar-web/src/main/js/components/__tests__/issue-test.js
  11. 109
    0
      server/sonar-web/src/main/js/components/__tests__/source-viewer-test.js
  12. 97
    0
      server/sonar-web/src/main/js/components/charts/__tests__/bar-chart-test.js
  13. 58
    0
      server/sonar-web/src/main/js/components/charts/__tests__/bubble-chart-test.js
  14. 74
    0
      server/sonar-web/src/main/js/components/charts/__tests__/line-chart-test.js
  15. 44
    0
      server/sonar-web/src/main/js/components/charts/__tests__/treemap-test.js
  16. 38
    0
      server/sonar-web/src/main/js/components/charts/__tests__/work-cloud-test.js
  17. 20
    1
      server/sonar-web/src/main/js/helpers/__tests__/l10n-test.js
  18. 25
    7
      server/sonar-web/src/main/js/helpers/__tests__/measures-test.js
  19. 20
    1
      server/sonar-web/src/main/js/helpers/__tests__/path-test.js
  20. 21
    5
      server/sonar-web/src/main/js/helpers/__tests__/urls-test.js
  21. 39
    0
      server/sonar-web/src/main/js/main/nav/__tests__/nav-test.js
  22. 0
    36
      server/sonar-web/tests/apps/projects-test.js
  23. 0
    56
      server/sonar-web/tests/components/charts/bar-chart-test.js
  24. 0
    40
      server/sonar-web/tests/components/charts/bubble-chart-test.js
  25. 0
    42
      server/sonar-web/tests/components/charts/line-chart-test.js
  26. 0
    21
      server/sonar-web/tests/components/charts/treemap-test.js
  27. 0
    20
      server/sonar-web/tests/components/charts/work-cloud-test.js
  28. 0
    90
      server/sonar-web/tests/components/source-viewer-test.js
  29. 0
    22
      server/sonar-web/tests/nav-test.js

+ 1
- 1
server/sonar-web/package.json View File

@@ -85,7 +85,7 @@
"scripts": {
"build-fast": "gulp build:dev",
"build": "gulp build",
"test": "mocha --opts tests/mocha.opts tests",
"test": "mocha --opts tests/mocha.opts src/main/js/**/__tests__/**/*",
"coverage": "babel-node node_modules/.bin/isparta cover --root 'src/main/js' --include-all-sources --excludes '**/libs/**' --dir 'target/coverage' node_modules/.bin/_mocha -- --opts tests/mocha.opts tests",
"lint": "eslint src/main/js && jscs src/main/js",
"dev": "NODE_ENV=hot node devServer"

+ 3
- 1
server/sonar-web/pom.xml View File

@@ -14,7 +14,9 @@
<properties>
<!-- self-analysis -->
<sonar.sources>src/main/js,src/main/less</sonar.sources>
<sonar.exclusions>src/main/js/libs/third-party/**/*,src/main/js/libs/require.js</sonar.exclusions>
<sonar.tests>src/main/js</sonar.tests>
<sonar.test.inclusions>src/main/js/**/__tests__/**</sonar.test.inclusions>
<sonar.exclusions>src/main/js/libs/third-party/**/*,src/main/js/libs/require.js,src/main/js/**/__tests__/**</sonar.exclusions>
<npm.script>build</npm.script>
</properties>

server/sonar-web/tests/apps/background-tasks-test.js → server/sonar-web/src/main/js/apps/background-tasks/__tests__/background-tasks-test.js View File

@@ -1,19 +1,35 @@
/* eslint no-unused-expressions: 0 */
/*
* SonarQube
* Copyright (C) 2009-2016 SonarSource SA
* mailto:contact AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
import React from 'react';
import ReactDOM from 'react-dom';
import TestUtils from 'react-addons-test-utils';
import chai, { expect } from 'chai';
import sinon from 'sinon';
import sinonChai from 'sinon-chai';

import Header from '../../src/main/js/apps/background-tasks/components/Header';
import Stats from '../../src/main/js/apps/background-tasks/components/Stats';
import Search from '../../src/main/js/apps/background-tasks/components/Search';
import Tasks from '../../src/main/js/apps/background-tasks/components/Tasks';
import { STATUSES, CURRENTS, DEBOUNCE_DELAY, DEFAULT_FILTERS } from '../../src/main/js/apps/background-tasks/constants';
import { formatDuration } from '../../src/main/js/apps/background-tasks/utils';
import Stats from '../components/Stats';
import Search from '../components/Search';
import { STATUSES, CURRENTS, DEBOUNCE_DELAY, DEFAULT_FILTERS } from '../constants';
import { formatDuration } from '../utils';

let chai = require('chai');
let expect = chai.expect;
let sinon = require('sinon');
chai.use(require('sinon-chai'));
chai.use(sinonChai);

describe('Background Tasks', function () {
describe('Constants', () => {
@@ -38,41 +54,41 @@ describe('Background Tasks', function () {
};

it('should render search form', () => {
let component = TestUtils.renderIntoDocument(
const component = TestUtils.renderIntoDocument(
<Search {...defaultProps}/>
);
let searchBox = TestUtils.scryRenderedDOMComponentsWithClass(component, 'js-search');
const searchBox = TestUtils.scryRenderedDOMComponentsWithClass(component, 'js-search');
expect(searchBox).to.have.length(1);
});

it('should not render search form', () => {
let component = TestUtils.renderIntoDocument(
const component = TestUtils.renderIntoDocument(
<Search {...defaultProps} component={{ id: 'ABCD' }}/>
);
let searchBox = TestUtils.scryRenderedDOMComponentsWithClass(component, 'js-search');
const searchBox = TestUtils.scryRenderedDOMComponentsWithClass(component, 'js-search');
expect(searchBox).to.be.empty;
});

it('should search', (done) => {
let searchSpy = sinon.spy();
let component = TestUtils.renderIntoDocument(
const searchSpy = sinon.spy();
const component = TestUtils.renderIntoDocument(
<Search {...defaultProps} onFilterUpdate={searchSpy}/>);
let searchInput = ReactDOM.findDOMNode(
const searchInput = ReactDOM.findDOMNode(
TestUtils.findRenderedDOMComponentWithClass(component, 'js-search'));
searchInput.value = 'some search query';
TestUtils.Simulate.change(searchInput);
setTimeout(() => {
expect(searchSpy).to.have.been.calledWith({ query: "some search query" });
expect(searchSpy).to.have.been.calledWith({ query: 'some search query' });
done();
}, DEBOUNCE_DELAY);
});

it('should reload', () => {
let reloadSpy = sinon.spy();
let component = TestUtils.renderIntoDocument(
const reloadSpy = sinon.spy();
const component = TestUtils.renderIntoDocument(
<Search {...defaultProps} onReload={reloadSpy}/>
);
let reloadButton = component.refs.reloadButton;
const reloadButton = component.refs.reloadButton;
expect(reloadSpy).to.not.have.been.called;
TestUtils.Simulate.click(reloadButton);
expect(reloadSpy).to.have.been.called;
@@ -82,33 +98,33 @@ describe('Background Tasks', function () {
describe('Stats', () => {
describe('Pending', () => {
it('should show zero pending', () => {
let result = TestUtils.renderIntoDocument(<Stats pendingCount={0}/>);
let pendingCounter = result.refs.pendingCount;
const result = TestUtils.renderIntoDocument(<Stats pendingCount={0}/>);
const pendingCounter = result.refs.pendingCount;
expect(pendingCounter.textContent).to.contain('0');
});

it('should show 5 pending', () => {
let result = TestUtils.renderIntoDocument(<Stats pendingCount={5}/>);
let pendingCounter = result.refs.pendingCount;
const result = TestUtils.renderIntoDocument(<Stats pendingCount={5}/>);
const pendingCounter = result.refs.pendingCount;
expect(pendingCounter.textContent).to.contain('5');
});

it('should not show cancel pending button', () => {
let result = TestUtils.renderIntoDocument(<Stats pendingCount={0}/>);
let cancelPending = result.refs.cancelPending;
const result = TestUtils.renderIntoDocument(<Stats pendingCount={0}/>);
const cancelPending = result.refs.cancelPending;
expect(cancelPending).to.not.be.ok;
});

it('should show cancel pending button', () => {
let result = TestUtils.renderIntoDocument(<Stats pendingCount={5}/>);
let cancelPending = result.refs.cancelPending;
const result = TestUtils.renderIntoDocument(<Stats pendingCount={5}/>);
const cancelPending = result.refs.cancelPending;
expect(cancelPending).to.be.ok;
});

it('should trigger cancelling pending', () => {
let spy = sinon.spy();
let result = TestUtils.renderIntoDocument(<Stats pendingCount={5} onCancelAllPending={spy}/>);
let cancelPending = result.refs.cancelPending;
const spy = sinon.spy();
const result = TestUtils.renderIntoDocument(<Stats pendingCount={5} onCancelAllPending={spy}/>);
const cancelPending = result.refs.cancelPending;
expect(spy).to.not.have.been.called;
TestUtils.Simulate.click(cancelPending);
expect(spy).to.have.been.called;
@@ -117,33 +133,33 @@ describe('Background Tasks', function () {

describe('Failures', () => {
it('should show zero failures', () => {
let result = TestUtils.renderIntoDocument(<Stats failingCount={0}/>);
let failureCounter = result.refs.failureCount;
const result = TestUtils.renderIntoDocument(<Stats failingCount={0}/>);
const failureCounter = result.refs.failureCount;
expect(failureCounter.textContent).to.contain('0');
});

it('should show 5 failures', () => {
let result = TestUtils.renderIntoDocument(<Stats failingCount={5}/>);
let failureCounter = result.refs.failureCount;
const result = TestUtils.renderIntoDocument(<Stats failingCount={5}/>);
const failureCounter = result.refs.failureCount;
expect(failureCounter.textContent).to.contain('5');
});

it('should not show link to failures', () => {
let result = TestUtils.renderIntoDocument(<Stats failingCount={0}/>);
let failureCounter = result.refs.failureCount;
const result = TestUtils.renderIntoDocument(<Stats failingCount={0}/>);
const failureCounter = result.refs.failureCount;
expect(failureCounter.tagName.toLowerCase()).to.not.equal('a');
});

it('should show link to failures', () => {
let result = TestUtils.renderIntoDocument(<Stats failingCount={5}/>);
let failureCounter = result.refs.failureCount;
const result = TestUtils.renderIntoDocument(<Stats failingCount={5}/>);
const failureCounter = result.refs.failureCount;
expect(failureCounter.tagName.toLowerCase()).to.equal('a');
});

it('should trigger filtering failures', () => {
let spy = sinon.spy();
let result = TestUtils.renderIntoDocument(<Stats failingCount={5} onShowFailing={spy}/>);
let failureCounter = result.refs.failureCount;
const spy = sinon.spy();
const result = TestUtils.renderIntoDocument(<Stats failingCount={5} onShowFailing={spy}/>);
const failureCounter = result.refs.failureCount;
expect(spy).to.not.have.been.called;
TestUtils.Simulate.click(failureCounter);
expect(spy).to.have.been.called;

server/sonar-web/tests/apps/overview/components/App-test.js → server/sonar-web/src/main/js/apps/overview/components/__tests__/App-test.js View File

@@ -21,9 +21,9 @@ import React from 'react';
import { expect } from 'chai';
import { shallow } from 'enzyme';

import App from '../../../../src/main/js/apps/overview/components/App';
import OverviewApp from '../../../../src/main/js/apps/overview/components/OverviewApp';
import EmptyOverview from '../../../../src/main/js/apps/overview/components/EmptyOverview';
import App from '../App';
import OverviewApp from '../OverviewApp';
import EmptyOverview from '../EmptyOverview';

describe('Overview :: App', () => {
it('should render OverviewApp', () => {

server/sonar-web/tests/apps/overview/components/EmptyOverview-test.js → server/sonar-web/src/main/js/apps/overview/components/__tests__/EmptyOverview-test.js View File

@@ -21,7 +21,7 @@ import React from 'react';
import { expect } from 'chai';
import { shallow } from 'enzyme';

import EmptyOverview from '../../../../src/main/js/apps/overview/components/EmptyOverview';
import EmptyOverview from '../EmptyOverview';

describe('Overview :: EmptyOverview', () => {
it('should render component key', () => {

server/sonar-web/tests/apps/overview/qualityGate/QualityGateCondition-test.js → server/sonar-web/src/main/js/apps/overview/qualityGate/__tests__/QualityGateCondition-test.js View File

@@ -21,8 +21,8 @@ import React from 'react';
import { expect } from 'chai';
import { shallow } from 'enzyme';

import QualityGateCondition from '../../../../src/main/js/apps/overview/qualityGate/QualityGateCondition';
import { DrilldownLink } from '../../../../src/main/js/components/shared/drilldown-link';
import QualityGateCondition from '../QualityGateCondition';
import { DrilldownLink } from '../../../../components/shared/drilldown-link';

describe('Overview :: QualityGateCondition', () => {
it('should render DrilldownLink', () => {

server/sonar-web/tests/apps/permission-templates-test.js → server/sonar-web/src/main/js/apps/permission-templates/__tests__/permission-templates-test.js View File

@@ -1,19 +1,37 @@
/*
* SonarQube
* Copyright (C) 2009-2016 SonarSource SA
* mailto:contact AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
/* eslint no-unused-expressions: 0 */
import React from 'react';
import TestUtils from 'react-addons-test-utils';
import { expect } from 'chai';
import sinon from 'sinon';

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');
import Defaults from '../permission-template-defaults';
import SetDefaults from '../permission-template-set-defaults';

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

it('should display two qualifiers', () => {
let permissionTemplate = { defaultFor: ['TRK', 'VW'] },
topQualifiers = ['TRK', 'VW'];
let result = TestUtils.renderIntoDocument(
const permissionTemplate = { defaultFor: ['TRK', 'VW'] };
const topQualifiers = ['TRK', 'VW'];
const result = TestUtils.renderIntoDocument(
<Defaults permissionTemplate={permissionTemplate} topQualifiers={topQualifiers}/>
);
expect(TestUtils.scryRenderedDOMComponentsWithClass(result, 'icon-qualifier-trk')).to.have.length(1);
@@ -31,9 +49,9 @@ describe('Permission Templates', function () {
});

it('should not display qualifiers', () => {
let permissionTemplate = { defaultFor: [] },
topQualifiers = ['TRK', 'VW'];
let result = TestUtils.renderIntoDocument(
const permissionTemplate = { defaultFor: [] };
const topQualifiers = ['TRK', 'VW'];
const result = TestUtils.renderIntoDocument(
<Defaults permissionTemplate={permissionTemplate} topQualifiers={topQualifiers}/>
);
expect(TestUtils.scryRenderedDOMComponentsWithClass(result, 'icon-qualifier-trk')).to.be.empty;
@@ -41,9 +59,9 @@ describe('Permission Templates', function () {
});

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

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

it('should display a dropdown with one option', () => {
let permissionTemplate = { defaultFor: ['VW'] },
topQualifiers = ['TRK', 'VW'];
let result = TestUtils.renderIntoDocument(
const permissionTemplate = { defaultFor: ['VW'] };
const topQualifiers = ['TRK', 'VW'];
const result = TestUtils.renderIntoDocument(
<SetDefaults permissionTemplate={permissionTemplate} topQualifiers={topQualifiers} refresh={refresh}/>
);
expect(TestUtils.scryRenderedDOMComponentsWithClass(result, 'dropdown')).to.have.length(1);
@@ -64,9 +82,9 @@ describe('Permission Templates', function () {
});

it('should display a dropdown with two options', () => {
let permissionTemplate = { defaultFor: [] },
topQualifiers = ['TRK', 'VW'];
let result = TestUtils.renderIntoDocument(
const permissionTemplate = { defaultFor: [] };
const topQualifiers = ['TRK', 'VW'];
const result = TestUtils.renderIntoDocument(
<SetDefaults permissionTemplate={permissionTemplate} topQualifiers={topQualifiers} refresh={refresh}/>
);
expect(TestUtils.scryRenderedDOMComponentsWithClass(result, 'dropdown')).to.have.length(1);
@@ -74,9 +92,9 @@ describe('Permission Templates', function () {
});

it('should not display a dropdown', () => {
let permissionTemplate = { defaultFor: ['TRK', 'VW'] },
topQualifiers = ['TRK', 'VW'];
let result = TestUtils.renderIntoDocument(
const permissionTemplate = { defaultFor: ['TRK', 'VW'] };
const topQualifiers = ['TRK', 'VW'];
const result = TestUtils.renderIntoDocument(
<SetDefaults permissionTemplate={permissionTemplate} topQualifiers={topQualifiers} refresh={refresh}/>
);
expect(TestUtils.scryRenderedDOMComponentsWithClass(result, 'dropdown')).to.be.empty;
@@ -84,9 +102,9 @@ describe('Permission Templates', function () {
});

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

+ 54
- 0
server/sonar-web/src/main/js/apps/projects/__tests__/projects-test.js View File

@@ -0,0 +1,54 @@
/*
* SonarQube
* Copyright (C) 2009-2016 SonarSource SA
* mailto:contact AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
import React from 'react';
import TestUtils from 'react-addons-test-utils';
import { expect } from 'chai';
import sinon from 'sinon';

import Projects from '../projects';

describe('Projects', function () {
describe('Projects', () => {
it('should render list of projects with no selection', () => {
const projects = [
{ id: '1', key: 'a', name: 'A', qualifier: 'TRK' },
{ id: '2', key: 'b', name: 'B', qualifier: 'TRK' }
];

const result = TestUtils.renderIntoDocument(
<Projects projects={projects} selection={[]} refresh={sinon.spy()}/>);
expect(TestUtils.scryRenderedDOMComponentsWithTag(result, 'tr')).to.have.length(2);
expect(TestUtils.scryRenderedDOMComponentsWithClass(result, 'icon-checkbox-checked')).to.be.empty;
});

it('should render list of projects with one selected', () => {
const projects = [
{ id: '1', key: 'a', name: 'A', qualifier: 'TRK' },
{ id: '2', key: 'b', name: 'B', qualifier: 'TRK' }
];
const selection = ['1'];

const result = TestUtils.renderIntoDocument(
<Projects projects={projects} selection={selection} refresh={sinon.spy()}/>);
expect(TestUtils.scryRenderedDOMComponentsWithTag(result, 'tr')).to.have.length(2);
expect(TestUtils.scryRenderedDOMComponentsWithClass(result, 'icon-checkbox-checked')).to.have.length(1);
});
});
});

server/sonar-web/tests/apps/system-test.js → server/sonar-web/src/main/js/apps/system/__tests__/system-test.js View File

@@ -1,53 +1,72 @@
/*
* SonarQube
* Copyright (C) 2009-2016 SonarSource SA
* mailto:contact AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
import React from 'react';
import ReactDOM from 'react-dom';
import TestUtils from 'react-addons-test-utils';
import { expect } from 'chai';

import ItemValue from '../../src/main/js/apps/system/item-value';

let expect = require('chai').expect;
let sinon = require('sinon');
import ItemValue from '../item-value';

describe('System', function () {

describe('Item Value', function () {
it('should render string', () => {
let result = TestUtils.renderIntoDocument(<ItemValue value="/some/path/as/an/example"/>);
let content = ReactDOM.findDOMNode(TestUtils.findRenderedDOMComponentWithTag(result, 'code'));
const result = TestUtils.renderIntoDocument(<ItemValue value="/some/path/as/an/example"/>);
const content = ReactDOM.findDOMNode(TestUtils.findRenderedDOMComponentWithTag(result, 'code'));
expect(content.textContent).to.equal('/some/path/as/an/example');
});

it('should render `true`', () => {
let result = TestUtils.renderIntoDocument(<ItemValue value={true}/>);
const result = TestUtils.renderIntoDocument(<ItemValue value={true}/>);
TestUtils.findRenderedDOMComponentWithClass(result, 'icon-check');
});

it('should render `false`', () => {
let result = TestUtils.renderIntoDocument(<ItemValue value={false}/>);
const result = TestUtils.renderIntoDocument(<ItemValue value={false}/>);
TestUtils.findRenderedDOMComponentWithClass(result, 'icon-delete');
});

it('should render object', () => {
let result = TestUtils.renderIntoDocument(<ItemValue value={{ name: 'Java', version: '3.2' }}/>);
const result = TestUtils.renderIntoDocument(<ItemValue value={{ name: 'Java', version: '3.2' }}/>);
TestUtils.findRenderedDOMComponentWithTag(result, 'table');
expect(TestUtils.scryRenderedDOMComponentsWithTag(result, 'tr')).to.have.length(2);
});

it('should render `true` inside object', () => {
let result = TestUtils.renderIntoDocument(<ItemValue value={{ name: 'Java', isCool: true }}/>);
const result = TestUtils.renderIntoDocument(<ItemValue value={{ name: 'Java', isCool: true }}/>);
TestUtils.findRenderedDOMComponentWithTag(result, 'table');
TestUtils.findRenderedDOMComponentWithClass(result, 'icon-check');
});

it('should render object inside object', () => {
let result = TestUtils.renderIntoDocument(
<ItemValue value={{ users: { docs: 1, shards: 5 }, tests: { docs: 68, shards: 5 } }}/>);
const result = TestUtils.renderIntoDocument(
<ItemValue value={{ users: { docs: 1, shards: 5 }, tests: { docs: 68, shards: 5 } }}/>);
expect(TestUtils.scryRenderedDOMComponentsWithTag(result, 'table')).to.have.length(3);
expect(TestUtils.scryRenderedDOMComponentsWithTag(result, 'tr')).to.have.length(6);
});
});

describe('Log Level', function () {
var previousFetch, fetchUrl, fetchOptions;
let previousFetch;
let fetchUrl;
let fetchOptions;

before(function () {
previousFetch = window.fetch;
@@ -63,30 +82,30 @@ describe('System', function () {
});

it('should render select box', () => {
let result = TestUtils.renderIntoDocument(<ItemValue value="INFO" name="Logs Level"/>);
const result = TestUtils.renderIntoDocument(<ItemValue value="INFO" name="Logs Level"/>);
TestUtils.findRenderedDOMComponentWithTag(result, 'select');
expect(TestUtils.scryRenderedDOMComponentsWithTag(result, 'option')).to.have.length(3);
});

it('should set initial value', () => {
let result = TestUtils.renderIntoDocument(<ItemValue value="DEBUG" name="Logs Level"/>);
let select = ReactDOM.findDOMNode(TestUtils.findRenderedDOMComponentWithTag(result, 'select'));
const result = TestUtils.renderIntoDocument(<ItemValue value="DEBUG" name="Logs Level"/>);
const select = ReactDOM.findDOMNode(TestUtils.findRenderedDOMComponentWithTag(result, 'select'));
expect(select.value).to.equal('DEBUG');
});

it('should render warning', () => {
let result = TestUtils.renderIntoDocument(<ItemValue value="DEBUG" name="Logs Level"/>);
const result = TestUtils.renderIntoDocument(<ItemValue value="DEBUG" name="Logs Level"/>);
TestUtils.findRenderedDOMComponentWithClass(result, 'alert');
});

it('should not render warning', () => {
let result = TestUtils.renderIntoDocument(<ItemValue value="INFO" name="Logs Level"/>);
const result = TestUtils.renderIntoDocument(<ItemValue value="INFO" name="Logs Level"/>);
expect(TestUtils.scryRenderedDOMComponentsWithClass(result, 'alert')).to.be.empty;
});

it('should change value', () => {
let result = TestUtils.renderIntoDocument(<ItemValue value="INFO" name="Logs Level"/>);
let select = ReactDOM.findDOMNode(TestUtils.findRenderedDOMComponentWithTag(result, 'select'));
const result = TestUtils.renderIntoDocument(<ItemValue value="INFO" name="Logs Level"/>);
const select = ReactDOM.findDOMNode(TestUtils.findRenderedDOMComponentWithTag(result, 'select'));
select.value = 'TRACE';
TestUtils.Simulate.change(select);
expect(fetchUrl).to.equal('/api/system/change_log_level');

server/sonar-web/tests/components/issue-test.js → server/sonar-web/src/main/js/components/__tests__/issue-test.js View File

@@ -1,68 +1,86 @@
import Issue from '../../src/main/js/components/issue/models/issue';

let sinon = require('sinon'),
sinonChai = require('sinon-chai'),
chai = require('chai'),
expect = chai.expect;
/*
* SonarQube
* Copyright (C) 2009-2016 SonarSource SA
* mailto:contact AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
import chai, { expect } from 'chai';
import sinon from 'sinon';
import sinonChai from 'sinon-chai';

import Issue from '../issue/models/issue';

chai.use(sinonChai);

describe('Issue', function () {
describe('Model', function () {
it('should have correct urlRoot', function () {
var issue = new Issue();
const issue = new Issue();
expect(issue.urlRoot()).to.equal('/api/issues');
});

it('should parse response without root issue object', function () {
var issue = new Issue();
var example = { a: 1 };
const issue = new Issue();
const example = { a: 1 };
expect(issue.parse(example)).to.deep.equal(example);
});

it('should parse response with the root issue object', function () {
var issue = new Issue();
var example = { a: 1 };
const issue = new Issue();
const example = { a: 1 };
expect(issue.parse({ issue: example })).to.deep.equal(example);
});

it('should reset attributes (no attributes initially)', function () {
var issue = new Issue();
var example = { a: 1 };
const issue = new Issue();
const example = { a: 1 };
issue.reset(example);
expect(issue.toJSON()).to.deep.equal(example);
});

it('should reset attributes (override attribute)', function () {
var issue = new Issue({ a: 2 });
var example = { a: 1 };
const issue = new Issue({ a: 2 });
const example = { a: 1 };
issue.reset(example);
expect(issue.toJSON()).to.deep.equal(example);
});

it('should reset attributes (different attributes)', function () {
var issue = new Issue({ a: 2 });
var example = { b: 1 };
const issue = new Issue({ a: 2 });
const example = { b: 1 };
issue.reset(example);
expect(issue.toJSON()).to.deep.equal(example);
});

it('should unset `textRange` of a closed issue', function () {
var issue = new Issue();
var result = issue.parse({ issue: { status: 'CLOSED', textRange: { startLine: 5 } } });
const issue = new Issue();
const result = issue.parse({ issue: { status: 'CLOSED', textRange: { startLine: 5 } } });
expect(result.textRange).to.not.be.ok;
});

it('should unset `flows` of a closed issue', function () {
var issue = new Issue();
var result = issue.parse({ issue: { status: 'CLOSED', flows: [1, 2, 3] } });
const issue = new Issue();
const result = issue.parse({ issue: { status: 'CLOSED', flows: [1, 2, 3] } });
expect(result.flows).to.deep.equal([]);
});

describe('Actions', function () {
it('should assign', function () {
var issue = new Issue({ key: 'issue-key' });
var spy = sinon.spy();
const issue = new Issue({ key: 'issue-key' });
const spy = sinon.spy();
issue._action = spy;
issue.assign('admin');
expect(spy).to.have.been.calledWith({
@@ -72,8 +90,8 @@ describe('Issue', function () {
});

it('should unassign', function () {
var issue = new Issue({ key: 'issue-key' });
var spy = sinon.spy();
const issue = new Issue({ key: 'issue-key' });
const spy = sinon.spy();
issue._action = spy;
issue.assign();
expect(spy).to.have.been.calledWith({
@@ -83,24 +101,24 @@ describe('Issue', function () {
});

it('should plan', function () {
var issue = new Issue({ key: 'issue-key' });
var spy = sinon.spy();
const issue = new Issue({ key: 'issue-key' });
const spy = sinon.spy();
issue._action = spy;
issue.plan('plan');
expect(spy).to.have.been.calledWith({ data: { plan: 'plan', issue: 'issue-key' }, url: '/api/issues/plan' });
});

it('should unplan', function () {
var issue = new Issue({ key: 'issue-key' });
var spy = sinon.spy();
const issue = new Issue({ key: 'issue-key' });
const spy = sinon.spy();
issue._action = spy;
issue.plan();
expect(spy).to.have.been.calledWith({ data: { plan: undefined, issue: 'issue-key' }, url: '/api/issues/plan' });
});

it('should set severity', function () {
var issue = new Issue({ key: 'issue-key' });
var spy = sinon.spy();
const issue = new Issue({ key: 'issue-key' });
const spy = sinon.spy();
issue._action = spy;
issue.setSeverity('BLOCKER');
expect(spy).to.have.been.calledWith({
@@ -112,8 +130,8 @@ describe('Issue', function () {

describe('#getLinearLocations', function () {
it('should return single line location', function () {
var issue = new Issue({ textRange: { startLine: 1, endLine: 1, startOffset: 0, endOffset: 10 } }),
locations = issue.getLinearLocations();
const issue = new Issue({ textRange: { startLine: 1, endLine: 1, startOffset: 0, endOffset: 10 } });
const locations = issue.getLinearLocations();
expect(locations.length).to.equal(1);

expect(locations[0].line).to.equal(1);
@@ -122,8 +140,8 @@ describe('Issue', function () {
});

it('should return location not from 0', function () {
var issue = new Issue({ textRange: { startLine: 1, endLine: 1, startOffset: 5, endOffset: 10 } }),
locations = issue.getLinearLocations();
const issue = new Issue({ textRange: { startLine: 1, endLine: 1, startOffset: 5, endOffset: 10 } });
const locations = issue.getLinearLocations();
expect(locations.length).to.equal(1);

expect(locations[0].line).to.equal(1);
@@ -132,8 +150,8 @@ describe('Issue', function () {
});

it('should return 2-lines location', function () {
var issue = new Issue({ textRange: { startLine: 2, endLine: 3, startOffset: 5, endOffset: 10 } }),
locations = issue.getLinearLocations();
const issue = new Issue({ textRange: { startLine: 2, endLine: 3, startOffset: 5, endOffset: 10 } });
const locations = issue.getLinearLocations();
expect(locations.length).to.equal(2);

expect(locations[0].line).to.equal(2);
@@ -146,8 +164,8 @@ describe('Issue', function () {
});

it('should return 3-lines location', function () {
var issue = new Issue({ textRange: { startLine: 4, endLine: 6, startOffset: 5, endOffset: 10 } }),
locations = issue.getLinearLocations();
const issue = new Issue({ textRange: { startLine: 4, endLine: 6, startOffset: 5, endOffset: 10 } });
const locations = issue.getLinearLocations();
expect(locations.length).to.equal(3);

expect(locations[0].line).to.equal(4);
@@ -164,8 +182,8 @@ describe('Issue', function () {
});

it('should return [] when no location', function () {
var issue = new Issue(),
locations = issue.getLinearLocations();
const issue = new Issue();
const locations = issue.getLinearLocations();
expect(locations.length).to.equal(0);
});
});

+ 109
- 0
server/sonar-web/src/main/js/components/__tests__/source-viewer-test.js View File

@@ -0,0 +1,109 @@
/*
* SonarQube
* Copyright (C) 2009-2016 SonarSource SA
* mailto:contact AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
import { expect } from 'chai';

import helper from '../source-viewer/helpers/code-with-issue-locations-helper';

describe('Source Viewer', function () {
describe('Code With Issue Locations Helper', function () {
it('should be a function', function () {
expect(helper).to.be.a('function');
});

it('should mark one location', function () {
const code = '<span class="k">if</span> (<span class="sym-2 sym">a</span> + <span class="c">1</span>) {';
const locations = [{ from: 1, to: 5 }];
const result = helper(code, locations, 'x');
expect(result).to.equal([
'<span class="k">i</span>',
'<span class="k x">f</span>',
'<span class=" x"> (</span>',
'<span class="sym-2 sym x">a</span>',
'<span class=""> + </span>',
'<span class="c">1</span>',
'<span class="">) {</span>'
].join(''));
});

it('should mark two locations', function () {
const code = 'abcdefghijklmnopqrst';
const locations = [
{ from: 1, to: 6 },
{ from: 11, to: 16 }
];
const result = helper(code, locations, 'x');
expect(result).to.equal([
'<span class="">a</span>',
'<span class=" x">bcdef</span>',
'<span class="">ghijk</span>',
'<span class=" x">lmnop</span>',
'<span class="">qrst</span>'
].join(''));
});

it('should mark one locations', function () {
const code = '<span class="cppd"> * Copyright (C) 2008-2014 SonarSource</span>';
const locations = [{ from: 15, to: 20 }];
const result = helper(code, locations, 'x');
expect(result).to.equal([
'<span class="cppd"> * Copyright (C</span>',
'<span class="cppd x">) 200</span>',
'<span class="cppd">8-2014 SonarSource</span>'
].join(''));
});

it('should mark two locations', function () {
const code = '<span class="cppd"> * Copyright (C) 2008-2014 SonarSource</span>';
const locations = [
{ from: 24, to: 29 },
{ from: 15, to: 20 }
];
const result = helper(code, locations, 'x');
expect(result).to.equal([
'<span class="cppd"> * Copyright (C</span>',
'<span class="cppd x">) 200</span>',
'<span class="cppd">8-20</span>',
'<span class="cppd x">14 So</span>',
'<span class="cppd">narSource</span>'
].join(''));
});

it('should parse line with < and >', function () {
const code = '<span class="j">#include &lt;stdio.h&gt;</span>';
const result = helper(code, []);
expect(result).to.equal('<span class="j">#include &lt;stdio.h&gt;</span>');
});

it('should parse syntax and usage highlighting', function () {
const code = '<span class="k"><span class="sym-3 sym">this</span></span>';
const expected = '<span class="k sym-3 sym">this</span>';
const result = helper(code, []);
expect(result).to.equal(expected);
});

it('should parse nested tags', function () {
const code = '<span class="k"><span class="sym-3 sym">this</span> is</span>';
const expected = '<span class="k sym-3 sym">this</span><span class="k"> is</span>';
const result = helper(code, []);
expect(result).to.equal(expected);
});
});
});


+ 97
- 0
server/sonar-web/src/main/js/components/charts/__tests__/bar-chart-test.js View File

@@ -0,0 +1,97 @@
/*
* SonarQube
* Copyright (C) 2009-2016 SonarSource SA
* mailto:contact AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
import React from 'react';
import TestUtils from 'react-addons-test-utils';
import { expect } from 'chai';

import { BarChart } from '../bar-chart';

describe('Bar Chart', function () {

it('should display bars', function () {
const data = [
{ x: 1, y: 10 },
{ x: 2, y: 30 },
{ x: 3, y: 20 }
];
const chart = TestUtils.renderIntoDocument(
<BarChart
data={data}
width={100}
height={100}
barsWidth={20}/>);
expect(TestUtils.scryRenderedDOMComponentsWithClass(chart, 'bar-chart-bar')).to.have.length(3);
});

it('should display ticks', function () {
const data = [
{ x: 1, y: 10 },
{ x: 2, y: 30 },
{ x: 3, y: 20 }
];
const ticks = ['A', 'B', 'C'];
const chart = TestUtils.renderIntoDocument(
<BarChart
data={data}
xTicks={ticks}
width={100}
height={100}
barsWidth={20}/>);
expect(TestUtils.scryRenderedDOMComponentsWithClass(chart, 'bar-chart-tick')).to.have.length(3);
});

it('should display values', function () {
const data = [
{ x: 1, y: 10 },
{ x: 2, y: 30 },
{ x: 3, y: 20 }
];
const values = ['A', 'B', 'C'];
const chart = TestUtils.renderIntoDocument(
<BarChart
data={data}
xValues={values}
width={100}
height={100}
barsWidth={20}/>);
expect(TestUtils.scryRenderedDOMComponentsWithClass(chart, 'bar-chart-tick')).to.have.length(3);
});

it('should display bars, ticks and values', function () {
const data = [
{ x: 1, y: 10 },
{ x: 2, y: 30 },
{ x: 3, y: 20 }
];
const ticks = ['A', 'B', 'C'];
const values = ['A', 'B', 'C'];
const chart = TestUtils.renderIntoDocument(
<BarChart
data={data}
xTicks={ticks}
xValues={values}
width={100}
height={100}
barsWidth={20}/>);
expect(TestUtils.scryRenderedDOMComponentsWithClass(chart, 'bar-chart-bar')).to.have.length(3);
expect(TestUtils.scryRenderedDOMComponentsWithClass(chart, 'bar-chart-tick')).to.have.length(6);
});

});

+ 58
- 0
server/sonar-web/src/main/js/components/charts/__tests__/bubble-chart-test.js View File

@@ -0,0 +1,58 @@
/*
* SonarQube
* Copyright (C) 2009-2016 SonarSource SA
* mailto:contact AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
import React from 'react';
import TestUtils from 'react-addons-test-utils';
import { expect } from 'chai';

import { BubbleChart } from '../bubble-chart';

describe('Bubble Chart', function () {

it('should display bubbles', function () {
const items = [
{ x: 1, y: 10, size: 7 },
{ x: 2, y: 30, size: 5 },
{ x: 3, y: 20, size: 2 }
];
const chart = TestUtils.renderIntoDocument(<BubbleChart items={items} width={100} height={100}/>);
expect(TestUtils.scryRenderedDOMComponentsWithClass(chart, 'bubble-chart-bubble')).to.have.length(3);
});

it('should display grid', function () {
const items = [
{ x: 1, y: 10, size: 7 },
{ x: 2, y: 30, size: 5 },
{ x: 3, y: 20, size: 2 }
];
const chart = TestUtils.renderIntoDocument(<BubbleChart items={items} width={100} height={100}/>);
expect(TestUtils.scryRenderedDOMComponentsWithTag(chart, 'line')).to.not.be.empty;
});

it('should display ticks', function () {
const items = [
{ x: 1, y: 10, size: 7 },
{ x: 2, y: 30, size: 5 },
{ x: 3, y: 20, size: 2 }
];
const chart = TestUtils.renderIntoDocument(<BubbleChart items={items} width={100} height={100}/>);
expect(TestUtils.scryRenderedDOMComponentsWithClass(chart, 'bubble-chart-tick')).to.not.be.empty;
});

});

+ 74
- 0
server/sonar-web/src/main/js/components/charts/__tests__/line-chart-test.js View File

@@ -0,0 +1,74 @@
/*
* SonarQube
* Copyright (C) 2009-2016 SonarSource SA
* mailto:contact AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
import React from 'react';
import TestUtils from 'react-addons-test-utils';
import { expect } from 'chai';

import { LineChart } from '../line-chart';

describe('Line Chart', function () {

it('should display line', function () {
const data = [
{ x: 1, y: 10 },
{ x: 2, y: 30 },
{ x: 3, y: 20 }
];
const chart = TestUtils.renderIntoDocument(
<LineChart
data={data}
width={100}
height={100}/>);
expect(TestUtils.scryRenderedDOMComponentsWithClass(chart, 'line-chart-path')).to.have.length(1);
});

it('should display ticks', function () {
const data = [
{ x: 1, y: 10 },
{ x: 2, y: 30 },
{ x: 3, y: 20 }
];
const ticks = ['A', 'B', 'C'];
const chart = TestUtils.renderIntoDocument(
<LineChart
data={data}
xTicks={ticks}
width={100}
height={100}/>);
expect(TestUtils.scryRenderedDOMComponentsWithClass(chart, 'line-chart-tick')).to.have.length(3);
});

it('should display values', function () {
const data = [
{ x: 1, y: 10 },
{ x: 2, y: 30 },
{ x: 3, y: 20 }
];
const values = ['A', 'B', 'C'];
const chart = TestUtils.renderIntoDocument(
<LineChart
data={data}
xValues={values}
width={100}
height={100}/>);
expect(TestUtils.scryRenderedDOMComponentsWithClass(chart, 'line-chart-tick')).to.have.length(3);
});

});

+ 44
- 0
server/sonar-web/src/main/js/components/charts/__tests__/treemap-test.js View File

@@ -0,0 +1,44 @@
/*
* SonarQube
* Copyright (C) 2009-2016 SonarSource SA
* mailto:contact AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
import React from 'react';
import TestUtils from 'react-addons-test-utils';
import { expect } from 'chai';

import { Treemap } from '../treemap';

describe('Treemap', function () {

it('should display', function () {
const items = [
{ size: 10, color: '#777', label: 'SonarQube :: Server' },
{ size: 30, color: '#777', label: 'SonarQube :: Web' },
{ size: 20, color: '#777', label: 'SonarQube :: Search' }
];
const chart = TestUtils.renderIntoDocument(
<Treemap
items={items}
width={100}
height={100}
breadcrumbs={[]}
canBeClicked={() => true}/>);
expect(TestUtils.scryRenderedDOMComponentsWithClass(chart, 'treemap-cell')).to.have.length(3);
});

});

+ 38
- 0
server/sonar-web/src/main/js/components/charts/__tests__/work-cloud-test.js View File

@@ -0,0 +1,38 @@
/*
* SonarQube
* Copyright (C) 2009-2016 SonarSource SA
* mailto:contact AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
import React from 'react';
import TestUtils from 'react-addons-test-utils';
import { expect } from 'chai';

import { WordCloud } from '../word-cloud';

describe('Word Cloud', function () {

it('should display', function () {
const items = [
{ size: 10, link: '#', text: 'SonarQube :: Server' },
{ size: 30, link: '#', text: 'SonarQube :: Web' },
{ size: 20, link: '#', text: 'SonarQube :: Search' }
];
const chart = TestUtils.renderIntoDocument(<WordCloud items={items} width={100} height={100}/>);
expect(TestUtils.scryRenderedDOMComponentsWithTag(chart, 'a')).to.have.length(3);
});

});

server/sonar-web/tests/helpers/l10n-test.js → server/sonar-web/src/main/js/helpers/__tests__/l10n-test.js View File

@@ -1,5 +1,24 @@
/*
* SonarQube
* Copyright (C) 2009-2016 SonarSource SA
* mailto:contact AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
import { expect } from 'chai';
import { resetBundle, translate, translateWithParameters } from '../../src/main/js/helpers/l10n';
import { resetBundle, translate, translateWithParameters } from '../l10n';

describe('l10n', () => {
afterEach(() => {

server/sonar-web/tests/helpers/measures-test.js → server/sonar-web/src/main/js/helpers/__tests__/measures-test.js View File

@@ -1,14 +1,32 @@
/*
* SonarQube
* Copyright (C) 2009-2016 SonarSource SA
* mailto:contact AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
import { expect } from 'chai';

import { resetBundle } from '../../src/main/js/helpers/l10n';
import { formatMeasure, formatMeasureVariation } from '../../src/main/js/helpers/measures';

import { resetBundle } from '../l10n';
import { formatMeasure, formatMeasureVariation } from '../measures';

describe('Measures', function () {
var HOURS_IN_DAY = 8,
ONE_MINUTE = 1,
ONE_HOUR = ONE_MINUTE * 60,
ONE_DAY = HOURS_IN_DAY * ONE_HOUR;
const HOURS_IN_DAY = 8;
const ONE_MINUTE = 1;
const ONE_HOUR = ONE_MINUTE * 60;
const ONE_DAY = HOURS_IN_DAY * ONE_HOUR;

before(function () {
resetBundle({

server/sonar-web/tests/helpers/path-test.js → server/sonar-web/src/main/js/helpers/__tests__/path-test.js View File

@@ -1,5 +1,24 @@
/*
* SonarQube
* Copyright (C) 2009-2016 SonarSource SA
* mailto:contact AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
import { expect } from 'chai';
import { collapsedDirFromPath, fileFromPath } from '../../src/main/js/helpers/path'
import { collapsedDirFromPath, fileFromPath } from '../path';

describe('Path', function () {
describe('#collapsedDirFromPath()', function () {

server/sonar-web/tests/helpers/urls-test.js → server/sonar-web/src/main/js/helpers/__tests__/urls-test.js View File

@@ -1,17 +1,33 @@
/*
* SonarQube
* Copyright (C) 2009-2016 SonarSource SA
* mailto:contact AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
import { expect } from 'chai';

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

import { getComponentUrl, getComponentIssuesUrl, getComponentDrilldownUrl } from '../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;
let oldBaseUrl;

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

+ 39
- 0
server/sonar-web/src/main/js/main/nav/__tests__/nav-test.js View File

@@ -0,0 +1,39 @@
/*
* SonarQube
* Copyright (C) 2009-2016 SonarSource SA
* mailto:contact AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
import React from 'react';
import TestUtils from 'react-addons-test-utils';
import { expect } from 'chai';

import ComponentNavBreadcrumbs from '../component/component-nav-breadcrumbs';

describe('Nav', function () {
describe('ComponentNavBreadcrumbs', () => {
it('should not render breadcrumbs with one element', function () {
const breadcrumbs = [
{ key: 'my-project', name: 'My Project', qualifier: 'TRK' }
];
const result = TestUtils.renderIntoDocument(
React.createElement(ComponentNavBreadcrumbs, { breadcrumbs })
);
expect(TestUtils.scryRenderedDOMComponentsWithTag(result, 'li')).to.have.length(1);
expect(TestUtils.scryRenderedDOMComponentsWithTag(result, 'a')).to.have.length(1);
});
});
});

+ 0
- 36
server/sonar-web/tests/apps/projects-test.js View File

@@ -1,36 +0,0 @@
import React from 'react';
import TestUtils from 'react-addons-test-utils';

import Projects from '../../src/main/js/apps/projects/projects';

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

describe('Projects', function () {
describe('Projects', () => {
it('should render list of projects with no selection', () => {
let projects = [
{ id: '1', key: 'a', name: 'A', qualifier: 'TRK' },
{ id: '2', key: 'b', name: 'B', qualifier: 'TRK' }
];

let result = TestUtils.renderIntoDocument(
<Projects projects={projects} selection={[]} refresh={sinon.spy()}/>);
expect(TestUtils.scryRenderedDOMComponentsWithTag(result, 'tr')).to.have.length(2);
expect(TestUtils.scryRenderedDOMComponentsWithClass(result, 'icon-checkbox-checked')).to.be.empty;
});

it('should render list of projects with one selected', () => {
let projects = [
{ id: '1', key: 'a', name: 'A', qualifier: 'TRK' },
{ id: '2', key: 'b', name: 'B', qualifier: 'TRK' }
],
selection = ['1'];

let result = TestUtils.renderIntoDocument(
<Projects projects={projects} selection={selection} refresh={sinon.spy()}/>);
expect(TestUtils.scryRenderedDOMComponentsWithTag(result, 'tr')).to.have.length(2);
expect(TestUtils.scryRenderedDOMComponentsWithClass(result, 'icon-checkbox-checked')).to.have.length(1);
});
});
});

+ 0
- 56
server/sonar-web/tests/components/charts/bar-chart-test.js View File

@@ -1,56 +0,0 @@
import React from 'react';
import TestUtils from 'react-addons-test-utils';
import { expect } from 'chai';

import { BarChart } from '../../../src/main/js/components/charts/bar-chart';


describe('Bar Chart', function () {

it('should display bars', function () {
const data = [
{ x: 1, y: 10 },
{ x: 2, y: 30 },
{ x: 3, y: 20 }
];
let chart = TestUtils.renderIntoDocument(<BarChart data={data} width={100} height={100} barsWidth={20}/>);
expect(TestUtils.scryRenderedDOMComponentsWithClass(chart, 'bar-chart-bar')).to.have.length(3);
});

it('should display ticks', function () {
const data = [
{ x: 1, y: 10 },
{ x: 2, y: 30 },
{ x: 3, y: 20 }
];
const ticks = ['A', 'B', 'C'];
let chart = TestUtils.renderIntoDocument(<BarChart data={data} xTicks={ticks} width={100} height={100} barsWidth={20}/>);
expect(TestUtils.scryRenderedDOMComponentsWithClass(chart, 'bar-chart-tick')).to.have.length(3);
});

it('should display values', function () {
const data = [
{ x: 1, y: 10 },
{ x: 2, y: 30 },
{ x: 3, y: 20 }
];
const values = ['A', 'B', 'C'];
let chart = TestUtils.renderIntoDocument(<BarChart data={data} xValues={values} width={100} height={100} barsWidth={20}/>);
expect(TestUtils.scryRenderedDOMComponentsWithClass(chart, 'bar-chart-tick')).to.have.length(3);
});

it('should display bars, ticks and values', function () {
const data = [
{ x: 1, y: 10 },
{ x: 2, y: 30 },
{ x: 3, y: 20 }
];
const ticks = ['A', 'B', 'C'];
const values = ['A', 'B', 'C'];
let chart = TestUtils.renderIntoDocument(
<BarChart data={data} xTicks={ticks} xValues={values} width={100} height={100} barsWidth={20}/>);
expect(TestUtils.scryRenderedDOMComponentsWithClass(chart, 'bar-chart-bar')).to.have.length(3);
expect(TestUtils.scryRenderedDOMComponentsWithClass(chart, 'bar-chart-tick')).to.have.length(6);
});

});

+ 0
- 40
server/sonar-web/tests/components/charts/bubble-chart-test.js View File

@@ -1,40 +0,0 @@
import React from 'react';
import TestUtils from 'react-addons-test-utils';
import { expect } from 'chai';

import { BubbleChart } from '../../../src/main/js/components/charts/bubble-chart';


describe('Bubble Chart', function () {

it('should display bubbles', function () {
const items = [
{ x: 1, y: 10, size: 7 },
{ x: 2, y: 30, size: 5 },
{ x: 3, y: 20, size: 2 }
];
let chart = TestUtils.renderIntoDocument(<BubbleChart items={items} width={100} height={100}/>);
expect(TestUtils.scryRenderedDOMComponentsWithClass(chart, 'bubble-chart-bubble')).to.have.length(3);
});

it('should display grid', function () {
const items = [
{ x: 1, y: 10, size: 7 },
{ x: 2, y: 30, size: 5 },
{ x: 3, y: 20, size: 2 }
];
let chart = TestUtils.renderIntoDocument(<BubbleChart items={items} width={100} height={100}/>);
expect(TestUtils.scryRenderedDOMComponentsWithTag(chart, 'line')).to.not.be.empty;
});

it('should display ticks', function () {
const items = [
{ x: 1, y: 10, size: 7 },
{ x: 2, y: 30, size: 5 },
{ x: 3, y: 20, size: 2 }
];
let chart = TestUtils.renderIntoDocument(<BubbleChart items={items} width={100} height={100}/>);
expect(TestUtils.scryRenderedDOMComponentsWithClass(chart, 'bubble-chart-tick')).to.not.be.empty;
});

});

+ 0
- 42
server/sonar-web/tests/components/charts/line-chart-test.js View File

@@ -1,42 +0,0 @@
import React from 'react';
import TestUtils from 'react-addons-test-utils';
import { expect } from 'chai';

import { LineChart } from '../../../src/main/js/components/charts/line-chart';


describe('Line Chart', function () {

it('should display line', function () {
const data = [
{ x: 1, y: 10 },
{ x: 2, y: 30 },
{ x: 3, y: 20 }
];
let chart = TestUtils.renderIntoDocument(<LineChart data={data} width={100} height={100}/>);
expect(TestUtils.scryRenderedDOMComponentsWithClass(chart, 'line-chart-path')).to.have.length(1);
});

it('should display ticks', function () {
const data = [
{ x: 1, y: 10 },
{ x: 2, y: 30 },
{ x: 3, y: 20 }
];
const ticks = ['A', 'B', 'C'];
let chart = TestUtils.renderIntoDocument(<LineChart data={data} xTicks={ticks} width={100} height={100}/>);
expect(TestUtils.scryRenderedDOMComponentsWithClass(chart, 'line-chart-tick')).to.have.length(3);
});

it('should display values', function () {
const data = [
{ x: 1, y: 10 },
{ x: 2, y: 30 },
{ x: 3, y: 20 }
];
const values = ['A', 'B', 'C'];
let chart = TestUtils.renderIntoDocument(<LineChart data={data} xValues={values} width={100} height={100}/>);
expect(TestUtils.scryRenderedDOMComponentsWithClass(chart, 'line-chart-tick')).to.have.length(3);
});

});

+ 0
- 21
server/sonar-web/tests/components/charts/treemap-test.js View File

@@ -1,21 +0,0 @@
import React from 'react';
import TestUtils from 'react-addons-test-utils';
import { expect } from 'chai';

import { Treemap } from '../../../src/main/js/components/charts/treemap';


describe('Treemap', function () {

it('should display', function () {
const items = [
{ size: 10, color: '#777', label: 'SonarQube :: Server' },
{ size: 30, color: '#777', label: 'SonarQube :: Web' },
{ size: 20, color: '#777', label: 'SonarQube :: Search' }
];
let chart = TestUtils.renderIntoDocument(
<Treemap items={items} width={100} height={100} breadcrumbs={[]} canBeClicked={() => true}/>);
expect(TestUtils.scryRenderedDOMComponentsWithClass(chart, 'treemap-cell')).to.have.length(3);
});

});

+ 0
- 20
server/sonar-web/tests/components/charts/work-cloud-test.js View File

@@ -1,20 +0,0 @@
import React from 'react';
import TestUtils from 'react-addons-test-utils';
import { expect } from 'chai';

import { WordCloud } from '../../../src/main/js/components/charts/word-cloud';


describe('Word Cloud', function () {

it('should display', function () {
const items = [
{ size: 10, link: '#', text: 'SonarQube :: Server' },
{ size: 30, link: '#', text: 'SonarQube :: Web' },
{ size: 20, link: '#', text: 'SonarQube :: Search' }
];
let chart = TestUtils.renderIntoDocument(<WordCloud items={items} width={100} height={100}/>);
expect(TestUtils.scryRenderedDOMComponentsWithTag(chart, 'a')).to.have.length(3);
});

});

+ 0
- 90
server/sonar-web/tests/components/source-viewer-test.js View File

@@ -1,90 +0,0 @@
import helper from '../../src/main/js/components/source-viewer/helpers/code-with-issue-locations-helper';

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

describe('Source Viewer', function () {
describe('Code With Issue Locations Helper', function () {
it('should be a function', function () {
expect(helper).to.be.a('function');
});

it('should mark one location', function () {
var code = '<span class="k">if</span> (<span class="sym-2 sym">a</span> + <span class="c">1</span>) {',
locations = [{ from: 1, to: 5 }],
result = helper(code, locations, 'x');
expect(result).to.equal([
'<span class="k">i</span>',
'<span class="k x">f</span>',
'<span class=" x"> (</span>',
'<span class="sym-2 sym x">a</span>',
'<span class=""> + </span>',
'<span class="c">1</span>',
'<span class="">) {</span>'
].join(''));
});

it('should mark two locations', function () {
var code = 'abcdefghijklmnopqrst',
locations = [
{ from: 1, to: 6 },
{ from: 11, to: 16 }
],
result = helper(code, locations, 'x');
expect(result).to.equal([
'<span class="">a</span>',
'<span class=" x">bcdef</span>',
'<span class="">ghijk</span>',
'<span class=" x">lmnop</span>',
'<span class="">qrst</span>'
].join(''));
});

it('should mark one locations', function () {
var code = '<span class="cppd"> * Copyright (C) 2008-2014 SonarSource</span>',
locations = [{ from: 15, to: 20 }],
result = helper(code, locations, 'x');
expect(result).to.equal([
'<span class="cppd"> * Copyright (C</span>',
'<span class="cppd x">) 200</span>',
'<span class="cppd">8-2014 SonarSource</span>'
].join(''));
});

it('should mark two locations', function () {
var code = '<span class="cppd"> * Copyright (C) 2008-2014 SonarSource</span>',
locations = [
{ from: 24, to: 29 },
{ from: 15, to: 20 }
],
result = helper(code, locations, 'x');
expect(result).to.equal([
'<span class="cppd"> * Copyright (C</span>',
'<span class="cppd x">) 200</span>',
'<span class="cppd">8-20</span>',
'<span class="cppd x">14 So</span>',
'<span class="cppd">narSource</span>'
].join(''));
});

it('should parse line with < and >', function () {
var code = '<span class="j">#include &lt;stdio.h&gt;</span>',
result = helper(code, []);
expect(result).to.equal('<span class="j">#include &lt;stdio.h&gt;</span>');
});

it('should parse syntax and usage highlighting', function () {
var code = '<span class="k"><span class="sym-3 sym">this</span></span>',
expected = '<span class="k sym-3 sym">this</span>',
result = helper(code, []);
expect(result).to.equal(expected);
});

it('should parse nested tags', function () {
var code = '<span class="k"><span class="sym-3 sym">this</span> is</span>',
expected = '<span class="k sym-3 sym">this</span><span class="k"> is</span>',
result = helper(code, []);
expect(result).to.equal(expected);
});
});
});


+ 0
- 22
server/sonar-web/tests/nav-test.js View File

@@ -1,22 +0,0 @@
import React from 'react';
import TestUtils from 'react-addons-test-utils';
import ComponentNavBreadcrumbs from '../src/main/js/main/nav/component/component-nav-breadcrumbs';


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


describe('Nav', function () {
describe('ComponentNavBreadcrumbs', () => {
it('should not render breadcrumbs with one element', function () {
var breadcrumbs = [
{ key: 'my-project', name: 'My Project', qualifier: 'TRK' }
];
var result = TestUtils.renderIntoDocument(
React.createElement(ComponentNavBreadcrumbs, { breadcrumbs: breadcrumbs })
);
expect(TestUtils.scryRenderedDOMComponentsWithTag(result, 'li')).to.have.length(1);
expect(TestUtils.scryRenderedDOMComponentsWithTag(result, 'a')).to.have.length(1);
});
});
});

Loading…
Cancel
Save