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

Updated dashboard tests #592

Merged
merged 1 commit into from
Dec 3, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 7 additions & 56 deletions app/my-dashboard/header-dashboard/header-dashboard.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,9 @@ describe('Header Dashboard Controller', function() {
$rootScope.$apply();
});

xit('variables should be initialized to correct value', function() {
expect(controller.domain).to.equal(domain);
expect(controller.isCopilot).to.equal(false);
expect(controller.hasRatings).to.equal(true);
expect(controller.loading).to.equal(false);
it('variables should be initialized to correct value', function() {
expect(controller.profile).to.exist;
expect(controller.profile.handle).to.equal('albertwang');
expect(controller.rankStats).to.exist;
// there are 7 sub tracks with non null/zero value for one of rank/wins/fulfillment
expect(controller.rankStats).to.have.length(7);
expect(controller.moneyEarned).to.equal(60.50);
});
});

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

it('variables should be initialized to correct value', function() {
// expect(controller.loading).to.equal(false);
// TODO Fixme
// expect(controller.profile).to.exist;
// expect(controller.profile.handle).to.equal('albertwang');
// expect(controller.rankStats).to.exist;
// expect(controller.rankStats).to.have.length(0);
// expect(controller.moneyEarned).to.equal(60.50);
expect(controller.profile).to.exist;
expect(controller.profile.handle).to.equal('albertwang');
});
});

Expand All @@ -148,50 +135,14 @@ describe('Header Dashboard Controller', function() {
UserService : userService,
ProfileService: profileService,
userIdentity: identity,
profile: profile
profile: profileService.getUserProfile()
});
$rootScope.$apply();
});

xit('variables should be initialized to correct value', function() {
expect(controller.loading).to.equal(false);
expect(controller.profile).not.to.exist;
expect(controller.rankStats).to.exist;
// there are 7 sub tracks with non null/zero value for one of rank/wins/fulfillment
expect(controller.rankStats).to.have.length(7);
expect(controller.hasRatings).to.equal(true);
expect(controller.moneyEarned).to.equal(60.50);
});
});

