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

71 lines
2 KiB
JavaScript
Raw Normal View History

2017-03-14 01:35:48 +00:00
'use strict';
describe.only('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;
$window = {
env: {
t: sandbox.stub(),
},
};
$controller('RootCtrl', { $scope: scope, $window: $window, User: User});
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-14 01:35:48 +00:00
it('should return initial progress', function() {
2017-03-22 13:41:28 +00:00
$window.env.t.onFirstCall().returns('');
scope.profile.loginIncentives = 0;
content.loginIncentives = [{
nextRewardAt: 1,
reward: true
}];
var actual = scope.getProgressDisplay();
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
}];
2017-03-14 01:35:48 +00:00
var actual = scope.getProgressDisplay();
2017-03-22 13:41:28 +00:00
expect(actual.trim()).to.eql('0/1');
2017-03-14 01:35:48 +00:00
});
});
});