From 5fac9ad9ac653dba89f5f53457c8d17959cef7cc Mon Sep 17 00:00:00 2001 From: Stas Vilchik Date: Fri, 2 Sep 2016 16:13:51 +0200 Subject: [PATCH] use jest (#1202) --- server/sonar-web/.eslintrc | 2 +- server/sonar-web/package.json | 29 +- .../projects/__tests__/ProjectCard-test.js | 103 ++--- .../projects/__tests__/Projects-test.js | 96 ++-- .../__tests__/background-tasks-test.js | 301 ++++++------- .../background-tasks/components/Search.js | 2 +- .../apps/background-tasks/components/Stats.js | 14 +- .../overview/components/__tests__/App-test.js | 53 +-- .../__tests__/EmptyOverview-test.js | 25 +- .../__tests__/QualityGateCondition-test.js | 61 ++- .../components/__tests__/ActionsCell-test.js | 31 +- .../components/__tests__/Defaults-test.js | 21 +- .../apps/projects/__tests__/projects-test.js | 48 +- .../quality-profiles/__tests__/utils-test.js | 77 ++-- .../changelog/__tests__/Changelog-test.js | 79 ++-- .../__tests__/ChangelogSearch-test.js | 74 ++-- .../changelog/__tests__/ChangesList-test.js | 43 +- .../__tests__/ParameterChange-test.js | 11 +- .../__tests__/SeverityChange-test.js | 13 +- .../compare/__tests__/ComparisonForm-test.js | 39 +- .../__tests__/ComparisonResults-test.js | 129 +++--- .../__tests__/ProfileContainer-test.js | 114 +++-- .../js/apps/settings/__tests__/utils-test.js | 27 +- .../components/inputs/InputForPassword.js | 18 +- .../components/inputs/__tests__/Input-test.js | 58 ++- .../inputs/__tests__/InputForBoolean-test.js | 91 ++-- .../inputs/__tests__/InputForNumber-test.js | 32 +- .../inputs/__tests__/InputForPassword-test.js | 125 +++--- .../InputForSingleSelectList-test.js | 73 ++-- .../inputs/__tests__/InputForString-test.js | 32 +- .../inputs/__tests__/InputForText-test.js | 59 ++- .../inputs/__tests__/MultiValueInput-test.js | 104 ++--- .../inputs/__tests__/SimpleInput-test.js | 71 ++- .../js/apps/system/__tests__/system-test.js | 141 +++--- .../js/components/__tests__/issue-test.js | 270 ++++++------ .../__tests__/source-viewer-test.js | 152 ++++--- .../charts/__tests__/bar-chart-test.js | 136 +++--- .../charts/__tests__/bubble-chart-test.js | 62 ++- .../charts/__tests__/line-chart-test.js | 88 ++-- .../charts/__tests__/treemap-test.js | 38 +- .../charts/__tests__/work-cloud-test.js | 26 +- .../controls/__tests__/Checkbox-test.js | 71 +-- .../controls/__tests__/FavoriteBase-test.js | 57 +-- .../controls/__tests__/ListFooter-test.js | 51 +-- .../controls/__tests__/RadioToggle-test.js | 32 +- .../controls/__tests__/Toggle-test.js | 33 +- .../js/components/ui/__tests__/Avatar-test.js | 54 +-- .../js/components/ui/__tests__/Level-test.js | 11 +- .../js/components/ui/__tests__/Rating-test.js | 21 +- .../main/js/helpers/__tests__/l10n-test.js | 85 ++-- .../js/helpers/__tests__/measures-test.js | 411 +++++++++--------- .../main/js/helpers/__tests__/path-test.js | 69 ++- .../main/js/helpers/__tests__/urls-test.js | 110 +++-- .../main/js/main/nav/__tests__/nav-test.js | 22 +- .../tests/{null-compiler.js => FileStub.js} | 7 +- .../sonar-web/tests/SetupTestEnvironment.js | 26 ++ server/sonar-web/tests/jsdom-setup.js | 16 - server/sonar-web/tests/mocha.opts | 3 - server/sonar-web/tests/utils.js | 1 + 59 files changed, 1820 insertions(+), 2228 deletions(-) rename server/sonar-web/tests/{null-compiler.js => FileStub.js} (87%) create mode 100644 server/sonar-web/tests/SetupTestEnvironment.js delete mode 100644 server/sonar-web/tests/jsdom-setup.js delete mode 100644 server/sonar-web/tests/mocha.opts diff --git a/server/sonar-web/.eslintrc b/server/sonar-web/.eslintrc index c1cff1a0ef4..06d77b7ab50 100644 --- a/server/sonar-web/.eslintrc +++ b/server/sonar-web/.eslintrc @@ -8,7 +8,7 @@ "env": { "browser": true, "es6": true, - "mocha": true, + "jest": true, "node": true }, diff --git a/server/sonar-web/package.json b/server/sonar-web/package.json index 9e285ebb642..25aa6b38c18 100644 --- a/server/sonar-web/package.json +++ b/server/sonar-web/package.json @@ -8,6 +8,7 @@ "autoprefixer": "6.2.2", "babel-core": "6.13.2", "babel-eslint": "^6.0.4", + "babel-jest": "15.0.0", "babel-loader": "6.2.4", "babel-plugin-react-transform": "2.0.2", "babel-plugin-transform-class-properties": "6.11.5", @@ -21,7 +22,6 @@ "backbone": "1.2.3", "backbone.marionette": "2.4.3", "blueimp-md5": "1.1.1", - "chai": "3.3.0", "chalk": "1.1.3", "classnames": "2.2.0", "clipboard": "1.5.5", @@ -40,15 +40,13 @@ "handlebars-loader": "1.1.4", "history": "2.0.0", "imports-loader": "0.6.5", + "jest-cli": "15.1.0", "jquery": "2.2.0", - "jsdom": "6.5.1", "less": "2.7.1", "less-loader": "2.2.3", "lodash": "4.6.1", - "mocha": "2.3.4", "moment": "2.10.6", "numeral": "1.5.3", - "nyc": "^8.1.0", "postcss-loader": "0.8.0", "react": "15.0.1", "react-addons-shallow-compare": "15.0.1", @@ -66,8 +64,6 @@ "redux-thunk": "1.0.2", "rimraf": "2.5.4", "script-loader": "0.6.1", - "sinon": "1.15.4", - "sinon-chai": "2.8.0", "style-loader": "0.13.0", "underscore": "1.8.3", "webpack": "1.13.0", @@ -79,11 +75,28 @@ "start": "node ./scripts/start.js", "build-fast": "node ./scripts/build.js --fast", "build": "node ./scripts/build.js", - "test": "cross-env NODE_ENV=test mocha --opts tests/mocha.opts src/main/js/**/__tests__/**/*", - "coverage": "cross-env NODE_ENV=test nyc mocha --opts tests/mocha.opts src/main/js/**/__tests__/**/* && nyc report --reporter lcov --report-dir target/coverage", + "test": "cross-env NODE_ENV=test jest", + "coverage": "npm test -- --coverage", "lint": "eslint src/main/js" }, "engines": { "node": ">=4" + }, + "jest": { + "coverageDirectory": "/target/coverage", + "coveragePathIgnorePatterns": [ + "/node_modules", + "/tests" + ], + "moduleNameMapper": { + "^[./a-zA-Z0-9$_-]+\\.(css|hbs)": "/tests/FileStub.js" + }, + "setupFiles": [ + "/tests/SetupTestEnvironment.js" + ], + "testPathIgnorePatterns": [ + "/node_modules", + "/src/main/webapp" + ] } } diff --git a/server/sonar-web/src/main/js/apps/account/projects/__tests__/ProjectCard-test.js b/server/sonar-web/src/main/js/apps/account/projects/__tests__/ProjectCard-test.js index 7f2e5d579f5..8f85a86d722 100644 --- a/server/sonar-web/src/main/js/apps/account/projects/__tests__/ProjectCard-test.js +++ b/server/sonar-web/src/main/js/apps/account/projects/__tests__/ProjectCard-test.js @@ -19,76 +19,57 @@ */ import React from 'react'; import { shallow } from 'enzyme'; -import { expect } from 'chai'; import ProjectCard from '../ProjectCard'; import Level from '../../../../components/ui/Level'; const BASE = { id: 'id', key: 'key', name: 'name', links: [] }; -describe('My Account :: ProjectCard', () => { - it('should render key and name', () => { - const project = { ...BASE }; - const output = shallow( - - ); - expect(output.find('.account-project-key').text()).to.equal('key'); - expect(output.find('.account-project-name').text()).to.equal('name'); - }); +it('should render key and name', () => { + const project = { ...BASE }; + const output = shallow(); + expect(output.find('.account-project-key').text()).toBe('key'); + expect(output.find('.account-project-name').text()).toBe('name'); +}); - it('should render description', () => { - const project = { ...BASE, description: 'bla' }; - const output = shallow( - - ); - expect(output.find('.account-project-description').text()).to.equal('bla'); - }); +it('should render description', () => { + const project = { ...BASE, description: 'bla' }; + const output = shallow(); + expect(output.find('.account-project-description').text()).toBe('bla'); +}); - it('should not render optional fields', () => { - const project = { ...BASE }; - const output = shallow( - - ); - expect(output.find('.account-project-description')).to.have.length(0); - expect(output.find('.account-project-quality-gate')).to.have.length(0); - expect(output.find('.account-project-links')).to.have.length(0); - }); +it('should not render optional fields', () => { + const project = { ...BASE }; + const output = shallow(); + expect(output.find('.account-project-description').length).toBe(0); + expect(output.find('.account-project-quality-gate').length).toBe(0); + expect(output.find('.account-project-links').length).toBe(0); +}); - it('should render analysis date', () => { - const project = { ...BASE, lastAnalysisDate: '2016-05-17' }; - const output = shallow( - - ); - expect(output.find('.account-project-analysis').text()) - .to.contain('my_account.projects.analyzed_x'); - }); +it('should render analysis date', () => { + const project = { ...BASE, lastAnalysisDate: '2016-05-17' }; + const output = shallow(); + expect(output.find('.account-project-analysis').text()).toContain('my_account.projects.analyzed_x'); +}); - it('should not render analysis date', () => { - const project = { ...BASE }; - const output = shallow( - - ); - expect(output.find('.account-project-analysis').text()) - .to.contain('my_account.projects.never_analyzed'); - }); +it('should not render analysis date', () => { + const project = { ...BASE }; + const output = shallow(); + expect(output.find('.account-project-analysis').text()).toContain('my_account.projects.never_analyzed'); +}); - it('should render quality gate status', () => { - const project = { ...BASE, qualityGate: 'ERROR' }; - const output = shallow( - - ); - expect( - output.find('.account-project-quality-gate').find(Level).prop('level') - ).to.equal('ERROR'); - }); +it('should render quality gate status', () => { + const project = { ...BASE, qualityGate: 'ERROR' }; + const output = shallow( + + ); + expect(output.find('.account-project-quality-gate').find(Level).prop('level')).toBe('ERROR'); +}); - it('should render links', () => { - const project = { - ...BASE, - links: [{ name: 'n', type: 't', href: 'h' }] - }; - const output = shallow( - - ); - expect(output.find('.account-project-links').find('li')).to.have.length(1); - }); +it('should render links', () => { + const project = { + ...BASE, + links: [{ name: 'n', type: 't', href: 'h' }] + }; + const output = shallow(); + expect(output.find('.account-project-links').find('li').length).toBe(1); }); diff --git a/server/sonar-web/src/main/js/apps/account/projects/__tests__/Projects-test.js b/server/sonar-web/src/main/js/apps/account/projects/__tests__/Projects-test.js index 1908f929d7c..f3188d05e90 100644 --- a/server/sonar-web/src/main/js/apps/account/projects/__tests__/Projects-test.js +++ b/server/sonar-web/src/main/js/apps/account/projects/__tests__/Projects-test.js @@ -19,65 +19,61 @@ */ import React from 'react'; import { shallow } from 'enzyme'; -import { expect } from 'chai'; -import sinon from 'sinon'; import Projects from '../Projects'; import ProjectCard from '../ProjectCard'; import ListFooter from '../../../../components/controls/ListFooter'; -describe('My Account :: Projects', () => { - it('should render list of ProjectCards', () => { - const projects = [ - { id: 'id1', key: 'key1', name: 'name1', links: [] }, - { id: 'id2', key: 'key2', name: 'name2', links: [] } - ]; +it('should render list of ProjectCards', () => { + const projects = [ + { id: 'id1', key: 'key1', name: 'name1', links: [] }, + { id: 'id2', key: 'key2', name: 'name2', links: [] } + ]; - const output = shallow( - true} - loadMore={() => true}/> - ); + const output = shallow( + true} + loadMore={() => true}/> + ); - expect(output.find(ProjectCard)).to.have.length(2); - }); + expect(output.find(ProjectCard).length).toBe(2); +}); - it('should render ListFooter', () => { - const projects = [ - { id: 'id1', key: 'key1', name: 'name1', links: [] }, - { id: 'id2', key: 'key2', name: 'name2', links: [] } - ]; - const loadMore = sinon.stub().throws(); +it('should render ListFooter', () => { + const projects = [ + { id: 'id1', key: 'key1', name: 'name1', links: [] }, + { id: 'id2', key: 'key2', name: 'name2', links: [] } + ]; + const loadMore = jest.fn(); - const footer = shallow( - true} - loadMore={loadMore}/> - ).find(ListFooter); + const footer = shallow( + true} + loadMore={loadMore}/> + ).find(ListFooter); - expect(footer).to.have.length(1); - expect(footer.prop('count')).to.equal(2); - expect(footer.prop('total')).to.equal(5); - expect(footer.prop('loadMore')).to.equal(loadMore); - }); + expect(footer.length).toBe(1); + expect(footer.prop('count')).toBe(2); + expect(footer.prop('total')).toBe(5); + expect(footer.prop('loadMore')).toBe(loadMore); +}); - it('should render when no results', () => { - const output = shallow( - true} - loadMore={() => true}/> - ); +it('should render when no results', () => { + const output = shallow( + true} + loadMore={() => true}/> + ); - expect(output.find('.js-no-results')).to.have.length(1); - expect(output.find(ProjectCard)).to.have.length(0); - expect(output.find(ListFooter)).to.have.length(0); - }); + expect(output.find('.js-no-results').length).toBe(1); + expect(output.find(ProjectCard).length).toBe(0); + expect(output.find(ListFooter).length).toBe(0); }); diff --git a/server/sonar-web/src/main/js/apps/background-tasks/__tests__/background-tasks-test.js b/server/sonar-web/src/main/js/apps/background-tasks/__tests__/background-tasks-test.js index ab0583a3c50..b8561256a60 100644 --- a/server/sonar-web/src/main/js/apps/background-tasks/__tests__/background-tasks-test.js +++ b/server/sonar-web/src/main/js/apps/background-tasks/__tests__/background-tasks-test.js @@ -18,196 +18,167 @@ * 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 { shallow } from 'enzyme'; import Stats from '../components/Stats'; import Search from '../components/Search'; import { STATUSES, CURRENTS, DEBOUNCE_DELAY, DEFAULT_FILTERS } from '../constants'; import { formatDuration } from '../utils'; +import { change, click } from '../../../../../../tests/utils'; + +const stub = jest.fn(); + +describe('Constants', () => { + it('should have STATUSES', () => { + expect(Object.keys(STATUSES).length).toBe(7); + }); + + it('should have CURRENTS', () => { + expect(Object.keys(CURRENTS).length).toBe(2); + }); +}); -chai.use(sinonChai); +describe('Search', () => { + const defaultProps = { + ...DEFAULT_FILTERS, + loading: false, + types: [], + onFilterUpdate: () => true, + onReload: () => true + }; + + it('should render search form', () => { + const component = shallow(); + expect(component.find('.js-search').length).toBe(1); + }); + + it('should not render search form', () => { + const component = shallow(); + expect(component.find('.js-search').length).toBe(0); + }); -describe('Background Tasks', function () { - describe('Constants', () => { - it('should have STATUSES', () => { - expect(STATUSES).to.be.a('object'); - expect(Object.keys(STATUSES).length).to.equal(7); + it('should search', (done) => { + const searchSpy = jest.fn(); + const component = shallow(); + const searchInput = component.find('.js-search'); + change(searchInput, 'some search query'); + setTimeout(() => { + expect(searchSpy).toBeCalledWith({ query: 'some search query' }); + done(); + }, DEBOUNCE_DELAY); + }); + + it('should reload', () => { + const reloadSpy = jest.fn(); + const component = shallow(); + const reloadButton = component.find('.js-reload'); + expect(reloadSpy).not.toBeCalled(); + click(reloadButton); + expect(reloadSpy).toBeCalled(); + }); +}); + +describe('Stats', () => { + describe('Pending', () => { + it('should show zero pending', () => { + const result = shallow(); + expect(result.find('.js-pending-count').text()).toContain('0'); }); - it('should have CURRENTS', () => { - expect(CURRENTS).to.be.a('object'); - expect(Object.keys(CURRENTS).length).to.equal(2); + it('should show 5 pending', () => { + const result = shallow(); + expect(result.find('.js-pending-count').text()).toContain('5'); + }); + + it('should not show cancel pending button', () => { + const result = shallow(); + expect(result.find('.js-cancel-pending').length).toBe(0); + }); + + it('should show cancel pending button', () => { + const result = shallow(); + expect(result.find('.js-cancel-pending').length).toBe(1); }); - }); - describe('Search', () => { - const defaultProps = { - ...DEFAULT_FILTERS, - loading: false, - types: [], - onFilterUpdate: () => true, - onReload: () => true - }; - - it('should render search form', () => { - const component = TestUtils.renderIntoDocument( - - ); - const searchBox = TestUtils.scryRenderedDOMComponentsWithClass(component, 'js-search'); - expect(searchBox).to.have.length(1); - }); - - it('should not render search form', () => { - const component = TestUtils.renderIntoDocument( - - ); - const searchBox = TestUtils.scryRenderedDOMComponentsWithClass(component, 'js-search'); - expect(searchBox).to.be.empty; - }); - - it('should search', (done) => { - const searchSpy = sinon.spy(); - const component = TestUtils.renderIntoDocument( - ); - 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' }); - done(); - }, DEBOUNCE_DELAY); - }); - - it('should reload', () => { - const reloadSpy = sinon.spy(); - const component = TestUtils.renderIntoDocument( - - ); - const reloadButton = component.refs.reloadButton; - expect(reloadSpy).to.not.have.been.called; - TestUtils.Simulate.click(reloadButton); - expect(reloadSpy).to.have.been.called; + it('should trigger cancelling pending', () => { + const spy = jest.fn(); + const result = shallow(); + expect(spy).not.toBeCalled(); + click(result.find('.js-cancel-pending')); + expect(spy).toBeCalled(); }); }); - describe('Stats', () => { - describe('Pending', () => { - it('should show zero pending', () => { - const result = TestUtils.renderIntoDocument(); - const pendingCounter = result.refs.pendingCount; - expect(pendingCounter.textContent).to.contain('0'); - }); - - it('should show 5 pending', () => { - const result = TestUtils.renderIntoDocument(); - const pendingCounter = result.refs.pendingCount; - expect(pendingCounter.textContent).to.contain('5'); - }); - - it('should not show cancel pending button', () => { - const result = TestUtils.renderIntoDocument(); - const cancelPending = result.refs.cancelPending; - expect(cancelPending).to.not.be.ok; - }); - - it('should show cancel pending button', () => { - const result = TestUtils.renderIntoDocument(); - const cancelPending = result.refs.cancelPending; - expect(cancelPending).to.be.ok; - }); - - it('should trigger cancelling pending', () => { - const spy = sinon.spy(); - const result = TestUtils.renderIntoDocument(); - const cancelPending = result.refs.cancelPending; - expect(spy).to.not.have.been.called; - TestUtils.Simulate.click(cancelPending); - expect(spy).to.have.been.called; - }); - }); - - describe('Failures', () => { - it('should show zero failures', () => { - const result = TestUtils.renderIntoDocument(); - const failureCounter = result.refs.failureCount; - expect(failureCounter.textContent).to.contain('0'); - }); - - it('should show 5 failures', () => { - const result = TestUtils.renderIntoDocument(); - const failureCounter = result.refs.failureCount; - expect(failureCounter.textContent).to.contain('5'); - }); - - it('should not show link to failures', () => { - const result = TestUtils.renderIntoDocument(); - const failureCounter = result.refs.failureCount; - expect(failureCounter.tagName.toLowerCase()).to.not.equal('a'); - }); - - it('should show link to failures', () => { - const result = TestUtils.renderIntoDocument(); - const failureCounter = result.refs.failureCount; - expect(failureCounter.tagName.toLowerCase()).to.equal('a'); - }); - - it('should trigger filtering failures', () => { - const spy = sinon.spy(); - const result = TestUtils.renderIntoDocument(); - const failureCounter = result.refs.failureCount; - expect(spy).to.not.have.been.called; - TestUtils.Simulate.click(failureCounter); - expect(spy).to.have.been.called; - }); + describe('Failures', () => { + it('should show zero failures', () => { + const result = shallow(); + expect(result.find('.js-failures-count').text()).toContain('0'); + }); + + it('should show 5 failures', () => { + const result = shallow(); + expect(result.find('.js-failures-count').text()).toContain('5'); + }); + + it('should not show link to failures', () => { + const result = shallow(); + expect(result.find('.js-failures-count').is('a')).toBeFalsy(); + }); + + it('should show link to failures', () => { + const result = shallow(); + expect(result.find('.js-failures-count').is('a')).toBeTruthy(); + }); + + it('should trigger filtering failures', () => { + const spy = jest.fn(); + const result = shallow(); + expect(spy).not.toBeCalled(); + click(result.find('.js-failures-count')); + expect(spy).toBeCalled(); }); }); +}); - describe('Helpers', () => { - describe('#formatDuration()', () => { - it('should format 173ms', () => { - expect(formatDuration(173)).to.equal('173ms'); - }); +describe('Helpers', () => { + describe('#formatDuration()', () => { + it('should format 173ms', () => { + expect(formatDuration(173)).toBe('173ms'); + }); - it('should format 999ms', () => { - expect(formatDuration(999)).to.equal('999ms'); - }); + it('should format 999ms', () => { + expect(formatDuration(999)).toBe('999ms'); + }); - it('should format 1s', () => { - expect(formatDuration(1000)).to.equal('1s'); - }); + it('should format 1s', () => { + expect(formatDuration(1000)).toBe('1s'); + }); - it('should format 1s', () => { - expect(formatDuration(1001)).to.equal('1s'); - }); + it('should format 1s', () => { + expect(formatDuration(1001)).toBe('1s'); + }); - it('should format 2s', () => { - expect(formatDuration(1501)).to.equal('2s'); - }); + it('should format 2s', () => { + expect(formatDuration(1501)).toBe('2s'); + }); - it('should format 59s', () => { - expect(formatDuration(59000)).to.equal('59s'); - }); + it('should format 59s', () => { + expect(formatDuration(59000)).toBe('59s'); + }); - it('should format 1min', () => { - expect(formatDuration(60000)).to.equal('1min'); - }); + it('should format 1min', () => { + expect(formatDuration(60000)).toBe('1min'); + }); - it('should format 1min', () => { - expect(formatDuration(62757)).to.equal('1min'); - }); + it('should format 1min', () => { + expect(formatDuration(62757)).toBe('1min'); + }); - it('should format 4min', () => { - expect(formatDuration(224567)).to.equal('4min'); - }); + it('should format 4min', () => { + expect(formatDuration(224567)).toBe('4min'); + }); - it('should format 80min', () => { - expect(formatDuration(80 * 60 * 1000)).to.equal('80min'); - }); + it('should format 80min', () => { + expect(formatDuration(80 * 60 * 1000)).toBe('80min'); }); }); }); diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/Search.js b/server/sonar-web/src/main/js/apps/background-tasks/components/Search.js index bfffb1021e4..9dd234a6207 100644 --- a/server/sonar-web/src/main/js/apps/background-tasks/components/Search.js +++ b/server/sonar-web/src/main/js/apps/background-tasks/components/Search.js @@ -151,7 +151,7 @@ export default class Search extends React.Component {
  • this.handleCancelChangeClick(e)}> {translate('cancel')} diff --git a/server/sonar-web/src/main/js/apps/settings/components/inputs/__tests__/Input-test.js b/server/sonar-web/src/main/js/apps/settings/components/inputs/__tests__/Input-test.js index dbe570ec878..d45fd7fe833 100644 --- a/server/sonar-web/src/main/js/apps/settings/components/inputs/__tests__/Input-test.js +++ b/server/sonar-web/src/main/js/apps/settings/components/inputs/__tests__/Input-test.js @@ -18,43 +18,41 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ import React from 'react'; -import { expect } from 'chai'; import { shallow } from 'enzyme'; -import sinon from 'sinon'; import Input from '../Input'; import PrimitiveInput from '../PrimitiveInput'; import MultiValueInput from '../MultiValueInput'; import PropertySetInput from '../PropertySetInput'; import { TYPE_STRING, TYPE_PROPERTY_SET } from '../../../constants'; -describe('Settings :: Inputs :: Input', () => { - it('should render PrimitiveInput', () => { - const setting = { definition: { key: 'example', type: TYPE_STRING } }; - const onChange = sinon.spy(); - const input = shallow().find(PrimitiveInput); - expect(input).to.have.length(1); - expect(input.prop('setting')).to.equal(setting); - expect(input.prop('value')).to.equal('foo'); - expect(input.prop('onChange')).to.equal(onChange); - }); +it('should render PrimitiveInput', () => { + const setting = { definition: { key: 'example', type: TYPE_STRING } }; + const onChange = jest.fn(); + const input = shallow().find(PrimitiveInput); + expect(input.length).toBe(1); + expect(input.prop('setting')).toBe(setting); + expect(input.prop('value')).toBe('foo'); + expect(input.prop('onChange')).toBe(onChange); +}); - it('should render MultiValueInput', () => { - const setting = { definition: { key: 'example', type: TYPE_STRING, multiValues: true } }; - const onChange = sinon.spy(); - const input = shallow().find(MultiValueInput); - expect(input).to.have.length(1); - expect(input.prop('setting')).to.equal(setting); - expect(input.prop('value')).to.equal('foo'); - expect(input.prop('onChange')).to.equal(onChange); - }); +it('should render MultiValueInput', () => { + const setting = { definition: { key: 'example', type: TYPE_STRING, multiValues: true } }; + const value = ['foo', 'bar']; + const onChange = jest.fn(); + const input = shallow().find(MultiValueInput); + expect(input.length).toBe(1); + expect(input.prop('setting')).toBe(setting); + expect(input.prop('value')).toBe(value); + expect(input.prop('onChange')).toBe(onChange); +}); - it('should render PropertySetInput', () => { - const setting = { definition: { key: 'example', type: TYPE_PROPERTY_SET, fields: [] } }; - const onChange = sinon.spy(); - const input = shallow().find(PropertySetInput); - expect(input).to.have.length(1); - expect(input.prop('setting')).to.equal(setting); - expect(input.prop('value')).to.equal('foo'); - expect(input.prop('onChange')).to.equal(onChange); - }); +it('should render PropertySetInput', () => { + const setting = { definition: { key: 'example', type: TYPE_PROPERTY_SET, fields: [] } }; + const value = [{ foo: 'bar' }]; + const onChange = jest.fn(); + const input = shallow().find(PropertySetInput); + expect(input.length).toBe(1); + expect(input.prop('setting')).toBe(setting); + expect(input.prop('value')).toBe(value); + expect(input.prop('onChange')).toBe(onChange); }); diff --git a/server/sonar-web/src/main/js/apps/settings/components/inputs/__tests__/InputForBoolean-test.js b/server/sonar-web/src/main/js/apps/settings/components/inputs/__tests__/InputForBoolean-test.js index 2fc8b9bb9c5..9b0c51a9067 100644 --- a/server/sonar-web/src/main/js/apps/settings/components/inputs/__tests__/InputForBoolean-test.js +++ b/server/sonar-web/src/main/js/apps/settings/components/inputs/__tests__/InputForBoolean-test.js @@ -18,60 +18,55 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ import React from 'react'; -import { expect } from 'chai'; import { shallow } from 'enzyme'; -import sinon from 'sinon'; import InputForBoolean from '../InputForBoolean'; import Toggle from '../../../../../components/controls/Toggle'; -describe('Settings :: Inputs :: InputForBoolean', () => { - it('should render Toggle', () => { - const onChange = sinon.spy(); - const toggle = shallow( - - ).find(Toggle); - expect(toggle).to.have.length(1); - expect(toggle.prop('name')).to.equal('foo'); - expect(toggle.prop('value')).to.equal(true); - expect(toggle.prop('onChange')).to.be.a('function'); - }); +it('should render Toggle', () => { + const onChange = jest.fn(); + const toggle = shallow( + + ).find(Toggle); + expect(toggle.length).toBe(1); + expect(toggle.prop('name')).toBe('foo'); + expect(toggle.prop('value')).toBe(true); + expect(toggle.prop('onChange')).toBeTruthy(); +}); - it('should render Toggle without value', () => { - const onChange = sinon.spy(); - const input = shallow( - - ); - const toggle = input.find(Toggle); - expect(toggle).to.have.length(1); - expect(toggle.prop('name')).to.equal('foo'); - expect(toggle.prop('value')).to.equal(false); - expect(toggle.prop('onChange')).to.be.a('function'); - expect(input.find('.note')).to.have.length(1); - }); +it('should render Toggle without value', () => { + const onChange = jest.fn(); + const input = shallow( + + ); + const toggle = input.find(Toggle); + expect(toggle.length).toBe(1); + expect(toggle.prop('name')).toBe('foo'); + expect(toggle.prop('value')).toBe(false); + expect(toggle.prop('onChange')).toBeTruthy(); + expect(input.find('.note').length).toBe(1); +}); - it('should call onChange', () => { - const onChange = sinon.spy(); - const input = shallow( - - ); - const toggle = input.find(Toggle); - expect(toggle).to.have.length(1); - expect(toggle.prop('onChange')).to.be.a('function'); +it('should call onChange', () => { + const onChange = jest.fn(); + const input = shallow( + + ); + const toggle = input.find(Toggle); + expect(toggle.length).toBe(1); + expect(toggle.prop('onChange')).toBeTruthy(); - toggle.prop('onChange')(false); + toggle.prop('onChange')(false); - expect(onChange.called).to.equal(true); - expect(onChange.lastCall.args).to.deep.equal([false]); - }); + expect(onChange).toBeCalledWith(false); }); diff --git a/server/sonar-web/src/main/js/apps/settings/components/inputs/__tests__/InputForNumber-test.js b/server/sonar-web/src/main/js/apps/settings/components/inputs/__tests__/InputForNumber-test.js index 3544898fa2e..c82a88dd084 100644 --- a/server/sonar-web/src/main/js/apps/settings/components/inputs/__tests__/InputForNumber-test.js +++ b/server/sonar-web/src/main/js/apps/settings/components/inputs/__tests__/InputForNumber-test.js @@ -18,26 +18,22 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ import React from 'react'; -import { expect } from 'chai'; import { shallow } from 'enzyme'; -import sinon from 'sinon'; import InputForNumber from '../InputForNumber'; import SimpleInput from '../SimpleInput'; -describe('Settings :: Inputs :: InputForNumber', () => { - it('should render SimpleInput', () => { - const onChange = sinon.spy(); - const simpleInput = shallow( - - ).find(SimpleInput); - expect(simpleInput).to.have.length(1); - expect(simpleInput.prop('name')).to.equal('foo'); - expect(simpleInput.prop('value')).to.equal(17); - expect(simpleInput.prop('type')).to.equal('text'); - expect(simpleInput.prop('onChange')).to.be.a('function'); - }); +it('should render SimpleInput', () => { + const onChange = jest.fn(); + const simpleInput = shallow( + + ).find(SimpleInput); + expect(simpleInput.length).toBe(1); + expect(simpleInput.prop('name')).toBe('foo'); + expect(simpleInput.prop('value')).toBe(17); + expect(simpleInput.prop('type')).toBe('text'); + expect(simpleInput.prop('onChange')).toBeTruthy(); }); diff --git a/server/sonar-web/src/main/js/apps/settings/components/inputs/__tests__/InputForPassword-test.js b/server/sonar-web/src/main/js/apps/settings/components/inputs/__tests__/InputForPassword-test.js index 6e463644879..4c52fd60c22 100644 --- a/server/sonar-web/src/main/js/apps/settings/components/inputs/__tests__/InputForPassword-test.js +++ b/server/sonar-web/src/main/js/apps/settings/components/inputs/__tests__/InputForPassword-test.js @@ -18,80 +18,69 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ import React from 'react'; -import { expect } from 'chai'; -import { shallow, mount } from 'enzyme'; -import sinon from 'sinon'; +import { shallow } from 'enzyme'; import InputForPassword from '../InputForPassword'; -import { click, submit } from '../../../../../../../../tests/utils'; +import { click, submit, change } from '../../../../../../../../tests/utils'; -describe('Settings :: Inputs :: InputForPassword', () => { - it('should render lock icon, but no form', () => { - const onChange = sinon.spy(); - const input = shallow( - - ); - expect(input.find('.icon-lock')).to.have.length(1); - expect(input.find('form')).to.have.length(0); - }); - - it('should open form', () => { - const onChange = sinon.spy(); - const input = shallow( - - ); - const button = input.find('button'); - expect(button).to.have.length(1); - - click(button); - expect(input.find('form')).to.have.length(1); - }); - - it('should close form', () => { - const onChange = sinon.spy(); - const input = shallow( - - ); - const button = input.find('button'); - expect(button).to.have.length(1); +it('should render lock icon, but no form', () => { + const onChange = jest.fn(); + const input = shallow( + + ); + expect(input.find('.icon-lock').length).toBe(1); + expect(input.find('form').length).toBe(0); +}); - click(button); - expect(input.find('form')).to.have.length(1); +it('should open form', () => { + const onChange = jest.fn(); + const input = shallow( + + ); + const button = input.find('button'); + expect(button.length).toBe(1); - click(input.find('form').find('a')); - expect(input.find('form')).to.have.length(0); - }); + click(button); + expect(input.find('form').length).toBe(1); +}); - it('should set value', () => { - const onChange = sinon.stub().returns(Promise.resolve()); - const input = mount( - - ); - const button = input.find('button'); - expect(button).to.have.length(1); +it('should close form', () => { + const onChange = jest.fn(); + const input = shallow( + + ); + const button = input.find('button'); + expect(button.length).toBe(1); - click(button); - const form = input.find('form'); - expect(form).to.have.length(1); + click(button); + expect(input.find('form').length).toBe(1); - input.ref('input').value = 'secret'; - submit(form); + click(input.find('form').find('a')); + expect(input.find('form').length).toBe(0); +}); - expect(onChange.called).to.equal(true); - }); +it('should set value', () => { + const onChange = jest.fn(() => Promise.resolve()); + const input = shallow( + + ); + click(input.find('button')); + change(input.find('.js-password-input'), 'secret'); + submit(input.find('form')); + expect(onChange).toBeCalledWith('secret'); }); diff --git a/server/sonar-web/src/main/js/apps/settings/components/inputs/__tests__/InputForSingleSelectList-test.js b/server/sonar-web/src/main/js/apps/settings/components/inputs/__tests__/InputForSingleSelectList-test.js index 2be66e0ad80..15057954ef8 100644 --- a/server/sonar-web/src/main/js/apps/settings/components/inputs/__tests__/InputForSingleSelectList-test.js +++ b/server/sonar-web/src/main/js/apps/settings/components/inputs/__tests__/InputForSingleSelectList-test.js @@ -18,49 +18,44 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ import React from 'react'; -import { expect } from 'chai'; import { shallow } from 'enzyme'; -import sinon from 'sinon'; import Select from 'react-select'; import InputForSingleSelectList from '../InputForSingleSelectList'; -describe('Settings :: Inputs :: InputForSingleSelectList', () => { - it('should render Select', () => { - const onChange = sinon.spy(); - const select = shallow( - - ).find(Select); - expect(select).to.have.length(1); - expect(select.prop('name')).to.equal('foo'); - expect(select.prop('value')).to.equal('bar'); - expect(select.prop('options')).to.deep.equal([ - { value: 'foo', label: 'foo' }, - { value: 'bar', label: 'bar' }, - { value: 'baz', label: 'baz' } - ]); - expect(select.prop('onChange')).to.be.a('function'); - }); +it('should render Select', () => { + const onChange = jest.fn(); + const select = shallow( + + ).find(Select); + expect(select.length).toBe(1); + expect(select.prop('name')).toBe('foo'); + expect(select.prop('value')).toBe('bar'); + expect(select.prop('options')).toEqual([ + { value: 'foo', label: 'foo' }, + { value: 'bar', label: 'bar' }, + { value: 'baz', label: 'baz' } + ]); + expect(select.prop('onChange')).toBeTruthy(); +}); - it('should call onChange', () => { - const onChange = sinon.spy(); - const select = shallow( - - ).find(Select); - expect(select).to.have.length(1); - expect(select.prop('onChange')).to.be.a('function'); +it('should call onChange', () => { + const onChange = jest.fn(); + const select = shallow( + + ).find(Select); + expect(select.length).toBe(1); + expect(select.prop('onChange')).toBeTruthy(); - select.prop('onChange')({ value: 'baz', label: 'baz' }); - expect(onChange.called).to.equal(true); - expect(onChange.lastCall.args).to.deep.equal(['baz']); - }); + select.prop('onChange')({ value: 'baz', label: 'baz' }); + expect(onChange).toBeCalledWith('baz'); }); diff --git a/server/sonar-web/src/main/js/apps/settings/components/inputs/__tests__/InputForString-test.js b/server/sonar-web/src/main/js/apps/settings/components/inputs/__tests__/InputForString-test.js index 4fd3c7a4b39..31f2cbc5a43 100644 --- a/server/sonar-web/src/main/js/apps/settings/components/inputs/__tests__/InputForString-test.js +++ b/server/sonar-web/src/main/js/apps/settings/components/inputs/__tests__/InputForString-test.js @@ -18,26 +18,22 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ import React from 'react'; -import { expect } from 'chai'; import { shallow } from 'enzyme'; -import sinon from 'sinon'; import InputForString from '../InputForString'; import SimpleInput from '../SimpleInput'; -describe('Settings :: Inputs :: InputForString', () => { - it('should render SimpleInput', () => { - const onChange = sinon.spy(); - const simpleInput = shallow( - - ).find(SimpleInput); - expect(simpleInput).to.have.length(1); - expect(simpleInput.prop('name')).to.equal('foo'); - expect(simpleInput.prop('value')).to.equal('bar'); - expect(simpleInput.prop('type')).to.equal('text'); - expect(simpleInput.prop('onChange')).to.be.a('function'); - }); +it('should render SimpleInput', () => { + const onChange = jest.fn(); + const simpleInput = shallow( + + ).find(SimpleInput); + expect(simpleInput.length).toBe(1); + expect(simpleInput.prop('name')).toBe('foo'); + expect(simpleInput.prop('value')).toBe('bar'); + expect(simpleInput.prop('type')).toBe('text'); + expect(simpleInput.prop('onChange')).toBeTruthy(); }); diff --git a/server/sonar-web/src/main/js/apps/settings/components/inputs/__tests__/InputForText-test.js b/server/sonar-web/src/main/js/apps/settings/components/inputs/__tests__/InputForText-test.js index 97ef6ec5fab..326f58058d5 100644 --- a/server/sonar-web/src/main/js/apps/settings/components/inputs/__tests__/InputForText-test.js +++ b/server/sonar-web/src/main/js/apps/settings/components/inputs/__tests__/InputForText-test.js @@ -18,43 +18,38 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ import React from 'react'; -import { expect } from 'chai'; import { shallow } from 'enzyme'; -import sinon from 'sinon'; import InputForText from '../InputForText'; import { change } from '../../../../../../../../tests/utils'; -describe('Settings :: Inputs :: InputForText', () => { - it('should render textarea', () => { - const onChange = sinon.spy(); - const textarea = shallow( - - ).find('textarea'); - expect(textarea).to.have.length(1); - expect(textarea.prop('name')).to.equal('foo'); - expect(textarea.prop('value')).to.equal('bar'); - expect(textarea.prop('onChange')).to.be.a('function'); - }); +it('should render textarea', () => { + const onChange = jest.fn(); + const textarea = shallow( + + ).find('textarea'); + expect(textarea.length).toBe(1); + expect(textarea.prop('name')).toBe('foo'); + expect(textarea.prop('value')).toBe('bar'); + expect(textarea.prop('onChange')).toBeTruthy(); +}); - it('should call onChange', () => { - const onChange = sinon.spy(); - const textarea = shallow( - - ).find('textarea'); - expect(textarea).to.have.length(1); - expect(textarea.prop('onChange')).to.be.a('function'); +it('should call onChange', () => { + const onChange = jest.fn(); + const textarea = shallow( + + ).find('textarea'); + expect(textarea.length).toBe(1); + expect(textarea.prop('onChange')).toBeTruthy(); - change(textarea, 'qux'); + change(textarea, 'qux'); - expect(onChange.called).to.equal(true); - expect(onChange.lastCall.args).to.deep.equal(['qux']); - }); + expect(onChange).toBeCalledWith('qux'); }); diff --git a/server/sonar-web/src/main/js/apps/settings/components/inputs/__tests__/MultiValueInput-test.js b/server/sonar-web/src/main/js/apps/settings/components/inputs/__tests__/MultiValueInput-test.js index 126a7a5a0ed..1e52f7a0018 100644 --- a/server/sonar-web/src/main/js/apps/settings/components/inputs/__tests__/MultiValueInput-test.js +++ b/server/sonar-web/src/main/js/apps/settings/components/inputs/__tests__/MultiValueInput-test.js @@ -18,86 +18,54 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ import React from 'react'; -import { expect } from 'chai'; -import { shallow, mount } from 'enzyme'; -import sinon from 'sinon'; +import { shallow } from 'enzyme'; import MultiValueInput from '../MultiValueInput'; -import InputForString from '../InputForString'; -import { click, change } from '../../../../../../../../tests/utils'; +import PrimitiveInput from '../PrimitiveInput'; +import { click } from '../../../../../../../../tests/utils'; const definition = { multiValues: true }; const assertValues = (inputs, values) => { values.forEach((value, index) => { const input = inputs.at(index); - expect(input.prop('value')).to.equal(value); + expect(input.prop('value')).toBe(value); }); }; -describe('Settings :: Inputs :: MultiValueInput', () => { - it('should render one value', () => { - const multiValueInput = mount( - - ); - const stringInputs = multiValueInput.find(InputForString); - expect(stringInputs).to.have.length(1 + 1); - assertValues(stringInputs, ['foo', '']); - }); - - it('should render several values', () => { - const multiValueInput = mount( - - ); - const stringInputs = multiValueInput.find(InputForString); - expect(stringInputs).to.have.length(3 + 1); - assertValues(stringInputs, ['foo', 'bar', 'baz', '']); - }); - - it('should remove value', () => { - const onChange = sinon.spy(); - const multiValueInput = mount( - - ); - - click(multiValueInput.find('.js-remove-value').at(1)); - expect(onChange.called).to.equal(true); - expect(onChange.lastCall.args).to.deep.equal([['foo', 'baz']]); - }); +it('should render one value', () => { + const multiValueInput = shallow(); + const stringInputs = multiValueInput.find(PrimitiveInput); + expect(stringInputs.length).toBe(1 + 1); + assertValues(stringInputs, ['foo', '']); +}); - it('should change existing value', () => { - const onChange = sinon.spy(); - const multiValueInput = mount( - - ); +it('should render several values', () => { + const multiValueInput = shallow( + ); + const stringInputs = multiValueInput.find(PrimitiveInput); + expect(stringInputs.length).toBe(3 + 1); + assertValues(stringInputs, ['foo', 'bar', 'baz', '']); +}); - change(multiValueInput.find(InputForString).at(1).find('input'), 'qux'); - expect(onChange.called).to.equal(true); - expect(onChange.lastCall.args).to.deep.equal([['foo', 'qux', 'baz']]); - }); +it('should remove value', () => { + const onChange = jest.fn(); + const multiValueInput = shallow( + ); + click(multiValueInput.find('.js-remove-value').at(1)); + expect(onChange).toBeCalledWith(['foo', 'baz']); +}); - it('should add new value', () => { - const onChange = sinon.spy(); - const multiValueInput = mount( - - ); +it('should change existing value', () => { + const onChange = jest.fn(); + const multiValueInput = shallow( + ); + multiValueInput.find(PrimitiveInput).at(1).prop('onChange')('qux'); + expect(onChange).toBeCalledWith(['foo', 'qux', 'baz']); +}); - change(multiValueInput.find(InputForString).at(1).find('input'), 'bar'); - expect(onChange.called).to.equal(true); - expect(onChange.lastCall.args).to.deep.equal([['foo', 'bar']]); - }); +it('should add new value', () => { + const onChange = jest.fn(); + const multiValueInput = shallow(); + multiValueInput.find(PrimitiveInput).at(1).prop('onChange')('bar'); + expect(onChange).toBeCalledWith(['foo', 'bar']); }); diff --git a/server/sonar-web/src/main/js/apps/settings/components/inputs/__tests__/SimpleInput-test.js b/server/sonar-web/src/main/js/apps/settings/components/inputs/__tests__/SimpleInput-test.js index 679d5302eb9..1637dd18f30 100644 --- a/server/sonar-web/src/main/js/apps/settings/components/inputs/__tests__/SimpleInput-test.js +++ b/server/sonar-web/src/main/js/apps/settings/components/inputs/__tests__/SimpleInput-test.js @@ -18,49 +18,44 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ import React from 'react'; -import { expect } from 'chai'; import { shallow } from 'enzyme'; -import sinon from 'sinon'; import SimpleInput from '../SimpleInput'; import { change } from '../../../../../../../../tests/utils'; -describe('Settings :: Inputs :: SimpleInput', () => { - it('should render input', () => { - const onChange = sinon.spy(); - const input = shallow( - - ).find('input'); - expect(input).to.have.length(1); - expect(input.prop('type')).to.equal('text'); - expect(input.prop('className')).to.include('input-large'); - expect(input.prop('name')).to.equal('foo'); - expect(input.prop('value')).to.equal('bar'); - expect(input.prop('onChange')).to.be.a('function'); - }); +it('should render input', () => { + const onChange = jest.fn(); + const input = shallow( + + ).find('input'); + expect(input.length).toBe(1); + expect(input.prop('type')).toBe('text'); + expect(input.prop('className')).toContain('input-large'); + expect(input.prop('name')).toBe('foo'); + expect(input.prop('value')).toBe('bar'); + expect(input.prop('onChange')).toBeTruthy(); +}); - it('should call onChange', () => { - const onChange = sinon.spy(); - const input = shallow( - - ).find('input'); - expect(input).to.have.length(1); - expect(input.prop('onChange')).to.be.a('function'); +it('should call onChange', () => { + const onChange = jest.fn(); + const input = shallow( + + ).find('input'); + expect(input.length).toBe(1); + expect(input.prop('onChange')).toBeTruthy(); - change(input, 'qux'); + change(input, 'qux'); - expect(onChange.called).to.equal(true); - expect(onChange.lastCall.args).to.deep.equal(['qux']); - }); + expect(onChange).toBeCalledWith('qux'); }); diff --git a/server/sonar-web/src/main/js/apps/system/__tests__/system-test.js b/server/sonar-web/src/main/js/apps/system/__tests__/system-test.js index fc31d9d0b8b..4e038d05b0a 100644 --- a/server/sonar-web/src/main/js/apps/system/__tests__/system-test.js +++ b/server/sonar-web/src/main/js/apps/system/__tests__/system-test.js @@ -18,101 +18,72 @@ * 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 { shallow } from 'enzyme'; import ItemValue from '../item-value'; - -describe('System', function () { - - describe('Item Value', function () { - it('should render string', () => { - const result = TestUtils.renderIntoDocument(); - const content = ReactDOM.findDOMNode(TestUtils.findRenderedDOMComponentWithTag(result, 'code')); - expect(content.textContent).to.equal('/some/path/as/an/example'); - }); - - it('should render `true`', () => { - const result = TestUtils.renderIntoDocument(); - TestUtils.findRenderedDOMComponentWithClass(result, 'icon-check'); - }); - - it('should render `false`', () => { - const result = TestUtils.renderIntoDocument(); - TestUtils.findRenderedDOMComponentWithClass(result, 'icon-delete'); - }); - - it('should render object', () => { - const result = TestUtils.renderIntoDocument(); - TestUtils.findRenderedDOMComponentWithTag(result, 'table'); - expect(TestUtils.scryRenderedDOMComponentsWithTag(result, 'tr')).to.have.length(2); - }); - - it('should render `true` inside object', () => { - const result = TestUtils.renderIntoDocument(); - TestUtils.findRenderedDOMComponentWithTag(result, 'table'); - TestUtils.findRenderedDOMComponentWithClass(result, 'icon-check'); - }); - - it('should render object inside object', () => { - const result = TestUtils.renderIntoDocument( - ); - expect(TestUtils.scryRenderedDOMComponentsWithTag(result, 'table')).to.have.length(3); - expect(TestUtils.scryRenderedDOMComponentsWithTag(result, 'tr')).to.have.length(6); - }); +import ItemBoolean from '../item-boolean'; +import ItemObject from '../item-object'; +import ItemLogLevel from '../item-log-level'; + +describe('Item Value', function () { + it('should render string', () => { + const result = shallow(); + expect(result.find('code').text()).toBe('/some/path/as/an/example'); }); +}); - describe('Log Level', function () { - let previousFetch; - let fetchUrl; - let fetchOptions; +describe('ItemBoolean', () => { + it('should render `true`', () => { + const result = shallow(); + expect(result.find('.icon-check').length).toBe(1); + }); - before(function () { - previousFetch = window.fetch; - window.fetch = function (url, options) { - fetchUrl = url; - fetchOptions = options; - return Promise.resolve(); - }; - }); + it('should render `false`', () => { + const result = shallow(); + expect(result.find('.icon-delete').length).toBe(1); + }); +}); - after(function () { - window.fetch = previousFetch; - }); +describe('ItemObject', () => { + it('should render object', () => { + const result = shallow(); + expect(result.find('table').length).toBe(1); + expect(result.find('tr').length).toBe(2); + }); - it('should render select box', () => { - const result = TestUtils.renderIntoDocument(); - TestUtils.findRenderedDOMComponentWithTag(result, 'select'); - expect(TestUtils.scryRenderedDOMComponentsWithTag(result, 'option')).to.have.length(3); - }); + it('should render `true` inside object', () => { + const result = shallow(); + const itemValue = result.find(ItemValue); + expect(itemValue.length).toBe(1); + expect(itemValue.prop('value')).toBe(true); + }); - it('should set initial value', () => { - const result = TestUtils.renderIntoDocument(); - const select = ReactDOM.findDOMNode(TestUtils.findRenderedDOMComponentWithTag(result, 'select')); - expect(select.value).to.equal('DEBUG'); - }); + it('should render object inside object', () => { + const result = shallow(); + expect(result.find(ItemValue).length).toBe(2); + expect(result.find(ItemValue).at(0).prop('value')).toEqual({ docs: 1, shards: 5 }); + expect(result.find(ItemValue).at(1).prop('value')).toEqual({ docs: 68, shards: 5 }); + }); +}); - it('should render warning', () => { - const result = TestUtils.renderIntoDocument(); - TestUtils.findRenderedDOMComponentWithClass(result, 'alert'); - }); +describe('Log Level', function () { + it('should render select box', () => { + const result = shallow(); + expect(result.find('select').length).toBe(1); + expect(result.find('option').length).toBe(3); + }); - it('should not render warning', () => { - const result = TestUtils.renderIntoDocument(); - expect(TestUtils.scryRenderedDOMComponentsWithClass(result, 'alert')).to.be.empty; - }); + it('should set initial value', () => { + const result = shallow(); + expect(result.find('select').prop('value')).toBe('DEBUG'); + }); - // TODO replace with test with no WS call - it.skip('should change value', () => { - const result = TestUtils.renderIntoDocument(); - const select = ReactDOM.findDOMNode(TestUtils.findRenderedDOMComponentWithTag(result, 'select')); - select.value = 'TRACE'; - TestUtils.Simulate.change(select); - expect(fetchUrl).to.equal('/api/system/change_log_level'); - expect(fetchOptions.method).to.equal('POST'); - expect(fetchOptions.body).to.equal('level=TRACE'); - }); + it('should render warning', () => { + const result = shallow(); + expect(result.find('.alert').length).toBe(1); }); + it('should not render warning', () => { + const result = shallow(); + expect(result.find('.alert').length).toBe(0); + }); }); diff --git a/server/sonar-web/src/main/js/components/__tests__/issue-test.js b/server/sonar-web/src/main/js/components/__tests__/issue-test.js index 75d4e89f119..66f124afaf1 100644 --- a/server/sonar-web/src/main/js/components/__tests__/issue-test.js +++ b/server/sonar-web/src/main/js/components/__tests__/issue-test.js @@ -17,175 +17,167 @@ * 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 () { - const issue = new Issue(); - expect(issue.urlRoot()).to.equal('/api/issues'); - }); +describe('Model', function () { + it('should have correct urlRoot', function () { + const issue = new Issue(); + expect(issue.urlRoot()).toBe('/api/issues'); + }); - it('should parse response without root issue object', function () { - const issue = new Issue(); - const example = { a: 1 }; - expect(issue.parse(example)).to.deep.equal(example); - }); + it('should parse response without root issue object', function () { + const issue = new Issue(); + const example = { a: 1 }; + expect(issue.parse(example)).toEqual(example); + }); - it('should parse response with the root issue object', function () { - const issue = new Issue(); - const example = { a: 1 }; - expect(issue.parse({ issue: example })).to.deep.equal(example); - }); + it('should parse response with the root issue object', function () { + const issue = new Issue(); + const example = { a: 1 }; + expect(issue.parse({ issue: example })).toEqual(example); + }); - it('should reset attributes (no attributes initially)', function () { - const issue = new Issue(); - const example = { a: 1 }; - issue.reset(example); - expect(issue.toJSON()).to.deep.equal(example); - }); + it('should reset attributes (no attributes initially)', function () { + const issue = new Issue(); + const example = { a: 1 }; + issue.reset(example); + expect(issue.toJSON()).toEqual(example); + }); - it('should reset attributes (override attribute)', function () { - const issue = new Issue({ a: 2 }); - const example = { a: 1 }; - issue.reset(example); - expect(issue.toJSON()).to.deep.equal(example); - }); + it('should reset attributes (override attribute)', function () { + const issue = new Issue({ a: 2 }); + const example = { a: 1 }; + issue.reset(example); + expect(issue.toJSON()).toEqual(example); + }); - it('should reset attributes (different attributes)', function () { - const issue = new Issue({ a: 2 }); - const example = { b: 1 }; - issue.reset(example); - expect(issue.toJSON()).to.deep.equal(example); - }); + it('should reset attributes (different attributes)', function () { + const issue = new Issue({ a: 2 }); + const example = { b: 1 }; + issue.reset(example); + expect(issue.toJSON()).toEqual(example); + }); - it('should unset `textRange` of a closed issue', function () { - const issue = new Issue(); - const result = issue.parse({ issue: { status: 'CLOSED', textRange: { startLine: 5 } } }); - expect(result.textRange).to.not.be.ok; - }); + it('should unset `textRange` of a closed issue', function () { + const issue = new Issue(); + const result = issue.parse({ issue: { status: 'CLOSED', textRange: { startLine: 5 } } }); + expect(result.textRange).toBeFalsy(); + }); - it('should unset `flows` of a closed issue', function () { - const issue = new Issue(); - const result = issue.parse({ issue: { status: 'CLOSED', flows: [1, 2, 3] } }); - expect(result.flows).to.deep.equal([]); - }); + it('should unset `flows` of a closed issue', function () { + const issue = new Issue(); + const result = issue.parse({ issue: { status: 'CLOSED', flows: [1, 2, 3] } }); + expect(result.flows).toEqual([]); + }); - describe('Actions', function () { - it('should assign', function () { - const issue = new Issue({ key: 'issue-key' }); - const spy = sinon.spy(); - issue._action = spy; - issue.assign('admin'); - expect(spy).to.have.been.calledWith({ - data: { assignee: 'admin', issue: 'issue-key' }, - url: '/api/issues/assign' - }); + describe('Actions', function () { + it('should assign', function () { + const issue = new Issue({ key: 'issue-key' }); + const spy = jest.fn(); + issue._action = spy; + issue.assign('admin'); + expect(spy).toBeCalledWith({ + data: { assignee: 'admin', issue: 'issue-key' }, + url: '/api/issues/assign' }); + }); - it('should unassign', function () { - const issue = new Issue({ key: 'issue-key' }); - const spy = sinon.spy(); - issue._action = spy; - issue.assign(); - expect(spy).to.have.been.calledWith({ - data: { assignee: undefined, issue: 'issue-key' }, - url: '/api/issues/assign' - }); + it('should unassign', function () { + const issue = new Issue({ key: 'issue-key' }); + const spy = jest.fn(); + issue._action = spy; + issue.assign(); + expect(spy).toBeCalledWith({ + data: { assignee: undefined, issue: 'issue-key' }, + url: '/api/issues/assign' }); + }); - it('should plan', function () { - 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 plan', function () { + const issue = new Issue({ key: 'issue-key' }); + const spy = jest.fn(); + issue._action = spy; + issue.plan('plan'); + expect(spy).toBeCalledWith({ data: { plan: 'plan', issue: 'issue-key' }, url: '/api/issues/plan' }); + }); - it('should unplan', function () { - 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 unplan', function () { + const issue = new Issue({ key: 'issue-key' }); + const spy = jest.fn(); + issue._action = spy; + issue.plan(); + expect(spy).toBeCalledWith({ data: { plan: undefined, issue: 'issue-key' }, url: '/api/issues/plan' }); + }); - it('should set severity', function () { - const issue = new Issue({ key: 'issue-key' }); - const spy = sinon.spy(); - issue._action = spy; - issue.setSeverity('BLOCKER'); - expect(spy).to.have.been.calledWith({ - data: { severity: 'BLOCKER', issue: 'issue-key' }, - url: '/api/issues/set_severity' - }); + it('should set severity', function () { + const issue = new Issue({ key: 'issue-key' }); + const spy = jest.fn(); + issue._action = spy; + issue.setSeverity('BLOCKER'); + expect(spy).toBeCalledWith({ + data: { severity: 'BLOCKER', issue: 'issue-key' }, + url: '/api/issues/set_severity' }); }); + }); - describe('#getLinearLocations', function () { - it('should return single line location', function () { - const issue = new Issue({ textRange: { startLine: 1, endLine: 1, startOffset: 0, endOffset: 10 } }); - const locations = issue.getLinearLocations(); - expect(locations.length).to.equal(1); + describe('#getLinearLocations', function () { + it('should return single line location', function () { + const issue = new Issue({ textRange: { startLine: 1, endLine: 1, startOffset: 0, endOffset: 10 } }); + const locations = issue.getLinearLocations(); + expect(locations.length).toBe(1); - expect(locations[0].line).to.equal(1); - expect(locations[0].from).to.equal(0); - expect(locations[0].to).to.equal(10); - }); + expect(locations[0].line).toBe(1); + expect(locations[0].from).toBe(0); + expect(locations[0].to).toBe(10); + }); - it('should return location not from 0', function () { - const issue = new Issue({ textRange: { startLine: 1, endLine: 1, startOffset: 5, endOffset: 10 } }); - const locations = issue.getLinearLocations(); - expect(locations.length).to.equal(1); + it('should return location not from 0', function () { + const issue = new Issue({ textRange: { startLine: 1, endLine: 1, startOffset: 5, endOffset: 10 } }); + const locations = issue.getLinearLocations(); + expect(locations.length).toBe(1); - expect(locations[0].line).to.equal(1); - expect(locations[0].from).to.equal(5); - expect(locations[0].to).to.equal(10); - }); + expect(locations[0].line).toBe(1); + expect(locations[0].from).toBe(5); + expect(locations[0].to).toBe(10); + }); - it('should return 2-lines location', function () { - const issue = new Issue({ textRange: { startLine: 2, endLine: 3, startOffset: 5, endOffset: 10 } }); - const locations = issue.getLinearLocations(); - expect(locations.length).to.equal(2); + it('should return 2-lines location', function () { + const issue = new Issue({ textRange: { startLine: 2, endLine: 3, startOffset: 5, endOffset: 10 } }); + const locations = issue.getLinearLocations(); + expect(locations.length).toBe(2); - expect(locations[0].line).to.equal(2); - expect(locations[0].from).to.equal(5); - expect(locations[0].to).to.equal(999999); + expect(locations[0].line).toBe(2); + expect(locations[0].from).toBe(5); + expect(locations[0].to).toBe(999999); - expect(locations[1].line).to.equal(3); - expect(locations[1].from).to.equal(0); - expect(locations[1].to).to.equal(10); - }); + expect(locations[1].line).toBe(3); + expect(locations[1].from).toBe(0); + expect(locations[1].to).toBe(10); + }); - it('should return 3-lines location', function () { - const issue = new Issue({ textRange: { startLine: 4, endLine: 6, startOffset: 5, endOffset: 10 } }); - const locations = issue.getLinearLocations(); - expect(locations.length).to.equal(3); + it('should return 3-lines location', function () { + const issue = new Issue({ textRange: { startLine: 4, endLine: 6, startOffset: 5, endOffset: 10 } }); + const locations = issue.getLinearLocations(); + expect(locations.length).toBe(3); - expect(locations[0].line).to.equal(4); - expect(locations[0].from).to.equal(5); - expect(locations[0].to).to.equal(999999); + expect(locations[0].line).toBe(4); + expect(locations[0].from).toBe(5); + expect(locations[0].to).toBe(999999); - expect(locations[1].line).to.equal(5); - expect(locations[1].from).to.equal(0); - expect(locations[1].to).to.equal(999999); + expect(locations[1].line).toBe(5); + expect(locations[1].from).toBe(0); + expect(locations[1].to).toBe(999999); - expect(locations[2].line).to.equal(6); - expect(locations[2].from).to.equal(0); - expect(locations[2].to).to.equal(10); - }); + expect(locations[2].line).toBe(6); + expect(locations[2].from).toBe(0); + expect(locations[2].to).toBe(10); + }); - it('should return [] when no location', function () { - const issue = new Issue(); - const locations = issue.getLinearLocations(); - expect(locations.length).to.equal(0); - }); + it('should return [] when no location', function () { + const issue = new Issue(); + const locations = issue.getLinearLocations(); + expect(locations.length).toBe(0); }); }); }); diff --git a/server/sonar-web/src/main/js/components/__tests__/source-viewer-test.js b/server/sonar-web/src/main/js/components/__tests__/source-viewer-test.js index 99ce9b0d700..5d27c5ad0b1 100644 --- a/server/sonar-web/src/main/js/components/__tests__/source-viewer-test.js +++ b/server/sonar-web/src/main/js/components/__tests__/source-viewer-test.js @@ -17,93 +17,89 @@ * 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'); - }); +describe('Code With Issue Locations Helper', function () { + it('should be a function', function () { + expect(helper).toBeTruthy(); + }); - it('should mark one location', function () { - const code = 'if (a + 1) {'; - const locations = [{ from: 1, to: 5 }]; - const result = helper(code, locations, 'x'); - expect(result).to.equal([ - 'i', - 'f', - ' (', - 'a', - ' + ', - '1', - ') {' - ].join('')); - }); + it('should mark one location', function () { + const code = 'if (a + 1) {'; + const locations = [{ from: 1, to: 5 }]; + const result = helper(code, locations, 'x'); + expect(result).toBe([ + 'i', + 'f', + ' (', + 'a', + ' + ', + '1', + ') {' + ].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([ - 'a', - 'bcdef', - 'ghijk', - 'lmnop', - 'qrst' - ].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).toBe([ + 'a', + 'bcdef', + 'ghijk', + 'lmnop', + 'qrst' + ].join('')); + }); - it('should mark one locations', function () { - const code = ' * Copyright (C) 2008-2014 SonarSource'; - const locations = [{ from: 15, to: 20 }]; - const result = helper(code, locations, 'x'); - expect(result).to.equal([ - ' * Copyright (C', - ') 200', - '8-2014 SonarSource' - ].join('')); - }); + it('should mark one locations', function () { + const code = ' * Copyright (C) 2008-2014 SonarSource'; + const locations = [{ from: 15, to: 20 }]; + const result = helper(code, locations, 'x'); + expect(result).toBe([ + ' * Copyright (C', + ') 200', + '8-2014 SonarSource' + ].join('')); + }); - it('should mark two locations', function () { - const code = ' * Copyright (C) 2008-2014 SonarSource'; - const locations = [ - { from: 24, to: 29 }, - { from: 15, to: 20 } - ]; - const result = helper(code, locations, 'x'); - expect(result).to.equal([ - ' * Copyright (C', - ') 200', - '8-20', - '14 So', - 'narSource' - ].join('')); - }); + it('should mark two locations', function () { + const code = ' * Copyright (C) 2008-2014 SonarSource'; + const locations = [ + { from: 24, to: 29 }, + { from: 15, to: 20 } + ]; + const result = helper(code, locations, 'x'); + expect(result).toBe([ + ' * Copyright (C', + ') 200', + '8-20', + '14 So', + 'narSource' + ].join('')); + }); - it('should parse line with < and >', function () { - const code = '#include <stdio.h>'; - const result = helper(code, []); - expect(result).to.equal('#include <stdio.h>'); - }); + it('should parse line with < and >', function () { + const code = '#include <stdio.h>'; + const result = helper(code, []); + expect(result).toBe('#include <stdio.h>'); + }); - it('should parse syntax and usage highlighting', function () { - const code = 'this'; - const expected = 'this'; - const result = helper(code, []); - expect(result).to.equal(expected); - }); + it('should parse syntax and usage highlighting', function () { + const code = 'this'; + const expected = 'this'; + const result = helper(code, []); + expect(result).toBe(expected); + }); - it('should parse nested tags', function () { - const code = 'this is'; - const expected = 'this is'; - const result = helper(code, []); - expect(result).to.equal(expected); - }); + it('should parse nested tags', function () { + const code = 'this is'; + const expected = 'this is'; + const result = helper(code, []); + expect(result).toBe(expected); }); }); diff --git a/server/sonar-web/src/main/js/components/charts/__tests__/bar-chart-test.js b/server/sonar-web/src/main/js/components/charts/__tests__/bar-chart-test.js index d3c50a49eb6..5b0d0b2abfb 100644 --- a/server/sonar-web/src/main/js/components/charts/__tests__/bar-chart-test.js +++ b/server/sonar-web/src/main/js/components/charts/__tests__/bar-chart-test.js @@ -18,80 +18,74 @@ * 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 { shallow } from 'enzyme'; 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( - ); - 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( - ); - expect(TestUtils.scryRenderedDOMComponentsWithClass(chart, 'bar-chart-tick')).to.have.length(3); - }); +it('should display bars', function () { + const data = [ + { x: 1, y: 10 }, + { x: 2, y: 30 }, + { x: 3, y: 20 } + ]; + const chart = shallow( + ); + expect(chart.find('.bar-chart-bar').length).toBe(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( - ); - expect(TestUtils.scryRenderedDOMComponentsWithClass(chart, 'bar-chart-tick')).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 = shallow( + ); + expect(chart.find('.bar-chart-tick').length).toBe(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( - ); - expect(TestUtils.scryRenderedDOMComponentsWithClass(chart, 'bar-chart-bar')).to.have.length(3); - expect(TestUtils.scryRenderedDOMComponentsWithClass(chart, 'bar-chart-tick')).to.have.length(6); - }); +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 = shallow( + ); + expect(chart.find('.bar-chart-tick').length).toBe(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 = shallow( + ); + expect(chart.find('.bar-chart-bar').length).toBe(3); + expect(chart.find('.bar-chart-tick').length).toBe(6); }); diff --git a/server/sonar-web/src/main/js/components/charts/__tests__/bubble-chart-test.js b/server/sonar-web/src/main/js/components/charts/__tests__/bubble-chart-test.js index bb03185276a..65374ff393c 100644 --- a/server/sonar-web/src/main/js/components/charts/__tests__/bubble-chart-test.js +++ b/server/sonar-web/src/main/js/components/charts/__tests__/bubble-chart-test.js @@ -18,41 +18,35 @@ * 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 { shallow } from 'enzyme'; +import { BubbleChart, Bubble } from '../bubble-chart'; -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(); - 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(); - expect(TestUtils.scryRenderedDOMComponentsWithTag(chart, 'line')).to.not.be.empty; - }); +it('should display bubbles', () => { + const items = [ + { x: 1, y: 10, size: 7 }, + { x: 2, y: 30, size: 5 }, + { x: 3, y: 20, size: 2 } + ]; + const chart = shallow(); + expect(chart.find(Bubble).length).toBe(3); +}); - 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(); - expect(TestUtils.scryRenderedDOMComponentsWithClass(chart, 'bubble-chart-tick')).to.not.be.empty; - }); +it('should display grid', () => { + const items = [ + { x: 1, y: 10, size: 7 }, + { x: 2, y: 30, size: 5 }, + { x: 3, y: 20, size: 2 } + ]; + const chart = shallow(); + expect(chart.find('line').length).toBeGreaterThan(0); +}); +it('should display ticks', () => { + const items = [ + { x: 1, y: 10, size: 7 }, + { x: 2, y: 30, size: 5 }, + { x: 3, y: 20, size: 2 } + ]; + const chart = shallow(); + expect(chart.find('.bubble-chart-tick').length).toBeGreaterThan(0); }); diff --git a/server/sonar-web/src/main/js/components/charts/__tests__/line-chart-test.js b/server/sonar-web/src/main/js/components/charts/__tests__/line-chart-test.js index e4144bb97bf..adbe6ce3462 100644 --- a/server/sonar-web/src/main/js/components/charts/__tests__/line-chart-test.js +++ b/server/sonar-web/src/main/js/components/charts/__tests__/line-chart-test.js @@ -18,57 +18,47 @@ * 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 { shallow } from 'enzyme'; 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( - ); - 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( - ); - expect(TestUtils.scryRenderedDOMComponentsWithClass(chart, 'line-chart-tick')).to.have.length(3); - }); +it('should display line', function () { + const data = [ + { x: 1, y: 10 }, + { x: 2, y: 30 }, + { x: 3, y: 20 } + ]; + const chart = shallow(); + expect(chart.find('.line-chart-path').length).toBe(1); +}); - 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( - ); - expect(TestUtils.scryRenderedDOMComponentsWithClass(chart, 'line-chart-tick')).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 = shallow( + ); + expect(chart.find('.line-chart-tick').length).toBe(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 = shallow( + ); + expect(chart.find('.line-chart-tick').length).toBe(3); }); diff --git a/server/sonar-web/src/main/js/components/charts/__tests__/treemap-test.js b/server/sonar-web/src/main/js/components/charts/__tests__/treemap-test.js index 1ce0054bcb7..ac5c72039a5 100644 --- a/server/sonar-web/src/main/js/components/charts/__tests__/treemap-test.js +++ b/server/sonar-web/src/main/js/components/charts/__tests__/treemap-test.js @@ -18,27 +18,21 @@ * 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( - true}/>); - expect(TestUtils.scryRenderedDOMComponentsWithClass(chart, 'treemap-cell')).to.have.length(3); - }); +import { shallow } from 'enzyme'; +import { Treemap, TreemapRect } from '../treemap'; +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 = shallow( + true}/>); + expect(chart.find(TreemapRect).length).toBe(3); }); diff --git a/server/sonar-web/src/main/js/components/charts/__tests__/work-cloud-test.js b/server/sonar-web/src/main/js/components/charts/__tests__/work-cloud-test.js index 177151ae053..4ba52d60c34 100644 --- a/server/sonar-web/src/main/js/components/charts/__tests__/work-cloud-test.js +++ b/server/sonar-web/src/main/js/components/charts/__tests__/work-cloud-test.js @@ -18,21 +18,15 @@ * 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(); - expect(TestUtils.scryRenderedDOMComponentsWithTag(chart, 'a')).to.have.length(3); - }); +import { shallow } from 'enzyme'; +import { WordCloud, Word } from '../word-cloud'; +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 = shallow(); + expect(chart.find(Word).length).toBe(3); }); diff --git a/server/sonar-web/src/main/js/components/controls/__tests__/Checkbox-test.js b/server/sonar-web/src/main/js/components/controls/__tests__/Checkbox-test.js index 3f26878824a..10509ca66a2 100644 --- a/server/sonar-web/src/main/js/components/controls/__tests__/Checkbox-test.js +++ b/server/sonar-web/src/main/js/components/controls/__tests__/Checkbox-test.js @@ -17,59 +17,36 @@ * 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 { shallow } from 'enzyme'; -import sinon from 'sinon'; -import sinonChai from 'sinon-chai'; import React from 'react'; import Checkbox from '../Checkbox'; +import { click } from '../../../../../../tests/utils'; -chai.use(sinonChai); - -function click (element) { - return element.simulate('click', { - target: { blur () {} }, - preventDefault () {} - }); -} - -describe('Components :: Controls :: Checkbox', () => { - it('should render unchecked', () => { - const checkbox = shallow( - true}/> - ); - expect(checkbox.is('.icon-checkbox-checked')).to.equal(false); - }); +it('should render unchecked', () => { + const checkbox = shallow( true}/>); + expect(checkbox.is('.icon-checkbox-checked')).toBe(false); +}); - it('should render checked', () => { - const checkbox = shallow( - true}/> - ); - expect(checkbox.is('.icon-checkbox-checked')).to.equal(true); - }); +it('should render checked', () => { + const checkbox = shallow( true}/>); + expect(checkbox.is('.icon-checkbox-checked')).toBe(true); +}); - it('should render unchecked third state', () => { - const checkbox = shallow( - true}/> - ); - expect(checkbox.is('.icon-checkbox-single')).to.equal(true); - expect(checkbox.is('.icon-checkbox-checked')).to.equal(false); - }); +it('should render unchecked third state', () => { + const checkbox = shallow( true}/>); + expect(checkbox.is('.icon-checkbox-single')).toBe(true); + expect(checkbox.is('.icon-checkbox-checked')).toBe(false); +}); - it('should render checked third state', () => { - const checkbox = shallow( - true}/> - ); - expect(checkbox.is('.icon-checkbox-single')).to.equal(true); - expect(checkbox.is('.icon-checkbox-checked')).to.equal(true); - }); +it('should render checked third state', () => { + const checkbox = shallow( true}/>); + expect(checkbox.is('.icon-checkbox-single')).toBe(true); + expect(checkbox.is('.icon-checkbox-checked')).toBe(true); +}); - it('should call onCheck', () => { - const onCheck = sinon.spy(); - const checkbox = shallow( - - ); - click(checkbox); - expect(onCheck).to.have.been.calledWith(true); - }); +it('should call onCheck', () => { + const onCheck = jest.fn(); + const checkbox = shallow(); + click(checkbox); + expect(onCheck).toBeCalledWith(true); }); diff --git a/server/sonar-web/src/main/js/components/controls/__tests__/FavoriteBase-test.js b/server/sonar-web/src/main/js/components/controls/__tests__/FavoriteBase-test.js index 6a8db197bc4..475c7a1b392 100644 --- a/server/sonar-web/src/main/js/components/controls/__tests__/FavoriteBase-test.js +++ b/server/sonar-web/src/main/js/components/controls/__tests__/FavoriteBase-test.js @@ -17,54 +17,41 @@ * 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 { shallow } from 'enzyme'; -import sinon from 'sinon'; -import sinonChai from 'sinon-chai'; import React from 'react'; import FavoriteBase from '../FavoriteBase'; - -chai.use(sinonChai); - -function click (element) { - return element.simulate('click', { - target: { blur () {} }, - preventDefault () {} - }); -} +import { click } from '../../../../../../tests/utils'; function renderFavoriteBase (props) { return shallow( ); } -describe('Components :: Controls :: FavoriteBase', () => { - it('should render favorite', () => { - const favorite = renderFavoriteBase({ favorite: true }); - expect(favorite.is('.icon-star-favorite')).to.equal(true); - }); +it('should render favorite', () => { + const favorite = renderFavoriteBase({ favorite: true }); + expect(favorite.is('.icon-star-favorite')).toBe(true); +}); - it('should render not favorite', () => { - const favorite = renderFavoriteBase({ favorite: false }); - expect(favorite.is('.icon-star-favorite')).to.equal(false); - }); +it('should render not favorite', () => { + const favorite = renderFavoriteBase({ favorite: false }); + expect(favorite.is('.icon-star-favorite')).toBe(false); +}); - it('should add favorite', () => { - const addFavorite = sinon.stub().returns(Promise.resolve()); - const favorite = renderFavoriteBase({ favorite: false, addFavorite }); - click(favorite.find('a')); - expect(addFavorite).to.have.been.called; - }); +it('should add favorite', () => { + const addFavorite = jest.fn(() => Promise.resolve()); + const favorite = renderFavoriteBase({ favorite: false, addFavorite }); + click(favorite.find('a')); + expect(addFavorite).toBeCalled(); +}); - it('should remove favorite', () => { - const removeFavorite = sinon.stub().returns(Promise.resolve()); - const favorite = renderFavoriteBase({ favorite: true, removeFavorite }); - click(favorite.find('a')); - expect(removeFavorite).to.have.been.called; - }); +it('should remove favorite', () => { + const removeFavorite = jest.fn(() => Promise.resolve()); + const favorite = renderFavoriteBase({ favorite: true, removeFavorite }); + click(favorite.find('a')); + expect(removeFavorite).toBeCalled(); }); diff --git a/server/sonar-web/src/main/js/components/controls/__tests__/ListFooter-test.js b/server/sonar-web/src/main/js/components/controls/__tests__/ListFooter-test.js index 5d02cf7ef36..727938d46bd 100644 --- a/server/sonar-web/src/main/js/components/controls/__tests__/ListFooter-test.js +++ b/server/sonar-web/src/main/js/components/controls/__tests__/ListFooter-test.js @@ -17,45 +17,26 @@ * 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 { shallow } from 'enzyme'; -import sinon from 'sinon'; -import sinonChai from 'sinon-chai'; import React from 'react'; import ListFooter from '../ListFooter'; +import { click } from '../../../../../../tests/utils'; -chai.use(sinonChai); - -function click (element) { - return element.simulate('click', { - target: { blur () {} }, - preventDefault () {} - }); -} - -describe('Components :: Controls :: ListFooter', () => { - it('should render "3 of 5 shown"', () => { - const listFooter = shallow( - - ); - expect(listFooter.text()).to.contain('x_of_y_shown.3.5'); - }); +it('should render "3 of 5 shown"', () => { + const listFooter = shallow(); + expect(listFooter.text()).toContain('x_of_y_shown.3.5'); +}); - it('should not render "show more"', () => { - const listFooter = shallow( - - ); - expect(listFooter.find('a')).to.have.length(0); - }); +it('should not render "show more"', () => { + const listFooter = shallow(); + expect(listFooter.find('a').length).toBe(0); +}); - it('should "show more"', () => { - const loadMore = sinon.spy(); - const listFooter = shallow( - - ); - const link = listFooter.find('a'); - expect(link).to.have.length(1); - click(link); - expect(loadMore).to.have.been.called; - }); +it('should "show more"', () => { + const loadMore = jest.fn(); + const listFooter = shallow(); + const link = listFooter.find('a'); + expect(link.length).toBe(1); + click(link); + expect(loadMore).toBeCalled(); }); diff --git a/server/sonar-web/src/main/js/components/controls/__tests__/RadioToggle-test.js b/server/sonar-web/src/main/js/components/controls/__tests__/RadioToggle-test.js index 8da0df6cca5..47955d43ce0 100644 --- a/server/sonar-web/src/main/js/components/controls/__tests__/RadioToggle-test.js +++ b/server/sonar-web/src/main/js/components/controls/__tests__/RadioToggle-test.js @@ -17,14 +17,10 @@ * 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 { shallow } from 'enzyme'; -import sinon from 'sinon'; -import sinonChai from 'sinon-chai'; import React from 'react'; import RadioToggle from '../RadioToggle'; - -chai.use(sinonChai); +import { change } from '../../../../../../tests/utils'; function getSample (props) { const options = [ @@ -40,21 +36,15 @@ function getSample (props) { ); } -function change (element, value) { - return element.simulate('change', { currentTarget: { value } }); -} - -describe('Components :: Controls :: RadioToggle', () => { - it('should render', () => { - const radioToggle = shallow(getSample()); - expect(radioToggle.find('input[type="radio"]')).to.have.length(2); - expect(radioToggle.find('label')).to.have.length(2); - }); +it('should render', () => { + const radioToggle = shallow(getSample()); + expect(radioToggle.find('input[type="radio"]').length).toBe(2); + expect(radioToggle.find('label').length).toBe(2); +}); - it('should call onCheck', () => { - const onCheck = sinon.spy(); - const radioToggle = shallow(getSample({ onCheck })); - change(radioToggle.find('input[value="two"]'), 'two'); - expect(onCheck).to.have.been.calledWith('two'); - }); +it('should call onCheck', () => { + const onCheck = jest.fn(); + const radioToggle = shallow(getSample({ onCheck })); + change(radioToggle.find('input[value="two"]'), 'two'); + expect(onCheck).toBeCalledWith('two'); }); diff --git a/server/sonar-web/src/main/js/components/controls/__tests__/Toggle-test.js b/server/sonar-web/src/main/js/components/controls/__tests__/Toggle-test.js index f194063188b..cf6c992edca 100644 --- a/server/sonar-web/src/main/js/components/controls/__tests__/Toggle-test.js +++ b/server/sonar-web/src/main/js/components/controls/__tests__/Toggle-test.js @@ -17,37 +17,24 @@ * 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 { shallow } from 'enzyme'; -import sinon from 'sinon'; -import sinonChai from 'sinon-chai'; import React from 'react'; import Toggle from '../Toggle'; - -chai.use(sinonChai); +import { click } from '../../../../../../tests/utils'; function getSample (props) { return ( true} {...props}/>); } -function click (element) { - return element.simulate('click', { - currentTarget: { blur () {} }, - preventDefault () {} - }); -} - -describe('Components :: Controls :: Toggle', () => { - it('should render', () => { - const Toggle = shallow(getSample()); - expect(Toggle.is('button')).to.equal(true); - }); +it('should render', () => { + const Toggle = shallow(getSample()); + expect(Toggle.is('button')).toBe(true); +}); - it('should call onChange', () => { - const onChange = sinon.spy(); - const Toggle = shallow(getSample({ onChange })); - click(Toggle); - expect(onChange).to.have.been.calledWith(false); - }); +it('should call onChange', () => { + const onChange = jest.fn(); + const Toggle = shallow(getSample({ onChange })); + click(Toggle); + expect(onChange).toBeCalledWith(false); }); diff --git a/server/sonar-web/src/main/js/components/ui/__tests__/Avatar-test.js b/server/sonar-web/src/main/js/components/ui/__tests__/Avatar-test.js index cbfd3e848b7..1a5239d0727 100644 --- a/server/sonar-web/src/main/js/components/ui/__tests__/Avatar-test.js +++ b/server/sonar-web/src/main/js/components/ui/__tests__/Avatar-test.js @@ -17,42 +17,34 @@ * 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 { shallow } from 'enzyme'; import React from 'react'; import Avatar from '../Avatar'; -describe('Components :: UI :: Avatar', () => { - beforeEach(() => { - window.SS = { - lf: { - enableGravatar: true, - gravatarServerUrl: 'http://example.com/{EMAIL_MD5}.jpg?s={SIZE}' - } - }; - }); +beforeEach(() => { + window.SS = { + lf: { + enableGravatar: true, + gravatarServerUrl: 'http://example.com/{EMAIL_MD5}.jpg?s={SIZE}' + } + }; +}); - afterEach(() => { - window.SS = undefined; - }); +afterEach(() => { + window.SS = undefined; +}); - it('should render', () => { - const avatar = shallow( - - ); - expect(avatar.is('img')).to.equal(true); - expect(avatar.prop('width')).to.equal(20); - expect(avatar.prop('height')).to.equal(20); - expect(avatar.prop('alt')).to.equal('mail@example.com'); - expect(avatar.prop('src')).to.equal( - 'http://example.com/7daf6c79d4802916d83f6266e24850af.jpg?s=40'); - }); +it('should render', () => { + const avatar = shallow(); + expect(avatar.is('img')).toBe(true); + expect(avatar.prop('width')).toBe(20); + expect(avatar.prop('height')).toBe(20); + expect(avatar.prop('alt')).toBe('mail@example.com'); + expect(avatar.prop('src')).toBe('http://example.com/7daf6c79d4802916d83f6266e24850af.jpg?s=40'); +}); - it('should not render', () => { - window.SS.lf.enableGravatar = false; - const avatar = shallow( - - ); - expect(avatar.is('img')).to.equal(false); - }); +it('should not render', () => { + window.SS.lf.enableGravatar = false; + const avatar = shallow(); + expect(avatar.is('img')).toBe(false); }); diff --git a/server/sonar-web/src/main/js/components/ui/__tests__/Level-test.js b/server/sonar-web/src/main/js/components/ui/__tests__/Level-test.js index 3d38503927b..4f7aa453b0b 100644 --- a/server/sonar-web/src/main/js/components/ui/__tests__/Level-test.js +++ b/server/sonar-web/src/main/js/components/ui/__tests__/Level-test.js @@ -17,16 +17,11 @@ * 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 { shallow } from 'enzyme'; import React from 'react'; import Level from '../Level'; -describe('Components :: UI :: Level', () => { - it('should render', () => { - const rating = shallow( - - ); - expect(rating.is('.level-ERROR')).to.equal(true); - }); +it('should render', () => { + const rating = shallow(); + expect(rating.is('.level-ERROR')).toBe(true); }); diff --git a/server/sonar-web/src/main/js/components/ui/__tests__/Rating-test.js b/server/sonar-web/src/main/js/components/ui/__tests__/Rating-test.js index bcd89111e76..59b5a21fb27 100644 --- a/server/sonar-web/src/main/js/components/ui/__tests__/Rating-test.js +++ b/server/sonar-web/src/main/js/components/ui/__tests__/Rating-test.js @@ -17,23 +17,16 @@ * 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 { shallow } from 'enzyme'; import React from 'react'; import Rating from '../Rating'; -describe('Components :: UI :: Rating', () => { - it('should render with numeric value', () => { - const rating = shallow( - - ); - expect(rating.is('.rating-B')).to.equal(true); - }); +it('should render with numeric value', () => { + const rating = shallow(); + expect(rating.is('.rating-B')).toBe(true); +}); - it('should render with string value', () => { - const rating = shallow( - - ); - expect(rating.is('.rating-B')).to.equal(true); - }); +it('should render with string value', () => { + const rating = shallow(); + expect(rating.is('.rating-B')).toBe(true); }); diff --git a/server/sonar-web/src/main/js/helpers/__tests__/l10n-test.js b/server/sonar-web/src/main/js/helpers/__tests__/l10n-test.js index 2bfb21308c1..6dff12779b8 100644 --- a/server/sonar-web/src/main/js/helpers/__tests__/l10n-test.js +++ b/server/sonar-web/src/main/js/helpers/__tests__/l10n-test.js @@ -17,60 +17,57 @@ * 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 '../l10n'; -describe('l10n', () => { - afterEach(() => { - resetBundle({}); - }); +afterEach(() => { + resetBundle({}); +}); - describe('#translate', () => { - it('should translate simple message', () => { - resetBundle({ 'my_key': 'my message' }); - expect(translate('my_key')).to.equal('my message'); - }); +describe('#translate', () => { + it('should translate simple message', () => { + resetBundle({ 'my_key': 'my message' }); + expect(translate('my_key')).toBe('my message'); + }); - it('should translate message with composite key', () => { - resetBundle({ 'my.composite.message': 'my message' }); - expect(translate('my', 'composite', 'message')).to.equal('my message'); - expect(translate('my.composite', 'message')).to.equal('my message'); - expect(translate('my', 'composite.message')).to.equal('my message'); - expect(translate('my.composite.message')).to.equal('my message'); - }); + it('should translate message with composite key', () => { + resetBundle({ 'my.composite.message': 'my message' }); + expect(translate('my', 'composite', 'message')).toBe('my message'); + expect(translate('my.composite', 'message')).toBe('my message'); + expect(translate('my', 'composite.message')).toBe('my message'); + expect(translate('my.composite.message')).toBe('my message'); + }); - it('should not translate message but return its key', () => { - expect(translate('random')).to.equal('random'); - expect(translate('random', 'key')).to.equal('random.key'); - expect(translate('composite.random', 'key')).to.equal('composite.random.key'); - }); + it('should not translate message but return its key', () => { + expect(translate('random')).toBe('random'); + expect(translate('random', 'key')).toBe('random.key'); + expect(translate('composite.random', 'key')).toBe('composite.random.key'); }); +}); - describe('#translateWithParameters', () => { - it('should translate message with one parameter in the beginning', () => { - resetBundle({ 'x_apples': '{0} apples' }); - expect(translateWithParameters('x_apples', 5)).to.equal('5 apples'); - }); +describe('#translateWithParameters', () => { + it('should translate message with one parameter in the beginning', () => { + resetBundle({ 'x_apples': '{0} apples' }); + expect(translateWithParameters('x_apples', 5)).toBe('5 apples'); + }); - it('should translate message with one parameter in the middle', () => { - resetBundle({ 'x_apples': 'I have {0} apples' }); - expect(translateWithParameters('x_apples', 5)).to.equal('I have 5 apples'); - }); + it('should translate message with one parameter in the middle', () => { + resetBundle({ 'x_apples': 'I have {0} apples' }); + expect(translateWithParameters('x_apples', 5)).toBe('I have 5 apples'); + }); - it('should translate message with one parameter in the end', () => { - resetBundle({ 'x_apples': 'Apples: {0}' }); - expect(translateWithParameters('x_apples', 5)).to.equal('Apples: 5'); - }); + it('should translate message with one parameter in the end', () => { + resetBundle({ 'x_apples': 'Apples: {0}' }); + expect(translateWithParameters('x_apples', 5)).toBe('Apples: 5'); + }); - it('should translate message with several parameters', () => { - resetBundle({ 'x_apples': '{0}: I have {2} apples in my {1} baskets - {3}' }); - expect(translateWithParameters('x_apples', 1, 2, 3, 4)).to.equal('1: I have 3 apples in my 2 baskets - 4'); - }); + it('should translate message with several parameters', () => { + resetBundle({ 'x_apples': '{0}: I have {2} apples in my {1} baskets - {3}' }); + expect(translateWithParameters('x_apples', 1, 2, 3, 4)).toBe('1: I have 3 apples in my 2 baskets - 4'); + }); - it('should not translate message but return its key', () => { - expect(translateWithParameters('random', 5)).to.equal('random.5'); - expect(translateWithParameters('random', 1, 2, 3)).to.equal('random.1.2.3'); - expect(translateWithParameters('composite.random', 1, 2)).to.equal('composite.random.1.2'); - }); + it('should not translate message but return its key', () => { + expect(translateWithParameters('random', 5)).toBe('random.5'); + expect(translateWithParameters('random', 1, 2, 3)).toBe('random.1.2.3'); + expect(translateWithParameters('composite.random', 1, 2)).toBe('composite.random.1.2'); }); }); diff --git a/server/sonar-web/src/main/js/helpers/__tests__/measures-test.js b/server/sonar-web/src/main/js/helpers/__tests__/measures-test.js index 23b624ff5e3..19aa065750d 100644 --- a/server/sonar-web/src/main/js/helpers/__tests__/measures-test.js +++ b/server/sonar-web/src/main/js/helpers/__tests__/measures-test.js @@ -17,240 +17,235 @@ * 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 '../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; - - before(function () { - resetBundle({ - 'work_duration.x_days': '{0}d', - 'work_duration.x_hours': '{0}h', - 'work_duration.x_minutes': '{0}min', - 'work_duration.about': '~ {0}', - 'metric.level.ERROR': 'Error', - 'metric.level.WARN': 'Warning', - 'metric.level.OK': 'Ok' - }); - window.SS = { hoursInDay: HOURS_IN_DAY }; +const HOURS_IN_DAY = 8; +const ONE_MINUTE = 1; +const ONE_HOUR = ONE_MINUTE * 60; +const ONE_DAY = HOURS_IN_DAY * ONE_HOUR; + +beforeEach(function () { + resetBundle({ + 'work_duration.x_days': '{0}d', + 'work_duration.x_hours': '{0}h', + 'work_duration.x_minutes': '{0}min', + 'work_duration.about': '~ {0}', + 'metric.level.ERROR': 'Error', + 'metric.level.WARN': 'Warning', + 'metric.level.OK': 'Ok' }); + window.SS = { hoursInDay: HOURS_IN_DAY }; +}); - describe('#formatMeasure()', function () { - it('should format INT', function () { - expect(formatMeasure(0, 'INT')).to.equal('0'); - expect(formatMeasure(1, 'INT')).to.equal('1'); - expect(formatMeasure(-5, 'INT')).to.equal('-5'); - expect(formatMeasure(999, 'INT')).to.equal('999'); - expect(formatMeasure(1000, 'INT')).to.equal('1,000'); - expect(formatMeasure(1529, 'INT')).to.equal('1,529'); - expect(formatMeasure(10000, 'INT')).to.equal('10,000'); - expect(formatMeasure(1234567890, 'INT')).to.equal('1,234,567,890'); - }); - - it('should format SHORT_INT', function () { - expect(formatMeasure(0, 'SHORT_INT')).to.equal('0'); - expect(formatMeasure(1, 'SHORT_INT')).to.equal('1'); - expect(formatMeasure(999, 'SHORT_INT')).to.equal('999'); - expect(formatMeasure(1000, 'SHORT_INT')).to.equal('1k'); - expect(formatMeasure(1529, 'SHORT_INT')).to.equal('1.5k'); - expect(formatMeasure(10000, 'SHORT_INT')).to.equal('10k'); - expect(formatMeasure(10678, 'SHORT_INT')).to.equal('11k'); - expect(formatMeasure(1234567890, 'SHORT_INT')).to.equal('1b'); - }); - - it('should format FLOAT', function () { - expect(formatMeasure(0.0, 'FLOAT')).to.equal('0.0'); - expect(formatMeasure(1.0, 'FLOAT')).to.equal('1.0'); - expect(formatMeasure(1.3, 'FLOAT')).to.equal('1.3'); - expect(formatMeasure(1.34, 'FLOAT')).to.equal('1.34'); - expect(formatMeasure(50.89, 'FLOAT')).to.equal('50.89'); - expect(formatMeasure(100.0, 'FLOAT')).to.equal('100.0'); - expect(formatMeasure(123.456, 'FLOAT')).to.equal('123.456'); - expect(formatMeasure(123456.7, 'FLOAT')).to.equal('123,456.7'); - expect(formatMeasure(1234567890.0, 'FLOAT')).to.equal('1,234,567,890.0'); - }); +describe('#formatMeasure()', function () { + it('should format INT', function () { + expect(formatMeasure(0, 'INT')).toBe('0'); + expect(formatMeasure(1, 'INT')).toBe('1'); + expect(formatMeasure(-5, 'INT')).toBe('-5'); + expect(formatMeasure(999, 'INT')).toBe('999'); + expect(formatMeasure(1000, 'INT')).toBe('1,000'); + expect(formatMeasure(1529, 'INT')).toBe('1,529'); + expect(formatMeasure(10000, 'INT')).toBe('10,000'); + expect(formatMeasure(1234567890, 'INT')).toBe('1,234,567,890'); + }); - it('should respect FLOAT precision', function () { - expect(formatMeasure(0.1, 'FLOAT')).to.equal('0.1'); - expect(formatMeasure(0.12, 'FLOAT')).to.equal('0.12'); - expect(formatMeasure(0.12345, 'FLOAT')).to.equal('0.12345'); - expect(formatMeasure(0.123456, 'FLOAT')).to.equal('0.12346'); - }); + it('should format SHORT_INT', function () { + expect(formatMeasure(0, 'SHORT_INT')).toBe('0'); + expect(formatMeasure(1, 'SHORT_INT')).toBe('1'); + expect(formatMeasure(999, 'SHORT_INT')).toBe('999'); + expect(formatMeasure(1000, 'SHORT_INT')).toBe('1k'); + expect(formatMeasure(1529, 'SHORT_INT')).toBe('1.5k'); + expect(formatMeasure(10000, 'SHORT_INT')).toBe('10k'); + expect(formatMeasure(10678, 'SHORT_INT')).toBe('11k'); + expect(formatMeasure(1234567890, 'SHORT_INT')).toBe('1b'); + }); - it('should format PERCENT', function () { - expect(formatMeasure(0.0, 'PERCENT')).to.equal('0.0%'); - expect(formatMeasure(1.0, 'PERCENT')).to.equal('1.0%'); - expect(formatMeasure(1.3, 'PERCENT')).to.equal('1.3%'); - expect(formatMeasure(1.34, 'PERCENT')).to.equal('1.3%'); - expect(formatMeasure(50.89, 'PERCENT')).to.equal('50.9%'); - expect(formatMeasure(100.0, 'PERCENT')).to.equal('100.0%'); - }); + it('should format FLOAT', function () { + expect(formatMeasure(0.0, 'FLOAT')).toBe('0.0'); + expect(formatMeasure(1.0, 'FLOAT')).toBe('1.0'); + expect(formatMeasure(1.3, 'FLOAT')).toBe('1.3'); + expect(formatMeasure(1.34, 'FLOAT')).toBe('1.34'); + expect(formatMeasure(50.89, 'FLOAT')).toBe('50.89'); + expect(formatMeasure(100.0, 'FLOAT')).toBe('100.0'); + expect(formatMeasure(123.456, 'FLOAT')).toBe('123.456'); + expect(formatMeasure(123456.7, 'FLOAT')).toBe('123,456.7'); + expect(formatMeasure(1234567890.0, 'FLOAT')).toBe('1,234,567,890.0'); + }); - it('should format WORK_DUR', function () { - expect(formatMeasure(0, 'WORK_DUR')).to.equal('0'); - expect(formatMeasure(5 * ONE_DAY, 'WORK_DUR')).to.equal('5d'); - expect(formatMeasure(2 * ONE_HOUR, 'WORK_DUR')).to.equal('2h'); - expect(formatMeasure(40 * ONE_MINUTE, 'WORK_DUR')).to.equal('40min'); - expect(formatMeasure(ONE_MINUTE, 'WORK_DUR')).to.equal('1min'); - expect(formatMeasure(5 * ONE_DAY + 2 * ONE_HOUR, 'WORK_DUR')).to.equal('5d 2h'); - expect(formatMeasure(2 * ONE_HOUR + ONE_MINUTE, 'WORK_DUR')).to.equal('2h 1min'); - expect(formatMeasure(5 * ONE_DAY + 2 * ONE_HOUR + ONE_MINUTE, 'WORK_DUR')).to.equal('5d 2h'); - expect(formatMeasure(15 * ONE_DAY + 2 * ONE_HOUR + ONE_MINUTE, 'WORK_DUR')).to.equal('15d'); - expect(formatMeasure(-5 * ONE_DAY, 'WORK_DUR')).to.equal('-5d'); - expect(formatMeasure(-2 * ONE_HOUR, 'WORK_DUR')).to.equal('-2h'); - expect(formatMeasure(-1 * ONE_MINUTE, 'WORK_DUR')).to.equal('-1min'); - }); + it('should respect FLOAT precision', function () { + expect(formatMeasure(0.1, 'FLOAT')).toBe('0.1'); + expect(formatMeasure(0.12, 'FLOAT')).toBe('0.12'); + expect(formatMeasure(0.12345, 'FLOAT')).toBe('0.12345'); + expect(formatMeasure(0.123456, 'FLOAT')).toBe('0.12346'); + }); - it('should format SHORT_WORK_DUR', function () { - expect(formatMeasure(0, 'SHORT_WORK_DUR')).to.equal('0'); - expect(formatMeasure(5 * ONE_DAY, 'SHORT_WORK_DUR')).to.equal('5d'); - expect(formatMeasure(2 * ONE_HOUR, 'SHORT_WORK_DUR')).to.equal('2h'); - expect(formatMeasure(ONE_MINUTE, 'SHORT_WORK_DUR')).to.equal('1min'); - expect(formatMeasure(40 * ONE_MINUTE, 'SHORT_WORK_DUR')).to.equal('40min'); - expect(formatMeasure(58 * ONE_MINUTE, 'SHORT_WORK_DUR')).to.equal('1h'); - expect(formatMeasure(5 * ONE_DAY + 2 * ONE_HOUR, 'SHORT_WORK_DUR')).to.equal('5d'); - expect(formatMeasure(2 * ONE_HOUR + ONE_MINUTE, 'SHORT_WORK_DUR')).to.equal('2h'); - expect(formatMeasure(ONE_HOUR + 55 * ONE_MINUTE, 'SHORT_WORK_DUR')).to.equal('2h'); - expect(formatMeasure(3 * ONE_DAY + 6 * ONE_HOUR, 'SHORT_WORK_DUR')).to.equal('4d'); - expect(formatMeasure(7 * ONE_HOUR + 59 * ONE_MINUTE, 'SHORT_WORK_DUR')).to.equal('1d'); - expect(formatMeasure(5 * ONE_DAY + 2 * ONE_HOUR + ONE_MINUTE, 'SHORT_WORK_DUR')).to.equal('5d'); - expect(formatMeasure(15 * ONE_DAY + 2 * ONE_HOUR + ONE_MINUTE, 'SHORT_WORK_DUR')).to.equal('15d'); - expect(formatMeasure(7 * ONE_MINUTE, 'SHORT_WORK_DUR')).to.equal('7min'); - expect(formatMeasure(-5 * ONE_DAY, 'SHORT_WORK_DUR')).to.equal('-5d'); - expect(formatMeasure(-2 * ONE_HOUR, 'SHORT_WORK_DUR')).to.equal('-2h'); - expect(formatMeasure(-1 * ONE_MINUTE, 'SHORT_WORK_DUR')).to.equal('-1min'); + it('should format PERCENT', function () { + expect(formatMeasure(0.0, 'PERCENT')).toBe('0.0%'); + expect(formatMeasure(1.0, 'PERCENT')).toBe('1.0%'); + expect(formatMeasure(1.3, 'PERCENT')).toBe('1.3%'); + expect(formatMeasure(1.34, 'PERCENT')).toBe('1.3%'); + expect(formatMeasure(50.89, 'PERCENT')).toBe('50.9%'); + expect(formatMeasure(100.0, 'PERCENT')).toBe('100.0%'); + }); - expect(formatMeasure(1529 * ONE_DAY, 'SHORT_WORK_DUR')).to.equal('1.5kd'); - expect(formatMeasure(1234567 * ONE_DAY, 'SHORT_WORK_DUR')).to.equal('1md'); - expect(formatMeasure(1234567 * ONE_DAY + 2 * ONE_HOUR, 'SHORT_WORK_DUR')).to.equal('1md'); - }); + it('should format WORK_DUR', function () { + expect(formatMeasure(0, 'WORK_DUR')).toBe('0'); + expect(formatMeasure(5 * ONE_DAY, 'WORK_DUR')).toBe('5d'); + expect(formatMeasure(2 * ONE_HOUR, 'WORK_DUR')).toBe('2h'); + expect(formatMeasure(40 * ONE_MINUTE, 'WORK_DUR')).toBe('40min'); + expect(formatMeasure(ONE_MINUTE, 'WORK_DUR')).toBe('1min'); + expect(formatMeasure(5 * ONE_DAY + 2 * ONE_HOUR, 'WORK_DUR')).toBe('5d 2h'); + expect(formatMeasure(2 * ONE_HOUR + ONE_MINUTE, 'WORK_DUR')).toBe('2h 1min'); + expect(formatMeasure(5 * ONE_DAY + 2 * ONE_HOUR + ONE_MINUTE, 'WORK_DUR')).toBe('5d 2h'); + expect(formatMeasure(15 * ONE_DAY + 2 * ONE_HOUR + ONE_MINUTE, 'WORK_DUR')).toBe('15d'); + expect(formatMeasure(-5 * ONE_DAY, 'WORK_DUR')).toBe('-5d'); + expect(formatMeasure(-2 * ONE_HOUR, 'WORK_DUR')).toBe('-2h'); + expect(formatMeasure(-1 * ONE_MINUTE, 'WORK_DUR')).toBe('-1min'); + }); - it('should format RATING', function () { - expect(formatMeasure(1, 'RATING')).to.equal('A'); - expect(formatMeasure(2, 'RATING')).to.equal('B'); - expect(formatMeasure(3, 'RATING')).to.equal('C'); - expect(formatMeasure(4, 'RATING')).to.equal('D'); - expect(formatMeasure(5, 'RATING')).to.equal('E'); - }); + it('should format SHORT_WORK_DUR', function () { + expect(formatMeasure(0, 'SHORT_WORK_DUR')).toBe('0'); + expect(formatMeasure(5 * ONE_DAY, 'SHORT_WORK_DUR')).toBe('5d'); + expect(formatMeasure(2 * ONE_HOUR, 'SHORT_WORK_DUR')).toBe('2h'); + expect(formatMeasure(ONE_MINUTE, 'SHORT_WORK_DUR')).toBe('1min'); + expect(formatMeasure(40 * ONE_MINUTE, 'SHORT_WORK_DUR')).toBe('40min'); + expect(formatMeasure(58 * ONE_MINUTE, 'SHORT_WORK_DUR')).toBe('1h'); + expect(formatMeasure(5 * ONE_DAY + 2 * ONE_HOUR, 'SHORT_WORK_DUR')).toBe('5d'); + expect(formatMeasure(2 * ONE_HOUR + ONE_MINUTE, 'SHORT_WORK_DUR')).toBe('2h'); + expect(formatMeasure(ONE_HOUR + 55 * ONE_MINUTE, 'SHORT_WORK_DUR')).toBe('2h'); + expect(formatMeasure(3 * ONE_DAY + 6 * ONE_HOUR, 'SHORT_WORK_DUR')).toBe('4d'); + expect(formatMeasure(7 * ONE_HOUR + 59 * ONE_MINUTE, 'SHORT_WORK_DUR')).toBe('1d'); + expect(formatMeasure(5 * ONE_DAY + 2 * ONE_HOUR + ONE_MINUTE, 'SHORT_WORK_DUR')).toBe('5d'); + expect(formatMeasure(15 * ONE_DAY + 2 * ONE_HOUR + ONE_MINUTE, 'SHORT_WORK_DUR')).toBe('15d'); + expect(formatMeasure(7 * ONE_MINUTE, 'SHORT_WORK_DUR')).toBe('7min'); + expect(formatMeasure(-5 * ONE_DAY, 'SHORT_WORK_DUR')).toBe('-5d'); + expect(formatMeasure(-2 * ONE_HOUR, 'SHORT_WORK_DUR')).toBe('-2h'); + expect(formatMeasure(-1 * ONE_MINUTE, 'SHORT_WORK_DUR')).toBe('-1min'); + + expect(formatMeasure(1529 * ONE_DAY, 'SHORT_WORK_DUR')).toBe('1.5kd'); + expect(formatMeasure(1234567 * ONE_DAY, 'SHORT_WORK_DUR')).toBe('1md'); + expect(formatMeasure(1234567 * ONE_DAY + 2 * ONE_HOUR, 'SHORT_WORK_DUR')).toBe('1md'); + }); - it('should format LEVEL', function () { - expect(formatMeasure('ERROR', 'LEVEL')).to.equal('Error'); - expect(formatMeasure('WARN', 'LEVEL')).to.equal('Warning'); - expect(formatMeasure('OK', 'LEVEL')).to.equal('Ok'); - expect(formatMeasure('UNKNOWN', 'LEVEL')).to.equal('UNKNOWN'); - }); + it('should format RATING', function () { + expect(formatMeasure(1, 'RATING')).toBe('A'); + expect(formatMeasure(2, 'RATING')).toBe('B'); + expect(formatMeasure(3, 'RATING')).toBe('C'); + expect(formatMeasure(4, 'RATING')).toBe('D'); + expect(formatMeasure(5, 'RATING')).toBe('E'); + }); - it('should format MILLISEC', function () { - expect(formatMeasure(0, 'MILLISEC')).to.equal('0ms'); - expect(formatMeasure(1, 'MILLISEC')).to.equal('1ms'); - expect(formatMeasure(173, 'MILLISEC')).to.equal('173ms'); - expect(formatMeasure(3649, 'MILLISEC')).to.equal('4s'); - expect(formatMeasure(893481, 'MILLISEC')).to.equal('15min'); - expect(formatMeasure(17862325, 'MILLISEC')).to.equal('298min'); - }); + it('should format LEVEL', function () { + expect(formatMeasure('ERROR', 'LEVEL')).toBe('Error'); + expect(formatMeasure('WARN', 'LEVEL')).toBe('Warning'); + expect(formatMeasure('OK', 'LEVEL')).toBe('Ok'); + expect(formatMeasure('UNKNOWN', 'LEVEL')).toBe('UNKNOWN'); + }); - it('should not format unknown type', function () { - expect(formatMeasure('random value', 'RANDOM_TYPE')).to.equal('random value'); - }); + it('should format MILLISEC', function () { + expect(formatMeasure(0, 'MILLISEC')).toBe('0ms'); + expect(formatMeasure(1, 'MILLISEC')).toBe('1ms'); + expect(formatMeasure(173, 'MILLISEC')).toBe('173ms'); + expect(formatMeasure(3649, 'MILLISEC')).toBe('4s'); + expect(formatMeasure(893481, 'MILLISEC')).toBe('15min'); + expect(formatMeasure(17862325, 'MILLISEC')).toBe('298min'); + }); - it('should return null if value is empty string', function () { - expect(formatMeasure('', 'PERCENT')).to.be.null; - }); + it('should not format unknown type', function () { + expect(formatMeasure('random value', 'RANDOM_TYPE')).toBe('random value'); + }); - it('should not fail without parameters', function () { - expect(formatMeasure()).to.be.null; - }); + it('should return null if value is empty string', function () { + expect(formatMeasure('', 'PERCENT')).toBeNull(); }); - describe('#formatMeasureVariation()', function () { - it('should format INT', function () { - expect(formatMeasureVariation(0, 'INT')).to.equal('+0'); - expect(formatMeasureVariation(1, 'INT')).to.equal('+1'); - expect(formatMeasureVariation(-1, 'INT')).to.equal('-1'); - expect(formatMeasureVariation(1529, 'INT')).to.equal('+1,529'); - expect(formatMeasureVariation(-1529, 'INT')).to.equal('-1,529'); - }); + it('should not fail without parameters', function () { + expect(formatMeasure()).toBeNull(); + }); +}); - it('should format SHORT_INT', function () { - expect(formatMeasureVariation(0, 'SHORT_INT')).to.equal('+0'); - expect(formatMeasureVariation(1, 'SHORT_INT')).to.equal('+1'); - expect(formatMeasureVariation(-1, 'SHORT_INT')).to.equal('-1'); - expect(formatMeasureVariation(1529, 'SHORT_INT')).to.equal('+1.5k'); - expect(formatMeasureVariation(-1529, 'SHORT_INT')).to.equal('-1.5k'); - expect(formatMeasureVariation(10678, 'SHORT_INT')).to.equal('+11k'); - expect(formatMeasureVariation(-10678, 'SHORT_INT')).to.equal('-11k'); - }); +describe('#formatMeasureVariation()', function () { + it('should format INT', function () { + expect(formatMeasureVariation(0, 'INT')).toBe('+0'); + expect(formatMeasureVariation(1, 'INT')).toBe('+1'); + expect(formatMeasureVariation(-1, 'INT')).toBe('-1'); + expect(formatMeasureVariation(1529, 'INT')).toBe('+1,529'); + expect(formatMeasureVariation(-1529, 'INT')).toBe('-1,529'); + }); - it('should format FLOAT', function () { - expect(formatMeasureVariation(0.0, 'FLOAT')).to.equal('+0.0'); - expect(formatMeasureVariation(1.0, 'FLOAT')).to.equal('+1.0'); - expect(formatMeasureVariation(-1.0, 'FLOAT')).to.equal('-1.0'); - expect(formatMeasureVariation(50.89, 'FLOAT')).to.equal('+50.89'); - expect(formatMeasureVariation(-50.89, 'FLOAT')).to.equal('-50.89'); - }); + it('should format SHORT_INT', function () { + expect(formatMeasureVariation(0, 'SHORT_INT')).toBe('+0'); + expect(formatMeasureVariation(1, 'SHORT_INT')).toBe('+1'); + expect(formatMeasureVariation(-1, 'SHORT_INT')).toBe('-1'); + expect(formatMeasureVariation(1529, 'SHORT_INT')).toBe('+1.5k'); + expect(formatMeasureVariation(-1529, 'SHORT_INT')).toBe('-1.5k'); + expect(formatMeasureVariation(10678, 'SHORT_INT')).toBe('+11k'); + expect(formatMeasureVariation(-10678, 'SHORT_INT')).toBe('-11k'); + }); - it('should respect FLOAT precision', function () { - expect(formatMeasureVariation(0.1, 'FLOAT')).to.equal('+0.1'); - expect(formatMeasureVariation(0.12, 'FLOAT')).to.equal('+0.12'); - expect(formatMeasureVariation(0.12345, 'FLOAT')).to.equal('+0.12345'); - expect(formatMeasureVariation(0.123456, 'FLOAT')).to.equal('+0.12346'); - }); + it('should format FLOAT', function () { + expect(formatMeasureVariation(0.0, 'FLOAT')).toBe('+0.0'); + expect(formatMeasureVariation(1.0, 'FLOAT')).toBe('+1.0'); + expect(formatMeasureVariation(-1.0, 'FLOAT')).toBe('-1.0'); + expect(formatMeasureVariation(50.89, 'FLOAT')).toBe('+50.89'); + expect(formatMeasureVariation(-50.89, 'FLOAT')).toBe('-50.89'); + }); - it('should format PERCENT', function () { - expect(formatMeasureVariation(0.0, 'PERCENT')).to.equal('+0.0%'); - expect(formatMeasureVariation(1.0, 'PERCENT')).to.equal('+1.0%'); - expect(formatMeasureVariation(-1.0, 'PERCENT')).to.equal('-1.0%'); - expect(formatMeasureVariation(50.89, 'PERCENT')).to.equal('+50.9%'); - expect(formatMeasureVariation(-50.89, 'PERCENT')).to.equal('-50.9%'); - }); + it('should respect FLOAT precision', function () { + expect(formatMeasureVariation(0.1, 'FLOAT')).toBe('+0.1'); + expect(formatMeasureVariation(0.12, 'FLOAT')).toBe('+0.12'); + expect(formatMeasureVariation(0.12345, 'FLOAT')).toBe('+0.12345'); + expect(formatMeasureVariation(0.123456, 'FLOAT')).toBe('+0.12346'); + }); - it('should format WORK_DUR', function () { - expect(formatMeasureVariation(0, 'WORK_DUR')).to.equal('+0'); - expect(formatMeasureVariation(5 * ONE_DAY, 'WORK_DUR')).to.equal('+5d'); - expect(formatMeasureVariation(2 * ONE_HOUR, 'WORK_DUR')).to.equal('+2h'); - expect(formatMeasureVariation(ONE_MINUTE, 'WORK_DUR')).to.equal('+1min'); - expect(formatMeasureVariation(-5 * ONE_DAY, 'WORK_DUR')).to.equal('-5d'); - expect(formatMeasureVariation(-2 * ONE_HOUR, 'WORK_DUR')).to.equal('-2h'); - expect(formatMeasureVariation(-1 * ONE_MINUTE, 'WORK_DUR')).to.equal('-1min'); - }); + it('should format PERCENT', function () { + expect(formatMeasureVariation(0.0, 'PERCENT')).toBe('+0.0%'); + expect(formatMeasureVariation(1.0, 'PERCENT')).toBe('+1.0%'); + expect(formatMeasureVariation(-1.0, 'PERCENT')).toBe('-1.0%'); + expect(formatMeasureVariation(50.89, 'PERCENT')).toBe('+50.9%'); + expect(formatMeasureVariation(-50.89, 'PERCENT')).toBe('-50.9%'); + }); - it('should format SHORT_WORK_DUR', function () { - expect(formatMeasureVariation(0, 'SHORT_WORK_DUR')).to.equal('+0'); - expect(formatMeasureVariation(5 * ONE_DAY, 'SHORT_WORK_DUR')).to.equal('+5d'); - expect(formatMeasureVariation(2 * ONE_HOUR, 'SHORT_WORK_DUR')).to.equal('+2h'); - expect(formatMeasureVariation(ONE_MINUTE, 'SHORT_WORK_DUR')).to.equal('+1min'); - expect(formatMeasureVariation(30 * ONE_MINUTE, 'SHORT_WORK_DUR')).to.equal('+30min'); - expect(formatMeasureVariation(58 * ONE_MINUTE, 'SHORT_WORK_DUR')).to.equal('+1h'); - expect(formatMeasureVariation(5 * ONE_DAY + 2 * ONE_HOUR, 'SHORT_WORK_DUR')).to.equal('+5d'); - expect(formatMeasureVariation(2 * ONE_HOUR + ONE_MINUTE, 'SHORT_WORK_DUR')).to.equal('+2h'); - expect(formatMeasureVariation(ONE_HOUR + 55 * ONE_MINUTE, 'SHORT_WORK_DUR')).to.equal('+2h'); - expect(formatMeasureVariation(3 * ONE_DAY + 6 * ONE_HOUR, 'SHORT_WORK_DUR')).to.equal('+4d'); - expect(formatMeasureVariation(7 * ONE_HOUR + 59 * ONE_MINUTE, 'SHORT_WORK_DUR')).to.equal('+1d'); - expect(formatMeasureVariation(5 * ONE_DAY + 2 * ONE_HOUR + ONE_MINUTE, 'SHORT_WORK_DUR')).to.equal('+5d'); - expect(formatMeasureVariation(15 * ONE_DAY + 2 * ONE_HOUR + ONE_MINUTE, 'SHORT_WORK_DUR')).to.equal('+15d'); - expect(formatMeasureVariation(7 * ONE_MINUTE, 'SHORT_WORK_DUR')).to.equal('+7min'); - expect(formatMeasureVariation(-5 * ONE_DAY, 'SHORT_WORK_DUR')).to.equal('-5d'); - expect(formatMeasureVariation(-2 * ONE_HOUR, 'SHORT_WORK_DUR')).to.equal('-2h'); - expect(formatMeasureVariation(-1 * ONE_MINUTE, 'SHORT_WORK_DUR')).to.equal('-1min'); + it('should format WORK_DUR', function () { + expect(formatMeasureVariation(0, 'WORK_DUR')).toBe('+0'); + expect(formatMeasureVariation(5 * ONE_DAY, 'WORK_DUR')).toBe('+5d'); + expect(formatMeasureVariation(2 * ONE_HOUR, 'WORK_DUR')).toBe('+2h'); + expect(formatMeasureVariation(ONE_MINUTE, 'WORK_DUR')).toBe('+1min'); + expect(formatMeasureVariation(-5 * ONE_DAY, 'WORK_DUR')).toBe('-5d'); + expect(formatMeasureVariation(-2 * ONE_HOUR, 'WORK_DUR')).toBe('-2h'); + expect(formatMeasureVariation(-1 * ONE_MINUTE, 'WORK_DUR')).toBe('-1min'); + }); - expect(formatMeasureVariation(1529 * ONE_DAY, 'SHORT_WORK_DUR')).to.equal('+1.5kd'); - expect(formatMeasureVariation(1234567 * ONE_DAY, 'SHORT_WORK_DUR')).to.equal('+1md'); - expect(formatMeasureVariation(1234567 * ONE_DAY + 2 * ONE_HOUR, 'SHORT_WORK_DUR')).to.equal('+1md'); - }); + it('should format SHORT_WORK_DUR', function () { + expect(formatMeasureVariation(0, 'SHORT_WORK_DUR')).toBe('+0'); + expect(formatMeasureVariation(5 * ONE_DAY, 'SHORT_WORK_DUR')).toBe('+5d'); + expect(formatMeasureVariation(2 * ONE_HOUR, 'SHORT_WORK_DUR')).toBe('+2h'); + expect(formatMeasureVariation(ONE_MINUTE, 'SHORT_WORK_DUR')).toBe('+1min'); + expect(formatMeasureVariation(30 * ONE_MINUTE, 'SHORT_WORK_DUR')).toBe('+30min'); + expect(formatMeasureVariation(58 * ONE_MINUTE, 'SHORT_WORK_DUR')).toBe('+1h'); + expect(formatMeasureVariation(5 * ONE_DAY + 2 * ONE_HOUR, 'SHORT_WORK_DUR')).toBe('+5d'); + expect(formatMeasureVariation(2 * ONE_HOUR + ONE_MINUTE, 'SHORT_WORK_DUR')).toBe('+2h'); + expect(formatMeasureVariation(ONE_HOUR + 55 * ONE_MINUTE, 'SHORT_WORK_DUR')).toBe('+2h'); + expect(formatMeasureVariation(3 * ONE_DAY + 6 * ONE_HOUR, 'SHORT_WORK_DUR')).toBe('+4d'); + expect(formatMeasureVariation(7 * ONE_HOUR + 59 * ONE_MINUTE, 'SHORT_WORK_DUR')).toBe('+1d'); + expect(formatMeasureVariation(5 * ONE_DAY + 2 * ONE_HOUR + ONE_MINUTE, 'SHORT_WORK_DUR')).toBe('+5d'); + expect(formatMeasureVariation(15 * ONE_DAY + 2 * ONE_HOUR + ONE_MINUTE, 'SHORT_WORK_DUR')).toBe('+15d'); + expect(formatMeasureVariation(7 * ONE_MINUTE, 'SHORT_WORK_DUR')).toBe('+7min'); + expect(formatMeasureVariation(-5 * ONE_DAY, 'SHORT_WORK_DUR')).toBe('-5d'); + expect(formatMeasureVariation(-2 * ONE_HOUR, 'SHORT_WORK_DUR')).toBe('-2h'); + expect(formatMeasureVariation(-1 * ONE_MINUTE, 'SHORT_WORK_DUR')).toBe('-1min'); + + expect(formatMeasureVariation(1529 * ONE_DAY, 'SHORT_WORK_DUR')).toBe('+1.5kd'); + expect(formatMeasureVariation(1234567 * ONE_DAY, 'SHORT_WORK_DUR')).toBe('+1md'); + expect(formatMeasureVariation(1234567 * ONE_DAY + 2 * ONE_HOUR, 'SHORT_WORK_DUR')).toBe('+1md'); + }); - it('should not format unknown type', function () { - expect(formatMeasureVariation('random value', 'RANDOM_TYPE')).to.equal('random value'); - }); + it('should not format unknown type', function () { + expect(formatMeasureVariation('random value', 'RANDOM_TYPE')).toBe('random value'); + }); - it('should not fail without parameters', function () { - expect(formatMeasureVariation()).to.be.null; - }); + it('should not fail without parameters', function () { + expect(formatMeasureVariation()).toBeNull(); }); }); diff --git a/server/sonar-web/src/main/js/helpers/__tests__/path-test.js b/server/sonar-web/src/main/js/helpers/__tests__/path-test.js index cdd4fb885c8..16177a734ca 100644 --- a/server/sonar-web/src/main/js/helpers/__tests__/path-test.js +++ b/server/sonar-web/src/main/js/helpers/__tests__/path-test.js @@ -17,53 +17,50 @@ * 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 '../path'; -describe('Path', function () { - describe('#collapsedDirFromPath()', function () { - it('should return null when pass null', function () { - expect(collapsedDirFromPath(null)).to.be.null; - }); +describe('#collapsedDirFromPath()', function () { + it('should return null when pass null', function () { + expect(collapsedDirFromPath(null)).toBeNull(); + }); - it('should return "/" when pass "/"', function () { - expect(collapsedDirFromPath('/')).to.equal('/'); - }); + it('should return "/" when pass "/"', function () { + expect(collapsedDirFromPath('/')).toBe('/'); + }); - it('should not cut short path', function () { - expect(collapsedDirFromPath('src/main/js/components/state.js')).to.equal('src/main/js/components/'); - }); + it('should not cut short path', function () { + expect(collapsedDirFromPath('src/main/js/components/state.js')).toBe('src/main/js/components/'); + }); - it('should cut long path', function () { - expect(collapsedDirFromPath('src/main/js/components/navigator/app/models/state.js')) - .to.equal('src/.../js/components/navigator/app/models/'); - }); + it('should cut long path', function () { + expect(collapsedDirFromPath('src/main/js/components/navigator/app/models/state.js')) + .toBe('src/.../js/components/navigator/app/models/'); + }); - it('should cut very long path', function () { - expect(collapsedDirFromPath('src/main/another/js/components/navigator/app/models/state.js')) - .to.equal('src/.../js/components/navigator/app/models/'); - }); + it('should cut very long path', function () { + expect(collapsedDirFromPath('src/main/another/js/components/navigator/app/models/state.js')) + .toBe('src/.../js/components/navigator/app/models/'); }); +}); - describe('#fileFromPath()', function () { - it('should return null when pass null', function () { - expect(fileFromPath(null)).to.be.null; - }); +describe('#fileFromPath()', function () { + it('should return null when pass null', function () { + expect(fileFromPath(null)).toBeNull(); + }); - it('should return empty string when pass "/"', function () { - expect(fileFromPath('/')).to.equal(''); - }); + it('should return empty string when pass "/"', function () { + expect(fileFromPath('/')).toBe(''); + }); - it('should return file name when pass only file name', function () { - expect(fileFromPath('file.js')).to.equal('file.js'); - }); + it('should return file name when pass only file name', function () { + expect(fileFromPath('file.js')).toBe('file.js'); + }); - it('should return file name when pass file path', function () { - expect(fileFromPath('src/main/js/file.js')).to.equal('file.js'); - }); + it('should return file name when pass file path', function () { + expect(fileFromPath('src/main/js/file.js')).toBe('file.js'); + }); - it('should return file name when pass file name without extension', function () { - expect(fileFromPath('src/main/file')).to.equal('file'); - }); + it('should return file name when pass file name without extension', function () { + expect(fileFromPath('src/main/file')).toBe('file'); }); }); diff --git a/server/sonar-web/src/main/js/helpers/__tests__/urls-test.js b/server/sonar-web/src/main/js/helpers/__tests__/urls-test.js index 293b8632253..a129d3abfc3 100644 --- a/server/sonar-web/src/main/js/helpers/__tests__/urls-test.js +++ b/server/sonar-web/src/main/js/helpers/__tests__/urls-test.js @@ -17,8 +17,6 @@ * 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 '../urls'; const SIMPLE_COMPONENT_KEY = 'sonarqube'; @@ -26,75 +24,73 @@ const COMPLEX_COMPONENT_KEY = 'org.sonarsource.sonarqube:sonarqube'; const COMPLEX_COMPONENT_KEY_ENCODED = encodeURIComponent(COMPLEX_COMPONENT_KEY); const METRIC = 'coverage'; -describe('URLs', function () { - let oldBaseUrl; +let oldBaseUrl; - beforeEach(function () { - oldBaseUrl = window.baseUrl; - }); +beforeEach(function () { + oldBaseUrl = window.baseUrl; +}); - afterEach(function () { - window.baseUrl = oldBaseUrl; - }); +afterEach(function () { + window.baseUrl = oldBaseUrl; +}); - describe('#getComponentUrl', function () { - it('should return component url', function () { - expect(getComponentUrl(SIMPLE_COMPONENT_KEY)).to.equal('/dashboard?id=' + SIMPLE_COMPONENT_KEY); - }); +describe('#getComponentUrl', function () { + it('should return component url', function () { + expect(getComponentUrl(SIMPLE_COMPONENT_KEY)).toBe('/dashboard?id=' + SIMPLE_COMPONENT_KEY); + }); - it('should encode component key', function () { - expect(getComponentUrl(COMPLEX_COMPONENT_KEY)).to.equal('/dashboard?id=' + COMPLEX_COMPONENT_KEY_ENCODED); - }); + it('should encode component key', function () { + expect(getComponentUrl(COMPLEX_COMPONENT_KEY)).toBe('/dashboard?id=' + COMPLEX_COMPONENT_KEY_ENCODED); + }); - it('should take baseUrl into account', function () { - window.baseUrl = '/context'; - expect(getComponentUrl(COMPLEX_COMPONENT_KEY)).to.equal('/context/dashboard?id=' + COMPLEX_COMPONENT_KEY_ENCODED); - }); + it('should take baseUrl into account', function () { + window.baseUrl = '/context'; + expect(getComponentUrl(COMPLEX_COMPONENT_KEY)).toBe('/context/dashboard?id=' + COMPLEX_COMPONENT_KEY_ENCODED); }); +}); - describe('#getComponentIssuesUrl', function () { - it('should work without parameters', function () { - expect(getComponentIssuesUrl(SIMPLE_COMPONENT_KEY, {})).to.equal( - '/component_issues?id=' + SIMPLE_COMPONENT_KEY + '#'); - }); +describe('#getComponentIssuesUrl', function () { + it('should work without parameters', function () { + expect(getComponentIssuesUrl(SIMPLE_COMPONENT_KEY, {})).toBe( + '/component_issues?id=' + SIMPLE_COMPONENT_KEY + '#'); + }); - it('should encode component key', function () { - expect(getComponentIssuesUrl(COMPLEX_COMPONENT_KEY, {})).to.equal( - '/component_issues?id=' + COMPLEX_COMPONENT_KEY_ENCODED + '#'); - }); + it('should encode component key', function () { + expect(getComponentIssuesUrl(COMPLEX_COMPONENT_KEY, {})).toBe( + '/component_issues?id=' + COMPLEX_COMPONENT_KEY_ENCODED + '#'); + }); - it('should work with parameters', function () { - expect(getComponentIssuesUrl(SIMPLE_COMPONENT_KEY, { resolved: 'false' })).to.equal( - '/component_issues?id=' + SIMPLE_COMPONENT_KEY + '#resolved=false'); - }); + it('should work with parameters', function () { + expect(getComponentIssuesUrl(SIMPLE_COMPONENT_KEY, { resolved: 'false' })).toBe( + '/component_issues?id=' + SIMPLE_COMPONENT_KEY + '#resolved=false'); + }); - it('should encode parameters', function () { - expect(getComponentIssuesUrl(SIMPLE_COMPONENT_KEY, { componentUuids: COMPLEX_COMPONENT_KEY })).to.equal( - '/component_issues?id=' + SIMPLE_COMPONENT_KEY + '#componentUuids=' + COMPLEX_COMPONENT_KEY_ENCODED); - }); + it('should encode parameters', function () { + expect(getComponentIssuesUrl(SIMPLE_COMPONENT_KEY, { componentUuids: COMPLEX_COMPONENT_KEY })).toBe( + '/component_issues?id=' + SIMPLE_COMPONENT_KEY + '#componentUuids=' + COMPLEX_COMPONENT_KEY_ENCODED); + }); - it('should take baseUrl into account', function () { - window.baseUrl = '/context'; - expect(getComponentIssuesUrl(SIMPLE_COMPONENT_KEY, {})).to.equal( - '/context/component_issues?id=' + SIMPLE_COMPONENT_KEY + '#'); - }); + it('should take baseUrl into account', function () { + window.baseUrl = '/context'; + expect(getComponentIssuesUrl(SIMPLE_COMPONENT_KEY, {})).toBe( + '/context/component_issues?id=' + SIMPLE_COMPONENT_KEY + '#'); }); +}); - describe('#getComponentDrilldownUrl', function () { - it('should return component drilldown url', function () { - expect(getComponentDrilldownUrl(SIMPLE_COMPONENT_KEY, METRIC)).to.equal( - '/component_measures/metric/' + METRIC + '?id=' + SIMPLE_COMPONENT_KEY); - }); +describe('#getComponentDrilldownUrl', function () { + it('should return component drilldown url', function () { + expect(getComponentDrilldownUrl(SIMPLE_COMPONENT_KEY, METRIC)).toBe( + '/component_measures/metric/' + METRIC + '?id=' + SIMPLE_COMPONENT_KEY); + }); - it('should encode component key', function () { - expect(getComponentDrilldownUrl(COMPLEX_COMPONENT_KEY, METRIC)).to.equal( - '/component_measures/metric/' + METRIC + '?id=' + COMPLEX_COMPONENT_KEY_ENCODED); - }); + it('should encode component key', function () { + expect(getComponentDrilldownUrl(COMPLEX_COMPONENT_KEY, METRIC)).toBe( + '/component_measures/metric/' + METRIC + '?id=' + COMPLEX_COMPONENT_KEY_ENCODED); + }); - it('should take baseUrl into account', function () { - window.baseUrl = '/context'; - expect(getComponentDrilldownUrl(SIMPLE_COMPONENT_KEY, METRIC)).to.equal( - '/context/component_measures/metric/' + METRIC + '?id=' + SIMPLE_COMPONENT_KEY); - }); + it('should take baseUrl into account', function () { + window.baseUrl = '/context'; + expect(getComponentDrilldownUrl(SIMPLE_COMPONENT_KEY, METRIC)).toBe( + '/context/component_measures/metric/' + METRIC + '?id=' + SIMPLE_COMPONENT_KEY); }); }); diff --git a/server/sonar-web/src/main/js/main/nav/__tests__/nav-test.js b/server/sonar-web/src/main/js/main/nav/__tests__/nav-test.js index f9b88a7da26..d5ddbab8afd 100644 --- a/server/sonar-web/src/main/js/main/nav/__tests__/nav-test.js +++ b/server/sonar-web/src/main/js/main/nav/__tests__/nav-test.js @@ -18,22 +18,14 @@ * 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 { shallow } from 'enzyme'; 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); - }); +describe('ComponentNavBreadcrumbs', () => { + it('should not render breadcrumbs with one element', function () { + const breadcrumbs = [{ key: 'my-project', name: 'My Project', qualifier: 'TRK' }]; + const result = shallow(); + expect(result.find('li').length).toBe(1); + expect(result.find('a').length).toBe(1); }); }); diff --git a/server/sonar-web/tests/null-compiler.js b/server/sonar-web/tests/FileStub.js similarity index 87% rename from server/sonar-web/tests/null-compiler.js rename to server/sonar-web/tests/FileStub.js index 22595ed6337..bff56dc8933 100644 --- a/server/sonar-web/tests/null-compiler.js +++ b/server/sonar-web/tests/FileStub.js @@ -17,9 +17,4 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -function nothing () { - return null; -} - -require.extensions['.css'] = nothing; -require.extensions['.hbs'] = nothing; +module.exports = 'test-file-stub'; diff --git a/server/sonar-web/tests/SetupTestEnvironment.js b/server/sonar-web/tests/SetupTestEnvironment.js new file mode 100644 index 00000000000..35829391382 --- /dev/null +++ b/server/sonar-web/tests/SetupTestEnvironment.js @@ -0,0 +1,26 @@ +/* + * 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. + */ +require('babel-polyfill'); + +window.baseUrl = ''; +window.t = window.tp = function () { + var args = Array.prototype.slice.call(arguments, 0); + return args.join('.'); +}; diff --git a/server/sonar-web/tests/jsdom-setup.js b/server/sonar-web/tests/jsdom-setup.js deleted file mode 100644 index f1d92d7d818..00000000000 --- a/server/sonar-web/tests/jsdom-setup.js +++ /dev/null @@ -1,16 +0,0 @@ -/* globals global: false */ -require("babel-polyfill"); - -var jsdom = require('jsdom'); - -// A super simple DOM ready for React to render into -// Store this DOM and the window in global scope ready for React to access -global.document = jsdom.jsdom(''); -global.window = document.defaultView; -global.navigator = document.defaultView.navigator; - -global.window.baseUrl = ''; -global.window.t = global.window.tp = function () { - var args = Array.prototype.slice.call(arguments, 0); - return args.join('.'); -}; diff --git a/server/sonar-web/tests/mocha.opts b/server/sonar-web/tests/mocha.opts deleted file mode 100644 index d3dbd50844c..00000000000 --- a/server/sonar-web/tests/mocha.opts +++ /dev/null @@ -1,3 +0,0 @@ ---recursive ---compilers js:babel-register,css:tests/null-compiler.js,hbs:tests/null-compiler.js ---require tests/jsdom-setup.js diff --git a/server/sonar-web/tests/utils.js b/server/sonar-web/tests/utils.js index afa4f53d0d4..03506208367 100644 --- a/server/sonar-web/tests/utils.js +++ b/server/sonar-web/tests/utils.js @@ -20,6 +20,7 @@ export const click = element => { return element.simulate('click', { target: { blur () {} }, + currentTarget: { blur () {} }, preventDefault () {} }); }; -- 2.39.5