@@ -11,12 +11,12 @@ var TestUtils = React.addons.TestUtils;
1111
1212describe ( 'Test for Login Component' , function ( ) {
1313
14- var apiRequests , Actions , Login , AuthStore , Router ;
14+ var apiRequests , Actions , Login , AuthStore , Router , browserWindow ;
1515
1616 beforeEach ( function ( ) {
1717 // Mock Electron's window.require
1818 // and remote.ipc
19- var browserWindow = function ( ) {
19+ browserWindow = function ( ) {
2020 return {
2121 loadUrl : function ( ) {
2222 return ;
@@ -103,7 +103,7 @@ describe('Test for Login Component', function () {
103103
104104 } ) ;
105105
106- it ( 'Should open the authWindow' , function ( ) {
106+ it ( 'Should open the authWindow and login successfully ' , function ( ) {
107107
108108 var instance = TestUtils . renderIntoDocument ( < Login /> ) ;
109109 expect ( instance . authGithub ) . toBeDefined ( ) ;
@@ -119,3 +119,67 @@ describe('Test for Login Component', function () {
119119 } ) ;
120120
121121} ) ;
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