Skip to content

Commit 80764f5

Browse files
author
Emmanouil Konstantinidis
committed
Test the settings component
1 parent 2d3d002 commit 80764f5

File tree

3 files changed

+81
-0
lines changed

3 files changed

+81
-0
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
"src/js/components/settings.js": true,
7373
"src/js/components/footer.js": true,
7474
"src/js/components/search-input.js": true,
75+
"src/js/components/settings.js": true,
7576
"src/js/stores/auth.js": true,
7677
"src/js/stores/notifications.js": true,
7778
"src/js/stores/search.js": true,
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* @jsx React.DOM
3+
*/
4+
5+
var React = require('react');
6+
7+
module.exports = React.createClass({
8+
displayName: 'ToggleMock',
9+
getInitialState: function () {
10+
return null;
11+
},
12+
defaultChecked: function () {
13+
14+
},
15+
onChange: function () {
16+
return;
17+
},
18+
render: function () {
19+
return (<div>{ this.props.children }</div>);
20+
}
21+
});
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/* global jest, describe, beforeEach, it, expect, spyOn */
2+
3+
jest.dontMock('reflux');
4+
jest.dontMock('../../actions/actions.js');
5+
jest.dontMock('../../components/settings.js');
6+
jest.dontMock('../../stores/settings.js');
7+
8+
var React = require('react/addons');
9+
var TestUtils = React.addons.TestUtils;
10+
11+
describe('Test for Settings Component', function () {
12+
13+
var Actions, SettingsStore, Settings;
14+
15+
beforeEach(function () {
16+
// Mock Electron's window.require
17+
// and remote.require('shell')
18+
window.require = function () {
19+
return {
20+
sendChannel: function () {
21+
return;
22+
}
23+
};
24+
};
25+
26+
// Mock localStorage
27+
window.localStorage = {
28+
item: false,
29+
getItem: function () {
30+
return this.item;
31+
}
32+
};
33+
34+
Actions = require('../../actions/actions.js');
35+
SettingsStore = require('../../stores/settings.js');
36+
Settings = require('../../components/settings.js');
37+
});
38+
39+
it('Should render the settings component', function () {
40+
41+
spyOn(Actions, 'setSetting');
42+
43+
var instance = TestUtils.renderIntoDocument(<Settings />);
44+
45+
expect(instance.state.participating).toBeFalsy();
46+
expect(instance.toggleParticipating).toBeDefined();
47+
expect(instance.appQuit).toBeDefined();
48+
49+
instance.toggleParticipating({
50+
target: {
51+
checked: true
52+
}
53+
});
54+
expect(Actions.setSetting).toHaveBeenCalledWith('participating', true);
55+
56+
instance.appQuit();
57+
});
58+
59+
});

0 commit comments

Comments
 (0)