mirror of
https://github.com/sudoxnym/habitica.git
synced 2026-07-13 15:38:59 +00:00
Merge branch 'develop' of https://github.com/eastwood/habitica into eastwood-develop
This commit is contained in:
commit
d0561512de
3 changed files with 73 additions and 2 deletions
69
test/client-old/spec/controllers/userCtrlSpec.js
Normal file
69
test/client-old/spec/controllers/userCtrlSpec.js
Normal file
|
|
@ -0,0 +1,69 @@
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
describe('User Controller', function() {
|
||||||
|
var $rootScope, $window, User, shared, scope, ctrl, content;
|
||||||
|
|
||||||
|
beforeEach(function() {
|
||||||
|
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()
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
inject(function($rootScope, $controller, User, Content) {
|
||||||
|
scope = $rootScope.$new();
|
||||||
|
content = Content;
|
||||||
|
$controller('RootCtrl', { $scope: scope, User: User});
|
||||||
|
ctrl = $controller('UserCtrl', { $scope: scope, User: User, $window: $window});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('getProgressDisplay', function() {
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
sandbox.stub(window.env, 't');
|
||||||
|
window.env.t.onFirstCall().returns('Progress until next');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return initial progress', function() {
|
||||||
|
scope.profile.loginIncentives = 0;
|
||||||
|
content.loginIncentives = [{
|
||||||
|
nextRewardAt: 1,
|
||||||
|
reward: true
|
||||||
|
}];
|
||||||
|
var actual = scope.getProgressDisplay();
|
||||||
|
expect(actual.trim()).to.eql('Progress until next 0/1');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return progress between next reward and current reward', function() {
|
||||||
|
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('Progress until next 0/1');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
habitrpg.controller("UserCtrl", ['$rootScope', '$scope', '$location', 'User', '$http', '$state', 'Guide', 'Shared', 'Content', 'Stats', 'Social', 'Costume',
|
habitrpg.controller('UserCtrl', ['$rootScope', '$scope', '$location', 'User', '$http', '$state', 'Guide', 'Shared', 'Content', 'Stats', 'Social', 'Costume',
|
||||||
function($rootScope, $scope, $location, User, $http, $state, Guide, Shared, Content, Stats, Social, Costume) {
|
function($rootScope, $scope, $location, User, $http, $state, Guide, Shared, Content, Stats, Social, Costume) {
|
||||||
$scope.profile = User.user;
|
$scope.profile = User.user;
|
||||||
|
|
||||||
|
|
@ -102,6 +102,8 @@ habitrpg.controller("UserCtrl", ['$rootScope', '$scope', '$location', 'User', '$
|
||||||
if (!currentLoginDay) return env.t('moreIncentivesComingSoon');
|
if (!currentLoginDay) return env.t('moreIncentivesComingSoon');
|
||||||
var nextRewardAt = currentLoginDay.nextRewardAt;
|
var nextRewardAt = currentLoginDay.nextRewardAt;
|
||||||
if (!nextRewardAt) return env.t('moreIncentivesComingSoon');
|
if (!nextRewardAt) return env.t('moreIncentivesComingSoon');
|
||||||
|
// if we are on a reward day, let's show progress relative to this
|
||||||
|
if (currentLoginDay.reward) currentLoginDay.prevRewardKey = $scope.profile.loginIncentives;
|
||||||
if (!currentLoginDay.prevRewardKey) currentLoginDay.prevRewardKey = 0;
|
if (!currentLoginDay.prevRewardKey) currentLoginDay.prevRewardKey = 0;
|
||||||
return env.t('checkinProgressTitle') + ' ' + ($scope.profile.loginIncentives - currentLoginDay.prevRewardKey) + '/' + (nextRewardAt - currentLoginDay.prevRewardKey);
|
return env.t('checkinProgressTitle') + ' ' + ($scope.profile.loginIncentives - currentLoginDay.prevRewardKey) + '/' + (nextRewardAt - currentLoginDay.prevRewardKey);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -226,7 +226,7 @@ module.exports = function getLoginIncentives (api) {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
// Add refence link to next reward and add filler days so we have a map to refernce the next reward from any day
|
// Add reference link to next reward and add filler days so we have a map to reference the next reward from any day
|
||||||
// We could also, use a list, but then we would be cloning each of the rewards.
|
// We could also, use a list, but then we would be cloning each of the rewards.
|
||||||
// Create a new array if we want the loginIncentives to be immutable in the future
|
// Create a new array if we want the loginIncentives to be immutable in the future
|
||||||
let nextRewardKey;
|
let nextRewardKey;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue