diff options
author | Stas Vilchik <vilchiks@gmail.com> | 2016-09-02 16:13:51 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-09-02 16:13:51 +0200 |
commit | 5fac9ad9ac653dba89f5f53457c8d17959cef7cc (patch) | |
tree | 8f1516f14adaaa1ffc421b50737b33a887d29f75 /server/sonar-web/src/main/js/apps | |
parent | e71ab396b44b4a4f6e03edcba97564b27de6efa9 (diff) | |
download | sonarqube-5fac9ad9ac653dba89f5f53457c8d17959cef7cc.tar.gz sonarqube-5fac9ad9ac653dba89f5f53457c8d17959cef7cc.zip |
use jest (#1202)
Diffstat (limited to 'server/sonar-web/src/main/js/apps')
32 files changed, 954 insertions, 1211 deletions
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( - <ProjectCard project={project}/> - ); - 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(<ProjectCard project={project}/>); + 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( - <ProjectCard project={project}/> - ); - expect(output.find('.account-project-description').text()).to.equal('bla'); - }); +it('should render description', () => { + const project = { ...BASE, description: 'bla' }; + const output = shallow(<ProjectCard project={project}/>); + expect(output.find('.account-project-description').text()).toBe('bla'); +}); - it('should not render optional fields', () => { - const project = { ...BASE }; - const output = shallow( - <ProjectCard project={project}/> - ); - 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(<ProjectCard project={project}/>); + 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( - <ProjectCard project={project}/> - ); - 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(<ProjectCard project={project}/>); + 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( - <ProjectCard project={project}/> - ); - 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(<ProjectCard project={project}/>); + 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( - <ProjectCard project={project}/> - ); - 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( + <ProjectCard project={project}/> + ); + 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( - <ProjectCard project={project}/> - ); - 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(<ProjectCard project={project}/>); + 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( - <Projects - projects={projects} - total={5} - loading={false} - search={() => true} - loadMore={() => true}/> - ); + const output = shallow( + <Projects + projects={projects} + total={5} + loading={false} + search={() => 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( - <Projects - projects={projects} - total={5} - loading={false} - search={() => true} - loadMore={loadMore}/> - ).find(ListFooter); + const footer = shallow( + <Projects + projects={projects} + total={5} + loading={false} + search={() => 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( - <Projects - projects={[]} - total={0} - loading={false} - search={() => true} - loadMore={() => true}/> - ); +it('should render when no results', () => { + const output = shallow( + <Projects + projects={[]} + total={0} + loading={false} + search={() => 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(<Search {...defaultProps}/>); + expect(component.find('.js-search').length).toBe(1); + }); + + it('should not render search form', () => { + const component = shallow(<Search {...defaultProps} component={{ id: 'ABCD' }}/>); + 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(<Search {...defaultProps} onFilterUpdate={searchSpy}/>); + 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(<Search {...defaultProps} onReload={reloadSpy}/>); + 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(<Stats pendingCount={0} onCancelAllPending={stub} onShowFailing={stub}/>); + 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(<Stats pendingCount={5} onCancelAllPending={stub} onShowFailing={stub}/>); + expect(result.find('.js-pending-count').text()).toContain('5'); + }); + + it('should not show cancel pending button', () => { + const result = shallow(<Stats pendingCount={0} onCancelAllPending={stub} onShowFailing={stub}/>); + expect(result.find('.js-cancel-pending').length).toBe(0); + }); + + it('should show cancel pending button', () => { + const result = shallow(<Stats pendingCount={5} onCancelAllPending={stub} onShowFailing={stub}/>); + 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( - <Search {...defaultProps}/> - ); - const searchBox = TestUtils.scryRenderedDOMComponentsWithClass(component, 'js-search'); - expect(searchBox).to.have.length(1); - }); - - it('should not render search form', () => { - const component = TestUtils.renderIntoDocument( - <Search {...defaultProps} component={{ id: 'ABCD' }}/> - ); - const searchBox = TestUtils.scryRenderedDOMComponentsWithClass(component, 'js-search'); - expect(searchBox).to.be.empty; - }); - - it('should search', (done) => { - const searchSpy = sinon.spy(); - const component = TestUtils.renderIntoDocument( - <Search {...defaultProps} onFilterUpdate={searchSpy}/>); - 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( - <Search {...defaultProps} onReload={reloadSpy}/> - ); - 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(<Stats pendingCount={5} onCancelAllPending={spy} onShowFailing={stub}/>); + 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(<Stats pendingCount={0}/>); - const pendingCounter = result.refs.pendingCount; - expect(pendingCounter.textContent).to.contain('0'); - }); - - it('should show 5 pending', () => { - const result = TestUtils.renderIntoDocument(<Stats pendingCount={5}/>); - const pendingCounter = result.refs.pendingCount; - expect(pendingCounter.textContent).to.contain('5'); - }); - - it('should not show cancel pending button', () => { - const result = TestUtils.renderIntoDocument(<Stats pendingCount={0}/>); - const cancelPending = result.refs.cancelPending; - expect(cancelPending).to.not.be.ok; - }); - - it('should show cancel pending button', () => { - const result = TestUtils.renderIntoDocument(<Stats pendingCount={5}/>); - const cancelPending = result.refs.cancelPending; - expect(cancelPending).to.be.ok; - }); - - it('should trigger cancelling pending', () => { - const spy = sinon.spy(); - const result = TestUtils.renderIntoDocument(<Stats pendingCount={5} onCancelAllPending={spy}/>); - const cancelPending = result.refs.cancelPending; - expect(spy).to.not.have.been.called; - TestUtils.Simulate.click(cancelPending); - expect(spy).to.have.been.called; - }); - }); - - describe('Failures', () => { - it('should show zero failures', () => { - const result = TestUtils.renderIntoDocument(<Stats failingCount={0}/>); - const failureCounter = result.refs.failureCount; - expect(failureCounter.textContent).to.contain('0'); - }); - - it('should show 5 failures', () => { - const result = TestUtils.renderIntoDocument(<Stats failingCount={5}/>); - const failureCounter = result.refs.failureCount; - expect(failureCounter.textContent).to.contain('5'); - }); - - it('should not show link to failures', () => { - const result = TestUtils.renderIntoDocument(<Stats failingCount={0}/>); - const failureCounter = result.refs.failureCount; - expect(failureCounter.tagName.toLowerCase()).to.not.equal('a'); - }); - - it('should show link to failures', () => { - const result = TestUtils.renderIntoDocument(<Stats failingCount={5}/>); - 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(<Stats failingCount={5} onShowFailing={spy}/>); - const failureCounter = result.refs.failureCount; - expect(spy).to.not.have.been.called; - TestUtils.Simulate.click(failureCounter); - expect(spy).to.have.been.called; - }); + describe('Failures', () => { + it('should show zero failures', () => { + const result = shallow(<Stats failingCount={0} onCancelAllPending={stub} onShowFailing={stub}/>); + expect(result.find('.js-failures-count').text()).toContain('0'); + }); + + it('should show 5 failures', () => { + const result = shallow(<Stats failingCount={5} onCancelAllPending={stub} onShowFailing={stub}/>); + expect(result.find('.js-failures-count').text()).toContain('5'); + }); + + it('should not show link to failures', () => { + const result = shallow(<Stats failingCount={0} onCancelAllPending={stub} onShowFailing={stub}/>); + expect(result.find('.js-failures-count').is('a')).toBeFalsy(); + }); + + it('should show link to failures', () => { + const result = shallow(<Stats failingCount={5} onCancelAllPending={stub} onShowFailing={stub}/>); + expect(result.find('.js-failures-count').is('a')).toBeTruthy(); + }); + + it('should trigger filtering failures', () => { + const spy = jest.fn(); + const result = shallow(<Stats failingCount={5} onCancelAllPending={stub} onShowFailing={spy}/>); + 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 { <li className="bt-search-form-right"> <button - ref="reloadButton" + className="js-reload" onClick={this.handleReload.bind(this)} disabled={loading}> {translate('reload')} diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/Stats.js b/server/sonar-web/src/main/js/apps/background-tasks/components/Stats.js index 6fe1e555236..46da2cbc416 100644 --- a/server/sonar-web/src/main/js/apps/background-tasks/components/Stats.js +++ b/server/sonar-web/src/main/js/apps/background-tasks/components/Stats.js @@ -53,13 +53,12 @@ export default class Stats extends React.Component { if (this.props.pendingCount > 0) { return ( <span> - <span ref="pendingCount" className="emphasised-measure">{this.props.pendingCount}</span> + <span className="js-pending-count emphasised-measure">{this.props.pendingCount}</span> {translate('background_tasks.pending')} <a - ref="cancelPending" onClick={this.handleCancelAllPending.bind(this)} - className="icon-delete spacer-left" + className="js-cancel-pending icon-delete spacer-left" title={translate('background_tasks.cancel_all_tasks')} data-toggle="tooltip" href="#"/> @@ -68,7 +67,7 @@ export default class Stats extends React.Component { } else { return ( <span> - <span ref="pendingCount" className="emphasised-measure">{this.props.pendingCount}</span> + <span className="js-pending-count emphasised-measure">{this.props.pendingCount}</span> {translate('background_tasks.pending')} </span> @@ -88,9 +87,8 @@ export default class Stats extends React.Component { if (this.props.failingCount > 0) { return ( <span> - <a ref="failureCount" - onClick={this.handleShowFailing.bind(this)} - className="emphasised-measure" + <a onClick={this.handleShowFailing.bind(this)} + className="js-failures-count emphasised-measure" data-toggle="tooltip" title="Count of projects where processing of most recent analysis report failed" href="#">{this.props.failingCount}</a> @@ -101,7 +99,7 @@ export default class Stats extends React.Component { } else { return ( <span> - <span ref="failureCount" className="emphasised-measure" data-toggle="tooltip" + <span className="js-failures-count emphasised-measure" data-toggle="tooltip" title="Count of projects where processing of most recent analysis report failed"> {this.props.failingCount} </span> diff --git a/server/sonar-web/src/main/js/apps/overview/components/__tests__/App-test.js b/server/sonar-web/src/main/js/apps/overview/components/__tests__/App-test.js index ad699ec13ab..520688a4eb7 100644 --- a/server/sonar-web/src/main/js/apps/overview/components/__tests__/App-test.js +++ b/server/sonar-web/src/main/js/apps/overview/components/__tests__/App-test.js @@ -18,50 +18,25 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ import React from 'react'; -import { expect } from 'chai'; import { shallow } from 'enzyme'; - import App from '../App'; import OverviewApp from '../OverviewApp'; import EmptyOverview from '../EmptyOverview'; -describe('Overview :: App', () => { - it('should render OverviewApp', () => { - const component = { - id: 'id', - snapshotDate: '2016-01-01' - }; - - const output = shallow( - <App component={component}/> - ); - - expect(output.type()) - .to.equal(OverviewApp); - }); - - it('should render EmptyOverview', () => { - const component = { id: 'id' }; - - const output = shallow( - <App component={component}/> - ); - - expect(output.type()) - .to.equal(EmptyOverview); - }); - - it('should pass leakPeriodIndex', () => { - const component = { - id: 'id', - snapshotDate: '2016-01-01' - }; +it('should render OverviewApp', () => { + const component = { id: 'id', snapshotDate: '2016-01-01' }; + const output = shallow(<App component={component}/>); + expect(output.type()).toBe(OverviewApp); +}); - const output = shallow( - <App component={component}/> - ); +it('should render EmptyOverview', () => { + const component = { id: 'id' }; + const output = shallow(<App component={component}/>); + expect(output.type()).toBe(EmptyOverview); +}); - expect(output.prop('leakPeriodIndex')) - .to.equal('1'); - }); +it('should pass leakPeriodIndex', () => { + const component = { id: 'id', snapshotDate: '2016-01-01' }; + const output = shallow(<App component={component}/>); + expect(output.prop('leakPeriodIndex')).toBe('1'); }); diff --git a/server/sonar-web/src/main/js/apps/overview/components/__tests__/EmptyOverview-test.js b/server/sonar-web/src/main/js/apps/overview/components/__tests__/EmptyOverview-test.js index d9c499a9bfe..2906ac925e6 100644 --- a/server/sonar-web/src/main/js/apps/overview/components/__tests__/EmptyOverview-test.js +++ b/server/sonar-web/src/main/js/apps/overview/components/__tests__/EmptyOverview-test.js @@ -18,24 +18,15 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ import React from 'react'; -import { expect } from 'chai'; import { shallow } from 'enzyme'; - import EmptyOverview from '../EmptyOverview'; -describe('Overview :: EmptyOverview', () => { - it('should render component key', () => { - const component = { - id: 'id', - key: 'abcd', - snapshotDate: '2016-01-01' - }; - - const output = shallow( - <EmptyOverview component={component}/> - ); - - expect(output.find('code').text()) - .to.equal('abcd'); - }); +it('should render component key', () => { + const component = { + id: 'id', + key: 'abcd', + snapshotDate: '2016-01-01' + }; + const output = shallow(<EmptyOverview component={component}/>); + expect(output.find('code').text()).toBe('abcd'); }); diff --git a/server/sonar-web/src/main/js/apps/overview/qualityGate/__tests__/QualityGateCondition-test.js b/server/sonar-web/src/main/js/apps/overview/qualityGate/__tests__/QualityGateCondition-test.js index dcd29111176..403719f4318 100644 --- a/server/sonar-web/src/main/js/apps/overview/qualityGate/__tests__/QualityGateCondition-test.js +++ b/server/sonar-web/src/main/js/apps/overview/qualityGate/__tests__/QualityGateCondition-test.js @@ -18,44 +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 QualityGateCondition from '../QualityGateCondition'; import { DrilldownLink } from '../../../../components/shared/drilldown-link'; -describe('Overview :: QualityGateCondition', () => { - it('should render DrilldownLink', () => { - const component = { - id: 'abcd', - key: 'abcd-key' - }; - const periods = []; - const condition = { - actual: '10', - error: '0', - level: 'ERROR', - measure: { - metric: { - key: 'open_issues', - type: 'INT', - name: 'Open Issues' - }, - value: '10' +it('should render DrilldownLink', () => { + const component = { + id: 'abcd', + key: 'abcd-key' + }; + const periods = []; + const condition = { + actual: '10', + error: '0', + level: 'ERROR', + measure: { + metric: { + key: 'open_issues', + type: 'INT', + name: 'Open Issues' }, - metric: 'open_issues', - op: 'GT' - }; + value: '10' + }, + metric: 'open_issues', + op: 'GT' + }; - const output = shallow( - <QualityGateCondition - component={component} - periods={periods} - condition={condition}/> - ); + const output = shallow( + <QualityGateCondition + component={component} + periods={periods} + condition={condition}/> + ); - const link = output.find(DrilldownLink); - expect(link.prop('component')).to.equal('abcd-key'); - expect(link.prop('metric')).to.equal('open_issues'); - }); + const link = output.find(DrilldownLink); + expect(link.prop('component')).toBe('abcd-key'); + expect(link.prop('metric')).toBe('open_issues'); }); diff --git a/server/sonar-web/src/main/js/apps/permission-templates/components/__tests__/ActionsCell-test.js b/server/sonar-web/src/main/js/apps/permission-templates/components/__tests__/ActionsCell-test.js index 97e71ba28e5..a3d0ed5588e 100644 --- a/server/sonar-web/src/main/js/apps/permission-templates/components/__tests__/ActionsCell-test.js +++ b/server/sonar-web/src/main/js/apps/permission-templates/components/__tests__/ActionsCell-test.js @@ -17,15 +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 sinon from 'sinon'; -import sinonChai from 'sinon-chai'; import { shallow } from 'enzyme'; import React from 'react'; import ActionsCell from '../ActionsCell'; -chai.use(sinonChai); - const SAMPLE = { id: 'id', name: 'name', @@ -43,21 +38,15 @@ function renderActionsCell (props) { ); } -describe('Permission Templates :: ActionsCell', () => { - it('should set default', () => { - const setDefault = renderActionsCell() - .find('.js-set-default'); - - expect(setDefault).to.have.length(2); - expect(setDefault.at(0).prop('data-qualifier')).to.equal('TRK'); - expect(setDefault.at(1).prop('data-qualifier')).to.equal('VW'); - }); - - it('should not set default', () => { - const permissionTemplate = { ...SAMPLE, defaultFor: ['TRK', 'VW'] }; - const setDefault = renderActionsCell({ permissionTemplate }) - .find('.js-set-default'); +it('should set default', () => { + const setDefault = renderActionsCell().find('.js-set-default'); + expect(setDefault.length).toBe(2); + expect(setDefault.at(0).prop('data-qualifier')).toBe('TRK'); + expect(setDefault.at(1).prop('data-qualifier')).toBe('VW'); +}); - expect(setDefault).to.have.length(0); - }); +it('should not set default', () => { + const permissionTemplate = { ...SAMPLE, defaultFor: ['TRK', 'VW'] }; + const setDefault = renderActionsCell({ permissionTemplate }).find('.js-set-default'); + expect(setDefault.length).toBe(0); }); diff --git a/server/sonar-web/src/main/js/apps/permission-templates/components/__tests__/Defaults-test.js b/server/sonar-web/src/main/js/apps/permission-templates/components/__tests__/Defaults-test.js index c74885f8ad4..d4480580233 100644 --- a/server/sonar-web/src/main/js/apps/permission-templates/components/__tests__/Defaults-test.js +++ b/server/sonar-web/src/main/js/apps/permission-templates/components/__tests__/Defaults-test.js @@ -17,7 +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 { shallow } from 'enzyme'; import React from 'react'; import Defaults from '../Defaults'; @@ -28,16 +27,14 @@ const SAMPLE = { permissions: [] }; -describe('Permission Templates :: Defaults', () => { - it('should render one qualifier', () => { - const sample = { ...SAMPLE, defaultFor: ['DEV'] }; - const output = shallow(<Defaults permissionTemplate={sample}/>); - expect(output.text()).to.contain('DEV'); - }); +it('should render one qualifier', () => { + const sample = { ...SAMPLE, defaultFor: ['DEV'] }; + const output = shallow(<Defaults permissionTemplate={sample}/>); + expect(output.text()).toContain('DEV'); +}); - it('should render several qualifiers', () => { - const sample = { ...SAMPLE, defaultFor: ['TRK', 'VW'] }; - const output = shallow(<Defaults permissionTemplate={sample}/>); - expect(output.text()).to.contain('TRK'); - }); +it('should render several qualifiers', () => { + const sample = { ...SAMPLE, defaultFor: ['TRK', 'VW'] }; + const output = shallow(<Defaults permissionTemplate={sample}/>); + expect(output.text()).toContain('TRK'); }); diff --git a/server/sonar-web/src/main/js/apps/projects/__tests__/projects-test.js b/server/sonar-web/src/main/js/apps/projects/__tests__/projects-test.js index 51f0ba2945c..85abb704b2b 100644 --- a/server/sonar-web/src/main/js/apps/projects/__tests__/projects-test.js +++ b/server/sonar-web/src/main/js/apps/projects/__tests__/projects-test.js @@ -18,37 +18,29 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ import React from 'react'; -import TestUtils from 'react-addons-test-utils'; -import { expect } from 'chai'; -import sinon from 'sinon'; - +import { shallow } from 'enzyme'; import Projects from '../projects'; +import Checkbox from '../../../components/controls/Checkbox'; -describe('Projects', function () { - describe('Projects', () => { - it('should render list of projects with no selection', () => { - const projects = [ - { id: '1', key: 'a', name: 'A', qualifier: 'TRK' }, - { id: '2', key: 'b', name: 'B', qualifier: 'TRK' } - ]; +it('should render list of projects with no selection', () => { + const projects = [ + { id: '1', key: 'a', name: 'A', qualifier: 'TRK' }, + { id: '2', key: 'b', name: 'B', qualifier: 'TRK' } + ]; - const result = TestUtils.renderIntoDocument( - <Projects projects={projects} selection={[]} refresh={sinon.spy()}/>); - expect(TestUtils.scryRenderedDOMComponentsWithTag(result, 'tr')).to.have.length(2); - expect(TestUtils.scryRenderedDOMComponentsWithClass(result, 'icon-checkbox-checked')).to.be.empty; - }); + const result = shallow(<Projects projects={projects} selection={[]} refresh={jest.fn()}/>); + expect(result.find('tr').length).toBe(2); + expect(result.find(Checkbox).filterWhere(n => n.prop('checked')).length).toBe(0); +}); - it('should render list of projects with one selected', () => { - const projects = [ - { id: '1', key: 'a', name: 'A', qualifier: 'TRK' }, - { id: '2', key: 'b', name: 'B', qualifier: 'TRK' } - ]; - const selection = ['1']; +it('should render list of projects with one selected', () => { + const projects = [ + { id: '1', key: 'a', name: 'A', qualifier: 'TRK' }, + { id: '2', key: 'b', name: 'B', qualifier: 'TRK' } + ]; + const selection = ['1']; - const result = TestUtils.renderIntoDocument( - <Projects projects={projects} selection={selection} refresh={sinon.spy()}/>); - expect(TestUtils.scryRenderedDOMComponentsWithTag(result, 'tr')).to.have.length(2); - expect(TestUtils.scryRenderedDOMComponentsWithClass(result, 'icon-checkbox-checked')).to.have.length(1); - }); - }); + const result = shallow(<Projects projects={projects} selection={selection} refresh={jest.fn()}/>); + expect(result.find('tr').length).toBe(2); + expect(result.find(Checkbox).filterWhere(n => n.prop('checked')).length).toBe(1); }); diff --git a/server/sonar-web/src/main/js/apps/quality-profiles/__tests__/utils-test.js b/server/sonar-web/src/main/js/apps/quality-profiles/__tests__/utils-test.js index 97811993e43..f74270d039f 100644 --- a/server/sonar-web/src/main/js/apps/quality-profiles/__tests__/utils-test.js +++ b/server/sonar-web/src/main/js/apps/quality-profiles/__tests__/utils-test.js @@ -17,7 +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 { sortProfiles } from '../utils'; function createProfile (key, parentKey) { @@ -26,49 +25,47 @@ function createProfile (key, parentKey) { function checkOrder (list, order) { const listKeys = list.map(item => item.key); - expect(listKeys).to.deep.equal(order); + expect(listKeys).toEqual(order); } -describe('Quality Profiles :: Utils', () => { - describe('#sortProfiles', () => { - it('should sort when no parents', () => { - const profile1 = createProfile('profile1'); - const profile2 = createProfile('profile2'); - const profile3 = createProfile('profile3'); - checkOrder( - sortProfiles([profile1, profile2, profile3]), - ['profile1', 'profile2', 'profile3'] - ); - }); +describe('#sortProfiles', () => { + it('should sort when no parents', () => { + const profile1 = createProfile('profile1'); + const profile2 = createProfile('profile2'); + const profile3 = createProfile('profile3'); + checkOrder( + sortProfiles([profile1, profile2, profile3]), + ['profile1', 'profile2', 'profile3'] + ); + }); - it('should sort by name', () => { - const profile1 = createProfile('profile1'); - const profile2 = createProfile('profile2'); - const profile3 = createProfile('profile3'); - checkOrder( - sortProfiles([profile3, profile1, profile2]), - ['profile1', 'profile2', 'profile3'] - ); - }); + it('should sort by name', () => { + const profile1 = createProfile('profile1'); + const profile2 = createProfile('profile2'); + const profile3 = createProfile('profile3'); + checkOrder( + sortProfiles([profile3, profile1, profile2]), + ['profile1', 'profile2', 'profile3'] + ); + }); - it('should sort with children', () => { - const child1 = createProfile('child1', 'parent'); - const child2 = createProfile('child2', 'parent'); - const parent = createProfile('parent'); - checkOrder( - sortProfiles([child1, child2, parent]), - ['parent', 'child1', 'child2'] - ); - }); + it('should sort with children', () => { + const child1 = createProfile('child1', 'parent'); + const child2 = createProfile('child2', 'parent'); + const parent = createProfile('parent'); + checkOrder( + sortProfiles([child1, child2, parent]), + ['parent', 'child1', 'child2'] + ); + }); - it('should sort single branch', () => { - const profile1 = createProfile('profile1'); - const profile2 = createProfile('profile2', 'profile3'); - const profile3 = createProfile('profile3', 'profile1'); - checkOrder( - sortProfiles([profile3, profile2, profile1]), - ['profile1', 'profile3', 'profile2'] - ); - }); + it('should sort single branch', () => { + const profile1 = createProfile('profile1'); + const profile2 = createProfile('profile2', 'profile3'); + const profile3 = createProfile('profile3', 'profile1'); + checkOrder( + sortProfiles([profile3, profile2, profile1]), + ['profile1', 'profile3', 'profile2'] + ); }); }); diff --git a/server/sonar-web/src/main/js/apps/quality-profiles/changelog/__tests__/Changelog-test.js b/server/sonar-web/src/main/js/apps/quality-profiles/changelog/__tests__/Changelog-test.js index 9a36c64207f..b17994f46fd 100644 --- a/server/sonar-web/src/main/js/apps/quality-profiles/changelog/__tests__/Changelog-test.js +++ b/server/sonar-web/src/main/js/apps/quality-profiles/changelog/__tests__/Changelog-test.js @@ -17,7 +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 { shallow } from 'enzyme'; import React from 'react'; import Changelog from '../Changelog'; @@ -35,50 +34,48 @@ function createEvent (overrides) { }; } -describe('Quality Profiles :: Changelog', () => { - it('should render events', () => { - const events = [createEvent(), createEvent()]; - const changelog = shallow(<Changelog events={events}/>); - expect(changelog.find('tbody').find('tr')).to.have.length(2); - }); +it('should render events', () => { + const events = [createEvent(), createEvent()]; + const changelog = shallow(<Changelog events={events}/>); + expect(changelog.find('tbody').find('tr').length).toBe(2); +}); - it('should render event date', () => { - const events = [createEvent()]; - const changelog = shallow(<Changelog events={events}/>); - expect(changelog.text()).to.include('2016'); - }); +it('should render event date', () => { + const events = [createEvent()]; + const changelog = shallow(<Changelog events={events}/>); + expect(changelog.text()).toContain('2016'); +}); - it('should render author', () => { - const events = [createEvent()]; - const changelog = shallow(<Changelog events={events}/>); - expect(changelog.text()).to.include('John'); - }); +it('should render author', () => { + const events = [createEvent()]; + const changelog = shallow(<Changelog events={events}/>); + expect(changelog.text()).toContain('John'); +}); - it('should render system author', () => { - const events = [createEvent({ authorName: undefined })]; - const changelog = shallow(<Changelog events={events}/>); - expect(changelog.text()).to.include('System'); - }); +it('should render system author', () => { + const events = [createEvent({ authorName: undefined })]; + const changelog = shallow(<Changelog events={events}/>); + expect(changelog.text()).toContain('System'); +}); - it('should render action', () => { - const events = [createEvent()]; - const changelog = shallow(<Changelog events={events}/>); - expect(changelog.text()).to.include('ACTIVATED'); - }); +it('should render action', () => { + const events = [createEvent()]; + const changelog = shallow(<Changelog events={events}/>); + expect(changelog.text()).toContain('ACTIVATED'); +}); - it('should render rule', () => { - const events = [createEvent()]; - const changelog = shallow(<Changelog events={events}/>); - expect(changelog.text()).to.include('Do not do this'); - expect(changelog.find('a').prop('href')).to.include('rule_key=squid1234'); - }); +it('should render rule', () => { + const events = [createEvent()]; + const changelog = shallow(<Changelog events={events}/>); + expect(changelog.text()).toContain('Do not do this'); + expect(changelog.find('a').prop('href')).toContain('rule_key=squid1234'); +}); - it('should render ChangesList', () => { - const params = { severity: 'BLOCKER' }; - const events = [createEvent({ params })]; - const changelog = shallow(<Changelog events={events}/>); - const changesList = changelog.find(ChangesList); - expect(changesList).to.have.length(1); - expect(changesList.prop('changes')).to.equal(params); - }); +it('should render ChangesList', () => { + const params = { severity: 'BLOCKER' }; + const events = [createEvent({ params })]; + const changelog = shallow(<Changelog events={events}/>); + const changesList = changelog.find(ChangesList); + expect(changesList.length).toBe(1); + expect(changesList.prop('changes')).toBe(params); }); diff --git a/server/sonar-web/src/main/js/apps/quality-profiles/changelog/__tests__/ChangelogSearch-test.js b/server/sonar-web/src/main/js/apps/quality-profiles/changelog/__tests__/ChangelogSearch-test.js index 302273cedf4..bbeb1a01c93 100644 --- a/server/sonar-web/src/main/js/apps/quality-profiles/changelog/__tests__/ChangelogSearch-test.js +++ b/server/sonar-web/src/main/js/apps/quality-profiles/changelog/__tests__/ChangelogSearch-test.js @@ -17,52 +17,42 @@ * 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 sinon from 'sinon'; import React from 'react'; import ChangelogSearch from '../ChangelogSearch'; import DateInput from '../../../../components/controls/DateInput'; +import { click } from '../../../../../../../tests/utils'; -function click (element) { - return element.simulate('click', { - target: { blur () {} }, - preventDefault () {} - }); -} - -describe('Quality Profiles :: ChangelogSearch', () => { - it('should render DateInput', () => { - const onFromDateChange = sinon.spy(); - const onToDateChange = sinon.spy(); - const output = shallow( - <ChangelogSearch - fromDate="2016-01-01" - toDate="2016-05-05" - onFromDateChange={onFromDateChange} - onToDateChange={onToDateChange} - onReset={sinon.spy()}/> - ); - const dateInputs = output.find(DateInput); - expect(dateInputs).to.have.length(2); - expect(dateInputs.at(0).prop('value')).to.equal('2016-01-01'); - expect(dateInputs.at(0).prop('onChange')).to.equal(onFromDateChange); - expect(dateInputs.at(1).prop('value')).to.equal('2016-05-05'); - expect(dateInputs.at(1).prop('onChange')).to.equal(onToDateChange); - }); +it('should render DateInput', () => { + const onFromDateChange = jest.fn(); + const onToDateChange = jest.fn(); + const output = shallow( + <ChangelogSearch + fromDate="2016-01-01" + toDate="2016-05-05" + onFromDateChange={onFromDateChange} + onToDateChange={onToDateChange} + onReset={jest.fn()}/> + ); + const dateInputs = output.find(DateInput); + expect(dateInputs.length).toBe(2); + expect(dateInputs.at(0).prop('value')).toBe('2016-01-01'); + expect(dateInputs.at(0).prop('onChange')).toBe(onFromDateChange); + expect(dateInputs.at(1).prop('value')).toBe('2016-05-05'); + expect(dateInputs.at(1).prop('onChange')).toBe(onToDateChange); +}); - it('should reset', () => { - const onReset = sinon.spy(); - const output = shallow( - <ChangelogSearch - fromDate="2016-01-01" - toDate="2016-05-05" - onFromDateChange={sinon.spy()} - onToDateChange={sinon.spy()} - onReset={onReset}/> - ); - expect(onReset.called).to.equal(false); - click(output.find('button')); - expect(onReset.called).to.equal(true); - }); +it('should reset', () => { + const onReset = jest.fn(); + const output = shallow( + <ChangelogSearch + fromDate="2016-01-01" + toDate="2016-05-05" + onFromDateChange={jest.fn()} + onToDateChange={jest.fn()} + onReset={onReset}/> + ); + expect(onReset).not.toBeCalled(); + click(output.find('button')); + expect(onReset).toBeCalled(); }); diff --git a/server/sonar-web/src/main/js/apps/quality-profiles/changelog/__tests__/ChangesList-test.js b/server/sonar-web/src/main/js/apps/quality-profiles/changelog/__tests__/ChangesList-test.js index 86e194b22aa..eaec0ebb106 100644 --- a/server/sonar-web/src/main/js/apps/quality-profiles/changelog/__tests__/ChangesList-test.js +++ b/server/sonar-web/src/main/js/apps/quality-profiles/changelog/__tests__/ChangesList-test.js @@ -17,38 +17,29 @@ * 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 ChangesList from '../ChangesList'; import SeverityChange from '../SeverityChange'; import ParameterChange from '../ParameterChange'; -describe('Quality Profiles :: ChangesList', () => { - it('should render changes', () => { - const changes = { severity: 'BLOCKER', foo: 'bar' }; - const output = shallow( - <ChangesList changes={changes}/> - ); - expect(output.find('li')).to.have.length(2); - }); +it('should render changes', () => { + const changes = { severity: 'BLOCKER', foo: 'bar' }; + const output = shallow(<ChangesList changes={changes}/>); + expect(output.find('li').length).toBe(2); +}); - it('should render severity change', () => { - const changes = { severity: 'BLOCKER' }; - const output = shallow( - <ChangesList changes={changes}/> - ).find(SeverityChange); - expect(output).to.have.length(1); - expect(output.prop('severity')).to.equal('BLOCKER'); - }); +it('should render severity change', () => { + const changes = { severity: 'BLOCKER' }; + const output = shallow(<ChangesList changes={changes}/>).find(SeverityChange); + expect(output.length).toBe(1); + expect(output.prop('severity')).toBe('BLOCKER'); +}); - it('should render parameter change', () => { - const changes = { foo: 'bar' }; - const output = shallow( - <ChangesList changes={changes}/> - ).find(ParameterChange); - expect(output).to.have.length(1); - expect(output.prop('name')).to.equal('foo'); - expect(output.prop('value')).to.equal('bar'); - }); +it('should render parameter change', () => { + const changes = { foo: 'bar' }; + const output = shallow(<ChangesList changes={changes}/>).find(ParameterChange); + expect(output.length).toBe(1); + expect(output.prop('name')).toBe('foo'); + expect(output.prop('value')).toBe('bar'); }); diff --git a/server/sonar-web/src/main/js/apps/quality-profiles/changelog/__tests__/ParameterChange-test.js b/server/sonar-web/src/main/js/apps/quality-profiles/changelog/__tests__/ParameterChange-test.js index 1845b09c506..0d8ce5f9a63 100644 --- a/server/sonar-web/src/main/js/apps/quality-profiles/changelog/__tests__/ParameterChange-test.js +++ b/server/sonar-web/src/main/js/apps/quality-profiles/changelog/__tests__/ParameterChange-test.js @@ -17,15 +17,12 @@ * 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 ParameterChange from '../ParameterChange'; -describe('Quality Profiles :: ParameterChange', () => { - it('should render different messages', () => { - const first = shallow(<ParameterChange name="foo"/>); - const second = shallow(<ParameterChange name="foo" value="bar"/>); - expect(first.text()).to.not.be.equal(second.text()); - }); +it('should render different messages', () => { + const first = shallow(<ParameterChange name="foo"/>); + const second = shallow(<ParameterChange name="foo" value="bar"/>); + expect(first.text()).not.toBe(second.text()); }); diff --git a/server/sonar-web/src/main/js/apps/quality-profiles/changelog/__tests__/SeverityChange-test.js b/server/sonar-web/src/main/js/apps/quality-profiles/changelog/__tests__/SeverityChange-test.js index 3a7fcb37b29..6abde9896c3 100644 --- a/server/sonar-web/src/main/js/apps/quality-profiles/changelog/__tests__/SeverityChange-test.js +++ b/server/sonar-web/src/main/js/apps/quality-profiles/changelog/__tests__/SeverityChange-test.js @@ -17,18 +17,13 @@ * 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 SeverityChange from '../SeverityChange'; import SeverityHelper from '../../../../components/shared/severity-helper'; -describe('Quality Profiles :: SeverityChange', () => { - it('should render SeverityHelper', () => { - const output = shallow( - <SeverityChange severity="BLOCKER"/> - ).find(SeverityHelper); - expect(output).to.have.length(1); - expect(output.prop('severity')).to.equal('BLOCKER'); - }); +it('should render SeverityHelper', () => { + const output = shallow(<SeverityChange severity="BLOCKER"/>).find(SeverityHelper); + expect(output.length).toBe(1); + expect(output.prop('severity')).toBe('BLOCKER'); }); diff --git a/server/sonar-web/src/main/js/apps/quality-profiles/compare/__tests__/ComparisonForm-test.js b/server/sonar-web/src/main/js/apps/quality-profiles/compare/__tests__/ComparisonForm-test.js index 42822331754..1ff5fdfad57 100644 --- a/server/sonar-web/src/main/js/apps/quality-profiles/compare/__tests__/ComparisonForm-test.js +++ b/server/sonar-web/src/main/js/apps/quality-profiles/compare/__tests__/ComparisonForm-test.js @@ -17,33 +17,28 @@ * 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 Select from 'react-select'; import ComparisonForm from '../ComparisonForm'; import { createFakeProfile } from '../../utils'; -describe('Quality Profiles :: ComparisonForm', () => { - it('should render Select with right options', () => { - const profile = createFakeProfile(); - const profiles = [ - profile, - createFakeProfile({ key: 'another', name: 'another name' }), - createFakeProfile({ key: 'java', name: 'java', language: 'java' }) - ]; +it('should render Select with right options', () => { + const profile = createFakeProfile(); + const profiles = [ + profile, + createFakeProfile({ key: 'another', name: 'another name' }), + createFakeProfile({ key: 'java', name: 'java', language: 'java' }) + ]; - const output = shallow( - <ComparisonForm - withKey="another" - profile={profile} - profiles={profiles} - onCompare={() => true}/> - ).find(Select); - expect(output).to.have.length(1); - expect(output.prop('value')).to.equal('another'); - expect(output.prop('options')).to.deep.equal([ - { value: 'another', label: 'another name' } - ]); - }); + const output = shallow( + <ComparisonForm + withKey="another" + profile={profile} + profiles={profiles} + onCompare={() => true}/> + ).find(Select); + expect(output.length).toBe(1); + expect(output.prop('value')).toBe('another'); + expect(output.prop('options')).toEqual([{ value: 'another', label: 'another name' }]); }); diff --git a/server/sonar-web/src/main/js/apps/quality-profiles/compare/__tests__/ComparisonResults-test.js b/server/sonar-web/src/main/js/apps/quality-profiles/compare/__tests__/ComparisonResults-test.js index 0482bcb5a58..ed7110ee6a8 100644 --- a/server/sonar-web/src/main/js/apps/quality-profiles/compare/__tests__/ComparisonResults-test.js +++ b/server/sonar-web/src/main/js/apps/quality-profiles/compare/__tests__/ComparisonResults-test.js @@ -17,82 +17,79 @@ * 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 ComparisonResults from '../ComparisonResults'; import ComparisonEmpty from '../ComparisonEmpty'; import SeverityIcon from '../../../../components/shared/severity-icon'; -describe('Quality Profiles :: ComparisonResults', () => { - it('should render ComparisonEmpty', () => { - const output = shallow( - <ComparisonResults - left={{ name: 'left' }} - right={{ name: 'right' }} - inLeft={[]} - inRight={[]} - modified={[]}/> - ); - expect(output.is(ComparisonEmpty)).to.equal(true); - }); +it('should render ComparisonEmpty', () => { + const output = shallow( + <ComparisonResults + left={{ name: 'left' }} + right={{ name: 'right' }} + inLeft={[]} + inRight={[]} + modified={[]}/> + ); + expect(output.is(ComparisonEmpty)).toBe(true); +}); - it('should compare', () => { - const inLeft = [ - { key: 'rule1', name: 'rule1', severity: 'BLOCKER' } - ]; - const inRight = [ - { key: 'rule2', name: 'rule2', severity: 'CRITICAL' }, - { key: 'rule3', name: 'rule3', severity: 'MAJOR' } - ]; - const modified = [ - { - key: 'rule4', - name: 'rule4', - left: { - severity: 'BLOCKER', - params: { foo: 'bar' } - }, - right: { - severity: 'INFO', - params: { foo: 'qwe' } - } +it('should compare', () => { + const inLeft = [ + { key: 'rule1', name: 'rule1', severity: 'BLOCKER' } + ]; + const inRight = [ + { key: 'rule2', name: 'rule2', severity: 'CRITICAL' }, + { key: 'rule3', name: 'rule3', severity: 'MAJOR' } + ]; + const modified = [ + { + key: 'rule4', + name: 'rule4', + left: { + severity: 'BLOCKER', + params: { foo: 'bar' } + }, + right: { + severity: 'INFO', + params: { foo: 'qwe' } } - ]; + } + ]; - const output = shallow( - <ComparisonResults - left={{ name: 'left' }} - right={{ name: 'right' }} - inLeft={inLeft} - inRight={inRight} - modified={modified}/> - ); + const output = shallow( + <ComparisonResults + left={{ name: 'left' }} + right={{ name: 'right' }} + inLeft={inLeft} + inRight={inRight} + modified={modified}/> + ); - const leftDiffs = output.find('.js-comparison-in-left'); - expect(leftDiffs).to.have.length(1); - expect(leftDiffs.find('a')).to.have.length(1); - expect(leftDiffs.find('a').prop('href')).to.include('rule_key=rule1'); - expect(leftDiffs.find('a').text()).to.include('rule1'); - expect(leftDiffs.find(SeverityIcon)).to.have.length(1); - expect(leftDiffs.find(SeverityIcon).prop('severity')).to.equal('BLOCKER'); + const leftDiffs = output.find('.js-comparison-in-left'); + expect(leftDiffs.length).toBe(1); + expect(leftDiffs.find('a').length).toBe(1); + expect(leftDiffs.find('a').prop('href')).toContain('rule_key=rule1'); + expect(leftDiffs.find('a').text()).toContain('rule1'); + expect(leftDiffs.find(SeverityIcon).length).toBe(1); + expect(leftDiffs.find(SeverityIcon).prop('severity')).toBe('BLOCKER'); - const rightDiffs = output.find('.js-comparison-in-right'); - expect(rightDiffs).to.have.length(2); - expect(rightDiffs.at(0).find('a')).to.have.length(1); - expect(rightDiffs.at(0).find('a').prop('href')) - .to.include('rule_key=rule2'); - expect(rightDiffs.at(0).find('a').text()).to.include('rule2'); - expect(rightDiffs.at(0).find(SeverityIcon)).to.have.length(1); - expect(rightDiffs.at(0).find(SeverityIcon).prop('severity')) - .to.equal('CRITICAL'); + const rightDiffs = output.find('.js-comparison-in-right'); + expect(rightDiffs.length).toBe(2); + expect(rightDiffs.at(0).find('a').length).toBe(1); + expect(rightDiffs.at(0).find('a').prop('href')) + .toContain('rule_key=rule2'); + expect(rightDiffs.at(0).find('a').text()).toContain('rule2'); + expect(rightDiffs.at(0).find(SeverityIcon).length).toBe(1); + expect(rightDiffs.at(0).find(SeverityIcon).prop('severity')) + .toBe('CRITICAL'); - const modifiedDiffs = output.find('.js-comparison-modified'); - expect(modifiedDiffs).to.have.length(1); - expect(modifiedDiffs.find('a').at(0).prop('href')).to.include('rule_key=rule4'); - expect(modifiedDiffs.find('a').at(0).text()).to.include('rule4'); - expect(modifiedDiffs.find(SeverityIcon)).to.have.length(2); - expect(modifiedDiffs.text()).to.include('bar'); - expect(modifiedDiffs.text()).to.include('qwe'); - }); + const modifiedDiffs = output.find('.js-comparison-modified'); + expect(modifiedDiffs.length).toBe(1); + expect(modifiedDiffs.find('a').at(0).prop('href')).toContain('rule_key=rule4'); + expect(modifiedDiffs.find('a').at(0).text()).toContain('rule4'); + expect(modifiedDiffs.find(SeverityIcon).length).toBe(2); + expect(modifiedDiffs.text()).toContain('bar'); + expect(modifiedDiffs.text()).toContain('qwe'); }); diff --git a/server/sonar-web/src/main/js/apps/quality-profiles/components/__tests__/ProfileContainer-test.js b/server/sonar-web/src/main/js/apps/quality-profiles/components/__tests__/ProfileContainer-test.js index 87dacc78d87..3c4696d7c5f 100644 --- a/server/sonar-web/src/main/js/apps/quality-profiles/components/__tests__/ProfileContainer-test.js +++ b/server/sonar-web/src/main/js/apps/quality-profiles/components/__tests__/ProfileContainer-test.js @@ -17,9 +17,7 @@ * 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 sinon from 'sinon'; import React from 'react'; import Helmet from 'react-helmet'; import ProfileContainer from '../ProfileContainer'; @@ -27,63 +25,61 @@ import ProfileNotFound from '../ProfileNotFound'; import ProfileHeader from '../../details/ProfileHeader'; import { createFakeProfile } from '../../utils'; -describe('Quality Profiles :: ProfileContainer', () => { - it('should render ProfileHeader', () => { - const targetProfile = createFakeProfile({ key: 'profile1' }); - const profiles = [ - targetProfile, - createFakeProfile({ key: 'profile2' }) - ]; - const updateProfiles = sinon.spy(); - const output = shallow( - <ProfileContainer - location={{ query: { key: 'profile1' } }} - profiles={profiles} - canAdmin={false} - updateProfiles={updateProfiles}> - <div/> - </ProfileContainer> - ); - const header = output.find(ProfileHeader); - expect(header).to.have.length(1); - expect(header.prop('profile')).to.equal(targetProfile); - expect(header.prop('canAdmin')).to.equal(false); - expect(header.prop('updateProfiles')).to.equal(updateProfiles); - }); +it('should render ProfileHeader', () => { + const targetProfile = createFakeProfile({ key: 'profile1' }); + const profiles = [ + targetProfile, + createFakeProfile({ key: 'profile2' }) + ]; + const updateProfiles = jest.fn(); + const output = shallow( + <ProfileContainer + location={{ query: { key: 'profile1' } }} + profiles={profiles} + canAdmin={false} + updateProfiles={updateProfiles}> + <div/> + </ProfileContainer> + ); + const header = output.find(ProfileHeader); + expect(header.length).toBe(1); + expect(header.prop('profile')).toBe(targetProfile); + expect(header.prop('canAdmin')).toBe(false); + expect(header.prop('updateProfiles')).toBe(updateProfiles); +}); - it('should render ProfileNotFound', () => { - const profiles = [ - createFakeProfile({ key: 'profile1' }), - createFakeProfile({ key: 'profile2' }) - ]; - const output = shallow( - <ProfileContainer - location={{ query: { key: 'random' } }} - profiles={profiles} - canAdmin={false} - updateProfiles={() => true}> - <div/> - </ProfileContainer> - ); - expect(output.is(ProfileNotFound)).to.equal(true); - }); +it('should render ProfileNotFound', () => { + const profiles = [ + createFakeProfile({ key: 'profile1' }), + createFakeProfile({ key: 'profile2' }) + ]; + const output = shallow( + <ProfileContainer + location={{ query: { key: 'random' } }} + profiles={profiles} + canAdmin={false} + updateProfiles={() => true}> + <div/> + </ProfileContainer> + ); + expect(output.is(ProfileNotFound)).toBe(true); +}); - it('should render Helmet', () => { - const profiles = [ - createFakeProfile({ key: 'profile1', name: 'First Profile' }) - ]; - const updateProfiles = sinon.spy(); - const output = shallow( - <ProfileContainer - location={{ query: { key: 'profile1' } }} - profiles={profiles} - canAdmin={false} - updateProfiles={updateProfiles}> - <div/> - </ProfileContainer> - ); - const helmet = output.find(Helmet); - expect(helmet).to.have.length(1); - expect(helmet.prop('title')).to.include('First Profile'); - }); +it('should render Helmet', () => { + const profiles = [ + createFakeProfile({ key: 'profile1', name: 'First Profile' }) + ]; + const updateProfiles = jest.fn(); + const output = shallow( + <ProfileContainer + location={{ query: { key: 'profile1' } }} + profiles={profiles} + canAdmin={false} + updateProfiles={updateProfiles}> + <div/> + </ProfileContainer> + ); + const helmet = output.find(Helmet); + expect(helmet.length).toBe(1); + expect(helmet.prop('title')).toContain('First Profile'); }); diff --git a/server/sonar-web/src/main/js/apps/settings/__tests__/utils-test.js b/server/sonar-web/src/main/js/apps/settings/__tests__/utils-test.js index 16b709d99ab..4a401058aff 100644 --- a/server/sonar-web/src/main/js/apps/settings/__tests__/utils-test.js +++ b/server/sonar-web/src/main/js/apps/settings/__tests__/utils-test.js @@ -17,7 +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 { getEmptyValue } from '../utils'; import { TYPE_PROPERTY_SET, TYPE_STRING, TYPE_SINGLE_SELECT_LIST, TYPE_BOOLEAN } from '../constants'; @@ -26,21 +25,19 @@ const fields = [ { key: 'bar', type: TYPE_SINGLE_SELECT_LIST } ]; -describe('Settings :: Utils', () => { - describe('#getEmptyValue()', () => { - it('should work for property sets', () => { - const setting = { type: TYPE_PROPERTY_SET, fields }; - expect(getEmptyValue(setting)).to.deep.equal([{ foo: '', bar: null }]); - }); +describe('#getEmptyValue()', () => { + it('should work for property sets', () => { + const setting = { type: TYPE_PROPERTY_SET, fields }; + expect(getEmptyValue(setting)).toEqual([{ foo: '', bar: null }]); + }); - it('should work for multi values string', () => { - const setting = { type: TYPE_STRING, multiValues: true }; - expect(getEmptyValue(setting)).to.deep.equal(['']); - }); + it('should work for multi values string', () => { + const setting = { type: TYPE_STRING, multiValues: true }; + expect(getEmptyValue(setting)).toEqual(['']); + }); - it('should work for multi values boolean', () => { - const setting = { type: TYPE_BOOLEAN, multiValues: true }; - expect(getEmptyValue(setting)).to.deep.equal([null]); - }); + it('should work for multi values boolean', () => { + const setting = { type: TYPE_BOOLEAN, multiValues: true }; + expect(getEmptyValue(setting)).toEqual([null]); }); }); diff --git a/server/sonar-web/src/main/js/apps/settings/components/inputs/InputForPassword.js b/server/sonar-web/src/main/js/apps/settings/components/inputs/InputForPassword.js index 4e2a783ce11..ddebb7563f8 100644 --- a/server/sonar-web/src/main/js/apps/settings/components/inputs/InputForPassword.js +++ b/server/sonar-web/src/main/js/apps/settings/components/inputs/InputForPassword.js @@ -25,9 +25,14 @@ export default class InputForPassword extends React.Component { static propTypes = defaultInputPropTypes; state = { + value: '', changing: false }; + handleInputChange (e) { + this.setState({ value: e.target.value }); + } + handleChangeClick (e) { e.preventDefault(); e.target.blur(); @@ -37,13 +42,13 @@ export default class InputForPassword extends React.Component { handleCancelChangeClick (e) { e.preventDefault(); e.target.blur(); - this.setState({ changing: false }); + this.setState({ changing: false, value: '' }); } handleFormSubmit (e) { e.preventDefault(); - this.props.onChange(this.refs.input.value); - this.setState({ changing: false }); + this.props.onChange(this.state.value); + this.setState({ changing: false, value: '' }); } renderInput () { @@ -52,12 +57,13 @@ export default class InputForPassword extends React.Component { <form onSubmit={e => this.handleFormSubmit(e)}> <input className="hidden" type="password"/> <input - ref="input" + value={this.state.value} name={this.props.name} - className="input-large text-top" + className="js-password-input input-large text-top" type="password" autoFocus={true} - autoComplete={false}/> + autoComplete={false} + onChange={e => this.handleInputChange(e)}/> <button className="spacer-left">{translate('set')}</button> <a className="spacer-left" href="#" onClick={e => 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(<Input setting={setting} value="foo" onChange={onChange}/>).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(<Input setting={setting} value="foo" onChange={onChange}/>).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(<Input setting={setting} value="foo" onChange={onChange}/>).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(<Input setting={setting} value={value} onChange={onChange}/>).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(<Input setting={setting} value="foo" onChange={onChange}/>).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(<Input setting={setting} value={value} onChange={onChange}/>).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( - <InputForBoolean - name="foo" - value={true} - isDefault={false} - onChange={onChange}/> - ).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( + <InputForBoolean + name="foo" + value={true} + isDefault={false} + onChange={onChange}/> + ).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( - <InputForBoolean - name="foo" - isDefault={false} - onChange={onChange}/> - ); - 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( + <InputForBoolean + name="foo" + isDefault={false} + onChange={onChange}/> + ); + 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( - <InputForBoolean - name="foo" - value={true} - isDefault={false} - onChange={onChange}/> - ); - 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( + <InputForBoolean + name="foo" + value={true} + isDefault={false} + onChange={onChange}/> + ); + 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( - <InputForNumber - name="foo" - value={17} - isDefault={false} - onChange={onChange}/> - ).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( + <InputForNumber + name="foo" + value={17} + isDefault={false} + onChange={onChange}/> + ).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( - <InputForPassword - name="foo" - value="bar" - isDefault={false} - onChange={onChange}/> - ); - 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( - <InputForPassword - name="foo" - value="bar" - isDefault={false} - onChange={onChange}/> - ); - 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( - <InputForPassword - name="foo" - value="bar" - isDefault={false} - onChange={onChange}/> - ); - 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( + <InputForPassword + name="foo" + value="bar" + isDefault={false} + onChange={onChange}/> + ); + 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( + <InputForPassword + name="foo" + value="bar" + isDefault={false} + onChange={onChange}/> + ); + 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( - <InputForPassword - name="foo" - value="bar" - isDefault={false} - onChange={onChange}/> - ); - const button = input.find('button'); - expect(button).to.have.length(1); +it('should close form', () => { + const onChange = jest.fn(); + const input = shallow( + <InputForPassword + name="foo" + value="bar" + isDefault={false} + onChange={onChange}/> + ); + 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( + <InputForPassword + name="foo" + value="bar" + isDefault={false} + onChange={onChange}/> + ); + 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( - <InputForSingleSelectList - name="foo" - value="bar" - options={['foo', 'bar', 'baz']} - isDefault={false} - onChange={onChange}/> - ).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( + <InputForSingleSelectList + name="foo" + value="bar" + options={['foo', 'bar', 'baz']} + isDefault={false} + onChange={onChange}/> + ).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( - <InputForSingleSelectList - name="foo" - value="bar" - options={['foo', 'bar', 'baz']} - isDefault={false} - onChange={onChange}/> - ).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( + <InputForSingleSelectList + name="foo" + value="bar" + options={['foo', 'bar', 'baz']} + isDefault={false} + onChange={onChange}/> + ).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( - <InputForString - name="foo" - value="bar" - isDefault={false} - onChange={onChange}/> - ).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( + <InputForString + name="foo" + value="bar" + isDefault={false} + onChange={onChange}/> + ).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( - <InputForText - name="foo" - value="bar" - isDefault={false} - onChange={onChange}/> - ).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( + <InputForText + name="foo" + value="bar" + isDefault={false} + onChange={onChange}/> + ).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( - <InputForText - name="foo" - value="bar" - isDefault={false} - onChange={onChange}/> - ).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( + <InputForText + name="foo" + value="bar" + isDefault={false} + onChange={onChange}/> + ).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( - <MultiValueInput - setting={{ definition }} - value={['foo']} - onChange={sinon.stub()}/> - ); - const stringInputs = multiValueInput.find(InputForString); - expect(stringInputs).to.have.length(1 + 1); - assertValues(stringInputs, ['foo', '']); - }); - - it('should render several values', () => { - const multiValueInput = mount( - <MultiValueInput - setting={{ definition }} - value={['foo', 'bar', 'baz']} - onChange={sinon.stub()}/> - ); - 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( - <MultiValueInput - setting={{ definition }} - value={['foo', 'bar', 'baz']} - onChange={onChange}/> - ); - - 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(<MultiValueInput setting={{ definition }} value={['foo']} onChange={jest.fn()}/>); + 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( - <MultiValueInput - setting={{ definition }} - value={['foo', 'bar', 'baz']} - onChange={onChange}/> - ); +it('should render several values', () => { + const multiValueInput = shallow( + <MultiValueInput setting={{ definition }} value={['foo', 'bar', 'baz']} onChange={jest.fn()}/>); + 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( + <MultiValueInput setting={{ definition }} value={['foo', 'bar', 'baz']} onChange={onChange}/>); + 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( - <MultiValueInput - setting={{ definition }} - value={['foo']} - onChange={onChange}/> - ); +it('should change existing value', () => { + const onChange = jest.fn(); + const multiValueInput = shallow( + <MultiValueInput setting={{ definition }} value={['foo', 'bar', 'baz']} onChange={onChange}/>); + 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 setting={{ definition }} value={['foo']} onChange={onChange}/>); + 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( - <SimpleInput - type="text" - className="input-large" - name="foo" - value="bar" - isDefault={false} - onChange={onChange}/> - ).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( + <SimpleInput + type="text" + className="input-large" + name="foo" + value="bar" + isDefault={false} + onChange={onChange}/> + ).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( - <SimpleInput - type="text" - className="input-large" - name="foo" - value="bar" - isDefault={false} - onChange={onChange}/> - ).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( + <SimpleInput + type="text" + className="input-large" + name="foo" + value="bar" + isDefault={false} + onChange={onChange}/> + ).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(<ItemValue value="/some/path/as/an/example"/>); - const content = ReactDOM.findDOMNode(TestUtils.findRenderedDOMComponentWithTag(result, 'code')); - expect(content.textContent).to.equal('/some/path/as/an/example'); - }); - - it('should render `true`', () => { - const result = TestUtils.renderIntoDocument(<ItemValue value={true}/>); - TestUtils.findRenderedDOMComponentWithClass(result, 'icon-check'); - }); - - it('should render `false`', () => { - const result = TestUtils.renderIntoDocument(<ItemValue value={false}/>); - TestUtils.findRenderedDOMComponentWithClass(result, 'icon-delete'); - }); - - it('should render object', () => { - const result = TestUtils.renderIntoDocument(<ItemValue value={{ name: 'Java', version: '3.2' }}/>); - TestUtils.findRenderedDOMComponentWithTag(result, 'table'); - expect(TestUtils.scryRenderedDOMComponentsWithTag(result, 'tr')).to.have.length(2); - }); - - it('should render `true` inside object', () => { - const result = TestUtils.renderIntoDocument(<ItemValue value={{ name: 'Java', isCool: true }}/>); - TestUtils.findRenderedDOMComponentWithTag(result, 'table'); - TestUtils.findRenderedDOMComponentWithClass(result, 'icon-check'); - }); - - it('should render object inside object', () => { - const result = TestUtils.renderIntoDocument( - <ItemValue value={{ users: { docs: 1, shards: 5 }, tests: { docs: 68, shards: 5 } }}/>); - expect(TestUtils.scryRenderedDOMComponentsWithTag(result, 'table')).to.have.length(3); - expect(TestUtils.scryRenderedDOMComponentsWithTag(result, 'tr')).to.have.length(6); - }); +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(<ItemValue value="/some/path/as/an/example"/>); + 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(<ItemBoolean value={true}/>); + 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(<ItemBoolean value={false}/>); + expect(result.find('.icon-delete').length).toBe(1); + }); +}); - after(function () { - window.fetch = previousFetch; - }); +describe('ItemObject', () => { + it('should render object', () => { + const result = shallow(<ItemObject value={{ name: 'Java', version: '3.2' }}/>); + expect(result.find('table').length).toBe(1); + expect(result.find('tr').length).toBe(2); + }); - it('should render select box', () => { - const result = TestUtils.renderIntoDocument(<ItemValue value="INFO" name="Logs Level"/>); - TestUtils.findRenderedDOMComponentWithTag(result, 'select'); - expect(TestUtils.scryRenderedDOMComponentsWithTag(result, 'option')).to.have.length(3); - }); + it('should render `true` inside object', () => { + const result = shallow(<ItemObject value={{ isCool: true }}/>); + 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(<ItemValue value="DEBUG" name="Logs Level"/>); - const select = ReactDOM.findDOMNode(TestUtils.findRenderedDOMComponentWithTag(result, 'select')); - expect(select.value).to.equal('DEBUG'); - }); + it('should render object inside object', () => { + const result = shallow(<ItemObject value={{ users: { docs: 1, shards: 5 }, tests: { docs: 68, shards: 5 } }}/>); + 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(<ItemValue value="DEBUG" name="Logs Level"/>); - TestUtils.findRenderedDOMComponentWithClass(result, 'alert'); - }); +describe('Log Level', function () { + it('should render select box', () => { + const result = shallow(<ItemLogLevel value="INFO"/>); + expect(result.find('select').length).toBe(1); + expect(result.find('option').length).toBe(3); + }); - it('should not render warning', () => { - const result = TestUtils.renderIntoDocument(<ItemValue value="INFO" name="Logs Level"/>); - expect(TestUtils.scryRenderedDOMComponentsWithClass(result, 'alert')).to.be.empty; - }); + it('should set initial value', () => { + const result = shallow(<ItemLogLevel value="DEBUG"/>); + 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(<ItemValue value="INFO" name="Logs Level"/>); - const select = ReactDOM.findDOMNode(TestUtils.findRenderedDOMComponentWithTag(result, 'select')); - select.value = 'TRACE'; - TestUtils.Simulate.change(select); - expect(fetchUrl).to.equal('/api/system/change_log_level'); - expect(fetchOptions.method).to.equal('POST'); - expect(fetchOptions.body).to.equal('level=TRACE'); - }); + it('should render warning', () => { + const result = shallow(<ItemLogLevel value="DEBUG"/>); + expect(result.find('.alert').length).toBe(1); }); + it('should not render warning', () => { + const result = shallow(<ItemLogLevel value="INFO"/>); + expect(result.find('.alert').length).toBe(0); + }); }); |