Fixes tests

This commit is contained in:
Clint Ryan
2017-03-23 00:41:28 +11:00
parent 9115be68b2
commit 7a543d07a4
2 changed files with 54 additions and 38 deletions

View File

@@ -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');
});
});
});