Jasmine:How to prevent the exectuion

35 views
Skip to first unread message

amit singh

unread,
Jan 16, 2015, 12:22:22 AM1/16/15
to jasmine...@googlegroups.com
My Controller:-
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.playerID = $scope.playerObj.id;
            $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");
    });


};

Test Case:-
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!
    * ReferenceError: Can't find variable: player in http://localhost:49478/src/controllers/bonusController.js (line 26)

How can I solve it?? Please suggest me

Davis Frank

unread,
Jan 16, 2015, 12:25:43 AM1/16/15
to jasmine...@googlegroups.com
Please send these types of requests to jasmine-js@ - this list is for maintainers.

--dwf

--
You received this message because you are subscribed to the Google Groups "Jasmine Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jasmine-js-de...@googlegroups.com.
To post to this group, send email to jasmine...@googlegroups.com.
Visit this group at http://groups.google.com/group/jasmine-js-dev.
For more options, visit https://groups.google.com/d/optout.

amit singh

unread,
Jan 16, 2015, 1:41:36 AM1/16/15
to jasmine...@googlegroups.com
I am not understand what you say?

Gregg Van Hove

unread,
Jan 19, 2015, 1:06:56 PM1/19/15
to jasmine...@googlegroups.com
The jasmine...@googlegroups.com list is intended for the discussion of maintaining jasmine itself. The jasmi...@googlegroups.com list is where you should post questions on how to use jasmine.

Thanks!

-Gregg

--
Reply all
Reply to author
Forward
0 new messages