@@ -11,12 +11,12 @@ var TestUtils = React.addons.TestUtils;
11
11
12
12
describe ( 'Test for Login Component' , function ( ) {
13
13
14
- var apiRequests , Actions , Login , AuthStore , Router ;
14
+ var apiRequests , Actions , Login , AuthStore , Router , browserWindow ;
15
15
16
16
beforeEach ( function ( ) {
17
17
// Mock Electron's window.require
18
18
// and remote.ipc
19
- var browserWindow = function ( ) {
19
+ browserWindow = function ( ) {
20
20
return {
21
21
loadUrl : function ( ) {
22
22
return ;
@@ -103,7 +103,7 @@ describe('Test for Login Component', function () {
103
103
104
104
} ) ;
105
105
106
- it ( 'Should open the authWindow' , function ( ) {
106
+ it ( 'Should open the authWindow and login successfully ' , function ( ) {
107
107
108
108
var instance = TestUtils . renderIntoDocument ( < Login /> ) ;
109
109
expect ( instance . authGithub ) . toBeDefined ( ) ;
@@ -119,3 +119,67 @@ describe('Test for Login Component', function () {
119
119
} ) ;
120
120
121
121
} ) ;
122
+
123
+ describe ( 'Test for Login Component - Callback with Error' , function ( ) {
124
+
125
+ var Login , browserWindow ;
126
+
127
+ beforeEach ( function ( ) {
128
+ // Mock Electron's window.require
129
+ // and remote.ipc
130
+ browserWindow = function ( ) {
131
+ return {
132
+ loadUrl : function ( ) {
133
+ return ;
134
+ } ,
135
+ webContents : {
136
+ on : function ( event , callback ) {
137
+
138
+ if ( event == 'did-get-redirect-request' ) {
139
+ callback (
140
+ 'did-get-redirect-request' ,
141
+ 'http://www.github.com/?error=FAILURE' ,
142
+ 'http://www.github.com/?error=FAILURE'
143
+ ) ;
144
+ }
145
+
146
+ }
147
+ } ,
148
+ on : function ( ) {
149
+ return ;
150
+ } ,
151
+ close : function ( ) {
152
+ return ;
153
+ }
154
+ } ;
155
+ } ;
156
+
157
+ window . require = function ( ) {
158
+ return {
159
+ require : function ( ) {
160
+ return browserWindow ;
161
+ } ,
162
+ sendChannel : function ( ) {
163
+ return ;
164
+ }
165
+ } ;
166
+ } ;
167
+
168
+ // Mock alert
169
+ window . alert = function ( ) {
170
+ return ;
171
+ } ;
172
+
173
+ Login = require ( '../../components/login.js' ) ;
174
+ } ) ;
175
+
176
+ it ( 'Should open the authWindow and fail to login' , function ( ) {
177
+
178
+ var instance = TestUtils . renderIntoDocument ( < Login /> ) ;
179
+ expect ( instance . authGithub ) . toBeDefined ( ) ;
180
+
181
+ instance . authGithub ( ) ;
182
+
183
+ } ) ;
184
+
185
+ } ) ;
0 commit comments