describe('inialization with profile api financials endpoint error', function() {
var controller = null;
beforeEach( function(){
$scope = $rootScope.$new();
profileService.getUserFinancials.restore();
sinon.stub(profileService, 'getUserFinancials', function(handle) {
var deferred = $q.defer();
deferred.reject('failed');
return deferred.promise;
});
controller = $controller('HeaderDashboardController', {
NotificationService : notificationService,
UserService : userService,
ProfileService: profileService,
userIdentity: identity
});
$rootScope.$apply();
});

xit('variables should be initialized to correct value', function() {
expect(controller.loading).to.equal(false);
expect(controller.profile).to.exist;
expect(controller.profile.handle).to.equal('albertwang');
expect(controller.rankStats).to.exist;
// there are 7 sub tracks with non null/zero value for one of rank/wins/fulfillment
expect(controller.rankStats).to.have.length(7);
expect(controller.hasRatings).to.equal(true);
expect(controller.moneyEarned).not.to.exist;
it('variables should be initialized to correct value', function() {
expect(controller.profile.$$state.status).to.equal(2);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious, is the double dollar sign $$state a property that we've defined or is it one of the double dollar sign Angular values that already exists?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's from Angular—it's one of the properties you get when you do the deferred.reject thing.

expect(controller.profile.$$state.value).to.equal('failed');
});
});

Expand Down
52 changes: 37 additions & 15 deletions app/my-dashboard/my-challenges/my-challenges.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ describe('Challenges Widget Controller', function() {
var authService, challengeService, userService;
var marathons = mockData.getMockMarathons();
var challenges = mockData.getMockiOSChallenges();
var marathons = mockData.getMockMarathons();

beforeEach(function() {
bard.appModule('topcoder');
Expand Down Expand Up @@ -49,37 +50,58 @@ describe('Challenges Widget Controller', function() {
deferred.resolve(resp);
return deferred.promise;
});

sinon.stub(challengeService, 'getUserMarathonMatches', function(handle, params) {
var deferred = $q.defer();
deferred.resolve(marathons);
return deferred.promise;
});

sinon.stub(challengeService, 'checkChallengeParticipation', function() {
var deferred = $q.defer();
deferred.resolve(false);
return deferred.promise;
});

});

bard.verifyNoOutstandingHttpRequests();

xdescribe('inialization', function() {
var myChallenges = null;
beforeEach( function(){
$scope = $rootScope.$new();
myChallenges = $controller('MyChallengesWidgetController', {
ChallengeService: challengeService,
UserService: userService,
userIdentity: {handle: 'username'}
});
$rootScope.$apply();
var controller;
beforeEach( function(){
$scope = $rootScope.$new();
controller = $controller('MyChallengesWidgetController', {
ChallengeService: challengeService,
UserService: userService,
userIdentity: {handle: 'username'}
});
$rootScope.$apply();
});

describe('initialization', function() {
it('vm.domain should be initialized to default value', function() {
// default value for domain
expect(myChallenges.domain).to.equal(domain);
expect(controller.domain).to.equal(domain);
});

it('vm.userHasChallenges should be initialized to default value', function() {
// default value for pageIndex
expect(myChallenges.userHasChallenges).to.equal(true);
expect(controller.userHasChallenges).to.equal(true);
});

it('myChallenges.myChallenges should be initialized', function() {
it('controller.myChallenges should be initialized', function() {
// default value for pageIndex
expect(myChallenges.myChallenges).to.exist;
expect(myChallenges.myChallenges.length).to.equal(challenges.length);
expect(controller.myChallenges).to.exist;
expect(controller.myChallenges.length).to.equal(4);
});
});

describe('functions', function() {
it('toggleView should work', function() {
controller.toggleView('foo');
expect(controller.challengeView).to.equal('foo');
});

});

});
19 changes: 19 additions & 0 deletions app/my-dashboard/programs/programs.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ describe('Programs Controller', function() {
deferred.resolve(resp);
return deferred.promise;
});

sinon.stub(memberCertService, 'registerMember', function() {
var deferred = $q.defer();
var resp = {eventId: 3445, userId: 12345};
deferred.resolve(resp);
return deferred.promise;
});


// mock challenges api
sinon.stub(challengeService, 'getChallenges', function() {
Expand Down Expand Up @@ -81,6 +89,17 @@ describe('Programs Controller', function() {
expect(controller.challenges).to.exist;
expect(controller.challenges.length).to.equal(challenges.length);
});

describe('functions', function() {
beforeEach(function() {
controller.registerUser();
$rootScope.$apply();
});

it('registerUser should work', function() {
expect(controller.registered).to.be.equal(true);
});
});
});

describe('inialization with unregistered memeber', function() {
Expand Down
2 changes: 1 addition & 1 deletion app/my-dashboard/srms/srms.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
var srms = data[0];
var userSrms = data[1];
var userSrmsMap = {};
var userSrms = userSrms.forEach(function (srm) {
var userSrms = userSrms.map(function (srm) {
var id = srm.id;
userSrmsMap[id] = srm;
});
Expand Down
20 changes: 8 additions & 12 deletions app/my-dashboard/srms/srms.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,7 @@ describe('SRMs Widget Controller', function() {
sinon.stub(srmService, 'getSRMs', function(params) {
var deferred = $q.defer();
var resp = null;
if (params.filter.indexOf('listType=past') != -1) {
resp = JSON.parse(JSON.stringify(srms));
} else {
resp = JSON.parse(JSON.stringify(srms.slice(1)));
}
resp = JSON.parse(JSON.stringify(srms));
resp.pagination = {
total: resp.length,
pageIndex: 1,
Expand Down Expand Up @@ -66,24 +62,24 @@ describe('SRMs Widget Controller', function() {
bard.verifyNoOutstandingHttpRequests();

describe('inialization', function() {
var mySRMs = null;
var controller = null;
beforeEach( function(){
$scope = $rootScope.$new();
mySRMs = $controller('SRMWidgetController', {
controller = $controller('SRMWidgetController', {
SRMService : srmService,
UserService : userService
});
$rootScope.$apply();
});

it('controller should exist', function() {
expect(mySRMs).to.exist;
expect(controller).to.exist;
});

it('mySRMs.srms should be initialized', function() {
expect(mySRMs.srms).to.exist;
expect(mySRMs.srms.length).to.equal(srms.length - 1);
it('controller.srms should be initialized', function() {
expect(controller.srms).to.exist;
expect(controller.srms.length).to.equal(srms.length);
});
});

});
});
61 changes: 61 additions & 0 deletions app/my-dashboard/subtrack-stats/subtrack-stats.controller.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/* jshint -W117, -W030 */
describe('Dashboard Subtrack Stats Controller', function() {
var controller;
var profileService, userStatsService;
var stats = mockData.getMockStats();
var userIdentity = {
userId: 1234567,
handle: 'ut',
email: '[email protected]'
};

beforeEach(function() {
bard.appModule('topcoder');
bard.inject(this,
'$controller',
'$rootScope',
'$q',
'ProfileService',
'UserStatsService',
'CONSTANTS',
'Helpers');

profileService = ProfileService;
userStatsService = UserStatsService;

sinon.stub(profileService, 'getUserStats', function() {
var deferred = $q.defer();
deferred.resolve(stats);
return deferred.promise;
});

});

bard.verifyNoOutstandingHttpRequests();

describe('controller', function() {
var controller = null;
beforeEach( function(){
$scope = $rootScope.$new();
controller = $controller('SubtrackStatsController', {
ProfileService : profileService,
UserStatsService : userStatsService,
userIdentity: userIdentity
});
$rootScope.$apply();
});

describe('initialization', function() {
it('should load data', function() {
expect(controller.loading).to.be.equal(false);
});

it('should have ranks', function() {
expect(controller.subtrackRanks.length).to.be.equal(10);
expect(controller.hasRanks).to.be.equal(true);
})
});

});

});
2 changes: 1 addition & 1 deletion app/services/profile.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
'track': 'DEVELOP',
'subTrack': subTrack.name,
'rank': subTrack.rank ? subTrack.rank.overallRank : 0,
'rating': subTrack.rank.rating || 0,
'rating': subTrack.rank ? subTrack.rank.rating || 0 : 0,
'wins': subTrack.wins,
'submissions': (subTrack.submissions && subTrack.submissions.submissions) || 0,
'mostRecentEventDate': new Date(subTrack.mostRecentEventDate),
Expand Down