@@ -4,43 +4,76 @@ import { shallow } from 'enzyme';
44import sinon from 'sinon' ;
55import Toggle from 'react-toggle' ;
66import { 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
2931describe ( '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
0 commit comments