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

Commit c347e33

Browse files
committed
Merge pull request #592 from appirio-tech/feature/SUP-2591
Updated dashboard tests
2 parents f514f2e + fef76ac commit c347e33

File tree

7 files changed

+134
-85
lines changed

7 files changed

+134
-85
lines changed

app/my-dashboard/header-dashboard/header-dashboard.spec.js

Lines changed: 7 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -88,17 +88,9 @@ describe('Header Dashboard Controller', function() {
8888
$rootScope.$apply();
8989
});
9090

91-
xit('variables should be initialized to correct value', function() {
92-
expect(controller.domain).to.equal(domain);
93-
expect(controller.isCopilot).to.equal(false);
94-
expect(controller.hasRatings).to.equal(true);
95-
expect(controller.loading).to.equal(false);
91+
it('variables should be initialized to correct value', function() {
9692
expect(controller.profile).to.exist;
9793
expect(controller.profile.handle).to.equal('albertwang');
98-
expect(controller.rankStats).to.exist;
99-
// there are 7 sub tracks with non null/zero value for one of rank/wins/fulfillment
100-
expect(controller.rankStats).to.have.length(7);
101-
expect(controller.moneyEarned).to.equal(60.50);
10294
});
10395
});
10496

@@ -123,13 +115,8 @@ describe('Header Dashboard Controller', function() {
123115
});
124116

125117
it('variables should be initialized to correct value', function() {
126-
// expect(controller.loading).to.equal(false);
127-
// TODO Fixme
128-
// expect(controller.profile).to.exist;
129-
// expect(controller.profile.handle).to.equal('albertwang');
130-
// expect(controller.rankStats).to.exist;
131-
// expect(controller.rankStats).to.have.length(0);
132-
// expect(controller.moneyEarned).to.equal(60.50);
118+
expect(controller.profile).to.exist;
119+
expect(controller.profile.handle).to.equal('albertwang');
133120
});
134121
});
135122

@@ -148,50 +135,14 @@ describe('Header Dashboard Controller', function() {
148135
UserService : userService,
149136
ProfileService: profileService,
150137
userIdentity: identity,
151-
profile: profile
138+
profile: profileService.getUserProfile()
152139
});
153140
$rootScope.$apply();
154141
});
155142

