From fef76acb245a621f3f029c8970244bff7462c6d8 Mon Sep 17 00:00:00 2001 From: Tom Ladendorf Date: Wed, 2 Dec 2015 11:00:33 -0600 Subject: [PATCH] Updated dashboard tests --- .../header-dashboard/header-dashboard.spec.js | 63 +++---------------- .../my-challenges/my-challenges.spec.js | 52 ++++++++++----- app/my-dashboard/programs/programs.spec.js | 19 ++++++ app/my-dashboard/srms/srms.controller.js | 2 +- app/my-dashboard/srms/srms.spec.js | 20 +++--- .../subtrack-stats.controller.spec.js | 61 ++++++++++++++++++ app/services/profile.service.js | 2 +- 7 files changed, 134 insertions(+), 85 deletions(-) create mode 100644 app/my-dashboard/subtrack-stats/subtrack-stats.controller.spec.js diff --git a/app/my-dashboard/header-dashboard/header-dashboard.spec.js b/app/my-dashboard/header-dashboard/header-dashboard.spec.js index 6e42f13ff..156f289d1 100644 --- a/app/my-dashboard/header-dashboard/header-dashboard.spec.js +++ b/app/my-dashboard/header-dashboard/header-dashboard.spec.js @@ -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); }); }); @@ -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'); }); }); @@ -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); + expect(controller.profile.$$state.value).to.equal('failed'); }); }); diff --git a/app/my-dashboard/my-challenges/my-challenges.spec.js b/app/my-dashboard/my-challenges/my-challenges.spec.js index 346e7ce5b..94df1c00a 100644 --- a/app/my-dashboard/my-challenges/my-challenges.spec.js +++ b/app/my-dashboard/my-challenges/my-challenges.spec.js @@ -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'); @@ -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'); + }); + + }); + }); diff --git a/app/my-dashboard/programs/programs.spec.js b/app/my-dashboard/programs/programs.spec.js index f991f591e..59e5e0720 100644 --- a/app/my-dashboard/programs/programs.spec.js +++ b/app/my-dashboard/programs/programs.spec.js @@ -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() { @@ -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() { diff --git a/app/my-dashboard/srms/srms.controller.js b/app/my-dashboard/srms/srms.controller.js index 243c3e135..01c0ef967 100644 --- a/app/my-dashboard/srms/srms.controller.js +++ b/app/my-dashboard/srms/srms.controller.js @@ -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; }); diff --git a/app/my-dashboard/srms/srms.spec.js b/app/my-dashboard/srms/srms.spec.js index 0d0fc6c06..521d55e06 100644 --- a/app/my-dashboard/srms/srms.spec.js +++ b/app/my-dashboard/srms/srms.spec.js @@ -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, @@ -66,10 +62,10 @@ 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 }); @@ -77,13 +73,13 @@ describe('SRMs Widget Controller', function() { }); 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); }); }); -}); \ No newline at end of file +}); diff --git a/app/my-dashboard/subtrack-stats/subtrack-stats.controller.spec.js b/app/my-dashboard/subtrack-stats/subtrack-stats.controller.spec.js new file mode 100644 index 000000000..1a0d1cb7f --- /dev/null +++ b/app/my-dashboard/subtrack-stats/subtrack-stats.controller.spec.js @@ -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: 'ut@topcoder.com' + }; + + 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); + }) + }); + + }); + +}); diff --git a/app/services/profile.service.js b/app/services/profile.service.js index 295ad6676..7e442b7d5 100644 --- a/app/services/profile.service.js +++ b/app/services/profile.service.js @@ -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),