Skip to content

Commit 8f6cc73

Browse files
author
Emmanouil Konstantinidis
committed
Even more tests
1 parent 6ce711c commit 8f6cc73

File tree

1 file changed

+67
-3
lines changed

1 file changed

+67
-3
lines changed

src/js/__tests__/components/login.js

Lines changed: 67 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ var TestUtils = React.addons.TestUtils;
1111

1212
describe('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

Comments
 (0)