Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .eslintrc
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,7 +2,8 @@
env: {
browser: true,
es6: true,
node: true
node: true,
mocha: true
},
"parserOptions": {
"ecmaVersion": 6,
Expand Down
8 changes: 8 additions & 0 deletions .istanbul.yml
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
verbose: false
instrumentation:
root: 'src/js/'
extensions:
- .js
default-excludes: true
excludes: ['**/__tests__/**']
include-all-sources: true
13 changes: 10 additions & 3 deletions package.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -12,7 +12,9 @@
"dist": "npm run release-js && npm run package && npm run codesign",
"lint-js": "eslint 'src/js/' 'src/js/app.js' 'main.js'",
"lint-sass": "sass-lint -c .sass-lint.yml -v -q",
"test": "npm run lint-js && npm run lint-sass",
"mocha": "./node_modules/mocha/bin/mocha --opts src/js/__tests__/__helpers__/mocha.opts",
"coverage": "babel-node ./node_modules/istanbul/lib/cli cover node_modules/mocha/bin/_mocha -- --opts src/js/__tests__/__helpers__/mocha.opts",
"test": "npm run lint-js && npm run lint-sass && npm run coverage",
"start": "electron . --enable-logging"
},
"repository": {
Expand DownExpand Up@@ -68,29 +70,34 @@
"redux-storage": "=4.0.0",
"redux-storage-decorator-filter": "=1.1.3",
"redux-storage-engine-localstorage": "=1.1.0",
"reflux": "=0.4.1",
"reloading": "0.0.6",
"superagent": "=1.8.3",
"underscore": "=1.8.3"
},
"devDependencies": {
"babel-cli": "=6.7.7",
"babel-core": "=6.7.7",
"babel-eslint": "=6.0.3",
"babel-jest": "=11.0.2",
"babel-loader": "=6.2.4",
"babel-preset-es2015": "=6.6.0",
"babel-preset-react": "=6.5.0",
"babel-preset-stage-0": "=6.5.0",
"chai": "=3.5.0",
"css-loader": "=0.23.1",
"electron-packager": "=7.0.1",
"electron-prebuilt": "=0.37.7",
"enzyme": "=2.2.0",
"eslint": "=2.8.0",
"eslint-plugin-react": "=5.0.1",
"file-loader": "=0.8.5",
"istanbul": "=1.0.0-alpha.2",
"jsdom": "=8.4.1",
"json-loader": "=0.5.4",
"mocha": "=2.4.5",
"node-sass": "=3.6.0",
"sass-lint": "=1.7.0",
"sass-loader": "=3.2.0",
"sinon": "=1.17.3",
"style-loader": "=0.13.1",
"webpack": "=1.13.0"
}
Expand Down
5 changes: 5 additions & 0 deletions src/js/__tests__/__helpers__/mocha.opts
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
--compilers js:babel-core/register
--require src/js/__tests__/__helpers__/tests-dom.js
--bail
--recursive
src/js/__tests__/**/*.js
16 changes: 16 additions & 0 deletions src/js/__tests__/__helpers__/tests-dom.js
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
import jsdom from 'jsdom';

global.document = jsdom.jsdom('<!doctype html><html><body></body></html>');
global.window = document.defaultView;
global.navigator = {userAgent: 'node.js'};

// Mocks for Electron
window.require = function () {
return {
ipcRenderer: {
send: function () {
// Fake sending message to ipcMain
}
},
};
};
9 changes: 9 additions & 0 deletions src/js/__tests__/basic.js
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
import { expect } from 'chai';

describe('basic.js', function () {

it('should make a basic test', function () {
expect(2).to.equal(2);
});

});
33 changes: 33 additions & 0 deletions src/js/__tests__/components/all-read.js
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
import React from 'react'; // eslint-disable-line no-unused-vars
import { expect } from 'chai';
import { mount } from 'enzyme';
import sinon from 'sinon';
import AllRead from '../../components/all-read';

function setup() {
const props = {};
const wrapper = mount(<AllRead {...props} />);

return {
props: props,
wrapper: wrapper,
};
};