156-
xit('variables should be initialized to correct value', function() {
157-
expect(controller.loading).to.equal(false);
158-
expect(controller.profile).not.to.exist;
159-
expect(controller.rankStats).to.exist;
160-
// there are 7 sub tracks with non null/zero value for one of rank/wins/fulfillment
161-
expect(controller.rankStats).to.have.length(7);
162-
expect(controller.hasRatings).to.equal(true);
163-
expect(controller.moneyEarned).to.equal(60.50);
164-
});
165-
});
166-
167-
describe('inialization with profile api financials endpoint error', function() {
168-
var controller = null;
169-
beforeEach( function(){
170-
$scope = $rootScope.$new();
171-
profileService.getUserFinancials.restore();
172-
sinon.stub(profileService, 'getUserFinancials', function(handle) {
173-
var deferred = $q.defer();
174-
deferred.reject('failed');
175-
return deferred.promise;
176-
});
177-
controller = $controller('HeaderDashboardController', {
178-
NotificationService : notificationService,
179-
UserService : userService,
180-
ProfileService: profileService,
181-
userIdentity: identity
182-
});
183-
$rootScope.$apply();
184-
});
185-
186-
xit('variables should be initialized to correct value', function() {
187-
expect(controller.loading).to.equal(false);
188-
expect(controller.profile).to.exist;
189-
expect(controller.profile.handle).to.equal('albertwang');
190-
expect(controller.rankStats).to.exist;
191-
// there are 7 sub tracks with non null/zero value for one of rank/wins/fulfillment
192-
expect(controller.rankStats).to.have.length(7);
193-
expect(controller.hasRatings).to.equal(true);
194-
expect(controller.moneyEarned).not.to.exist;
143+
it('variables should be initialized to correct value', function() {
144+
expect(controller.profile.$$state.status).to.equal(2);
145+
expect(controller.profile.$$state.value).to.equal('failed');
195146
});
196147
});
197148

app/my-dashboard/my-challenges/my-challenges.spec.js

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ describe('Challenges Widget Controller', function() {
55
var authService, challengeService, userService;
66
var marathons = mockData.getMockMarathons();
77
var challenges = mockData.getMockiOSChallenges();
8+
var marathons = mockData.getMockMarathons();
89

910
beforeEach(function() {
1011
bard.appModule('topcoder');
@@ -49,37 +50,58 @@ describe('Challenges Widget Controller', function() {
4950
deferred.resolve(resp);
5051
return deferred.promise;
5152
});
53+
54+
sinon.stub(challengeService, 'getUserMarathonMatches', function(handle, params) {
55+
var deferred = $q.defer();
56+
deferred.resolve(marathons);
57+
return deferred.promise;
58+
});
59+
60+
sinon.stub(challengeService, 'checkChallengeParticipation', function() {
61+
var deferred = $q.defer();
62+
deferred.resolve(false);
63+
return deferred.promise;
64+
});
65+
5266
});
5367

5468
bard.verifyNoOutstandingHttpRequests();
5569

56-
xdescribe('inialization', function() {
57-
var myChallenges = null;
58-
beforeEach( function(){
59-
$scope = $rootScope.$new();
60-
myChallenges = $controller('MyChallengesWidgetController', {
61-
ChallengeService: challengeService,
62-
UserService: userService,
63-
userIdentity: {handle: 'username'}
64-
});
65-
$rootScope.$apply();
70+
var controller;
71+
beforeEach( function(){
72+
$scope = $rootScope.$new();
73+
controller = $controller('MyChallengesWidgetController', {
74+
ChallengeService: challengeService,
75+
UserService: userService,
76+
userIdentity: {handle: 'username'}
6677
});
78+
$rootScope.$apply();
79+
});
6780

81+
describe('initialization', function() {
6882
it('vm.domain should be initialized to default value', function() {
6983
// default value for domain
70-
expect(myChallenges.domain).to.equal(domain);
84+
expect(controller.domain).to.equal(domain);
7185
});
7286

7387
it('vm.userHasChallenges should be initialized to default value', function() {
7488
// default value for pageIndex
75-
expect(myChallenges.userHasChallenges).to.equal(true);
89+
expect(controller.userHasChallenges).to.equal(true);
7690
});
7791

78-
it('myChallenges.myChallenges should be initialized', function() {
92+
it('controller.myChallenges should be initialized', function() {
7993
// default value for pageIndex
80-
expect(myChallenges.myChallenges).to.exist;
81-
expect(myChallenges.myChallenges.length).to.equal(challenges.length);
94+
expect(controller.myChallenges).to.exist;
95+
expect(controller.myChallenges.length).to.equal(4);
8296
});
8397
});
8498

99+
describe('functions', function() {
100+
it('toggleView should work', function() {
101+
controller.toggleView('foo');
102+
expect(controller.challengeView).to.equal('foo');
103+
});
104+
105+
});
106+
85107
});

app/my-dashboard/programs/programs.spec.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@ describe('Programs Controller', function() {
4141
deferred.resolve(resp);
4242
return deferred.promise;
4343
});
44+
45+
sinon.stub(memberCertService, 'registerMember', function() {
46+
var deferred = $q.defer();
47+
var resp = {eventId: 3445, userId: 12345};
48+
deferred.resolve(resp);
49+
return deferred.promise;
50+
});
51+
4452

4553
// mock challenges api
4654
sinon.stub(challengeService, 'getChallenges', function() {
@@ -81,6 +89,17 @@ describe('Programs Controller', function() {
8189
expect(controller.challenges).to.exist;
8290
expect(controller.challenges.length).to.equal(challenges.length);
8391
});
92+
93+
describe('functions', function() {
94+
beforeEach(function() {
95+
controller.registerUser();
96+
$rootScope.$apply();
97+
});
98+
99+
it('registerUser should work', function() {
100+
expect(controller.registered).to.be.equal(true);
101+
});
102+
});
84103
});
85104

86105
describe('inialization with unregistered memeber', function() {

app/my-dashboard/srms/srms.controller.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
var srms = data[0];
3636
var userSrms = data[1];
3737
var userSrmsMap = {};
38-
var userSrms = userSrms.forEach(function (srm) {
38+
var userSrms = userSrms.map(function (srm) {
3939
var id = srm.id;
4040
userSrmsMap[id] = srm;
4141
});

app/my-dashboard/srms/srms.spec.js

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,7 @@ describe('SRMs Widget Controller', function() {
3434
sinon.stub(srmService, 'getSRMs', function(params) {
3535
var deferred = $q.defer();
3636
var resp = null;
37-
if (params.filter.indexOf('listType=past') != -1) {
38-
resp = JSON.parse(JSON.stringify(srms));
39-
} else {
40-
resp = JSON.parse(JSON.stringify(srms.slice(1)));
41-
}
37+
resp = JSON.parse(JSON.stringify(srms));
4238
resp.pagination = {
4339
total: resp.length,
4440
pageIndex: 1,
@@ -66,24 +62,24 @@ describe('SRMs Widget Controller', function() {
6662
bard.verifyNoOutstandingHttpRequests();
6763

6864
describe('inialization', function() {
69-
var mySRMs = null;
65+
var controller = null;
7066
beforeEach( function(){
7167
$scope = $rootScope.$new();
72-
mySRMs = $controller('SRMWidgetController', {
68+
controller = $controller('SRMWidgetController', {
7369
SRMService : srmService,
7470
UserService : userService
7571
});
7672
$rootScope.$apply();
7773
});
7874

7975
it('controller should exist', function() {
80-
expect(mySRMs).to.exist;
76+
expect(controller).to.exist;
8177
});
8278

83-
it('mySRMs.srms should be initialized', function() {
84-
expect(mySRMs.srms).to.exist;
85-
expect(mySRMs.srms.length).to.equal(srms.length - 1);
79+
it('controller.srms should be initialized', function() {
80+
expect(controller.srms).to.exist;
81+
expect(controller.srms.length).to.equal(srms.length);
8682
});
8783
});
8884

89-
});
85+
});
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/* jshint -W117, -W030 */
2+
describe('Dashboard Subtrack Stats Controller', function() {
3+
var controller;
4+
var profileService, userStatsService;
5+
var stats = mockData.getMockStats();
6+
var userIdentity = {
7+
userId: 1234567,
8+
handle: 'ut',
9+
10+
};
11+
12+
beforeEach(function() {
13+
bard.appModule('topcoder');
14+
bard.inject(this,
15+
'$controller',
16+
'$rootScope',
17+
'$q',
18+
'ProfileService',
19+
'UserStatsService',
20+
'CONSTANTS',
21+
'Helpers');
22+
23+
profileService = ProfileService;
24+
userStatsService = UserStatsService;
25+
26+
sinon.stub(profileService, 'getUserStats', function() {
27+
var deferred = $q.defer();
28+
deferred.resolve(stats);
29+
return deferred.promise;
30+
});
31+
32+
});
33+
34+
bard.verifyNoOutstandingHttpRequests();
35+
36+
describe('controller', function() {
37+
var controller = null;
38+
beforeEach( function(){
39+
$scope = $rootScope.$new();
40+
controller = $controller('SubtrackStatsController', {
41+
ProfileService : profileService,
42+
UserStatsService : userStatsService,
43+
userIdentity: userIdentity
44+
});
45+
$rootScope.$apply();
46+
});
47+
48+
describe('initialization', function() {
49+
it('should load data', function() {
50+
expect(controller.loading).to.be.equal(false);
51+
});
52+
53+
it('should have ranks', function() {
54+
expect(controller.subtrackRanks.length).to.be.equal(10);
55+
expect(controller.hasRanks).to.be.equal(true);
56+
})
57+
});
58+
59+
});
60+
61+
});

app/services/profile.service.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@
106106
'track': 'DEVELOP',
107107
'subTrack': subTrack.name,
108108
'rank': subTrack.rank ? subTrack.rank.overallRank : 0,
109-
'rating': subTrack.rank.rating || 0,
109+
'rating': subTrack.rank ? subTrack.rank.rating || 0 : 0,
110110
'wins': subTrack.wins,
111111
'submissions': (subTrack.submissions && subTrack.submissions.submissions) || 0,
112112
'mostRecentEventDate': new Date(subTrack.mostRecentEventDate),

0 commit comments

Comments
 (0)