function BonusCtrl($scope, $state, $http, $ionicPopup, translationService, spinnerService, $timeout, $window, $ionicLoading) {
var translationTemplateName = "account_bonus";
translationService.setAllTranslations($scope, translationTemplateName,true);
$scope.init = function () {
angular.element("#menuHeaderLogoId").scope().checkPlayerSession();
$('.headerLogoContainer').css("display", 'block');
$('ion-header-bar').css("display", 'block');
$(".tooltip").css("display", "none");
$scope.updateCompoints();
};
$scope.updateCompoints=function(){
$scope.compPointsResponse = eoc.api.getEligibleForCompPointsSelfService();
if( eoc.api.isTrue($scope.compPointsResponse.eligibleForSelfService) ){
$('.bonusLast').show();
}
else{
$('.bonusLast').hide();
}
if(eoc.playerLoggedIn){
$scope.playerObj = eoc.api.getPlayer();
$scope.UrlBase = eoc.casino;
$scope.UrlRoot = eoc.casinoRoot;
$scope.cashable = eoc.api.convertAmountToCurrency(player.accountBalance.amount,player.accountBalance.currency);
$scope.bonusamount = eoc.api.convertAmountToCurrency(player.accountBalance.bonusAmount,player.accountBalance.currency);
if( $scope.playerObj.activeBonus ){
$('.bonusprogress').show();
$scope.bonusProgress = $scope.playerObj.currentBonusProgressInPercent;
}
else{
$('.bonusprogress').hide();
}
$scope.showProgressbar( $scope.bonusProgress );
if( $scope.playerObj.compPointBalance ){
$scope.compoints = $scope.playerObj.compPointBalance;
}
else{
$scope.compoints = 0;
}
$scope.ResetBonusValue();
if ($scope.$root.$$phase != '$apply' && $scope.$root.$$phase != '$digest') {
$scope.$apply();
}
}
};
$scope.bonusSubmit = function(){
event.preventDefault();
spinnerService.showSpinner($ionicLoading, $timeout)
//eoc.submitAccountFormPost('#accountFormCompPoints');
spinnerService.submitFormWithSpinner( eoc.submitAccountFormPost, ['#accountFormCompPoints'], null, $ionicLoading, $timeout);
};
$scope.ResetBonusValue = function(){
$("#accountFormCompPoints").find('input:text, input:password').val('');
};
$timeout( function(){
$(".BonusNameDetail").css("margin-top", Number($(".bonusChange").height() - $(".BonusNameDetail").height()) / 2 +'px');
$(".BonusNameDetails").css("margin-top", Number($(".bonusChange").height() - $(".BonusNameDetails").height()) / 2 +'px');
}, 10);
//ProgressBar function//
$scope.showProgressbar = function( percentValue ){
var progress = $('.bar-percentage');
var percentage = percentValue;
$({countNum: 0}).animate({countNum: percentage}, {
duration: 2000,
easing:'linear',
step: function() {
var pct = '';
if(percentage == 0){
pct = Math.floor(this.countNum) + '%';
}else{
pct = Math.floor(this.countNum+1) + '%';
}
progress.text( pct ) && progress.siblings().children().css('width', pct);
}
});
};
$scope.resetValidationErrorOfFields = function (fieldsForValidation) {
if (fieldsForValidation.length > 0) {
for(var i = 0 ; i < fieldsForValidation.length ; i++){
$('#'+fieldsForValidation[i]).parent().next().css('visibility', 'hidden');
}
console.log('Reset validate errors for fields: ' + fieldsForValidation);
} else {
console.log('Reset validation errors for all fields on this page');
}
//Add custom reset for validation errors
};
$scope.renderValidationErrorsForField = function (targetFieldID, validationErrors) {
var ele = $('#'+targetFieldID).parent().next();
ele.css('visibility', 'visible');
ele.text( validationErrors[0] )
//Add custom visualization for validation errors...
};
// Send Form End//
$(".bonusFormInput").find( "input" ).focus(function() {
if( $(this).parent().prev().hasClass("tooltip") )
$(this).parent().prev().css("display", "block");
});
$(".bonusFormInput").find( "input" ).blur(function() {
if( $(this).parent().prev().hasClass("tooltip") )
$(this).parent().prev().css("display", "none");
});
};
describe('BonusCtrl', function () {
'use strict';
var scope;
var $controller, $rootScope;
var transService;
var ctrlToTest,compile,elem, player;
var dummyPlayer={
id:123456,
accountBalance:{currency:'EUR',amount:100,bonusAmount:0}
}
beforeEach(function () {
module('portalApp');
inject(function (_$controller_, _$rootScope_,$compile) {
$controller = _$controller_;
$rootScope = _$rootScope_;
compile = $compile;
});
transService = jasmine.createSpyObj('translationService', ['setAllTranslations']);
scope = $rootScope.$new();
ctrlToTest = $controller('BonusCtrl', {$scope: scope, translationService: transService});
//eoc spies
eoc.api = {};
eoc.api.convertAmountToCurrency = jasmine.createSpy('eoc.api.convertAmountToCurrency').andReturn("123 €");
eoc.api.getPlayer = jasmine.createSpy('eoc.api.getPlayer').andReturn(dummyPlayer);
});
describe('Are callback methods for validation errors defined', function () {
it('validation errors are defined', function () {
expect(scope.resetValidationErrorOfFields).toBeDefined();
expect(scope.renderValidationErrorsForField).toBeDefined();
});
});
it('In BonusCtrl gets the correct translations during its creation.', function () {
expect(transService.setAllTranslations).toHaveBeenCalledWith(scope, 'account_bonus',true);
});
describe('its BonusCtrl Method', function () {
beforeEach(function () {
eoc.playerLoggedIn = true;
});
afterEach(function () {
eoc.playerLoggedIn = false;
});
it("should Check callBack Methods in BonusCtrl.",function(){
eoc.api.isTrue =jasmine.createSpy('eoc.api.isTrue').andReturn(false);
eoc.api.getEligibleForCompPointsSelfService = jasmine.createSpy('eoc.api.getEligibleForCompPointsSelfService').andReturn({eligibleForSelfService:false});
eoc.playerLoggedIn = true;
scope.updateCompoints();
expect(playerCall).toHaveBeenCalled();
});
});
});
ERROR:- 1.) BonusCtrl its BonusCtrl Method it should Check callBack Methods in BonusCtrl. <<< FAILURE!