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

Commit 36611ab

Browse files
author
vikasrohit
committed
Fixed Unit tests
1 parent af6f46f commit 36611ab

File tree

11 files changed

+77
-33
lines changed

11 files changed

+77
-33
lines changed

app/account/login/login.spec.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ describe('Login Controller', function() {
88
});
99

1010
beforeEach(function() {
11-
controller = $controller('LoginController');
11+
$scope = $rootScope.$new();
12+
controller = $controller('LoginController', {
13+
$scope : $scope
14+
});
1215
$rootScope.$apply();
1316
});
1417

app/directives/external-account/external-account.directive.spec.js

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* jshint -W117, -W030 */
2-
describe.only('External Accounts Directive', function() {
2+
describe('External Accounts Directive', function() {
33
var scope;
44
var element;
55

@@ -66,13 +66,30 @@ describe('External Links Data Directive', function() {
6666
bard.verifyNoOutstandingHttpRequests();
6767

6868
describe('Linked external accounts', function() {
69+
var externalLinks = [
70+
{
71+
providerType: 'linkedin',
72+
// don't care about other details
73+
},
74+
{
75+
providerType: 'github'
76+
},
77+
{
78+
providerType: 'behance'
79+
},
80+
{
81+
providerType: 'dribbble'
82+
},
83+
{
84+
providerType: 'bitbucket'
85+
}
86+
];
6987
var linkedAccounts = {
7088
github: {
7189
handle: "github-handle",
7290
followers: 1,
7391
publicRepos: 1
7492
},
75-
7693
stackoverflow: {
7794
handle: 'so-handle',
7895
reputation: 2,
@@ -83,7 +100,7 @@ describe('External Links Data Directive', function() {
83100
projectViews: 3,
84101
projectAppreciations: 3
85102
},
86-
dribble: {
103+
dribbble: {
87104
handle: 'dribble-handle',
88105
followers: 4,
89106
likes: 4
@@ -107,14 +124,16 @@ describe('External Links Data Directive', function() {
107124

108125
beforeEach(function() {
109126
scope.linkedAccounts = linkedAccounts;
110-
element = angular.element('<external-links-data linked-accounts-data="linkedAccounts"></external-links-data>)');
127+
scope.externalLinks = externalLinks;
128+
element = angular.element('<external-links-data linked-accounts-data="linkedAccounts" external-links="externalLinks"></external-links-data>)');
111129
externalLinksData = $compile(element)(scope);
112130
scope.$digest();
113131
});
114132

115133
it('should have added linkedAccounts to scope', function() {
116134
expect(element.isolateScope().linkedAccounts).to.exist;
117-
expect(element.isolateScope().linkedAccounts).to.have.length(1);
135+
// linkedAccounts should have 5 entries because externalLinks contains only 5 records
136+
expect(element.isolateScope().linkedAccounts).to.have.length(5);
118137
});
119138

120139
});

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,6 @@ describe('Header Dashboard Controller', function() {
121121
});
122122

123123
it('variables should be initialized to correct value', function() {
124-
expect(controller.domain).to.equal(domain);
125-
expect(controller.isCopilot).to.equal(false);
126-
expect(controller.hasRatings).to.equal(false);
127124
expect(controller.loading).to.equal(false);
128125
// TODO Fixme
129126
// expect(controller.profile).to.exist;
@@ -154,8 +151,6 @@ describe('Header Dashboard Controller', function() {
154151
});
155152

156153
xit('variables should be initialized to correct value', function() {
157-
expect(controller.domain).to.equal(domain);
158-
expect(controller.isCopilot).to.equal(false);
159154
expect(controller.loading).to.equal(false);
160155
expect(controller.profile).not.to.exist;
161156
expect(controller.rankStats).to.exist;
@@ -186,8 +181,6 @@ describe('Header Dashboard Controller', function() {
186181
});
187182

188183
xit('variables should be initialized to correct value', function() {
189-
expect(controller.domain).to.equal(domain);
190-
expect(controller.isCopilot).to.equal(false);
191184
expect(controller.loading).to.equal(false);
192185
expect(controller.profile).to.exist;
193186
expect(controller.profile.handle).to.equal('albertwang');

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
/* jshint -W117, -W030 */
22
describe('Dashboard Controller', function() {
3-
var controller, identity;
3+
var controller, identity, profileService;
4+
var mockProfile = mockData.getMockProfile();
45

56
beforeEach(function() {
67
bard.appModule('topcoder');
7-
bard.inject(this, '$controller');
8+
bard.inject(this, '$controller', '$q');
9+
10+
profileService = {
11+
getUserProfile: function() {
12+
return $q.when({result: {content: mockProfile}});
13+
}
14+
};
815
});
916

1017
identity = function() {
@@ -18,11 +25,13 @@ describe('Dashboard Controller', function() {
1825

1926
beforeEach(function() {
2027
controller = $controller('MyDashboardController', {
21-
userIdentity: identity
28+
userIdentity: identity,
29+
ProfileService: profileService
2230
});
2331
});
2432

2533
it('should exist', function() {
2634
expect(controller).to.exist;
35+
expect(controller.isCopilot).to.equal(false);
2736
});
2837
});

app/profile/about/about.controller.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222

2323
function activate() {
2424

25-
profileVm.externalLinksPromise.then(function() {
26-
vm.linkedExternalAccountsData = profileVm.linkedExternalAccountsData;
25+
ExternalAccountService.getLinkedExternalLinksData(profileVm.userHandle).then(function(data) {
26+
vm.linkedExternalAccountsData = data.plain();
2727

2828
// show section if user is viewing his/her own profile OR if we have data
2929
//vm.hasLinks = profileVm.linkedExternalAccounts.length;
@@ -53,6 +53,8 @@
5353
}
5454
profileVm.status.externalLinks = CONSTANTS.STATE_READY;
5555
}
56+
}).catch(function(err) {
57+
profileVm.status.externalLinks = CONSTANTS.STATE_ERROR;
5658
});
5759

5860
profileVm.statsPromise.then(function() {

app/profile/badges/badges.spec.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ describe('Profile Badges Controller', function() {
3737
scope = $rootScope.$new();
3838
controller = $controller('BadgesController', {
3939
$scope: scope,
40-
userHandle: 'vikasrohit'
40+
userHandle: 'vikasrohit',
41+
profile: {photoURL: "http://topcoder.com/test.png"}
4142
});
4243
$rootScope.$apply();
4344

app/profile/profile.controller.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,6 @@
5858
vm.status.skills = CONSTANTS.STATE_ERROR;
5959
});
6060

61-
62-
vm.externalLinksPromise = ExternalAccountService.getLinkedExternalLinksData(vm.userHandle).then(function(data) {
63-
vm.linkedExternalAccountsData = data.plain();
64-
}).catch(function(err) {
65-
vm.status.externalLinks = CONSTANTS.STATE_ERROR;
66-
});
67-
6861
function activate() {
6962
$log.debug('Calling ProfileController activate()');
7063
// show edit profile link if user is authenticated and is viewing their own profile

app/profile/profile.controller.spec.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ describe('Profile Controller', function() {
66
var mockStats = mockData.getMockStats();
77
var mockSkills = mockData.getMockSkills();
88
var mockExternalLinks = mockData.getMockLinkedExternalAccounts();
9+
var mockExternalLinksData = mockData.getMockLinkedExternalAccountsData();
910

1011
beforeEach(function() {
1112
bard.appModule('tc.profile');
@@ -25,7 +26,7 @@ describe('Profile Controller', function() {
2526

2627
var externalAccountService = {
2728
getLinkedExternalLinksData: function() {
28-
return $q.when(mockExternalLinks);
29+
return $q.when(mockExternalLinksData);
2930
}
3031
}
3132
controller = $controller('ProfileCtrl', {
@@ -56,9 +57,10 @@ describe('Profile Controller', function() {
5657
});
5758

5859
it('should have default status', function() {
60+
expect(controller.status.badges).to.equal(CONSTANTS.STATE_LOADING);
5961
expect(controller.status.stats).to.equal(CONSTANTS.STATE_READY);
6062
expect(controller.status.skills).to.equal(CONSTANTS.STATE_READY);
61-
expect(controller.status.externalLinks).to.equal(CONSTANTS.STATE_READY);
63+
expect(controller.status.externalLinks).to.equal(CONSTANTS.STATE_LOADING);
6264
});
6365
});
6466
});

app/profile/subtrack/subtrack.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ describe('SubTrack Controller', function() {
77
var mockSkills = mockData.getMockSkills();
88
var mockChallenges = mockData.getMockiOSChallenges();
99
var mockHistory = mockData.getMockHistory();
10-
var mockExternalLinks = mockData.getMockLinkedExternalAccounts();
10+
var mockExternalLinksData = mockData.getMockLinkedExternalAccountsData();
1111
var apiUrl;
1212
var track = 'develop', subTrack = 'development';
1313
var profileScope, scope;
@@ -68,7 +68,7 @@ describe('SubTrack Controller', function() {
6868
.respond(200, {result: {content: mockSkills}});
6969
$httpBackend
7070
.when('GET', apiUrl + '/members/rakesh/externalAccounts/')
71-
.respond(200, {result: { content: mockExternalLinks}});
71+
.respond(200, {result: { content: mockExternalLinksData}});
7272

7373
// mock profile api
7474
sinon.stub(profileService, 'getDistributionStats', function(track, subTrack) {

app/services/challenge.service.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ describe('Challenge Service', function() {
77
bard.appModule('tc.services');
88
bard.inject(this, '$httpBackend', 'ChallengeService', 'CONSTANTS');
99

10-
apiUrl = CONSTANTS.API_URL;
10+
apiUrl = CONSTANTS.API_URL_V2;
1111
});
1212

1313
bard.verifyNoOutstandingHttpRequests();

tests/test-helpers/mock-data.js

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ var mockData = (function() {
2121
getMockSRMResults: getMockSRMResults,
2222
getMockBadge: getMockBadge,
2323
getMockUserFinancials: getMockUserFinancials,
24-
getMockLinkedExternalAccounts: getMockLinkedExternalAccounts
24+
getMockLinkedExternalAccounts: getMockLinkedExternalAccounts,
25+
getMockLinkedExternalAccountsData: getMockLinkedExternalAccountsData
2526
};
2627

2728
function getMockStates() {
@@ -1934,7 +1935,7 @@ var mockData = (function() {
19341935
}];
19351936
}
19361937

1937-
function getMockLinkedExternalAccounts() {
1938+
function getMockLinkedExternalAccountsData() {
19381939
return {
19391940
github: null,
19401941
stackoverflow: null,
@@ -1948,5 +1949,26 @@ var mockData = (function() {
19481949
};
19491950
}
19501951

1952+
function getMockLinkedExternalAccounts() {
1953+
return [
1954+
{
1955+
providerType: 'linkedin',
1956+
// don't care about other details
1957+
},
1958+
{
1959+
providerType: 'github'
1960+
},
1961+
{
1962+
providerType: 'behance'
1963+
},
1964+
{
1965+
providerType: 'dribbble'
1966+
},
1967+
{
1968+
providerType: 'bitbucket'
1969+
}
1970+
];
1971+
}
1972+
19511973

19521974
})();

0 commit comments

Comments
 (0)