"env": {
"browser": true,
"es6": true,
- "mocha": true,
+ "jest": true,
"node": true
},
"autoprefixer": "6.2.2",
"babel-core": "6.13.2",
"babel-eslint": "^6.0.4",
+ "babel-jest": "15.0.0",
"babel-loader": "6.2.4",
"babel-plugin-react-transform": "2.0.2",
"babel-plugin-transform-class-properties": "6.11.5",
"backbone": "1.2.3",
"backbone.marionette": "2.4.3",
"blueimp-md5": "1.1.1",
- "chai": "3.3.0",
"chalk": "1.1.3",
"classnames": "2.2.0",
"clipboard": "1.5.5",
"handlebars-loader": "1.1.4",
"history": "2.0.0",
"imports-loader": "0.6.5",
+ "jest-cli": "15.1.0",
"jquery": "2.2.0",
- "jsdom": "6.5.1",
"less": "2.7.1",
"less-loader": "2.2.3",
"lodash": "4.6.1",
- "mocha": "2.3.4",
"moment": "2.10.6",
"numeral": "1.5.3",
- "nyc": "^8.1.0",
"postcss-loader": "0.8.0",
"react": "15.0.1",
"react-addons-shallow-compare": "15.0.1",
"redux-thunk": "1.0.2",
"rimraf": "2.5.4",
"script-loader": "0.6.1",
- "sinon": "1.15.4",
- "sinon-chai": "2.8.0",
"style-loader": "0.13.0",
"underscore": "1.8.3",
"webpack": "1.13.0",
"start": "node ./scripts/start.js",
"build-fast": "node ./scripts/build.js --fast",
"build": "node ./scripts/build.js",
- "test": "cross-env NODE_ENV=test mocha --opts tests/mocha.opts src/main/js/**/__tests__/**/*",
- "coverage": "cross-env NODE_ENV=test nyc mocha --opts tests/mocha.opts src/main/js/**/__tests__/**/* && nyc report --reporter lcov --report-dir target/coverage",
+ "test": "cross-env NODE_ENV=test jest",
+ "coverage": "npm test -- --coverage",
"lint": "eslint src/main/js"
},
"engines": {
"node": ">=4"
+ },
+ "jest": {
+ "coverageDirectory": "<rootDir>/target/coverage",
+ "coveragePathIgnorePatterns": [
+ "<rootDir>/node_modules",
+ "<rootDir>/tests"
+ ],
+ "moduleNameMapper": {
+ "^[./a-zA-Z0-9$_-]+\\.(css|hbs)": "<rootDir>/tests/FileStub.js"
+ },
+ "setupFiles": [
+ "<rootDir>/tests/SetupTestEnvironment.js"
+ ],
+ "testPathIgnorePatterns": [
+ "<rootDir>/node_modules",
+ "<rootDir>/src/main/webapp"
+ ]
}
}
*/
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);
});
*/
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);
});
* 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');
});
});
});
<li className="bt-search-form-right">
<button
- ref="reloadButton"
+ className="js-reload"
onClick={this.handleReload.bind(this)}
disabled={loading}>
{translate('reload')}
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="#"/>
} 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>
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>
} 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>
* 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');
});
* 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');
});
* 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');
});
* 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',
);
}
-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);
});
* 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';
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');
});
* 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);
});
* 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) {
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']
+ );
});
});
* 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';
};
}
-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);
});
* 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();
});
* 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');
});
* 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());
});
* 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');
});
* 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' }]);
});
* 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');
});
* 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';
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');
});
* 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';
{ 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]);
});
});
static propTypes = defaultInputPropTypes;
state = {
+ value: '',
changing: false
};
+ handleInputChange (e) {
+ this.setState({ value: e.target.value });
+ }
+
handleChangeClick (e) {
e.preventDefault();
e.target.blur();
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 () {
<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')}
* 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);
});
* 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);
});
* 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();
});
* 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');
});
* 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');
});
* 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();
});
* 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');
});
* 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']);
});
* 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');
});
* 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);
+ });
});
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-import chai, { expect } from 'chai';
-import sinon from 'sinon';
-import sinonChai from 'sinon-chai';
-
import Issue from '../issue/models/issue';
-chai.use(sinonChai);
-
-describe('Issue', function () {
- describe('Model', function () {
- it('should have correct urlRoot', function () {
- const issue = new Issue();
- expect(issue.urlRoot()).to.equal('/api/issues');
- });
+describe('Model', function () {
+ it('should have correct urlRoot', function () {
+ const issue = new Issue();
+ expect(issue.urlRoot()).toBe('/api/issues');
+ });
- it('should parse response without root issue object', function () {
- const issue = new Issue();
- const example = { a: 1 };
- expect(issue.parse(example)).to.deep.equal(example);
- });
+ it('should parse response without root issue object', function () {
+ const issue = new Issue();
+ const example = { a: 1 };
+ expect(issue.parse(example)).toEqual(example);
+ });
- it('should parse response with the root issue object', function () {
- const issue = new Issue();
- const example = { a: 1 };
- expect(issue.parse({ issue: example })).to.deep.equal(example);
- });
+ it('should parse response with the root issue object', function () {
+ const issue = new Issue();
+ const example = { a: 1 };
+ expect(issue.parse({ issue: example })).toEqual(example);
+ });
- it('should reset attributes (no attributes initially)', function () {
- const issue = new Issue();
- const example = { a: 1 };
- issue.reset(example);
- expect(issue.toJSON()).to.deep.equal(example);
- });
+ it('should reset attributes (no attributes initially)', function () {
+ const issue = new Issue();
+ const example = { a: 1 };
+ issue.reset(example);
+ expect(issue.toJSON()).toEqual(example);
+ });
- it('should reset attributes (override attribute)', function () {
- const issue = new Issue({ a: 2 });
- const example = { a: 1 };
- issue.reset(example);
- expect(issue.toJSON()).to.deep.equal(example);
- });
+ it('should reset attributes (override attribute)', function () {
+ const issue = new Issue({ a: 2 });
+ const example = { a: 1 };
+ issue.reset(example);
+ expect(issue.toJSON()).toEqual(example);
+ });
- it('should reset attributes (different attributes)', function () {
- const issue = new Issue({ a: 2 });
- const example = { b: 1 };
- issue.reset(example);
- expect(issue.toJSON()).to.deep.equal(example);
- });
+ it('should reset attributes (different attributes)', function () {
+ const issue = new Issue({ a: 2 });
+ const example = { b: 1 };
+ issue.reset(example);
+ expect(issue.toJSON()).toEqual(example);
+ });
- it('should unset `textRange` of a closed issue', function () {
- const issue = new Issue();
- const result = issue.parse({ issue: { status: 'CLOSED', textRange: { startLine: 5 } } });
- expect(result.textRange).to.not.be.ok;
- });
+ it('should unset `textRange` of a closed issue', function () {
+ const issue = new Issue();
+ const result = issue.parse({ issue: { status: 'CLOSED', textRange: { startLine: 5 } } });
+ expect(result.textRange).toBeFalsy();
+ });
- it('should unset `flows` of a closed issue', function () {
- const issue = new Issue();
- const result = issue.parse({ issue: { status: 'CLOSED', flows: [1, 2, 3] } });
- expect(result.flows).to.deep.equal([]);
- });
+ it('should unset `flows` of a closed issue', function () {
+ const issue = new Issue();
+ const result = issue.parse({ issue: { status: 'CLOSED', flows: [1, 2, 3] } });
+ expect(result.flows).toEqual([]);
+ });
- describe('Actions', function () {
- it('should assign', function () {
- const issue = new Issue({ key: 'issue-key' });
- const spy = sinon.spy();
- issue._action = spy;
- issue.assign('admin');
- expect(spy).to.have.been.calledWith({
- data: { assignee: 'admin', issue: 'issue-key' },
- url: '/api/issues/assign'
- });
+ describe('Actions', function () {
+ it('should assign', function () {
+ const issue = new Issue({ key: 'issue-key' });
+ const spy = jest.fn();
+ issue._action = spy;
+ issue.assign('admin');
+ expect(spy).toBeCalledWith({
+ data: { assignee: 'admin', issue: 'issue-key' },
+ url: '/api/issues/assign'
});
+ });
- it('should unassign', function () {
- const issue = new Issue({ key: 'issue-key' });
- const spy = sinon.spy();
- issue._action = spy;
- issue.assign();
- expect(spy).to.have.been.calledWith({
- data: { assignee: undefined, issue: 'issue-key' },
- url: '/api/issues/assign'
- });
+ it('should unassign', function () {
+ const issue = new Issue({ key: 'issue-key' });
+ const spy = jest.fn();
+ issue._action = spy;
+ issue.assign();
+ expect(spy).toBeCalledWith({
+ data: { assignee: undefined, issue: 'issue-key' },
+ url: '/api/issues/assign'
});
+ });
- it('should plan', function () {
- const issue = new Issue({ key: 'issue-key' });
- const spy = sinon.spy();
- issue._action = spy;
- issue.plan('plan');
- expect(spy).to.have.been.calledWith({ data: { plan: 'plan', issue: 'issue-key' }, url: '/api/issues/plan' });
- });
+ it('should plan', function () {
+ const issue = new Issue({ key: 'issue-key' });
+ const spy = jest.fn();
+ issue._action = spy;
+ issue.plan('plan');
+ expect(spy).toBeCalledWith({ data: { plan: 'plan', issue: 'issue-key' }, url: '/api/issues/plan' });
+ });
- it('should unplan', function () {
- const issue = new Issue({ key: 'issue-key' });
- const spy = sinon.spy();
- issue._action = spy;
- issue.plan();
- expect(spy).to.have.been.calledWith({ data: { plan: undefined, issue: 'issue-key' }, url: '/api/issues/plan' });
- });
+ it('should unplan', function () {
+ const issue = new Issue({ key: 'issue-key' });
+ const spy = jest.fn();
+ issue._action = spy;
+ issue.plan();
+ expect(spy).toBeCalledWith({ data: { plan: undefined, issue: 'issue-key' }, url: '/api/issues/plan' });
+ });
- it('should set severity', function () {
- const issue = new Issue({ key: 'issue-key' });
- const spy = sinon.spy();
- issue._action = spy;
- issue.setSeverity('BLOCKER');
- expect(spy).to.have.been.calledWith({
- data: { severity: 'BLOCKER', issue: 'issue-key' },
- url: '/api/issues/set_severity'
- });
+ it('should set severity', function () {
+ const issue = new Issue({ key: 'issue-key' });
+ const spy = jest.fn();
+ issue._action = spy;
+ issue.setSeverity('BLOCKER');
+ expect(spy).toBeCalledWith({
+ data: { severity: 'BLOCKER', issue: 'issue-key' },
+ url: '/api/issues/set_severity'
});
});
+ });
- describe('#getLinearLocations', function () {
- it('should return single line location', function () {
- const issue = new Issue({ textRange: { startLine: 1, endLine: 1, startOffset: 0, endOffset: 10 } });
- const locations = issue.getLinearLocations();
- expect(locations.length).to.equal(1);
+ describe('#getLinearLocations', function () {
+ it('should return single line location', function () {
+ const issue = new Issue({ textRange: { startLine: 1, endLine: 1, startOffset: 0, endOffset: 10 } });
+ const locations = issue.getLinearLocations();
+ expect(locations.length).toBe(1);
- expect(locations[0].line).to.equal(1);
- expect(locations[0].from).to.equal(0);
- expect(locations[0].to).to.equal(10);
- });
+ expect(locations[0].line).toBe(1);
+ expect(locations[0].from).toBe(0);
+ expect(locations[0].to).toBe(10);
+ });
- it('should return location not from 0', function () {
- const issue = new Issue({ textRange: { startLine: 1, endLine: 1, startOffset: 5, endOffset: 10 } });
- const locations = issue.getLinearLocations();
- expect(locations.length).to.equal(1);
+ it('should return location not from 0', function () {
+ const issue = new Issue({ textRange: { startLine: 1, endLine: 1, startOffset: 5, endOffset: 10 } });
+ const locations = issue.getLinearLocations();
+ expect(locations.length).toBe(1);
- expect(locations[0].line).to.equal(1);
- expect(locations[0].from).to.equal(5);
- expect(locations[0].to).to.equal(10);
- });
+ expect(locations[0].line).toBe(1);
+ expect(locations[0].from).toBe(5);
+ expect(locations[0].to).toBe(10);
+ });
- it('should return 2-lines location', function () {
- const issue = new Issue({ textRange: { startLine: 2, endLine: 3, startOffset: 5, endOffset: 10 } });
- const locations = issue.getLinearLocations();
- expect(locations.length).to.equal(2);
+ it('should return 2-lines location', function () {
+ const issue = new Issue({ textRange: { startLine: 2, endLine: 3, startOffset: 5, endOffset: 10 } });
+ const locations = issue.getLinearLocations();
+ expect(locations.length).toBe(2);
- expect(locations[0].line).to.equal(2);
- expect(locations[0].from).to.equal(5);
- expect(locations[0].to).to.equal(999999);
+ expect(locations[0].line).toBe(2);
+ expect(locations[0].from).toBe(5);
+ expect(locations[0].to).toBe(999999);
- expect(locations[1].line).to.equal(3);
- expect(locations[1].from).to.equal(0);
- expect(locations[1].to).to.equal(10);
- });
+ expect(locations[1].line).toBe(3);
+ expect(locations[1].from).toBe(0);
+ expect(locations[1].to).toBe(10);
+ });
- it('should return 3-lines location', function () {
- const issue = new Issue({ textRange: { startLine: 4, endLine: 6, startOffset: 5, endOffset: 10 } });
- const locations = issue.getLinearLocations();
- expect(locations.length).to.equal(3);
+ it('should return 3-lines location', function () {
+ const issue = new Issue({ textRange: { startLine: 4, endLine: 6, startOffset: 5, endOffset: 10 } });
+ const locations = issue.getLinearLocations();
+ expect(locations.length).toBe(3);
- expect(locations[0].line).to.equal(4);
- expect(locations[0].from).to.equal(5);
- expect(locations[0].to).to.equal(999999);
+ expect(locations[0].line).toBe(4);
+ expect(locations[0].from).toBe(5);
+ expect(locations[0].to).toBe(999999);
- expect(locations[1].line).to.equal(5);
- expect(locations[1].from).to.equal(0);
- expect(locations[1].to).to.equal(999999);
+ expect(locations[1].line).toBe(5);
+ expect(locations[1].from).toBe(0);
+ expect(locations[1].to).toBe(999999);
- expect(locations[2].line).to.equal(6);
- expect(locations[2].from).to.equal(0);
- expect(locations[2].to).to.equal(10);
- });
+ expect(locations[2].line).toBe(6);
+ expect(locations[2].from).toBe(0);
+ expect(locations[2].to).toBe(10);
+ });
- it('should return [] when no location', function () {
- const issue = new Issue();
- const locations = issue.getLinearLocations();
- expect(locations.length).to.equal(0);
- });
+ it('should return [] when no location', function () {
+ const issue = new Issue();
+ const locations = issue.getLinearLocations();
+ expect(locations.length).toBe(0);
});
});
});
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-import { expect } from 'chai';
-
import helper from '../source-viewer/helpers/code-with-issue-locations-helper';
-describe('Source Viewer', function () {
- describe('Code With Issue Locations Helper', function () {
- it('should be a function', function () {
- expect(helper).to.be.a('function');
- });
+describe('Code With Issue Locations Helper', function () {
+ it('should be a function', function () {
+ expect(helper).toBeTruthy();
+ });
- it('should mark one location', function () {
- const code = '<span class="k">if</span> (<span class="sym-2 sym">a</span> + <span class="c">1</span>) {';
- const locations = [{ from: 1, to: 5 }];
- const result = helper(code, locations, 'x');
- expect(result).to.equal([
- '<span class="k">i</span>',
- '<span class="k x">f</span>',
- '<span class=" x"> (</span>',
- '<span class="sym-2 sym x">a</span>',
- '<span class=""> + </span>',
- '<span class="c">1</span>',
- '<span class="">) {</span>'
- ].join(''));
- });
+ it('should mark one location', function () {
+ const code = '<span class="k">if</span> (<span class="sym-2 sym">a</span> + <span class="c">1</span>) {';
+ const locations = [{ from: 1, to: 5 }];
+ const result = helper(code, locations, 'x');
+ expect(result).toBe([
+ '<span class="k">i</span>',
+ '<span class="k x">f</span>',
+ '<span class=" x"> (</span>',
+ '<span class="sym-2 sym x">a</span>',
+ '<span class=""> + </span>',
+ '<span class="c">1</span>',
+ '<span class="">) {</span>'
+ ].join(''));
+ });
- it('should mark two locations', function () {
- const code = 'abcdefghijklmnopqrst';
- const locations = [
- { from: 1, to: 6 },
- { from: 11, to: 16 }
- ];
- const result = helper(code, locations, 'x');
- expect(result).to.equal([
- '<span class="">a</span>',
- '<span class=" x">bcdef</span>',
- '<span class="">ghijk</span>',
- '<span class=" x">lmnop</span>',
- '<span class="">qrst</span>'
- ].join(''));
- });
+ it('should mark two locations', function () {
+ const code = 'abcdefghijklmnopqrst';
+ const locations = [
+ { from: 1, to: 6 },
+ { from: 11, to: 16 }
+ ];
+ const result = helper(code, locations, 'x');
+ expect(result).toBe([
+ '<span class="">a</span>',
+ '<span class=" x">bcdef</span>',
+ '<span class="">ghijk</span>',
+ '<span class=" x">lmnop</span>',
+ '<span class="">qrst</span>'
+ ].join(''));
+ });
- it('should mark one locations', function () {
- const code = '<span class="cppd"> * Copyright (C) 2008-2014 SonarSource</span>';
- const locations = [{ from: 15, to: 20 }];
- const result = helper(code, locations, 'x');
- expect(result).to.equal([
- '<span class="cppd"> * Copyright (C</span>',
- '<span class="cppd x">) 200</span>',
- '<span class="cppd">8-2014 SonarSource</span>'
- ].join(''));
- });
+ it('should mark one locations', function () {
+ const code = '<span class="cppd"> * Copyright (C) 2008-2014 SonarSource</span>';
+ const locations = [{ from: 15, to: 20 }];
+ const result = helper(code, locations, 'x');
+ expect(result).toBe([
+ '<span class="cppd"> * Copyright (C</span>',
+ '<span class="cppd x">) 200</span>',
+ '<span class="cppd">8-2014 SonarSource</span>'
+ ].join(''));
+ });
- it('should mark two locations', function () {
- const code = '<span class="cppd"> * Copyright (C) 2008-2014 SonarSource</span>';
- const locations = [
- { from: 24, to: 29 },
- { from: 15, to: 20 }
- ];
- const result = helper(code, locations, 'x');
- expect(result).to.equal([
- '<span class="cppd"> * Copyright (C</span>',
- '<span class="cppd x">) 200</span>',
- '<span class="cppd">8-20</span>',
- '<span class="cppd x">14 So</span>',
- '<span class="cppd">narSource</span>'
- ].join(''));
- });
+ it('should mark two locations', function () {
+ const code = '<span class="cppd"> * Copyright (C) 2008-2014 SonarSource</span>';
+ const locations = [
+ { from: 24, to: 29 },
+ { from: 15, to: 20 }
+ ];
+ const result = helper(code, locations, 'x');
+ expect(result).toBe([
+ '<span class="cppd"> * Copyright (C</span>',
+ '<span class="cppd x">) 200</span>',
+ '<span class="cppd">8-20</span>',
+ '<span class="cppd x">14 So</span>',
+ '<span class="cppd">narSource</span>'
+ ].join(''));
+ });
- it('should parse line with < and >', function () {
- const code = '<span class="j">#include <stdio.h></span>';
- const result = helper(code, []);
- expect(result).to.equal('<span class="j">#include <stdio.h></span>');
- });
+ it('should parse line with < and >', function () {
+ const code = '<span class="j">#include <stdio.h></span>';
+ const result = helper(code, []);
+ expect(result).toBe('<span class="j">#include <stdio.h></span>');
+ });
- it('should parse syntax and usage highlighting', function () {
- const code = '<span class="k"><span class="sym-3 sym">this</span></span>';
- const expected = '<span class="k sym-3 sym">this</span>';
- const result = helper(code, []);
- expect(result).to.equal(expected);
- });
+ it('should parse syntax and usage highlighting', function () {
+ const code = '<span class="k"><span class="sym-3 sym">this</span></span>';
+ const expected = '<span class="k sym-3 sym">this</span>';
+ const result = helper(code, []);
+ expect(result).toBe(expected);
+ });
- it('should parse nested tags', function () {
- const code = '<span class="k"><span class="sym-3 sym">this</span> is</span>';
- const expected = '<span class="k sym-3 sym">this</span><span class="k"> is</span>';
- const result = helper(code, []);
- expect(result).to.equal(expected);
- });
+ it('should parse nested tags', function () {
+ const code = '<span class="k"><span class="sym-3 sym">this</span> is</span>';
+ const expected = '<span class="k sym-3 sym">this</span><span class="k"> is</span>';
+ const result = helper(code, []);
+ expect(result).toBe(expected);
});
});
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
import React from 'react';
-import TestUtils from 'react-addons-test-utils';
-import { expect } from 'chai';
-
+import { shallow } from 'enzyme';
import { BarChart } from '../bar-chart';
-describe('Bar Chart', function () {
-
- it('should display bars', function () {
- const data = [
- { x: 1, y: 10 },
- { x: 2, y: 30 },
- { x: 3, y: 20 }
- ];
- const chart = TestUtils.renderIntoDocument(
- <BarChart
- data={data}
- width={100}
- height={100}
- barsWidth={20}/>);
- expect(TestUtils.scryRenderedDOMComponentsWithClass(chart, 'bar-chart-bar')).to.have.length(3);
- });
-
- it('should display ticks', function () {
- const data = [
- { x: 1, y: 10 },
- { x: 2, y: 30 },
- { x: 3, y: 20 }
- ];
- const ticks = ['A', 'B', 'C'];
- const chart = TestUtils.renderIntoDocument(
- <BarChart
- data={data}
- xTicks={ticks}
- width={100}
- height={100}
- barsWidth={20}/>);
- expect(TestUtils.scryRenderedDOMComponentsWithClass(chart, 'bar-chart-tick')).to.have.length(3);
- });
+it('should display bars', function () {
+ const data = [
+ { x: 1, y: 10 },
+ { x: 2, y: 30 },
+ { x: 3, y: 20 }
+ ];
+ const chart = shallow(
+ <BarChart
+ data={data}
+ width={100}
+ height={100}
+ barsWidth={20}/>);
+ expect(chart.find('.bar-chart-bar').length).toBe(3);
+});
- it('should display values', function () {
- const data = [
- { x: 1, y: 10 },
- { x: 2, y: 30 },
- { x: 3, y: 20 }
- ];
- const values = ['A', 'B', 'C'];
- const chart = TestUtils.renderIntoDocument(
- <BarChart
- data={data}
- xValues={values}
- width={100}
- height={100}
- barsWidth={20}/>);
- expect(TestUtils.scryRenderedDOMComponentsWithClass(chart, 'bar-chart-tick')).to.have.length(3);
- });
+it('should display ticks', function () {
+ const data = [
+ { x: 1, y: 10 },
+ { x: 2, y: 30 },
+ { x: 3, y: 20 }
+ ];
+ const ticks = ['A', 'B', 'C'];
+ const chart = shallow(
+ <BarChart
+ data={data}
+ xTicks={ticks}
+ width={100}
+ height={100}
+ barsWidth={20}/>);
+ expect(chart.find('.bar-chart-tick').length).toBe(3);
+});
- it('should display bars, ticks and values', function () {
- const data = [
- { x: 1, y: 10 },
- { x: 2, y: 30 },
- { x: 3, y: 20 }
- ];
- const ticks = ['A', 'B', 'C'];
- const values = ['A', 'B', 'C'];
- const chart = TestUtils.renderIntoDocument(
- <BarChart
- data={data}
- xTicks={ticks}
- xValues={values}
- width={100}
- height={100}
- barsWidth={20}/>);
- expect(TestUtils.scryRenderedDOMComponentsWithClass(chart, 'bar-chart-bar')).to.have.length(3);
- expect(TestUtils.scryRenderedDOMComponentsWithClass(chart, 'bar-chart-tick')).to.have.length(6);
- });
+it('should display values', function () {
+ const data = [
+ { x: 1, y: 10 },
+ { x: 2, y: 30 },
+ { x: 3, y: 20 }
+ ];
+ const values = ['A', 'B', 'C'];
+ const chart = shallow(
+ <BarChart
+ data={data}
+ xValues={values}
+ width={100}
+ height={100}
+ barsWidth={20}/>);
+ expect(chart.find('.bar-chart-tick').length).toBe(3);
+});
+it('should display bars, ticks and values', function () {
+ const data = [
+ { x: 1, y: 10 },
+ { x: 2, y: 30 },
+ { x: 3, y: 20 }
+ ];
+ const ticks = ['A', 'B', 'C'];
+ const values = ['A', 'B', 'C'];
+ const chart = shallow(
+ <BarChart
+ data={data}
+ xTicks={ticks}
+ xValues={values}
+ width={100}
+ height={100}
+ barsWidth={20}/>);
+ expect(chart.find('.bar-chart-bar').length).toBe(3);
+ expect(chart.find('.bar-chart-tick').length).toBe(6);
});
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
import React from 'react';
-import TestUtils from 'react-addons-test-utils';
-import { expect } from 'chai';
+import { shallow } from 'enzyme';
+import { BubbleChart, Bubble } from '../bubble-chart';
-import { BubbleChart } from '../bubble-chart';
-
-describe('Bubble Chart', function () {
-
- it('should display bubbles', function () {
- const items = [
- { x: 1, y: 10, size: 7 },
- { x: 2, y: 30, size: 5 },
- { x: 3, y: 20, size: 2 }
- ];
- const chart = TestUtils.renderIntoDocument(<BubbleChart items={items} width={100} height={100}/>);
- expect(TestUtils.scryRenderedDOMComponentsWithClass(chart, 'bubble-chart-bubble')).to.have.length(3);
- });
-
- it('should display grid', function () {
- const items = [
- { x: 1, y: 10, size: 7 },
- { x: 2, y: 30, size: 5 },
- { x: 3, y: 20, size: 2 }
- ];
- const chart = TestUtils.renderIntoDocument(<BubbleChart items={items} width={100} height={100}/>);
- expect(TestUtils.scryRenderedDOMComponentsWithTag(chart, 'line')).to.not.be.empty;
- });
+it('should display bubbles', () => {
+ const items = [
+ { x: 1, y: 10, size: 7 },
+ { x: 2, y: 30, size: 5 },
+ { x: 3, y: 20, size: 2 }
+ ];
+ const chart = shallow(<BubbleChart items={items} width={100} height={100}/>);
+ expect(chart.find(Bubble).length).toBe(3);
+});
- it('should display ticks', function () {
- const items = [
- { x: 1, y: 10, size: 7 },
- { x: 2, y: 30, size: 5 },
- { x: 3, y: 20, size: 2 }
- ];
- const chart = TestUtils.renderIntoDocument(<BubbleChart items={items} width={100} height={100}/>);
- expect(TestUtils.scryRenderedDOMComponentsWithClass(chart, 'bubble-chart-tick')).to.not.be.empty;
- });
+it('should display grid', () => {
+ const items = [
+ { x: 1, y: 10, size: 7 },
+ { x: 2, y: 30, size: 5 },
+ { x: 3, y: 20, size: 2 }
+ ];
+ const chart = shallow(<BubbleChart items={items} width={100} height={100}/>);
+ expect(chart.find('line').length).toBeGreaterThan(0);
+});
+it('should display ticks', () => {
+ const items = [
+ { x: 1, y: 10, size: 7 },
+ { x: 2, y: 30, size: 5 },
+ { x: 3, y: 20, size: 2 }
+ ];
+ const chart = shallow(<BubbleChart items={items} width={100} height={100}/>);
+ expect(chart.find('.bubble-chart-tick').length).toBeGreaterThan(0);
});
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
import React from 'react';
-import TestUtils from 'react-addons-test-utils';
-import { expect } from 'chai';
-
+import { shallow } from 'enzyme';
import { LineChart } from '../line-chart';
-describe('Line Chart', function () {
-
- it('should display line', function () {
- const data = [
- { x: 1, y: 10 },
- { x: 2, y: 30 },
- { x: 3, y: 20 }
- ];
- const chart = TestUtils.renderIntoDocument(
- <LineChart
- data={data}
- width={100}
- height={100}/>);
- expect(TestUtils.scryRenderedDOMComponentsWithClass(chart, 'line-chart-path')).to.have.length(1);
- });
-
- it('should display ticks', function () {
- const data = [
- { x: 1, y: 10 },
- { x: 2, y: 30 },
- { x: 3, y: 20 }
- ];
- const ticks = ['A', 'B', 'C'];
- const chart = TestUtils.renderIntoDocument(
- <LineChart
- data={data}
- xTicks={ticks}
- width={100}
- height={100}/>);
- expect(TestUtils.scryRenderedDOMComponentsWithClass(chart, 'line-chart-tick')).to.have.length(3);
- });
+it('should display line', function () {
+ const data = [
+ { x: 1, y: 10 },
+ { x: 2, y: 30 },
+ { x: 3, y: 20 }
+ ];
+ const chart = shallow(<LineChart data={data} width={100} height={100}/>);
+ expect(chart.find('.line-chart-path').length).toBe(1);
+});
- it('should display values', function () {
- const data = [
- { x: 1, y: 10 },
- { x: 2, y: 30 },
- { x: 3, y: 20 }
- ];
- const values = ['A', 'B', 'C'];
- const chart = TestUtils.renderIntoDocument(
- <LineChart
- data={data}
- xValues={values}
- width={100}
- height={100}/>);
- expect(TestUtils.scryRenderedDOMComponentsWithClass(chart, 'line-chart-tick')).to.have.length(3);
- });
+it('should display ticks', function () {
+ const data = [
+ { x: 1, y: 10 },
+ { x: 2, y: 30 },
+ { x: 3, y: 20 }
+ ];
+ const ticks = ['A', 'B', 'C'];
+ const chart = shallow(
+ <LineChart
+ data={data}
+ xTicks={ticks}
+ width={100}
+ height={100}/>);
+ expect(chart.find('.line-chart-tick').length).toBe(3);
+});
+it('should display values', function () {
+ const data = [
+ { x: 1, y: 10 },
+ { x: 2, y: 30 },
+ { x: 3, y: 20 }
+ ];
+ const values = ['A', 'B', 'C'];
+ const chart = shallow(
+ <LineChart
+ data={data}
+ xValues={values}
+ width={100}
+ height={100}/>);
+ expect(chart.find('.line-chart-tick').length).toBe(3);
});
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
import React from 'react';
-import TestUtils from 'react-addons-test-utils';
-import { expect } from 'chai';
-
-import { Treemap } from '../treemap';
-
-describe('Treemap', function () {
-
- it('should display', function () {
- const items = [
- { size: 10, color: '#777', label: 'SonarQube :: Server' },
- { size: 30, color: '#777', label: 'SonarQube :: Web' },
- { size: 20, color: '#777', label: 'SonarQube :: Search' }
- ];
- const chart = TestUtils.renderIntoDocument(
- <Treemap
- items={items}
- width={100}
- height={100}
- breadcrumbs={[]}
- canBeClicked={() => true}/>);
- expect(TestUtils.scryRenderedDOMComponentsWithClass(chart, 'treemap-cell')).to.have.length(3);
- });
+import { shallow } from 'enzyme';
+import { Treemap, TreemapRect } from '../treemap';
+it('should display', function () {
+ const items = [
+ { size: 10, color: '#777', label: 'SonarQube :: Server' },
+ { size: 30, color: '#777', label: 'SonarQube :: Web' },
+ { size: 20, color: '#777', label: 'SonarQube :: Search' }
+ ];
+ const chart = shallow(
+ <Treemap
+ items={items}
+ width={100}
+ height={100}
+ breadcrumbs={[]}
+ canBeClicked={() => true}/>);
+ expect(chart.find(TreemapRect).length).toBe(3);
});
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
import React from 'react';
-import TestUtils from 'react-addons-test-utils';
-import { expect } from 'chai';
-
-import { WordCloud } from '../word-cloud';
-
-describe('Word Cloud', function () {
-
- it('should display', function () {
- const items = [
- { size: 10, link: '#', text: 'SonarQube :: Server' },
- { size: 30, link: '#', text: 'SonarQube :: Web' },
- { size: 20, link: '#', text: 'SonarQube :: Search' }
- ];
- const chart = TestUtils.renderIntoDocument(<WordCloud items={items} width={100} height={100}/>);
- expect(TestUtils.scryRenderedDOMComponentsWithTag(chart, 'a')).to.have.length(3);
- });
+import { shallow } from 'enzyme';
+import { WordCloud, Word } from '../word-cloud';
+it('should display', function () {
+ const items = [
+ { size: 10, link: '#', text: 'SonarQube :: Server' },
+ { size: 30, link: '#', text: 'SonarQube :: Web' },
+ { size: 20, link: '#', text: 'SonarQube :: Search' }
+ ];
+ const chart = shallow(<WordCloud items={items} width={100} height={100}/>);
+ expect(chart.find(Word).length).toBe(3);
});
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-import chai, { expect } from 'chai';
import { shallow } from 'enzyme';
-import sinon from 'sinon';
-import sinonChai from 'sinon-chai';
import React from 'react';
import Checkbox from '../Checkbox';
+import { click } from '../../../../../../tests/utils';
-chai.use(sinonChai);
-
-function click (element) {
- return element.simulate('click', {
- target: { blur () {} },
- preventDefault () {}
- });
-}
-
-describe('Components :: Controls :: Checkbox', () => {
- it('should render unchecked', () => {
- const checkbox = shallow(
- <Checkbox checked={false} onCheck={() => true}/>
- );
- expect(checkbox.is('.icon-checkbox-checked')).to.equal(false);
- });
+it('should render unchecked', () => {
+ const checkbox = shallow(<Checkbox checked={false} onCheck={() => true}/>);
+ expect(checkbox.is('.icon-checkbox-checked')).toBe(false);
+});
- it('should render checked', () => {
- const checkbox = shallow(
- <Checkbox checked={true} onCheck={() => true}/>
- );
- expect(checkbox.is('.icon-checkbox-checked')).to.equal(true);
- });
+it('should render checked', () => {
+ const checkbox = shallow(<Checkbox checked={true} onCheck={() => true}/>);
+ expect(checkbox.is('.icon-checkbox-checked')).toBe(true);
+});
- it('should render unchecked third state', () => {
- const checkbox = shallow(
- <Checkbox checked={false} thirdState={true} onCheck={() => true}/>
- );
- expect(checkbox.is('.icon-checkbox-single')).to.equal(true);
- expect(checkbox.is('.icon-checkbox-checked')).to.equal(false);
- });
+it('should render unchecked third state', () => {
+ const checkbox = shallow(<Checkbox checked={false} thirdState={true} onCheck={() => true}/>);
+ expect(checkbox.is('.icon-checkbox-single')).toBe(true);
+ expect(checkbox.is('.icon-checkbox-checked')).toBe(false);
+});
- it('should render checked third state', () => {
- const checkbox = shallow(
- <Checkbox checked={true} thirdState={true} onCheck={() => true}/>
- );
- expect(checkbox.is('.icon-checkbox-single')).to.equal(true);
- expect(checkbox.is('.icon-checkbox-checked')).to.equal(true);
- });
+it('should render checked third state', () => {
+ const checkbox = shallow(<Checkbox checked={true} thirdState={true} onCheck={() => true}/>);
+ expect(checkbox.is('.icon-checkbox-single')).toBe(true);
+ expect(checkbox.is('.icon-checkbox-checked')).toBe(true);
+});
- it('should call onCheck', () => {
- const onCheck = sinon.spy();
- const checkbox = shallow(
- <Checkbox checked={false} onCheck={onCheck}/>
- );
- click(checkbox);
- expect(onCheck).to.have.been.calledWith(true);
- });
+it('should call onCheck', () => {
+ const onCheck = jest.fn();
+ const checkbox = shallow(<Checkbox checked={false} onCheck={onCheck}/>);
+ click(checkbox);
+ expect(onCheck).toBeCalledWith(true);
});
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-import chai, { expect } from 'chai';
import { shallow } from 'enzyme';
-import sinon from 'sinon';
-import sinonChai from 'sinon-chai';
import React from 'react';
import FavoriteBase from '../FavoriteBase';
-
-chai.use(sinonChai);
-
-function click (element) {
- return element.simulate('click', {
- target: { blur () {} },
- preventDefault () {}
- });
-}
+import { click } from '../../../../../../tests/utils';
function renderFavoriteBase (props) {
return shallow(
<FavoriteBase
favorite={true}
- addFavorite={sinon.stub().throws()}
- removeFavorite={sinon.stub().throws()}
+ addFavorite={jest.fn()}
+ removeFavorite={jest.fn()}
{...props}/>
);
}
-describe('Components :: Controls :: FavoriteBase', () => {
- it('should render favorite', () => {
- const favorite = renderFavoriteBase({ favorite: true });
- expect(favorite.is('.icon-star-favorite')).to.equal(true);
- });
+it('should render favorite', () => {
+ const favorite = renderFavoriteBase({ favorite: true });
+ expect(favorite.is('.icon-star-favorite')).toBe(true);
+});
- it('should render not favorite', () => {
- const favorite = renderFavoriteBase({ favorite: false });
- expect(favorite.is('.icon-star-favorite')).to.equal(false);
- });
+it('should render not favorite', () => {
+ const favorite = renderFavoriteBase({ favorite: false });
+ expect(favorite.is('.icon-star-favorite')).toBe(false);
+});
- it('should add favorite', () => {
- const addFavorite = sinon.stub().returns(Promise.resolve());
- const favorite = renderFavoriteBase({ favorite: false, addFavorite });
- click(favorite.find('a'));
- expect(addFavorite).to.have.been.called;
- });
+it('should add favorite', () => {
+ const addFavorite = jest.fn(() => Promise.resolve());
+ const favorite = renderFavoriteBase({ favorite: false, addFavorite });
+ click(favorite.find('a'));
+ expect(addFavorite).toBeCalled();
+});
- it('should remove favorite', () => {
- const removeFavorite = sinon.stub().returns(Promise.resolve());
- const favorite = renderFavoriteBase({ favorite: true, removeFavorite });
- click(favorite.find('a'));
- expect(removeFavorite).to.have.been.called;
- });
+it('should remove favorite', () => {
+ const removeFavorite = jest.fn(() => Promise.resolve());
+ const favorite = renderFavoriteBase({ favorite: true, removeFavorite });
+ click(favorite.find('a'));
+ expect(removeFavorite).toBeCalled();
});
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-import chai, { expect } from 'chai';
import { shallow } from 'enzyme';
-import sinon from 'sinon';
-import sinonChai from 'sinon-chai';
import React from 'react';
import ListFooter from '../ListFooter';
+import { click } from '../../../../../../tests/utils';
-chai.use(sinonChai);
-
-function click (element) {
- return element.simulate('click', {
- target: { blur () {} },
- preventDefault () {}
- });
-}
-
-describe('Components :: Controls :: ListFooter', () => {
- it('should render "3 of 5 shown"', () => {
- const listFooter = shallow(
- <ListFooter count={3} total={5}/>
- );
- expect(listFooter.text()).to.contain('x_of_y_shown.3.5');
- });
+it('should render "3 of 5 shown"', () => {
+ const listFooter = shallow(<ListFooter count={3} total={5}/>);
+ expect(listFooter.text()).toContain('x_of_y_shown.3.5');
+});
- it('should not render "show more"', () => {
- const listFooter = shallow(
- <ListFooter count={3} total={5}/>
- );
- expect(listFooter.find('a')).to.have.length(0);
- });
+it('should not render "show more"', () => {
+ const listFooter = shallow(<ListFooter count={3} total={5}/>);
+ expect(listFooter.find('a').length).toBe(0);
+});
- it('should "show more"', () => {
- const loadMore = sinon.spy();
- const listFooter = shallow(
- <ListFooter count={3} total={5} loadMore={loadMore}/>
- );
- const link = listFooter.find('a');
- expect(link).to.have.length(1);
- click(link);
- expect(loadMore).to.have.been.called;
- });
+it('should "show more"', () => {
+ const loadMore = jest.fn();
+ const listFooter = shallow(<ListFooter count={3} total={5} loadMore={loadMore}/>);
+ const link = listFooter.find('a');
+ expect(link.length).toBe(1);
+ click(link);
+ expect(loadMore).toBeCalled();
});
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-import chai, { expect } from 'chai';
import { shallow } from 'enzyme';
-import sinon from 'sinon';
-import sinonChai from 'sinon-chai';
import React from 'react';
import RadioToggle from '../RadioToggle';
-
-chai.use(sinonChai);
+import { change } from '../../../../../../tests/utils';
function getSample (props) {
const options = [
);
}
-function change (element, value) {
- return element.simulate('change', { currentTarget: { value } });
-}
-
-describe('Components :: Controls :: RadioToggle', () => {
- it('should render', () => {
- const radioToggle = shallow(getSample());
- expect(radioToggle.find('input[type="radio"]')).to.have.length(2);
- expect(radioToggle.find('label')).to.have.length(2);
- });
+it('should render', () => {
+ const radioToggle = shallow(getSample());
+ expect(radioToggle.find('input[type="radio"]').length).toBe(2);
+ expect(radioToggle.find('label').length).toBe(2);
+});
- it('should call onCheck', () => {
- const onCheck = sinon.spy();
- const radioToggle = shallow(getSample({ onCheck }));
- change(radioToggle.find('input[value="two"]'), 'two');
- expect(onCheck).to.have.been.calledWith('two');
- });
+it('should call onCheck', () => {
+ const onCheck = jest.fn();
+ const radioToggle = shallow(getSample({ onCheck }));
+ change(radioToggle.find('input[value="two"]'), 'two');
+ expect(onCheck).toBeCalledWith('two');
});
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-import chai, { expect } from 'chai';
import { shallow } from 'enzyme';
-import sinon from 'sinon';
-import sinonChai from 'sinon-chai';
import React from 'react';
import Toggle from '../Toggle';
-
-chai.use(sinonChai);
+import { click } from '../../../../../../tests/utils';
function getSample (props) {
return (
<Toggle value={true} onChange={() => true} {...props}/>);
}
-function click (element) {
- return element.simulate('click', {
- currentTarget: { blur () {} },
- preventDefault () {}
- });
-}
-
-describe('Components :: Controls :: Toggle', () => {
- it('should render', () => {
- const Toggle = shallow(getSample());
- expect(Toggle.is('button')).to.equal(true);
- });
+it('should render', () => {
+ const Toggle = shallow(getSample());
+ expect(Toggle.is('button')).toBe(true);
+});
- it('should call onChange', () => {
- const onChange = sinon.spy();
- const Toggle = shallow(getSample({ onChange }));
- click(Toggle);
- expect(onChange).to.have.been.calledWith(false);
- });
+it('should call onChange', () => {
+ const onChange = jest.fn();
+ const Toggle = shallow(getSample({ onChange }));
+ click(Toggle);
+ expect(onChange).toBeCalledWith(false);
});
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-import { expect } from 'chai';
import { shallow } from 'enzyme';
import React from 'react';
import Avatar from '../Avatar';
-describe('Components :: UI :: Avatar', () => {
- beforeEach(() => {
- window.SS = {
- lf: {
- enableGravatar: true,
- gravatarServerUrl: 'http://example.com/{EMAIL_MD5}.jpg?s={SIZE}'
- }
- };
- });
+beforeEach(() => {
+ window.SS = {
+ lf: {
+ enableGravatar: true,
+ gravatarServerUrl: 'http://example.com/{EMAIL_MD5}.jpg?s={SIZE}'
+ }
+ };
+});
- afterEach(() => {
- window.SS = undefined;
- });
+afterEach(() => {
+ window.SS = undefined;
+});
- it('should render', () => {
- const avatar = shallow(
- <Avatar email="mail@example.com" size={20}/>
- );
- expect(avatar.is('img')).to.equal(true);
- expect(avatar.prop('width')).to.equal(20);
- expect(avatar.prop('height')).to.equal(20);
- expect(avatar.prop('alt')).to.equal('mail@example.com');
- expect(avatar.prop('src')).to.equal(
- 'http://example.com/7daf6c79d4802916d83f6266e24850af.jpg?s=40');
- });
+it('should render', () => {
+ const avatar = shallow(<Avatar email="mail@example.com" size={20}/>);
+ expect(avatar.is('img')).toBe(true);
+ expect(avatar.prop('width')).toBe(20);
+ expect(avatar.prop('height')).toBe(20);
+ expect(avatar.prop('alt')).toBe('mail@example.com');
+ expect(avatar.prop('src')).toBe('http://example.com/7daf6c79d4802916d83f6266e24850af.jpg?s=40');
+});
- it('should not render', () => {
- window.SS.lf.enableGravatar = false;
- const avatar = shallow(
- <Avatar email="mail@example.com" size={20}/>
- );
- expect(avatar.is('img')).to.equal(false);
- });
+it('should not render', () => {
+ window.SS.lf.enableGravatar = false;
+ const avatar = shallow(<Avatar email="mail@example.com" size={20}/>);
+ expect(avatar.is('img')).toBe(false);
});
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-import { expect } from 'chai';
import { shallow } from 'enzyme';
import React from 'react';
import Level from '../Level';
-describe('Components :: UI :: Level', () => {
- it('should render', () => {
- const rating = shallow(
- <Level level="ERROR"/>
- );
- expect(rating.is('.level-ERROR')).to.equal(true);
- });
+it('should render', () => {
+ const rating = shallow(<Level level="ERROR"/>);
+ expect(rating.is('.level-ERROR')).toBe(true);
});
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-import { expect } from 'chai';
import { shallow } from 'enzyme';
import React from 'react';
import Rating from '../Rating';
-describe('Components :: UI :: Rating', () => {
- it('should render with numeric value', () => {
- const rating = shallow(
- <Rating value={2}/>
- );
- expect(rating.is('.rating-B')).to.equal(true);
- });
+it('should render with numeric value', () => {
+ const rating = shallow(<Rating value={2}/>);
+ expect(rating.is('.rating-B')).toBe(true);
+});
- it('should render with string value', () => {
- const rating = shallow(
- <Rating value="2.0"/>
- );
- expect(rating.is('.rating-B')).to.equal(true);
- });
+it('should render with string value', () => {
+ const rating = shallow(<Rating value="2.0"/>);
+ expect(rating.is('.rating-B')).toBe(true);
});
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-import { expect } from 'chai';
import { resetBundle, translate, translateWithParameters } from '../l10n';
-describe('l10n', () => {
- afterEach(() => {
- resetBundle({});
- });
+afterEach(() => {
+ resetBundle({});
+});
- describe('#translate', () => {
- it('should translate simple message', () => {
- resetBundle({ 'my_key': 'my message' });
- expect(translate('my_key')).to.equal('my message');
- });
+describe('#translate', () => {
+ it('should translate simple message', () => {
+ resetBundle({ 'my_key': 'my message' });
+ expect(translate('my_key')).toBe('my message');
+ });
- it('should translate message with composite key', () => {
- resetBundle({ 'my.composite.message': 'my message' });
- expect(translate('my', 'composite', 'message')).to.equal('my message');
- expect(translate('my.composite', 'message')).to.equal('my message');
- expect(translate('my', 'composite.message')).to.equal('my message');
- expect(translate('my.composite.message')).to.equal('my message');
- });
+ it('should translate message with composite key', () => {
+ resetBundle({ 'my.composite.message': 'my message' });
+ expect(translate('my', 'composite', 'message')).toBe('my message');
+ expect(translate('my.composite', 'message')).toBe('my message');
+ expect(translate('my', 'composite.message')).toBe('my message');
+ expect(translate('my.composite.message')).toBe('my message');
+ });
- it('should not translate message but return its key', () => {
- expect(translate('random')).to.equal('random');
- expect(translate('random', 'key')).to.equal('random.key');
- expect(translate('composite.random', 'key')).to.equal('composite.random.key');
- });
+ it('should not translate message but return its key', () => {
+ expect(translate('random')).toBe('random');
+ expect(translate('random', 'key')).toBe('random.key');
+ expect(translate('composite.random', 'key')).toBe('composite.random.key');
});
+});
- describe('#translateWithParameters', () => {
- it('should translate message with one parameter in the beginning', () => {
- resetBundle({ 'x_apples': '{0} apples' });
- expect(translateWithParameters('x_apples', 5)).to.equal('5 apples');
- });
+describe('#translateWithParameters', () => {
+ it('should translate message with one parameter in the beginning', () => {
+ resetBundle({ 'x_apples': '{0} apples' });
+ expect(translateWithParameters('x_apples', 5)).toBe('5 apples');
+ });
- it('should translate message with one parameter in the middle', () => {
- resetBundle({ 'x_apples': 'I have {0} apples' });
- expect(translateWithParameters('x_apples', 5)).to.equal('I have 5 apples');
- });
+ it('should translate message with one parameter in the middle', () => {
+ resetBundle({ 'x_apples': 'I have {0} apples' });
+ expect(translateWithParameters('x_apples', 5)).toBe('I have 5 apples');
+ });
- it('should translate message with one parameter in the end', () => {
- resetBundle({ 'x_apples': 'Apples: {0}' });
- expect(translateWithParameters('x_apples', 5)).to.equal('Apples: 5');
- });
+ it('should translate message with one parameter in the end', () => {
+ resetBundle({ 'x_apples': 'Apples: {0}' });
+ expect(translateWithParameters('x_apples', 5)).toBe('Apples: 5');
+ });
- it('should translate message with several parameters', () => {
- resetBundle({ 'x_apples': '{0}: I have {2} apples in my {1} baskets - {3}' });
- expect(translateWithParameters('x_apples', 1, 2, 3, 4)).to.equal('1: I have 3 apples in my 2 baskets - 4');
- });
+ it('should translate message with several parameters', () => {
+ resetBundle({ 'x_apples': '{0}: I have {2} apples in my {1} baskets - {3}' });
+ expect(translateWithParameters('x_apples', 1, 2, 3, 4)).toBe('1: I have 3 apples in my 2 baskets - 4');
+ });
- it('should not translate message but return its key', () => {
- expect(translateWithParameters('random', 5)).to.equal('random.5');
- expect(translateWithParameters('random', 1, 2, 3)).to.equal('random.1.2.3');
- expect(translateWithParameters('composite.random', 1, 2)).to.equal('composite.random.1.2');
- });
+ it('should not translate message but return its key', () => {
+ expect(translateWithParameters('random', 5)).toBe('random.5');
+ expect(translateWithParameters('random', 1, 2, 3)).toBe('random.1.2.3');
+ expect(translateWithParameters('composite.random', 1, 2)).toBe('composite.random.1.2');
});
});
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-import { expect } from 'chai';
-
import { resetBundle } from '../l10n';
import { formatMeasure, formatMeasureVariation } from '../measures';
-
-describe('Measures', function () {
- var HOURS_IN_DAY = 8,
- ONE_MINUTE = 1,
- ONE_HOUR = ONE_MINUTE * 60,
- ONE_DAY = HOURS_IN_DAY * ONE_HOUR;
-
- before(function () {
- resetBundle({
- 'work_duration.x_days': '{0}d',
- 'work_duration.x_hours': '{0}h',
- 'work_duration.x_minutes': '{0}min',
- 'work_duration.about': '~ {0}',
- 'metric.level.ERROR': 'Error',
- 'metric.level.WARN': 'Warning',
- 'metric.level.OK': 'Ok'
- });
- window.SS = { hoursInDay: HOURS_IN_DAY };
+const HOURS_IN_DAY = 8;
+const ONE_MINUTE = 1;
+const ONE_HOUR = ONE_MINUTE * 60;
+const ONE_DAY = HOURS_IN_DAY * ONE_HOUR;
+
+beforeEach(function () {
+ resetBundle({
+ 'work_duration.x_days': '{0}d',
+ 'work_duration.x_hours': '{0}h',
+ 'work_duration.x_minutes': '{0}min',
+ 'work_duration.about': '~ {0}',
+ 'metric.level.ERROR': 'Error',
+ 'metric.level.WARN': 'Warning',
+ 'metric.level.OK': 'Ok'
});
+ window.SS = { hoursInDay: HOURS_IN_DAY };
+});
- describe('#formatMeasure()', function () {
- it('should format INT', function () {
- expect(formatMeasure(0, 'INT')).to.equal('0');
- expect(formatMeasure(1, 'INT')).to.equal('1');
- expect(formatMeasure(-5, 'INT')).to.equal('-5');
- expect(formatMeasure(999, 'INT')).to.equal('999');
- expect(formatMeasure(1000, 'INT')).to.equal('1,000');
- expect(formatMeasure(1529, 'INT')).to.equal('1,529');
- expect(formatMeasure(10000, 'INT')).to.equal('10,000');
- expect(formatMeasure(1234567890, 'INT')).to.equal('1,234,567,890');
- });
-
- it('should format SHORT_INT', function () {
- expect(formatMeasure(0, 'SHORT_INT')).to.equal('0');
- expect(formatMeasure(1, 'SHORT_INT')).to.equal('1');
- expect(formatMeasure(999, 'SHORT_INT')).to.equal('999');
- expect(formatMeasure(1000, 'SHORT_INT')).to.equal('1k');
- expect(formatMeasure(1529, 'SHORT_INT')).to.equal('1.5k');
- expect(formatMeasure(10000, 'SHORT_INT')).to.equal('10k');
- expect(formatMeasure(10678, 'SHORT_INT')).to.equal('11k');
- expect(formatMeasure(1234567890, 'SHORT_INT')).to.equal('1b');
- });
-
- it('should format FLOAT', function () {
- expect(formatMeasure(0.0, 'FLOAT')).to.equal('0.0');
- expect(formatMeasure(1.0, 'FLOAT')).to.equal('1.0');
- expect(formatMeasure(1.3, 'FLOAT')).to.equal('1.3');
- expect(formatMeasure(1.34, 'FLOAT')).to.equal('1.34');
- expect(formatMeasure(50.89, 'FLOAT')).to.equal('50.89');
- expect(formatMeasure(100.0, 'FLOAT')).to.equal('100.0');
- expect(formatMeasure(123.456, 'FLOAT')).to.equal('123.456');
- expect(formatMeasure(123456.7, 'FLOAT')).to.equal('123,456.7');
- expect(formatMeasure(1234567890.0, 'FLOAT')).to.equal('1,234,567,890.0');
- });
+describe('#formatMeasure()', function () {
+ it('should format INT', function () {
+ expect(formatMeasure(0, 'INT')).toBe('0');
+ expect(formatMeasure(1, 'INT')).toBe('1');
+ expect(formatMeasure(-5, 'INT')).toBe('-5');
+ expect(formatMeasure(999, 'INT')).toBe('999');
+ expect(formatMeasure(1000, 'INT')).toBe('1,000');
+ expect(formatMeasure(1529, 'INT')).toBe('1,529');
+ expect(formatMeasure(10000, 'INT')).toBe('10,000');
+ expect(formatMeasure(1234567890, 'INT')).toBe('1,234,567,890');
+ });
- it('should respect FLOAT precision', function () {
- expect(formatMeasure(0.1, 'FLOAT')).to.equal('0.1');
- expect(formatMeasure(0.12, 'FLOAT')).to.equal('0.12');
- expect(formatMeasure(0.12345, 'FLOAT')).to.equal('0.12345');
- expect(formatMeasure(0.123456, 'FLOAT')).to.equal('0.12346');
- });
+ it('should format SHORT_INT', function () {
+ expect(formatMeasure(0, 'SHORT_INT')).toBe('0');
+ expect(formatMeasure(1, 'SHORT_INT')).toBe('1');
+ expect(formatMeasure(999, 'SHORT_INT')).toBe('999');
+ expect(formatMeasure(1000, 'SHORT_INT')).toBe('1k');
+ expect(formatMeasure(1529, 'SHORT_INT')).toBe('1.5k');
+ expect(formatMeasure(10000, 'SHORT_INT')).toBe('10k');
+ expect(formatMeasure(10678, 'SHORT_INT')).toBe('11k');
+ expect(formatMeasure(1234567890, 'SHORT_INT')).toBe('1b');
+ });
- it('should format PERCENT', function () {
- expect(formatMeasure(0.0, 'PERCENT')).to.equal('0.0%');
- expect(formatMeasure(1.0, 'PERCENT')).to.equal('1.0%');
- expect(formatMeasure(1.3, 'PERCENT')).to.equal('1.3%');
- expect(formatMeasure(1.34, 'PERCENT')).to.equal('1.3%');
- expect(formatMeasure(50.89, 'PERCENT')).to.equal('50.9%');
- expect(formatMeasure(100.0, 'PERCENT')).to.equal('100.0%');
- });
+ it('should format FLOAT', function () {
+ expect(formatMeasure(0.0, 'FLOAT')).toBe('0.0');
+ expect(formatMeasure(1.0, 'FLOAT')).toBe('1.0');
+ expect(formatMeasure(1.3, 'FLOAT')).toBe('1.3');
+ expect(formatMeasure(1.34, 'FLOAT')).toBe('1.34');
+ expect(formatMeasure(50.89, 'FLOAT')).toBe('50.89');
+ expect(formatMeasure(100.0, 'FLOAT')).toBe('100.0');
+ expect(formatMeasure(123.456, 'FLOAT')).toBe('123.456');
+ expect(formatMeasure(123456.7, 'FLOAT')).toBe('123,456.7');
+ expect(formatMeasure(1234567890.0, 'FLOAT')).toBe('1,234,567,890.0');
+ });
- it('should format WORK_DUR', function () {
- expect(formatMeasure(0, 'WORK_DUR')).to.equal('0');
- expect(formatMeasure(5 * ONE_DAY, 'WORK_DUR')).to.equal('5d');
- expect(formatMeasure(2 * ONE_HOUR, 'WORK_DUR')).to.equal('2h');
- expect(formatMeasure(40 * ONE_MINUTE, 'WORK_DUR')).to.equal('40min');
- expect(formatMeasure(ONE_MINUTE, 'WORK_DUR')).to.equal('1min');
- expect(formatMeasure(5 * ONE_DAY + 2 * ONE_HOUR, 'WORK_DUR')).to.equal('5d 2h');
- expect(formatMeasure(2 * ONE_HOUR + ONE_MINUTE, 'WORK_DUR')).to.equal('2h 1min');
- expect(formatMeasure(5 * ONE_DAY + 2 * ONE_HOUR + ONE_MINUTE, 'WORK_DUR')).to.equal('5d 2h');
- expect(formatMeasure(15 * ONE_DAY + 2 * ONE_HOUR + ONE_MINUTE, 'WORK_DUR')).to.equal('15d');
- expect(formatMeasure(-5 * ONE_DAY, 'WORK_DUR')).to.equal('-5d');
- expect(formatMeasure(-2 * ONE_HOUR, 'WORK_DUR')).to.equal('-2h');
- expect(formatMeasure(-1 * ONE_MINUTE, 'WORK_DUR')).to.equal('-1min');
- });
+ it('should respect FLOAT precision', function () {
+ expect(formatMeasure(0.1, 'FLOAT')).toBe('0.1');
+ expect(formatMeasure(0.12, 'FLOAT')).toBe('0.12');
+ expect(formatMeasure(0.12345, 'FLOAT')).toBe('0.12345');
+ expect(formatMeasure(0.123456, 'FLOAT')).toBe('0.12346');
+ });
- it('should format SHORT_WORK_DUR', function () {
- expect(formatMeasure(0, 'SHORT_WORK_DUR')).to.equal('0');
- expect(formatMeasure(5 * ONE_DAY, 'SHORT_WORK_DUR')).to.equal('5d');
- expect(formatMeasure(2 * ONE_HOUR, 'SHORT_WORK_DUR')).to.equal('2h');
- expect(formatMeasure(ONE_MINUTE, 'SHORT_WORK_DUR')).to.equal('1min');
- expect(formatMeasure(40 * ONE_MINUTE, 'SHORT_WORK_DUR')).to.equal('40min');
- expect(formatMeasure(58 * ONE_MINUTE, 'SHORT_WORK_DUR')).to.equal('1h');
- expect(formatMeasure(5 * ONE_DAY + 2 * ONE_HOUR, 'SHORT_WORK_DUR')).to.equal('5d');
- expect(formatMeasure(2 * ONE_HOUR + ONE_MINUTE, 'SHORT_WORK_DUR')).to.equal('2h');
- expect(formatMeasure(ONE_HOUR + 55 * ONE_MINUTE, 'SHORT_WORK_DUR')).to.equal('2h');
- expect(formatMeasure(3 * ONE_DAY + 6 * ONE_HOUR, 'SHORT_WORK_DUR')).to.equal('4d');
- expect(formatMeasure(7 * ONE_HOUR + 59 * ONE_MINUTE, 'SHORT_WORK_DUR')).to.equal('1d');
- expect(formatMeasure(5 * ONE_DAY + 2 * ONE_HOUR + ONE_MINUTE, 'SHORT_WORK_DUR')).to.equal('5d');
- expect(formatMeasure(15 * ONE_DAY + 2 * ONE_HOUR + ONE_MINUTE, 'SHORT_WORK_DUR')).to.equal('15d');
- expect(formatMeasure(7 * ONE_MINUTE, 'SHORT_WORK_DUR')).to.equal('7min');
- expect(formatMeasure(-5 * ONE_DAY, 'SHORT_WORK_DUR')).to.equal('-5d');
- expect(formatMeasure(-2 * ONE_HOUR, 'SHORT_WORK_DUR')).to.equal('-2h');
- expect(formatMeasure(-1 * ONE_MINUTE, 'SHORT_WORK_DUR')).to.equal('-1min');
+ it('should format PERCENT', function () {
+ expect(formatMeasure(0.0, 'PERCENT')).toBe('0.0%');
+ expect(formatMeasure(1.0, 'PERCENT')).toBe('1.0%');
+ expect(formatMeasure(1.3, 'PERCENT')).toBe('1.3%');
+ expect(formatMeasure(1.34, 'PERCENT')).toBe('1.3%');
+ expect(formatMeasure(50.89, 'PERCENT')).toBe('50.9%');
+ expect(formatMeasure(100.0, 'PERCENT')).toBe('100.0%');
+ });
- expect(formatMeasure(1529 * ONE_DAY, 'SHORT_WORK_DUR')).to.equal('1.5kd');
- expect(formatMeasure(1234567 * ONE_DAY, 'SHORT_WORK_DUR')).to.equal('1md');
- expect(formatMeasure(1234567 * ONE_DAY + 2 * ONE_HOUR, 'SHORT_WORK_DUR')).to.equal('1md');
- });
+ it('should format WORK_DUR', function () {
+ expect(formatMeasure(0, 'WORK_DUR')).toBe('0');
+ expect(formatMeasure(5 * ONE_DAY, 'WORK_DUR')).toBe('5d');
+ expect(formatMeasure(2 * ONE_HOUR, 'WORK_DUR')).toBe('2h');
+ expect(formatMeasure(40 * ONE_MINUTE, 'WORK_DUR')).toBe('40min');
+ expect(formatMeasure(ONE_MINUTE, 'WORK_DUR')).toBe('1min');
+ expect(formatMeasure(5 * ONE_DAY + 2 * ONE_HOUR, 'WORK_DUR')).toBe('5d 2h');
+ expect(formatMeasure(2 * ONE_HOUR + ONE_MINUTE, 'WORK_DUR')).toBe('2h 1min');
+ expect(formatMeasure(5 * ONE_DAY + 2 * ONE_HOUR + ONE_MINUTE, 'WORK_DUR')).toBe('5d 2h');
+ expect(formatMeasure(15 * ONE_DAY + 2 * ONE_HOUR + ONE_MINUTE, 'WORK_DUR')).toBe('15d');
+ expect(formatMeasure(-5 * ONE_DAY, 'WORK_DUR')).toBe('-5d');
+ expect(formatMeasure(-2 * ONE_HOUR, 'WORK_DUR')).toBe('-2h');
+ expect(formatMeasure(-1 * ONE_MINUTE, 'WORK_DUR')).toBe('-1min');
+ });
- it('should format RATING', function () {
- expect(formatMeasure(1, 'RATING')).to.equal('A');
- expect(formatMeasure(2, 'RATING')).to.equal('B');
- expect(formatMeasure(3, 'RATING')).to.equal('C');
- expect(formatMeasure(4, 'RATING')).to.equal('D');
- expect(formatMeasure(5, 'RATING')).to.equal('E');
- });
+ it('should format SHORT_WORK_DUR', function () {
+ expect(formatMeasure(0, 'SHORT_WORK_DUR')).toBe('0');
+ expect(formatMeasure(5 * ONE_DAY, 'SHORT_WORK_DUR')).toBe('5d');
+ expect(formatMeasure(2 * ONE_HOUR, 'SHORT_WORK_DUR')).toBe('2h');
+ expect(formatMeasure(ONE_MINUTE, 'SHORT_WORK_DUR')).toBe('1min');
+ expect(formatMeasure(40 * ONE_MINUTE, 'SHORT_WORK_DUR')).toBe('40min');
+ expect(formatMeasure(58 * ONE_MINUTE, 'SHORT_WORK_DUR')).toBe('1h');
+ expect(formatMeasure(5 * ONE_DAY + 2 * ONE_HOUR, 'SHORT_WORK_DUR')).toBe('5d');
+ expect(formatMeasure(2 * ONE_HOUR + ONE_MINUTE, 'SHORT_WORK_DUR')).toBe('2h');
+ expect(formatMeasure(ONE_HOUR + 55 * ONE_MINUTE, 'SHORT_WORK_DUR')).toBe('2h');
+ expect(formatMeasure(3 * ONE_DAY + 6 * ONE_HOUR, 'SHORT_WORK_DUR')).toBe('4d');
+ expect(formatMeasure(7 * ONE_HOUR + 59 * ONE_MINUTE, 'SHORT_WORK_DUR')).toBe('1d');
+ expect(formatMeasure(5 * ONE_DAY + 2 * ONE_HOUR + ONE_MINUTE, 'SHORT_WORK_DUR')).toBe('5d');
+ expect(formatMeasure(15 * ONE_DAY + 2 * ONE_HOUR + ONE_MINUTE, 'SHORT_WORK_DUR')).toBe('15d');
+ expect(formatMeasure(7 * ONE_MINUTE, 'SHORT_WORK_DUR')).toBe('7min');
+ expect(formatMeasure(-5 * ONE_DAY, 'SHORT_WORK_DUR')).toBe('-5d');
+ expect(formatMeasure(-2 * ONE_HOUR, 'SHORT_WORK_DUR')).toBe('-2h');
+ expect(formatMeasure(-1 * ONE_MINUTE, 'SHORT_WORK_DUR')).toBe('-1min');
+
+ expect(formatMeasure(1529 * ONE_DAY, 'SHORT_WORK_DUR')).toBe('1.5kd');
+ expect(formatMeasure(1234567 * ONE_DAY, 'SHORT_WORK_DUR')).toBe('1md');
+ expect(formatMeasure(1234567 * ONE_DAY + 2 * ONE_HOUR, 'SHORT_WORK_DUR')).toBe('1md');
+ });
- it('should format LEVEL', function () {
- expect(formatMeasure('ERROR', 'LEVEL')).to.equal('Error');
- expect(formatMeasure('WARN', 'LEVEL')).to.equal('Warning');
- expect(formatMeasure('OK', 'LEVEL')).to.equal('Ok');
- expect(formatMeasure('UNKNOWN', 'LEVEL')).to.equal('UNKNOWN');
- });
+ it('should format RATING', function () {
+ expect(formatMeasure(1, 'RATING')).toBe('A');
+ expect(formatMeasure(2, 'RATING')).toBe('B');
+ expect(formatMeasure(3, 'RATING')).toBe('C');
+ expect(formatMeasure(4, 'RATING')).toBe('D');
+ expect(formatMeasure(5, 'RATING')).toBe('E');
+ });
- it('should format MILLISEC', function () {
- expect(formatMeasure(0, 'MILLISEC')).to.equal('0ms');
- expect(formatMeasure(1, 'MILLISEC')).to.equal('1ms');
- expect(formatMeasure(173, 'MILLISEC')).to.equal('173ms');
- expect(formatMeasure(3649, 'MILLISEC')).to.equal('4s');
- expect(formatMeasure(893481, 'MILLISEC')).to.equal('15min');
- expect(formatMeasure(17862325, 'MILLISEC')).to.equal('298min');
- });
+ it('should format LEVEL', function () {
+ expect(formatMeasure('ERROR', 'LEVEL')).toBe('Error');
+ expect(formatMeasure('WARN', 'LEVEL')).toBe('Warning');
+ expect(formatMeasure('OK', 'LEVEL')).toBe('Ok');
+ expect(formatMeasure('UNKNOWN', 'LEVEL')).toBe('UNKNOWN');
+ });
- it('should not format unknown type', function () {
- expect(formatMeasure('random value', 'RANDOM_TYPE')).to.equal('random value');
- });
+ it('should format MILLISEC', function () {
+ expect(formatMeasure(0, 'MILLISEC')).toBe('0ms');
+ expect(formatMeasure(1, 'MILLISEC')).toBe('1ms');
+ expect(formatMeasure(173, 'MILLISEC')).toBe('173ms');
+ expect(formatMeasure(3649, 'MILLISEC')).toBe('4s');
+ expect(formatMeasure(893481, 'MILLISEC')).toBe('15min');
+ expect(formatMeasure(17862325, 'MILLISEC')).toBe('298min');
+ });
- it('should return null if value is empty string', function () {
- expect(formatMeasure('', 'PERCENT')).to.be.null;
- });
+ it('should not format unknown type', function () {
+ expect(formatMeasure('random value', 'RANDOM_TYPE')).toBe('random value');
+ });
- it('should not fail without parameters', function () {
- expect(formatMeasure()).to.be.null;
- });
+ it('should return null if value is empty string', function () {
+ expect(formatMeasure('', 'PERCENT')).toBeNull();
});
- describe('#formatMeasureVariation()', function () {
- it('should format INT', function () {
- expect(formatMeasureVariation(0, 'INT')).to.equal('+0');
- expect(formatMeasureVariation(1, 'INT')).to.equal('+1');
- expect(formatMeasureVariation(-1, 'INT')).to.equal('-1');
- expect(formatMeasureVariation(1529, 'INT')).to.equal('+1,529');
- expect(formatMeasureVariation(-1529, 'INT')).to.equal('-1,529');
- });
+ it('should not fail without parameters', function () {
+ expect(formatMeasure()).toBeNull();
+ });
+});
- it('should format SHORT_INT', function () {
- expect(formatMeasureVariation(0, 'SHORT_INT')).to.equal('+0');
- expect(formatMeasureVariation(1, 'SHORT_INT')).to.equal('+1');
- expect(formatMeasureVariation(-1, 'SHORT_INT')).to.equal('-1');
- expect(formatMeasureVariation(1529, 'SHORT_INT')).to.equal('+1.5k');
- expect(formatMeasureVariation(-1529, 'SHORT_INT')).to.equal('-1.5k');
- expect(formatMeasureVariation(10678, 'SHORT_INT')).to.equal('+11k');
- expect(formatMeasureVariation(-10678, 'SHORT_INT')).to.equal('-11k');
- });
+describe('#formatMeasureVariation()', function () {
+ it('should format INT', function () {
+ expect(formatMeasureVariation(0, 'INT')).toBe('+0');
+ expect(formatMeasureVariation(1, 'INT')).toBe('+1');
+ expect(formatMeasureVariation(-1, 'INT')).toBe('-1');
+ expect(formatMeasureVariation(1529, 'INT')).toBe('+1,529');
+ expect(formatMeasureVariation(-1529, 'INT')).toBe('-1,529');
+ });
- it('should format FLOAT', function () {
- expect(formatMeasureVariation(0.0, 'FLOAT')).to.equal('+0.0');
- expect(formatMeasureVariation(1.0, 'FLOAT')).to.equal('+1.0');
- expect(formatMeasureVariation(-1.0, 'FLOAT')).to.equal('-1.0');
- expect(formatMeasureVariation(50.89, 'FLOAT')).to.equal('+50.89');
- expect(formatMeasureVariation(-50.89, 'FLOAT')).to.equal('-50.89');
- });
+ it('should format SHORT_INT', function () {
+ expect(formatMeasureVariation(0, 'SHORT_INT')).toBe('+0');
+ expect(formatMeasureVariation(1, 'SHORT_INT')).toBe('+1');
+ expect(formatMeasureVariation(-1, 'SHORT_INT')).toBe('-1');
+ expect(formatMeasureVariation(1529, 'SHORT_INT')).toBe('+1.5k');
+ expect(formatMeasureVariation(-1529, 'SHORT_INT')).toBe('-1.5k');
+ expect(formatMeasureVariation(10678, 'SHORT_INT')).toBe('+11k');
+ expect(formatMeasureVariation(-10678, 'SHORT_INT')).toBe('-11k');
+ });
- it('should respect FLOAT precision', function () {
- expect(formatMeasureVariation(0.1, 'FLOAT')).to.equal('+0.1');
- expect(formatMeasureVariation(0.12, 'FLOAT')).to.equal('+0.12');
- expect(formatMeasureVariation(0.12345, 'FLOAT')).to.equal('+0.12345');
- expect(formatMeasureVariation(0.123456, 'FLOAT')).to.equal('+0.12346');
- });
+ it('should format FLOAT', function () {
+ expect(formatMeasureVariation(0.0, 'FLOAT')).toBe('+0.0');
+ expect(formatMeasureVariation(1.0, 'FLOAT')).toBe('+1.0');
+ expect(formatMeasureVariation(-1.0, 'FLOAT')).toBe('-1.0');
+ expect(formatMeasureVariation(50.89, 'FLOAT')).toBe('+50.89');
+ expect(formatMeasureVariation(-50.89, 'FLOAT')).toBe('-50.89');
+ });
- it('should format PERCENT', function () {
- expect(formatMeasureVariation(0.0, 'PERCENT')).to.equal('+0.0%');
- expect(formatMeasureVariation(1.0, 'PERCENT')).to.equal('+1.0%');
- expect(formatMeasureVariation(-1.0, 'PERCENT')).to.equal('-1.0%');
- expect(formatMeasureVariation(50.89, 'PERCENT')).to.equal('+50.9%');
- expect(formatMeasureVariation(-50.89, 'PERCENT')).to.equal('-50.9%');
- });
+ it('should respect FLOAT precision', function () {
+ expect(formatMeasureVariation(0.1, 'FLOAT')).toBe('+0.1');
+ expect(formatMeasureVariation(0.12, 'FLOAT')).toBe('+0.12');
+ expect(formatMeasureVariation(0.12345, 'FLOAT')).toBe('+0.12345');
+ expect(formatMeasureVariation(0.123456, 'FLOAT')).toBe('+0.12346');
+ });
- it('should format WORK_DUR', function () {
- expect(formatMeasureVariation(0, 'WORK_DUR')).to.equal('+0');
- expect(formatMeasureVariation(5 * ONE_DAY, 'WORK_DUR')).to.equal('+5d');
- expect(formatMeasureVariation(2 * ONE_HOUR, 'WORK_DUR')).to.equal('+2h');
- expect(formatMeasureVariation(ONE_MINUTE, 'WORK_DUR')).to.equal('+1min');
- expect(formatMeasureVariation(-5 * ONE_DAY, 'WORK_DUR')).to.equal('-5d');
- expect(formatMeasureVariation(-2 * ONE_HOUR, 'WORK_DUR')).to.equal('-2h');
- expect(formatMeasureVariation(-1 * ONE_MINUTE, 'WORK_DUR')).to.equal('-1min');
- });
+ it('should format PERCENT', function () {
+ expect(formatMeasureVariation(0.0, 'PERCENT')).toBe('+0.0%');
+ expect(formatMeasureVariation(1.0, 'PERCENT')).toBe('+1.0%');
+ expect(formatMeasureVariation(-1.0, 'PERCENT')).toBe('-1.0%');
+ expect(formatMeasureVariation(50.89, 'PERCENT')).toBe('+50.9%');
+ expect(formatMeasureVariation(-50.89, 'PERCENT')).toBe('-50.9%');
+ });
- it('should format SHORT_WORK_DUR', function () {
- expect(formatMeasureVariation(0, 'SHORT_WORK_DUR')).to.equal('+0');
- expect(formatMeasureVariation(5 * ONE_DAY, 'SHORT_WORK_DUR')).to.equal('+5d');
- expect(formatMeasureVariation(2 * ONE_HOUR, 'SHORT_WORK_DUR')).to.equal('+2h');
- expect(formatMeasureVariation(ONE_MINUTE, 'SHORT_WORK_DUR')).to.equal('+1min');
- expect(formatMeasureVariation(30 * ONE_MINUTE, 'SHORT_WORK_DUR')).to.equal('+30min');
- expect(formatMeasureVariation(58 * ONE_MINUTE, 'SHORT_WORK_DUR')).to.equal('+1h');
- expect(formatMeasureVariation(5 * ONE_DAY + 2 * ONE_HOUR, 'SHORT_WORK_DUR')).to.equal('+5d');
- expect(formatMeasureVariation(2 * ONE_HOUR + ONE_MINUTE, 'SHORT_WORK_DUR')).to.equal('+2h');
- expect(formatMeasureVariation(ONE_HOUR + 55 * ONE_MINUTE, 'SHORT_WORK_DUR')).to.equal('+2h');
- expect(formatMeasureVariation(3 * ONE_DAY + 6 * ONE_HOUR, 'SHORT_WORK_DUR')).to.equal('+4d');
- expect(formatMeasureVariation(7 * ONE_HOUR + 59 * ONE_MINUTE, 'SHORT_WORK_DUR')).to.equal('+1d');
- expect(formatMeasureVariation(5 * ONE_DAY + 2 * ONE_HOUR + ONE_MINUTE, 'SHORT_WORK_DUR')).to.equal('+5d');
- expect(formatMeasureVariation(15 * ONE_DAY + 2 * ONE_HOUR + ONE_MINUTE, 'SHORT_WORK_DUR')).to.equal('+15d');
- expect(formatMeasureVariation(7 * ONE_MINUTE, 'SHORT_WORK_DUR')).to.equal('+7min');
- expect(formatMeasureVariation(-5 * ONE_DAY, 'SHORT_WORK_DUR')).to.equal('-5d');
- expect(formatMeasureVariation(-2 * ONE_HOUR, 'SHORT_WORK_DUR')).to.equal('-2h');
- expect(formatMeasureVariation(-1 * ONE_MINUTE, 'SHORT_WORK_DUR')).to.equal('-1min');
+ it('should format WORK_DUR', function () {
+ expect(formatMeasureVariation(0, 'WORK_DUR')).toBe('+0');
+ expect(formatMeasureVariation(5 * ONE_DAY, 'WORK_DUR')).toBe('+5d');
+ expect(formatMeasureVariation(2 * ONE_HOUR, 'WORK_DUR')).toBe('+2h');
+ expect(formatMeasureVariation(ONE_MINUTE, 'WORK_DUR')).toBe('+1min');
+ expect(formatMeasureVariation(-5 * ONE_DAY, 'WORK_DUR')).toBe('-5d');
+ expect(formatMeasureVariation(-2 * ONE_HOUR, 'WORK_DUR')).toBe('-2h');
+ expect(formatMeasureVariation(-1 * ONE_MINUTE, 'WORK_DUR')).toBe('-1min');
+ });
- expect(formatMeasureVariation(1529 * ONE_DAY, 'SHORT_WORK_DUR')).to.equal('+1.5kd');
- expect(formatMeasureVariation(1234567 * ONE_DAY, 'SHORT_WORK_DUR')).to.equal('+1md');
- expect(formatMeasureVariation(1234567 * ONE_DAY + 2 * ONE_HOUR, 'SHORT_WORK_DUR')).to.equal('+1md');
- });
+ it('should format SHORT_WORK_DUR', function () {
+ expect(formatMeasureVariation(0, 'SHORT_WORK_DUR')).toBe('+0');
+ expect(formatMeasureVariation(5 * ONE_DAY, 'SHORT_WORK_DUR')).toBe('+5d');
+ expect(formatMeasureVariation(2 * ONE_HOUR, 'SHORT_WORK_DUR')).toBe('+2h');
+ expect(formatMeasureVariation(ONE_MINUTE, 'SHORT_WORK_DUR')).toBe('+1min');
+ expect(formatMeasureVariation(30 * ONE_MINUTE, 'SHORT_WORK_DUR')).toBe('+30min');
+ expect(formatMeasureVariation(58 * ONE_MINUTE, 'SHORT_WORK_DUR')).toBe('+1h');
+ expect(formatMeasureVariation(5 * ONE_DAY + 2 * ONE_HOUR, 'SHORT_WORK_DUR')).toBe('+5d');
+ expect(formatMeasureVariation(2 * ONE_HOUR + ONE_MINUTE, 'SHORT_WORK_DUR')).toBe('+2h');
+ expect(formatMeasureVariation(ONE_HOUR + 55 * ONE_MINUTE, 'SHORT_WORK_DUR')).toBe('+2h');
+ expect(formatMeasureVariation(3 * ONE_DAY + 6 * ONE_HOUR, 'SHORT_WORK_DUR')).toBe('+4d');
+ expect(formatMeasureVariation(7 * ONE_HOUR + 59 * ONE_MINUTE, 'SHORT_WORK_DUR')).toBe('+1d');
+ expect(formatMeasureVariation(5 * ONE_DAY + 2 * ONE_HOUR + ONE_MINUTE, 'SHORT_WORK_DUR')).toBe('+5d');
+ expect(formatMeasureVariation(15 * ONE_DAY + 2 * ONE_HOUR + ONE_MINUTE, 'SHORT_WORK_DUR')).toBe('+15d');
+ expect(formatMeasureVariation(7 * ONE_MINUTE, 'SHORT_WORK_DUR')).toBe('+7min');
+ expect(formatMeasureVariation(-5 * ONE_DAY, 'SHORT_WORK_DUR')).toBe('-5d');
+ expect(formatMeasureVariation(-2 * ONE_HOUR, 'SHORT_WORK_DUR')).toBe('-2h');
+ expect(formatMeasureVariation(-1 * ONE_MINUTE, 'SHORT_WORK_DUR')).toBe('-1min');
+
+ expect(formatMeasureVariation(1529 * ONE_DAY, 'SHORT_WORK_DUR')).toBe('+1.5kd');
+ expect(formatMeasureVariation(1234567 * ONE_DAY, 'SHORT_WORK_DUR')).toBe('+1md');
+ expect(formatMeasureVariation(1234567 * ONE_DAY + 2 * ONE_HOUR, 'SHORT_WORK_DUR')).toBe('+1md');
+ });
- it('should not format unknown type', function () {
- expect(formatMeasureVariation('random value', 'RANDOM_TYPE')).to.equal('random value');
- });
+ it('should not format unknown type', function () {
+ expect(formatMeasureVariation('random value', 'RANDOM_TYPE')).toBe('random value');
+ });
- it('should not fail without parameters', function () {
- expect(formatMeasureVariation()).to.be.null;
- });
+ it('should not fail without parameters', function () {
+ expect(formatMeasureVariation()).toBeNull();
});
});
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-import { expect } from 'chai';
import { collapsedDirFromPath, fileFromPath } from '../path';
-describe('Path', function () {
- describe('#collapsedDirFromPath()', function () {
- it('should return null when pass null', function () {
- expect(collapsedDirFromPath(null)).to.be.null;
- });
+describe('#collapsedDirFromPath()', function () {
+ it('should return null when pass null', function () {
+ expect(collapsedDirFromPath(null)).toBeNull();
+ });
- it('should return "/" when pass "/"', function () {
- expect(collapsedDirFromPath('/')).to.equal('/');
- });
+ it('should return "/" when pass "/"', function () {
+ expect(collapsedDirFromPath('/')).toBe('/');
+ });
- it('should not cut short path', function () {
- expect(collapsedDirFromPath('src/main/js/components/state.js')).to.equal('src/main/js/components/');
- });
+ it('should not cut short path', function () {
+ expect(collapsedDirFromPath('src/main/js/components/state.js')).toBe('src/main/js/components/');
+ });
- it('should cut long path', function () {
- expect(collapsedDirFromPath('src/main/js/components/navigator/app/models/state.js'))
- .to.equal('src/.../js/components/navigator/app/models/');
- });
+ it('should cut long path', function () {
+ expect(collapsedDirFromPath('src/main/js/components/navigator/app/models/state.js'))
+ .toBe('src/.../js/components/navigator/app/models/');
+ });
- it('should cut very long path', function () {
- expect(collapsedDirFromPath('src/main/another/js/components/navigator/app/models/state.js'))
- .to.equal('src/.../js/components/navigator/app/models/');
- });
+ it('should cut very long path', function () {
+ expect(collapsedDirFromPath('src/main/another/js/components/navigator/app/models/state.js'))
+ .toBe('src/.../js/components/navigator/app/models/');
});
+});
- describe('#fileFromPath()', function () {
- it('should return null when pass null', function () {
- expect(fileFromPath(null)).to.be.null;
- });
+describe('#fileFromPath()', function () {
+ it('should return null when pass null', function () {
+ expect(fileFromPath(null)).toBeNull();
+ });
- it('should return empty string when pass "/"', function () {
- expect(fileFromPath('/')).to.equal('');
- });
+ it('should return empty string when pass "/"', function () {
+ expect(fileFromPath('/')).toBe('');
+ });
- it('should return file name when pass only file name', function () {
- expect(fileFromPath('file.js')).to.equal('file.js');
- });
+ it('should return file name when pass only file name', function () {
+ expect(fileFromPath('file.js')).toBe('file.js');
+ });
- it('should return file name when pass file path', function () {
- expect(fileFromPath('src/main/js/file.js')).to.equal('file.js');
- });
+ it('should return file name when pass file path', function () {
+ expect(fileFromPath('src/main/js/file.js')).toBe('file.js');
+ });
- it('should return file name when pass file name without extension', function () {
- expect(fileFromPath('src/main/file')).to.equal('file');
- });
+ it('should return file name when pass file name without extension', function () {
+ expect(fileFromPath('src/main/file')).toBe('file');
});
});
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-import { expect } from 'chai';
-
import { getComponentUrl, getComponentIssuesUrl, getComponentDrilldownUrl } from '../urls';
const SIMPLE_COMPONENT_KEY = 'sonarqube';
const COMPLEX_COMPONENT_KEY_ENCODED = encodeURIComponent(COMPLEX_COMPONENT_KEY);
const METRIC = 'coverage';
-describe('URLs', function () {
- let oldBaseUrl;
+let oldBaseUrl;
- beforeEach(function () {
- oldBaseUrl = window.baseUrl;
- });
+beforeEach(function () {
+ oldBaseUrl = window.baseUrl;
+});
- afterEach(function () {
- window.baseUrl = oldBaseUrl;
- });
+afterEach(function () {
+ window.baseUrl = oldBaseUrl;
+});
- describe('#getComponentUrl', function () {
- it('should return component url', function () {
- expect(getComponentUrl(SIMPLE_COMPONENT_KEY)).to.equal('/dashboard?id=' + SIMPLE_COMPONENT_KEY);
- });
+describe('#getComponentUrl', function () {
+ it('should return component url', function () {
+ expect(getComponentUrl(SIMPLE_COMPONENT_KEY)).toBe('/dashboard?id=' + SIMPLE_COMPONENT_KEY);
+ });
- it('should encode component key', function () {
- expect(getComponentUrl(COMPLEX_COMPONENT_KEY)).to.equal('/dashboard?id=' + COMPLEX_COMPONENT_KEY_ENCODED);
- });
+ it('should encode component key', function () {
+ expect(getComponentUrl(COMPLEX_COMPONENT_KEY)).toBe('/dashboard?id=' + COMPLEX_COMPONENT_KEY_ENCODED);
+ });
- it('should take baseUrl into account', function () {
- window.baseUrl = '/context';
- expect(getComponentUrl(COMPLEX_COMPONENT_KEY)).to.equal('/context/dashboard?id=' + COMPLEX_COMPONENT_KEY_ENCODED);
- });
+ it('should take baseUrl into account', function () {
+ window.baseUrl = '/context';
+ expect(getComponentUrl(COMPLEX_COMPONENT_KEY)).toBe('/context/dashboard?id=' + COMPLEX_COMPONENT_KEY_ENCODED);
});
+});
- describe('#getComponentIssuesUrl', function () {
- it('should work without parameters', function () {
- expect(getComponentIssuesUrl(SIMPLE_COMPONENT_KEY, {})).to.equal(
- '/component_issues?id=' + SIMPLE_COMPONENT_KEY + '#');
- });
+describe('#getComponentIssuesUrl', function () {
+ it('should work without parameters', function () {
+ expect(getComponentIssuesUrl(SIMPLE_COMPONENT_KEY, {})).toBe(
+ '/component_issues?id=' + SIMPLE_COMPONENT_KEY + '#');
+ });
- it('should encode component key', function () {
- expect(getComponentIssuesUrl(COMPLEX_COMPONENT_KEY, {})).to.equal(
- '/component_issues?id=' + COMPLEX_COMPONENT_KEY_ENCODED + '#');
- });
+ it('should encode component key', function () {
+ expect(getComponentIssuesUrl(COMPLEX_COMPONENT_KEY, {})).toBe(
+ '/component_issues?id=' + COMPLEX_COMPONENT_KEY_ENCODED + '#');
+ });
- it('should work with parameters', function () {
- expect(getComponentIssuesUrl(SIMPLE_COMPONENT_KEY, { resolved: 'false' })).to.equal(
- '/component_issues?id=' + SIMPLE_COMPONENT_KEY + '#resolved=false');
- });
+ it('should work with parameters', function () {
+ expect(getComponentIssuesUrl(SIMPLE_COMPONENT_KEY, { resolved: 'false' })).toBe(
+ '/component_issues?id=' + SIMPLE_COMPONENT_KEY + '#resolved=false');
+ });
- it('should encode parameters', function () {
- expect(getComponentIssuesUrl(SIMPLE_COMPONENT_KEY, { componentUuids: COMPLEX_COMPONENT_KEY })).to.equal(
- '/component_issues?id=' + SIMPLE_COMPONENT_KEY + '#componentUuids=' + COMPLEX_COMPONENT_KEY_ENCODED);
- });
+ it('should encode parameters', function () {
+ expect(getComponentIssuesUrl(SIMPLE_COMPONENT_KEY, { componentUuids: COMPLEX_COMPONENT_KEY })).toBe(
+ '/component_issues?id=' + SIMPLE_COMPONENT_KEY + '#componentUuids=' + COMPLEX_COMPONENT_KEY_ENCODED);
+ });
- it('should take baseUrl into account', function () {
- window.baseUrl = '/context';
- expect(getComponentIssuesUrl(SIMPLE_COMPONENT_KEY, {})).to.equal(
- '/context/component_issues?id=' + SIMPLE_COMPONENT_KEY + '#');
- });
+ it('should take baseUrl into account', function () {
+ window.baseUrl = '/context';
+ expect(getComponentIssuesUrl(SIMPLE_COMPONENT_KEY, {})).toBe(
+ '/context/component_issues?id=' + SIMPLE_COMPONENT_KEY + '#');
});
+});
- describe('#getComponentDrilldownUrl', function () {
- it('should return component drilldown url', function () {
- expect(getComponentDrilldownUrl(SIMPLE_COMPONENT_KEY, METRIC)).to.equal(
- '/component_measures/metric/' + METRIC + '?id=' + SIMPLE_COMPONENT_KEY);
- });
+describe('#getComponentDrilldownUrl', function () {
+ it('should return component drilldown url', function () {
+ expect(getComponentDrilldownUrl(SIMPLE_COMPONENT_KEY, METRIC)).toBe(
+ '/component_measures/metric/' + METRIC + '?id=' + SIMPLE_COMPONENT_KEY);
+ });
- it('should encode component key', function () {
- expect(getComponentDrilldownUrl(COMPLEX_COMPONENT_KEY, METRIC)).to.equal(
- '/component_measures/metric/' + METRIC + '?id=' + COMPLEX_COMPONENT_KEY_ENCODED);
- });
+ it('should encode component key', function () {
+ expect(getComponentDrilldownUrl(COMPLEX_COMPONENT_KEY, METRIC)).toBe(
+ '/component_measures/metric/' + METRIC + '?id=' + COMPLEX_COMPONENT_KEY_ENCODED);
+ });
- it('should take baseUrl into account', function () {
- window.baseUrl = '/context';
- expect(getComponentDrilldownUrl(SIMPLE_COMPONENT_KEY, METRIC)).to.equal(
- '/context/component_measures/metric/' + METRIC + '?id=' + SIMPLE_COMPONENT_KEY);
- });
+ it('should take baseUrl into account', function () {
+ window.baseUrl = '/context';
+ expect(getComponentDrilldownUrl(SIMPLE_COMPONENT_KEY, METRIC)).toBe(
+ '/context/component_measures/metric/' + METRIC + '?id=' + SIMPLE_COMPONENT_KEY);
});
});
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
import React from 'react';
-import TestUtils from 'react-addons-test-utils';
-import { expect } from 'chai';
-
+import { shallow } from 'enzyme';
import ComponentNavBreadcrumbs from '../component/component-nav-breadcrumbs';
-describe('Nav', function () {
- describe('ComponentNavBreadcrumbs', () => {
- it('should not render breadcrumbs with one element', function () {
- const breadcrumbs = [
- { key: 'my-project', name: 'My Project', qualifier: 'TRK' }
- ];
- const result = TestUtils.renderIntoDocument(
- React.createElement(ComponentNavBreadcrumbs, { breadcrumbs })
- );
- expect(TestUtils.scryRenderedDOMComponentsWithTag(result, 'li')).to.have.length(1);
- expect(TestUtils.scryRenderedDOMComponentsWithTag(result, 'a')).to.have.length(1);
- });
+describe('ComponentNavBreadcrumbs', () => {
+ it('should not render breadcrumbs with one element', function () {
+ const breadcrumbs = [{ key: 'my-project', name: 'My Project', qualifier: 'TRK' }];
+ const result = shallow(<ComponentNavBreadcrumbs breadcrumbs={breadcrumbs}/>);
+ expect(result.find('li').length).toBe(1);
+ expect(result.find('a').length).toBe(1);
});
});
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+module.exports = 'test-file-stub';
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+require('babel-polyfill');
+
+window.baseUrl = '';
+window.t = window.tp = function () {
+ var args = Array.prototype.slice.call(arguments, 0);
+ return args.join('.');
+};
+++ /dev/null
-/* globals global: false */
-require("babel-polyfill");
-
-var jsdom = require('jsdom');
-
-// A super simple DOM ready for React to render into
-// Store this DOM and the window in global scope ready for React to access
-global.document = jsdom.jsdom('<!doctype html><html><body></body></html>');
-global.window = document.defaultView;
-global.navigator = document.defaultView.navigator;
-
-global.window.baseUrl = '';
-global.window.t = global.window.tp = function () {
- var args = Array.prototype.slice.call(arguments, 0);
- return args.join('.');
-};
+++ /dev/null
---recursive
---compilers js:babel-register,css:tests/null-compiler.js,hbs:tests/null-compiler.js
---require tests/jsdom-setup.js
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-function nothing () {
- return null;
-}
-
-require.extensions['.css'] = nothing;
-require.extensions['.hbs'] = nothing;
export const click = element => {
return element.simulate('click', {
target: { blur () {} },
+ currentTarget: { blur () {} },
preventDefault () {}
});
};