describe('components/all-read.js', function () {

it('should render itself & its children', function () {

sinon.spy(AllRead.prototype, 'componentDidMount');

const { wrapper } = setup();

expect(wrapper).to.exist;
expect(AllRead.prototype.componentDidMount.calledOnce).to.be.true;
expect(wrapper.find('h4').text()).to.equal('No new notifications.');

AllRead.prototype.componentDidMount.restore();

});

});
95 changes: 95 additions & 0 deletions src/js/__tests__/components/search.js
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
import React from 'react'; // eslint-disable-line no-unused-vars
import { expect } from 'chai';
import { mount } from 'enzyme';
import sinon from 'sinon';
import { SearchBar } from '../../components/search';

function setup(props) {
const wrapper = mount(<SearchBar {...props} />);

return {
props: props,
wrapper: wrapper,
};
};

describe('components/search.js', function () {

it('should render itself & its children', function () {

const props = {
searchNotifications: sinon.spy(),
clearSearch: sinon.spy(),
showSearch: true,
query: ''
};

const { wrapper } = setup(props);

expect(wrapper).to.exist;
expect(wrapper.find('.octicon-x').length).to.equal(0);

wrapper.find('input').props().onChange({target: {value: 'hello'}});
expect(wrapper.props().searchNotifications.calledOnce).to.be.true;

});

it('should hide the search bar if not showSearch', function () {

const props = {
searchNotifications: sinon.spy(),
clearSearch: sinon.spy(),
showSearch: false,
query: ''
};

const { wrapper } = setup(props);

expect(wrapper).to.exist;

expect(wrapper.find('.container-fluid').length).to.equal(1);
expect(wrapper.find('.search-bar').length).to.equal(0);

});

it('should show the clear icon/button', function () {

const props = {
searchNotifications: sinon.spy(),
clearSearch: sinon.spy(),
showSearch: true,
query: 'hello'
};

const { wrapper } = setup(props);

expect(wrapper).to.exist;

wrapper.find('input').props().onChange({target: {value: 'hello'}});
expect(wrapper.find('.octicon-x').length).to.equal(1);

});

it('should test the componentWillReceiveProps function', function () {

sinon.spy(SearchBar.prototype, 'componentWillReceiveProps');

const props = {
searchNotifications: sinon.spy(),
clearSearch: sinon.spy(),
showSearch: true,
query: 'hello'
};

const { wrapper } = setup(props);

expect(wrapper).to.exist;

wrapper.setProps({showSearch: false});

expect(wrapper.props().clearSearch.calledOnce).to.be.true;
expect(SearchBar.prototype.componentWillReceiveProps.calledOnce).to.be.true;

});

});
62 changes: 62 additions & 0 deletions src/js/__tests__/components/settings.js
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
import React from 'react'; // eslint-disable-line no-unused-vars
import { expect } from 'chai';
import { mount } from 'enzyme';
import sinon from 'sinon';
import Toggle from 'react-toggle';
import { SettingsPage } from '../../components/settings';

function setup() {
const props = {
updateSetting: sinon.spy(),
settings: {
participating: false,
playSound: true,
showNotifications: true,
markOnClick: false,
openAtStartup: false
}
};

const wrapper = mount(<SettingsPage {...props} />);

return {
props: props,
wrapper: wrapper,
};
};

describe('components/settings.js', function () {

it('should render itself & its children', function () {

const { wrapper } = setup();

expect(wrapper).to.exist;
expect(wrapper.props().settings.participating).to.be.false;
expect(wrapper.find(Toggle).length).to.equal(5);
expect(wrapper.find('.footer').find('.text-right').text()).to.contain('Gitify - Version');

});

it('should update a setting', function () {

const { wrapper } = setup();

expect(wrapper).to.exist;
wrapper.find(Toggle).first().props().onChange({target: {checked: true}});
expect(wrapper.props().updateSetting.calledOnce).to.be.true;

});

it('should check for updates and quit the app', function () {

const { wrapper } = setup();

expect(wrapper).to.exist;

wrapper.find('.btn-primary').simulate('click');
wrapper.find('.btn-danger').simulate('click');

});

});
Loading