Skip to content
This repository was archived by the owner on Mar 4, 2025. It is now read-only.

Commit 86ee084

Browse files
author
Nick Litwin
committed
Add unit tests for social registrant
1 parent e174eaa commit 86ee084

File tree

3 files changed

+99
-35
lines changed

3 files changed

+99
-35
lines changed

app/settings/account-info/account-info.controller.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,25 @@
33

44
angular.module('tc.settings').controller('AccountInfoController', AccountInfoController);
55

6-
AccountInfoController.$inject = ['userData', 'UserService', 'ProfileService', '$log', 'ISO3166', 'toaster', '$scope', '$timeout'];
6+
AccountInfoController.$inject = ['userData', 'UserService', 'ProfileService', '$log', 'ISO3166', 'toaster', '$scope', '$timeout', '$state'];
77

8-
function AccountInfoController(userData, UserService, ProfileService, $log, ISO3166, toaster, $scope, $timeout) {
8+
function AccountInfoController(userData, UserService, ProfileService, $log, ISO3166, toaster, $scope, $timeout, $state) {
99
var vm = this;
10-
vm.saveAccountInfo = saveAccountInfo;
11-
vm.updateCountry = updateCountry;
12-
vm.submitNewPassword = submitNewPassword;
13-
vm.isSocialRegistrant = false;
14-
vm.formProcessing = {
15-
accountInfoForm: false,
16-
newPasswordForm: false
17-
};
1810
var originalUserData = userData;
11+
vm.saveAccountInfo = saveAccountInfo;
12+
vm.updateCountry = updateCountry;
13+
vm.submitNewPassword = submitNewPassword;
1914

2015
activate();
2116

2217
function activate() {
18+
vm.isSocialRegistrant = false;
19+
20+
vm.formProcessing = {
21+
accountInfoForm: false,
22+
newPasswordForm: false
23+
};
24+
2325
vm.userData = userData.clone();
2426
processData(vm.userData);
2527

Lines changed: 66 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,97 @@
11
/* jshint -W117, -W030 */
22
describe('Account Info Controller', function() {
33
var controller;
4+
var vm;
5+
var credential = {hasPassword: true};
6+
var deferred;
7+
var fakeStateGo;
48

59
beforeEach(function() {
610
bard.appModule('tc.settings');
711
bard.inject(this, '$controller', '$rootScope', '$q');
812

13+
deferred = $q.defer();
14+
915
var userService = {
1016
getUserIdentity: function() {
1117
return {handle: 'nicktest', email: '[email protected]'};
1218
},
1319
resetPassword: function() {
1420
return $q.when({});
21+
},
22+
getUserProfile: function() {
23+
return deferred.promise;
1524
}
1625
};
1726

1827
var userData = {
1928
handle: 'nicktest',
2029
21-
homeCountryCode: 'USA'
30+
homeCountryCode: 'USA',
31+
clone: function() {
32+
return angular.copy(this);
33+
}
2234
};
2335

36+
var state = {
37+
go: function(transitionTo) {
38+
return transitionTo;
39+
}
40+
}
41+
42+
fakeStateGo = sinon.spy(state, 'go');
43+
2444
controller = $controller('AccountInfoController', {
2545
UserService: userService,
26-
userData: userData
46+
userData: userData,
47+
$scope: $rootScope.$new(),
48+
$state: state
2749
});
50+
51+
vm = controller;
2852
});
2953

3054
bard.verifyNoOutstandingHttpRequests();
3155

32-
// TODO: re-add tests!
33-
// it('should be created successfully', function() {
34-
// expect(controller).to.exist;
35-
// });
36-
//
37-
// describe('updating a user\'s password', function() {
38-
// beforeEach(function() {
39-
// $rootScope.$apply();
40-
// });
41-
//
42-
// xit('should update a user\'s password if the current password was entered correctly', function() {
43-
// controller.submitNewPassword();
44-
// });
45-
//
46-
// xit('should return an error if the user entered an incorrect current password', function() {
47-
//
48-
// });
49-
//
50-
// xit('should return an error if there was a server error', function() {
51-
//
52-
// });
53-
// });
56+
it('should be created successfully', function() {
57+
expect(controller).to.exist;
58+
});
59+
60+
describe('updating a user\'s password', function() {
61+
// beforeEach(function() {
62+
// $rootScope.$apply();
63+
// });
64+
65+
xit('should return an error if the user entered an incorrect current password', function() {
66+
67+
});
68+
});
69+
70+
describe('vm.isSocialRegistrant', function() {
71+
it('should be false if a user has a password', function() {
72+
deferred.resolve({credential: credential});
73+
74+
$rootScope.$apply();
75+
76+
expect(vm.isSocialRegistrant).to.be.false;
77+
});
78+
79+
it('should be true if a user does not have a password', function() {
80+
credential.hasPassword = false;
81+
82+
deferred.resolve({credential: credential});
83+
84+
$rootScope.$apply();
5485

86+
expect(vm.isSocialRegistrant).to.be.true;
87+
});
88+
89+
it('should go to the edit page on error', function() {
90+
deferred.reject();
91+
92+
$rootScope.$apply();
93+
94+
expect(fakeStateGo).to.have.been.calledWith('settings.profile');
95+
});
96+
});
5597
});

app/specs.html

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ <h1><a href="specs.html">Spec Runner</a></h1>
7474
<script src="../bower_components/restangular/dist/restangular.js"></script>
7575
<script src="../bower_components/angular-touch/angular-touch.js"></script>
7676
<script src="../bower_components/angular-carousel/dist/angular-carousel.js"></script>
77+
<script src="../bower_components/matchmedia/matchMedia.js"></script>
78+
<script src="../bower_components/ngSticky/lib/sticky.js"></script>
7779
<script src="../bower_components/angular-mocks/angular-mocks.js"></script>
7880
<script src="../bower_components/sinon/index.js"></script>
7981
<script src="../bower_components/bardjs/dist/bard.js"></script>
@@ -95,6 +97,8 @@ <h1><a href="specs.html">Spec Runner</a></h1>
9597
<script src="/app/skill-picker/skill-picker.module.js"></script>
9698
<script src="/app/skill-picker/skill-picker.routes.js"></script>
9799
<script src="/app/skill-picker/skill-picker.controller.js"></script>
100+
<script src="/app/sitemap/sitemap.module.js"></script>
101+
<script src="/app/sitemap/sitemap.routes.js"></script>
98102
<script src="/app/settings/settings.module.js"></script>
99103
<script src="/app/settings/settings.routes.js"></script>
100104
<script src="/app/settings/settings.controller.js"></script>
@@ -106,17 +110,21 @@ <h1><a href="specs.html">Spec Runner</a></h1>
106110
<script src="/app/services/user.service.js"></script>
107111
<script src="/app/services/tcAuth.service.js"></script>
108112
<script src="/app/services/tags.service.js"></script>
113+
<script src="/app/services/statistics.service.js"></script>
109114
<script src="/app/services/srm.service.js"></script>
110115
<script src="/app/services/scorecard.service.js"></script>
111116
<script src="/app/services/review.service.js"></script>
112117
<script src="/app/services/profile.service.js"></script>
113118
<script src="/app/services/notification.service.js"></script>
119+
<script src="/app/services/nav.service.js"></script>
114120
<script src="/app/services/memberCert.service.js"></script>
115121
<script src="/app/services/jwtInterceptor.service.js"></script>
116122
<script src="/app/services/introduction.service.js"></script>
117123
<script src="/app/services/image.service.js"></script>
118124
<script src="/app/services/helpers.service.js"></script>
119125
<script src="/app/services/externalAccounts.service.js"></script>
126+
<script src="/app/services/emptyState.service.js"></script>
127+
<script src="/app/services/communityData.service.js"></script>
120128
<script src="/app/services/challenge.service.js"></script>
121129
<script src="/app/services/blog.service.js"></script>
122130
<script src="/app/services/authtoken.service.js"></script>
@@ -155,6 +163,7 @@ <h1><a href="specs.html">Spec Runner</a></h1>
155163
<script src="/app/layout/layout.module.js"></script>
156164
<script src="/app/layout/header/header.controller.js"></script>
157165
<script src="/app/filters/underscore-strip.filter.js"></script>
166+
<script src="/app/filters/truncate.filter.js"></script>
158167
<script src="/app/filters/track.filter.js"></script>
159168
<script src="/app/filters/time-diff.filter.js"></script>
160169
<script src="/app/filters/role.filter.js"></script>
@@ -173,6 +182,8 @@ <h1><a href="specs.html">Spec Runner</a></h1>
173182
<script src="/app/directives/tcui-components.module.js"></script>
174183
<script src="/app/directives/track-toggle/track-toggle.directive.js"></script>
175184
<script src="/app/directives/tc-transclude.directive.js"></script>
185+
<script src="/app/directives/tc-tabs/tc-tabs.directive.js"></script>
186+
<script src="/app/directives/tc-sticky/tc-sticky.directive.js"></script>
176187
<script src="/app/directives/tc-section/tc-section.directive.js"></script>
177188
<script src="/app/directives/tc-paginator/tc-paginator.directive.js"></script>
178189
<script src="/app/directives/tc-endless-paginator/tc-endless-paginator.directive.js"></script>
@@ -181,22 +192,29 @@ <h1><a href="specs.html">Spec Runner</a></h1>
181192
<script src="/app/directives/skill-tile/skill-tile.directive.js"></script>
182193
<script src="/app/directives/responsive-carousel/responsive-carousel.directive.js"></script>
183194
<script src="/app/directives/profile-widget/profile-widget.directive.js"></script>
195+
<script src="/app/directives/page-state-header/page-state-header.directive.js"></script>
184196
<script src="/app/directives/on-file-change.directive.js"></script>
185197
<script src="/app/directives/ios-card/ios-card.directive.js"></script>
186198
<script src="/app/directives/input-sticky-placeholder/input-sticky-placeholder.directive.js"></script>
187199
<script src="/app/directives/history-graph/history-graph.directive.js"></script>
188200
<script src="/app/directives/header/header-menu-item.directive.js"></script>
189201
<script src="/app/directives/focus-on.directive.js"></script>
190202
<script src="/app/directives/external-account/external-account.directive.js"></script>
203+
<script src="/app/directives/empty-state-placeholder/empty-state-placeholder.directive.js"></script>
191204
<script src="/app/directives/distribution-graph/distribution-graph.directive.js"></script>
192205
<script src="/app/directives/challenge-user-place/challenge-user-place.directive.js"></script>
193206
<script src="/app/directives/challenge-tile/challenge-tile.directive.js"></script>
207+
<script src="/app/directives/challenge-links/challenge-links.directive.js"></script>
194208
<script src="/app/directives/busy-button/busy-button.directive.js"></script>
195209
<script src="/app/directives/badges/badge-tooltip.directive.js"></script>
196210
<script src="/app/directives/account/validate-register.directive.js"></script>
197211
<script src="/app/directives/account/validate-email.directive.js"></script>
198212
<script src="/app/directives/account/toggle-password-with-tips/toggle-password-with-tips.directive.js"></script>
199213
<script src="/app/directives/account/toggle-password/toggle-password.directive.js"></script>
214+
<script src="/app/community/community.module.js"></script>
215+
<script src="/app/community/statistics.controller.js"></script>
216+
<script src="/app/community/members.controller.js"></script>
217+
<script src="/app/community/community.routes.js"></script>
200218
<script src="/app/blocks/logger/logger.module.js"></script>
201219
<script src="/app/blocks/logger/logger.js"></script>
202220
<script src="/app/blocks/logger/logEnhancer.js"></script>
@@ -221,6 +239,7 @@ <h1><a href="specs.html">Spec Runner</a></h1>
221239
<script src="/app/my-dashboard/my-dashboard.spec.js"></script>
222240
<script src="/app/my-srms/my-srms.spec.js"></script>
223241
<script src="/app/profile/profile.controller.spec.js"></script>
242+
<script src="/app/settings/settings.spec.js"></script>
224243
<script src="/app/services/authToken.service.spec.js"></script>
225244
<script src="/app/services/challenge.service.spec.js"></script>
226245
<script src="/app/services/helpers.service.spec.js"></script>
@@ -229,7 +248,6 @@ <h1><a href="specs.html">Spec Runner</a></h1>
229248
<script src="/app/services/tcAuth.service.spec.js"></script>
230249
<script src="/app/services/user.service.spec.js"></script>
231250
<script src="/app/services/userStats.service.spec.js"></script>
232-
<script src="/app/settings/settings.spec.js"></script>
233251
<script src="/app/skill-picker/skill-picker.spec.js"></script>
234252
<script src="/app/account/login/login.spec.js"></script>
235253
<script src="/app/account/register/register.spec.js"></script>
@@ -238,9 +256,11 @@ <h1><a href="specs.html">Spec Runner</a></h1>
238256
<script src="/app/directives/badges/badge-tooltip.spec.js"></script>
239257
<script src="/app/directives/busy-button/busy-button.directive.spec.js"></script>
240258
<script src="/app/directives/challenge-tile/challenge-tile.spec.js"></script>
259+
<script src="/app/directives/empty-state-placeholder/empty-state-placeholder.spec.js"></script>
241260
<script src="/app/directives/external-account/external-account.directive.spec.js"></script>
242261
<script src="/app/directives/tc-endless-paginator/tc-endless-paginator.spec.js"></script>
243262
<script src="/app/directives/tc-paginator/tc-paginator.spec.js"></script>
263+
<script src="/app/directives/tc-tabs/tc-tabs.directive.spec.js"></script>
244264
<script src="/app/my-dashboard/community-updates/community-updates.spec.js"></script>
245265
<script src="/app/my-dashboard/header-dashboard/header-dashboard.spec.js"></script>
246266
<script src="/app/my-dashboard/my-challenges/my-challenges.spec.js"></script>

0 commit comments

Comments
 (0)