01/01: add test for modules pollControllers
This is an automated email from the git hooks/post-receive script. New commit to branch feature/unitTest in repository pollen. See http://git.chorem.org/pollen.git commit 40ca60aa739b8aedc3f179213f9d667a0b3055ef Author: Adrien Garandel <a.garandel@dralagen.fr> Date: Wed Jul 16 12:25:31 2014 +0200 add test for modules pollControllers --- .../src/main/webapp/js/controllers/pollCtrl.js | 43 ++-- .../src/test/unit/pollControllersTest.js | 240 +++++++++++++++++++-- 2 files changed, 250 insertions(+), 33 deletions(-) diff --git a/pollen-ui-angular/src/main/webapp/js/controllers/pollCtrl.js b/pollen-ui-angular/src/main/webapp/js/controllers/pollCtrl.js index dafeadf..a59d583 100644 --- a/pollen-ui-angular/src/main/webapp/js/controllers/pollCtrl.js +++ b/pollen-ui-angular/src/main/webapp/js/controllers/pollCtrl.js @@ -540,10 +540,13 @@ angular.module('pollControllers', ['ngRoute', 'pollenServices', 'pascalprecht.tr var initPoll = function () { Poll.skeletonNew(function (poll) { $scope.data.poll = poll; - $scope.data.choices = []; - $scope.data.vote = {}; - $scope.data.vote.choices = $scope.data.choices; + }, function (error) { + $scope.data.poll = {}; }); + + $scope.data.choices = []; + $scope.data.vote = {}; + $scope.data.vote.choices = $scope.data.choices; } initPoll(); @@ -598,8 +601,6 @@ angular.module('pollControllers', ['ngRoute', 'pollenServices', 'pascalprecht.tr Page.setTitle('title.poll.edit'); - $scope.globalVariables.edit = true; - //////////////////////////////// //// CHOICE ///// //////////////////////////////// @@ -694,10 +695,11 @@ angular.module('pollControllers', ['ngRoute', 'pollenServices', 'pascalprecht.tr } }; - var memberIsEmpty = function (member) { + $scope.memberIsEmpty = function (member) { var isEmpty = true; try { - if (member.name != '' && member.email != '') { + if (angular.isDefined(member.name) && member.name != '' + || angular.isDefined(member.email) && member.email != '') { isEmpty = false; } } @@ -754,7 +756,7 @@ angular.module('pollControllers', ['ngRoute', 'pollenServices', 'pascalprecht.tr var vl = {group: voterList.group, members:[]}; angular.forEach(voterList.members, function(member, key) { - if (!memberIsEmpty(member)) { + if (!$scope.memberIsEmpty(member)) { vl.members.push(member); } }); @@ -780,7 +782,7 @@ angular.module('pollControllers', ['ngRoute', 'pollenServices', 'pascalprecht.tr voterList.group.restError = error.data; var deltaError = 0; angular.forEach(voterList.members, function (member, key) { - if (!memberIsEmpty(member)) { + if (!$scope.memberIsEmpty(member)) { var index = key - deltaError; member.restError = {}; if (angular.isDefined(error.data['member['+index+'].name'])) { @@ -807,7 +809,7 @@ angular.module('pollControllers', ['ngRoute', 'pollenServices', 'pascalprecht.tr }; $scope.saveVoterListMember = function (member, voterList) { - if (!memberIsEmpty(member)) { + if (!$scope.memberIsEmpty(member)) { var vlId = voterList.group.id; // Id Voter list var vlMemberPromise; if (angular.isDefined(vlId)) { @@ -1078,9 +1080,16 @@ angular.module('pollControllers', ['ngRoute', 'pollenServices', 'pascalprecht.tr } $scope.toggleValue = function (choice, event) { - if ($scope.data.voteCountingType.renderType == 'checkbox') { - choice.voteValue = !choice.voteValue; - event.stopPropagation(); + if ($scope.voteCountingIsBoolean()) { + if (angular.isUndefined(choice.voteValue)) { + choice.voteValue = true; + } + else { + choice.voteValue = !choice.voteValue; + } + if (angular.isDefined(event)) { + event.stopPropagation(); + } } } @@ -1099,7 +1108,7 @@ angular.module('pollControllers', ['ngRoute', 'pollenServices', 'pascalprecht.tr $scope.tab = $scope.setTab('comment'); - $scope.globalVariables.commentMode = true; + //$scope.globalVariables.commentMode = true; $scope.comment = {text:''}; var initAuthor = function () { @@ -1110,6 +1119,8 @@ angular.module('pollControllers', ['ngRoute', 'pollenServices', 'pascalprecht.tr else { $scope.comment.authorName = $scope.session.user.email; } + } else { + $scope.comment.authorName = ''; } }; initAuthor(); @@ -1125,7 +1136,9 @@ angular.module('pollControllers', ['ngRoute', 'pollenServices', 'pascalprecht.tr $scope.toggleOrder = function () { $scope.desc = !$scope.desc; paginationParameter.desc = $scope.desc; - paginationParameter.pageNumber = $scope.data.commentsPagination.lastPage - $scope.data.commentsPagination.currentPage; + if (angular.isDefined($scope.data.commentsPagination)) { + paginationParameter.pageNumber = $scope.data.commentsPagination.lastPage - $scope.data.commentsPagination.currentPage; + } initComments(); } diff --git a/pollen-ui-angular/src/test/unit/pollControllersTest.js b/pollen-ui-angular/src/test/unit/pollControllersTest.js index 9b69907..d658764 100644 --- a/pollen-ui-angular/src/test/unit/pollControllersTest.js +++ b/pollen-ui-angular/src/test/unit/pollControllersTest.js @@ -4,7 +4,7 @@ ///// TEST PollCtrl //// //////////////////////////// -describe('Test pollCtrl', function () { +describe('Global poll controller', function () { beforeEach(module('pollControllers')); beforeEach(inject(function($controller) { $scope = {}; @@ -175,10 +175,9 @@ describe('Test pollCtrl', function () { expect(receiveChoice.choiceType).toEqual('IMAGE'); }); }); - }); -describe('Test Admin Controller', function () { +describe('Admin poll controller', function () { beforeEach(module('pollControllers')); beforeEach(inject(function($controller) { $scope = {}; @@ -259,37 +258,242 @@ describe('Test Admin Controller', function () { }); -describe('load poll controllers', function () { +describe('Create poll Controller', function () { beforeEach(module('pollControllers')); - - it('should load PollCreateCtrl', inject(function($controller) { - var ctrl = $controller('PollCreateCtrl', {$scope:{}}); - expect(ctrl).toBeDefined(); + beforeEach(inject(function($controller) { + ctrl = $controller('PollCreateCtrl', {$scope:$scope}); })); - it('should load PollEditCtrl', inject(function($controller) { - var ctrl = $controller('PollEditCtrl', {$scope:{}}); + var $scope = {}; + var ctrl = null; + + it('should load PollCreateCtrl', function() { expect(ctrl).toBeDefined(); + }); + + it('should set good default tab', function() { + expect($scope.tab).toEqual('edit'); + }); + + it('should be on edited mode', function () { + expect($scope.globalVariables.editMode).toBeTruthy(); + }); + + it('should be on create mode', function () { + expect($scope.globalVariables.create).toBeTruthy(); + }); + + it('should load base of poll', function () { + expect($scope.data.poll).toBeDefined(); + expect($scope.data.choices).toBeDefined(); + expect($scope.data.vote).toBeDefined(); + expect($scope.data.vote.choices).toBeDefined(); + }); +}); + +describe('Edit poll controller', function () { + beforeEach(module('pollControllers')); + beforeEach(inject(function($controller) { + ctrl = $controller('PollEditCtrl', {$scope:$scope}); })); - it('should load PollVoteCtrl', inject(function($controller) { - var ctrl = $controller('PollVoteCtrl', {$scope:{}}); + var $scope = {}; + var ctrl = null; + + it('should load PollEditCtrl', function() { expect(ctrl).toBeDefined(); + }); + + it('should set good default tab', function() { + expect($scope.tab).toEqual('edit'); + }); + + it('should be on edited mode', function () { + expect($scope.globalVariables.editMode).toBeTruthy(); + }); + + it('should detect is member is empty', function () { + var member, isEmpty; + + // is empty + + member = {}; + isEmpty = $scope.memberIsEmpty(member); + expect(isEmpty).toBeTruthy(); + + member = {name:''} + isEmpty = $scope.memberIsEmpty(member); + expect(isEmpty).toBeTruthy(); + + member = {email:''} + isEmpty = $scope.memberIsEmpty(member); + expect(isEmpty).toBeTruthy(); + + member = {name:'', email:''} + isEmpty = $scope.memberIsEmpty(member); + expect(isEmpty).toBeTruthy(); + + // is not empty + + member = {name:'memberName'} + isEmpty = $scope.memberIsEmpty(member); + expect(isEmpty).toBeFalsy(); + + member = {email:'member@pollen.org'} + isEmpty = $scope.memberIsEmpty(member); + expect(isEmpty).toBeFalsy(); + + member = {name:'memberName', email:'member@pollen.org'} + isEmpty = $scope.memberIsEmpty(member); + expect(isEmpty).toBeFalsy(); + }); +}); + +describe('Vote poll controller', function () { + beforeEach(module('pollControllers')); + beforeEach(inject(function($controller) { + ctrl = $controller('PollVoteCtrl', {$scope:$scope}); })); - it('should load PollResultCtrl', inject(function($controller) { - var ctrl = $controller('PollResultCtrl', {$scope:{}}); + var ctrl = null; + var $scope = {}; + + it('should load PollVoteCtrl', function() { expect(ctrl).toBeDefined(); + }); + + it('should set good default tab', function() { + expect($scope.tab).toEqual('vote'); + }); + + it('should not be on edited mode', function () { + expect($scope.globalVariables.editMode).toBeFalsy(); + }); + + it('should be toggle choiceValue', function () { + // force vote counting on boolean + $scope.data.voteCountingType = {renderType:'checkbox'}; + + // choice.voteValue init to false + runs( function () { + var choice = {voteValue : false}; + $scope.toggleValue(choice); + expect(choice.voteValue).toBeTruthy(); + + $scope.toggleValue(choice); + expect(choice.voteValue).toBeFalsy(); + }); + + // choice.voteValue init to true + runs( function () { + var choice = {voteValue : true}; + $scope.toggleValue(choice); + expect(choice.voteValue).toBeFalsy(); + + $scope.toggleValue(choice); + expect(choice.voteValue).toBeTruthy(); + }); + + // choice.voteValue is not defined + runs(function () { + var choice = {}; + $scope.toggleValue(choice); + expect(choice.voteValue).toBeTruthy(); + + $scope.toggleValue(choice); + expect(choice.voteValue).toBeFalsy(); + }); + }); +}); + +describe('Poll comment controller', function () { + beforeEach(module('pollControllers')); + beforeEach(inject(function($controller) { + ctrl = $controller('PollCommentCtrl', {$scope:$scope}); })); - it('should load PollCommentCtrl', inject(function($controller) { - var ctrl = $controller('PollCommentCtrl', {$scope:{}}); + var ctrl = null; + var $scope = {}; + + it('should load PollCommentCtrl', function() { expect(ctrl).toBeDefined(); + }); + + it('should set good default tab', function() { + expect($scope.tab).toEqual('comment'); + }); + + it('should not be on edited mode', function () { + expect($scope.globalVariables.editMode).toBeFalsy(); + }); + + it('should initialize comment', function () { + expect($scope.comment.text).toBeDefined(); + expect($scope.comment.authorName).toBeDefined(); + }); + + it('should toggle order comments', function () { + // order desc + runs(function () { + $scope.desc = true; + + $scope.toggleOrder(); + + expect($scope.desc).toBeFalsy(); + }); + + // order asc + runs(function () { + $scope.desc = false; + + $scope.toggleOrder(); + + expect($scope.desc).toBeTruthy(); + }); + + // order not set + runs(function () { + delete $scope.desc; + + $scope.toggleOrder(); + + expect($scope.desc).toBeTruthy(); + }); + }); +}); + +describe('Poll result controller', function () { + beforeEach(module('pollControllers')); + beforeEach(inject(function($controller) { + ctrl = $controller('PollResultCtrl', {$scope:$scope}); })); - it('should load PollListCtrl', inject(function($controller) { - var ctrl = $controller('PollListCtrl', {$scope:{}}); + var ctrl = null; + var $scope = {}; + + it('should load PollResultCtrl', function() { expect(ctrl).toBeDefined(); + }); + + it('should set good default tab', function() { + expect($scope.tab).toEqual('result'); + }); + + it('should not be on edited mode', function () { + expect($scope.globalVariables.editMode).toBeFalsy(); + }); +}); + +describe('List of poll controller', function () { + beforeEach(module('pollControllers')); + beforeEach(inject(function($controller) { + ctrl = $controller('PollListCtrl', {$scope:$scope}); })); + var ctrl = null; + var $scope = {}; + + it('should load PollListCtrl', function() { + expect(ctrl).toBeDefined(); + }); }) \ No newline at end of file -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.
participants (1)
-
chorem.org scm