From 7a543d07a4c0003f746d458baa4069c2ea90d96f Mon Sep 17 00:00:00 2001 From: Clint Ryan Date: Thu, 23 Mar 2017 00:41:28 +1100 Subject: [PATCH] Fixes tests --- .../spec/controllers/userCtrlSpec.js | 91 +++++++++++-------- website/client-old/js/controllers/userCtrl.js | 1 + 2 files changed, 54 insertions(+), 38 deletions(-) diff --git a/test/client-old/spec/controllers/userCtrlSpec.js b/test/client-old/spec/controllers/userCtrlSpec.js index 2bba860704..8db58196ef 100644 --- a/test/client-old/spec/controllers/userCtrlSpec.js +++ b/test/client-old/spec/controllers/userCtrlSpec.js @@ -1,55 +1,70 @@ 'use strict'; describe.only('User Controller', function() { - var $rootScope, shared, scope, user, User, ctrl, content, achievement; + var $rootScope, $window, User, shared, scope, ctrl, content; beforeEach(function() { - user = specHelper.newUser({ - balance: 4, - items: { - gear: { owned: {} }, - eggs: { Cactus: 1 }, - hatchingPotions: { Base: 1 }, - food: { Meat: 1 }, - pets: {}, - mounts: {} - }, - flags: { - armoireEnabled: true - }, - preferences: { - suppressModals: {} - }, - purchased: { - plan: { - mysteryItems: [], + module(function ($provide) { + var user = specHelper.newUser(); + User = {user: user} + $provide.value('Guide', sandbox.stub()); + $provide.value('User', User); + $provide.value('Achievement', sandbox.stub()); + $provide.value('Social', sandbox.stub()); + $provide.value('Shared', { + achievements: { + getAchievementsForProfile: sandbox.stub() }, - }, + shops: { + getBackgroundShopSets: sandbox.stub() + } + }); + $provide.value('Content', { + loginIncentives: sandbox.stub() + }) }); - User = { - user: user - }; - - inject(function($rootScope, $controller, Shared, User, Achievement, Guide) { + inject(function($rootScope, $controller, User, Content) { scope = $rootScope.$new(); - Shared.wrap(user); - shared = Shared; - achievement = Achievement; - User.setUser(user); - $controller('RootCtrl', {$scope: scope, User: User, Guide: Guide}); - ctrl = $controller('UserCtrl', {$scope: scope, User: User, Guide: Guide}); + content = Content; + $window = { + env: { + t: sandbox.stub(), + }, + }; + $controller('RootCtrl', { $scope: scope, $window: $window, User: User}); + ctrl = $controller('UserCtrl', { $scope: scope, User: User, $window: $window}); }); }); - describe.only('getProgressDisplay', function() { + describe('getProgressDisplay', function() { it('should return initial progress', function() { - sinon.stub(content, 'loginIncentives').onFirstCall().returns({ - prevRewardKey: 0, - nextRewardKey: 1 - }); + $window.env.t.onFirstCall().returns(''); + scope.profile.loginIncentives = 0; + content.loginIncentives = [{ + nextRewardAt: 1, + reward: true + }]; var actual = scope.getProgressDisplay(); - expect(actual).to.eql(''); + expect(actual.trim()).to.eql('0/1'); + }); + + it('should return progress between next reward and current reward', function() { + $window.env.t.onFirstCall().returns(''); + scope.profile.loginIncentives = 1; + content.loginIncentives = [{ + nextRewardAt: 1, + reward: true + }, { + prevRewardAt: 0, + nextRewardAt: 2, + reward: true + }, { + prevRewardAt: 1, + nextRewardAt: 3 + }]; + var actual = scope.getProgressDisplay(); + expect(actual.trim()).to.eql('0/1'); }); }); }); diff --git a/website/client-old/js/controllers/userCtrl.js b/website/client-old/js/controllers/userCtrl.js index b13a941eff..3d8ca62bf2 100644 --- a/website/client-old/js/controllers/userCtrl.js +++ b/website/client-old/js/controllers/userCtrl.js @@ -93,6 +93,7 @@ habitrpg.controller('UserCtrl', ['$rootScope', '$scope', '$location', 'User', '$ $scope.getProgressDisplay = function () { var currentLoginDay = Content.loginIncentives[$scope.profile.loginIncentives]; + console.log('CURRENT DAY', currentLoginDay); if (!currentLoginDay) return env.t('moreIncentivesComingSoon'); var nextRewardAt = currentLoginDay.nextRewardAt; if (!nextRewardAt) return env.t('moreIncentivesComingSoon');