Skip to content

Commit 50d6e6d

Browse files
author
Emmanouil Konstantinidis
committed
Fix tests
1 parent d977520 commit 50d6e6d

File tree

5 files changed

+126
-72
lines changed

5 files changed

+126
-72
lines changed

src/js/__tests__/components/login.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ describe('components/login.js', function () {
4848
const { wrapper } = setup(props);
4949

5050
expect(wrapper).to.exist;
51-
expect(wrapper.find('.desc').text()).to.equal('GitHub notifications in your menu bar.');
51+
expect(wrapper.find('.desc').text()).to.contain('in your menu bar.');
5252

5353
});
5454

@@ -206,7 +206,6 @@ describe('components/login.js', function () {
206206
const { wrapper, context } = setup(props);
207207

208208
expect(wrapper).to.exist;
209-
expect(wrapper.find('.desc').text()).to.equal('GitHub notifications in your menu bar.');
210209

211210
wrapper.setProps({
212211
token: 'HELLO'

src/js/__tests__/components/navigation.js

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ describe('components/navigation.js', function () {
6161
expect(Navigation.prototype.componentDidMount).to.have.been.calledOnce;
6262
expect(wrapper.find('.fa-refresh').length).to.equal(1);
6363
expect(wrapper.find('.fa-refresh').first().hasClass('fa-spin')).to.be.false;
64-
expect(wrapper.find('.fa-sign-out').length).to.equal(1);
6564
expect(wrapper.find('.fa-cog').length).to.equal(1);
6665
expect(wrapper.find('.fa-search').length).to.equal(1);
6766
expect(wrapper.find('.fa-power-off').length).to.equal(0);
@@ -111,7 +110,6 @@ describe('components/navigation.js', function () {
111110
expect(wrapper).to.exist;
112111
expect(Navigation.prototype.componentDidMount).to.have.been.calledOnce;
113112
expect(wrapper.find('.fa-refresh').length).to.equal(0);
114-
expect(wrapper.find('.fa-sign-out').length).to.equal(0);
115113
expect(wrapper.find('.fa-cog').length).to.equal(0);
116114
expect(wrapper.find('.fa-search').length).to.equal(0);
117115
expect(wrapper.find('.fa-power-off').length).to.equal(1);
@@ -141,7 +139,6 @@ describe('components/navigation.js', function () {
141139
expect(Navigation.prototype.componentDidMount).to.have.been.calledOnce;
142140
expect(wrapper.find('.fa-refresh').length).to.equal(1);
143141
expect(wrapper.find('.fa-refresh').first().hasClass('fa-spin')).to.be.false;
144-
expect(wrapper.find('.fa-sign-out').length).to.equal(1);
145142
expect(wrapper.find('.fa-cog').length).to.equal(1);
146143
expect(wrapper.find('.fa-search').length).to.equal(1);
147144
expect(wrapper.find('.fa-power-off').length).to.equal(0);
@@ -168,7 +165,6 @@ describe('components/navigation.js', function () {
168165

169166
expect(wrapper).to.exist;
170167
expect(wrapper.find('.fa-refresh').length).to.equal(0);
171-
expect(wrapper.find('.fa-sign-out').length).to.equal(0);
172168
expect(wrapper.find('.fa-power-off').length).to.equal(1);
173169

174170
wrapper.find('.fa-power-off').simulate('click');
@@ -224,42 +220,6 @@ describe('components/navigation.js', function () {
224220

225221
});
226222

227-
it('should press the logout', function () {
228-
229-
const props = {
230-
logout: sinon.spy(),
231-
toggleSearch: sinon.spy(),
232-
isFetching: false,
233-
notifications: notifications.length,
234-
showSearch: true,
235-
token: 'IMLOGGEDIN',
236-
location: {
237-
pathname: '/settings'
238-
}
239-
};
240-
241-
const { wrapper, context } = setup(props);
242-
243-
expect(wrapper).to.exist;
244-
expect(wrapper.find('.fa-cog').length).to.equal(1);
245-
246-
wrapper.find('.fa-sign-out').simulate('click');
247-
248-
expect(props.logout).to.have.been.calledOnce;
249-
expect(props.toggleSearch).to.have.been.calledOnce;
250-
251-
expect(ipcRenderer.send).to.have.been.calledOnce;
252-
expect(ipcRenderer.send).to.have.been.calledWith('update-icon', 'IconPlain');
253-
254-
expect(context.router.replace).to.have.been.calledOnce;
255-
expect(context.router.replace).to.have.been.calledWith('/login');
256-
257-
context.router.replace.reset();
258-
props.logout.reset();
259-
props.toggleSearch.reset();
260-
261-
});
262-
263223
it('should go to settings from home', function () {
264224

265225
const props = {

src/js/__tests__/components/oops.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ describe('components/oops.js', function () {
2020
const { wrapper } = setup();
2121

2222
expect(wrapper).to.exist;
23-
expect(wrapper.find('h3').text()).to.equal('Oops something went wrong.');
23+
expect(wrapper.find('h2').text()).to.equal('Oops something went wrong.');
2424

2525
});
2626

src/js/__tests__/components/settings.js

Lines changed: 124 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,43 +4,76 @@ import { shallow } from 'enzyme';
44
import sinon from 'sinon';
55
import Toggle from 'react-toggle';
66
import { SettingsPage } from '../../components/settings';
7-
8-
function setup() {
9-
const props = {
10-
updateSetting: sinon.spy(),
11-
fetchNotifications: sinon.spy(),
12-
settings: {
13-
participating: false,
14-
playSound: true,
15-
showNotifications: true,
16-
markOnClick: false,
17-
openAtStartup: false
7+
const ipcRenderer = window.require('electron').ipcRenderer;
8+
9+
const options = {
10+
context: {
11+
location: {
12+
pathname: ''
13+
},
14+
router: {
15+
push: sinon.spy(),
16+
replace: sinon.spy()
1817
}
19-
};
18+
}
19+
};
2020

21-
const wrapper = shallow(<SettingsPage {...props} />);
21+
function setup(props) {
22+
const wrapper = shallow(<SettingsPage {...props} />, options);
2223

2324
return {
25+
context: options.context,
2426
props: props,
2527
wrapper: wrapper,
2628
};
2729
};
2830

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

33+
beforeEach(function() {
34+
ipcRenderer.send.reset();
35+
});
36+
3137
it('should render itself & its children', function () {
3238

33-
const { wrapper } = setup();
39+
const props = {
40+
updateSetting: sinon.spy(),
41+
fetchNotifications: sinon.spy(),
42+
logout: sinon.spy(),
43+
settings: {
44+
participating: false,
45+
playSound: true,
46+
showNotifications: true,
47+
markOnClick: false,
48+
openAtStartup: false
49+
}
50+
};
51+
52+
const { wrapper } = setup(props);
3453

3554
expect(wrapper).to.exist;
3655
expect(wrapper.find(Toggle).length).to.equal(5);
56+
expect(wrapper.find('.fa-sign-out').length).to.equal(1);
3757
expect(wrapper.find('.footer').find('.text-right').text()).to.contain('Gitify - Version');
3858

3959
});
4060

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

43-
const { wrapper, props } = setup();
63+
const props = {
64+
updateSetting: sinon.spy(),
65+
fetchNotifications: sinon.spy(),
66+
logout: sinon.spy(),
67+
settings: {
68+
participating: false,
69+
playSound: true,
70+
showNotifications: true,
71+
markOnClick: false,
72+
openAtStartup: false
73+
}
74+
};
75+
76+
const { wrapper } = setup(props);
4477
expect(wrapper).to.exist;
4578

4679
// Note: First Toggle is "participating"
@@ -58,14 +91,86 @@ describe('components/settings.js', function () {
5891

5992
});
6093

61-
it('should check for updates and quit the app', function () {
94+
it('should check for updates ', function () {
95+
96+
const props = {
97+
updateSetting: sinon.spy(),
98+
fetchNotifications: sinon.spy(),
99+
logout: sinon.spy(),
100+
settings: {
101+
participating: false,
102+
playSound: true,
103+
showNotifications: true,
104+
markOnClick: false,
105+
openAtStartup: false
106+
}
107+
};
108+
109+
const { wrapper } = setup(props);
110+
111+
expect(wrapper).to.exist;
112+
113+
wrapper.find('.fa-cloud-download').parent().simulate('click');
114+
expect(ipcRenderer.send).to.have.been.calledOnce;
115+
expect(ipcRenderer.send).to.have.been.calledWith('check-update');
116+
117+
});
118+
119+
it('should quit the app', function () {
120+
121+
const props = {
122+
updateSetting: sinon.spy(),
123+
fetchNotifications: sinon.spy(),
124+
logout: sinon.spy(),
125+
settings: {
126+
participating: false,
127+
playSound: true,
128+
showNotifications: true,
129+
markOnClick: false,
130+
openAtStartup: false
131+
}
132+
};
62133

63-
const { wrapper } = setup();
134+
const { wrapper } = setup(props);
64135

65136
expect(wrapper).to.exist;
66137

67-
wrapper.find('.btn-primary').simulate('click');
68-
wrapper.find('.btn-danger').simulate('click');
138+
wrapper.find('.fa-power-off').parent().simulate('click');
139+
expect(ipcRenderer.send).to.have.been.calledOnce;
140+
expect(ipcRenderer.send).to.have.been.calledWith('app-quit');
141+
142+
});
143+
144+
it('should press the logout', function () {
145+
146+
const props = {
147+
updateSetting: sinon.spy(),
148+
fetchNotifications: sinon.spy(),
149+
logout: sinon.spy(),
150+
settings: {
151+
participating: false,
152+
playSound: true,
153+
showNotifications: true,
154+
markOnClick: false,
155+
openAtStartup: false
156+
}
157+
};
158+
159+
const { wrapper, context } = setup(props);
160+
161+
expect(wrapper).to.exist;
162+
163+
wrapper.find('.fa-sign-out').parent().simulate('click');
164+
165+
expect(props.logout).to.have.been.calledOnce;
166+
167+
expect(ipcRenderer.send).to.have.been.calledOnce;
168+
expect(ipcRenderer.send).to.have.been.calledWith('update-icon', 'IconPlain');
169+
170+
expect(context.router.replace).to.have.been.calledOnce;
171+
expect(context.router.replace).to.have.been.calledWith('/login');
172+
173+
context.router.replace.reset();
69174

70175
});
71176

src/js/components/navigation.js

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,6 @@ export class Navigation extends React.Component {
2929
this.context.router.push('/settings');
3030
}
3131

32-
logoutButton() {
33-
if (this.props.showSearch) {
34-
this.props.toggleSearch();
35-
}
36-
37-
this.props.logout();
38-
this.context.router.replace('/login');
39-
ipcRenderer.send('update-icon', 'IconPlain');
40-
}
41-
4232
goBack() {
4333
this.context.router.push('/notifications');
4434
}

0 commit comments

Comments
 (0)