habitica-self-host/test/client-old/spec/controllers/userCtrlSpec.js

70 lines
1.9 KiB
JavaScript
Raw Normal View History

2017-03-14 01:35:48 +00:00
'use strict';
2017-03-24 12:45:56 +00:00
describe('User Controller', function() {
2017-03-22 13:41:28 +00:00
var $rootScope, $window, User, shared, scope, ctrl, content;
2017-03-14 01:35:48 +00:00
beforeEach(function() {
2017-03-22 13:41:28 +00:00
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()
},
2017-03-22 13:41:28 +00:00
shops: {
getBackgroundShopSets: sandbox.stub()
}
});
$provide.value('Content', {
loginIncentives: sandbox.stub()
})
});
2017-03-22 13:41:28 +00:00
inject(function($rootScope, $controller, User, Content) {
2017-03-14 01:35:48 +00:00
scope = $rootScope.$new();
2017-03-22 13:41:28 +00:00
content = Content;
2017-03-23 13:36:05 +00:00
$controller('RootCtrl', { $scope: scope, User: User});
2017-03-22 13:41:28 +00:00
ctrl = $controller('UserCtrl', { $scope: scope, User: User, $window: $window});
2017-03-14 01:35:48 +00:00
});
});
2017-03-22 13:41:28 +00:00
describe('getProgressDisplay', function() {
2017-03-23 13:36:05 +00:00
beforeEach(() => {
sandbox.stub(window.env, 't');
window.env.t.onFirstCall().returns('Progress until next');
});
2017-03-14 01:35:48 +00:00
it('should return initial progress', function() {
2017-03-22 13:41:28 +00:00
scope.profile.loginIncentives = 0;
content.loginIncentives = [{
nextRewardAt: 1,
reward: true
}];
var actual = scope.getProgressDisplay();
2017-03-23 13:36:05 +00:00
expect(actual.trim()).to.eql('Progress until next 0/1');
2017-03-22 13:41:28 +00:00
});
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
}];
2017-03-14 01:35:48 +00:00
var actual = scope.getProgressDisplay();
2017-03-23 13:36:05 +00:00
expect(actual.trim()).to.eql('Progress until next 0/1');
2017-03-14 01:35:48 +00:00
});
});
});