01/01: add unit test for alert
This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository pollen. See http://git.chorem.org/pollen.git commit f096df389586548ac9d43af982c5bf38552a527f Author: Adrien Garandel <a.garandel@dralagen.fr> Date: Wed Jul 16 15:29:20 2014 +0200 add unit test for alert --- .../src/main/webapp/js/controllers/alertCtrl.js | 22 +++--- .../src/test/unit/alertControllersTest.js | 78 ++++++++++++++++++++++ .../src/test/unit/pollControllersTest.js | 27 +++++++- 3 files changed, 114 insertions(+), 13 deletions(-) diff --git a/pollen-ui-angular/src/main/webapp/js/controllers/alertCtrl.js b/pollen-ui-angular/src/main/webapp/js/controllers/alertCtrl.js index 81a5802..d388b25 100644 --- a/pollen-ui-angular/src/main/webapp/js/controllers/alertCtrl.js +++ b/pollen-ui-angular/src/main/webapp/js/controllers/alertCtrl.js @@ -27,45 +27,47 @@ angular.module('alertControllers', []) if (angular.isUndefined($scope.data)) { $scope.data = {} } - $scope.data.alerts = []; + + $scope.data.alerts = []; $scope.$on('newError', function (event, error, timeout) { var alert = {msg:error, type:'danger', glyphicon:'glyphicon-remove'}; if (angular.isDefined(timeout)) { - addAlert(alert, timeout); + $scope.addAlert(alert, timeout); } else { - addAlert(alert, conf.defaultAlertTimeError); + $scope.addAlert(alert, conf.defaultAlertTimeError); } }); $scope.$on('newWarning', function (event, warning, timeout) { var alert = {msg:warning, type:'warning', glyphicon:'glyphicon-warning-sign'}; if (angular.isDefined(timeout)) { - addAlert(alert, timeout); + $scope.addAlert(alert, timeout); } else { - addAlert(alert, conf.defaultAlertTimeWarning); + $scope.addAlert(alert, conf.defaultAlertTimeWarning); } }); + $scope.$on('newSuccess', function (event, success, timeout) { var alert = {msg:success, type:'success', glyphicon:'glyphicon-ok'}; if (angular.isDefined(timeout)) { - addAlert(alert, timeout); + $scope.addAlert(alert, timeout); } else { - addAlert(alert, conf.defaultAlertTimeSuccess); + $scope.addAlert(alert, conf.defaultAlertTimeSuccess); } }); $scope.$on('newInfo', function (event, info, timeout) { var alert = {msg:info, type:'info', glyphicon:'glyphicon-info-sign'}; if (angular.isDefined(timeout)) { - addAlert(alert, timeout); + $scope.addAlert(alert, timeout); } else { - addAlert(alert, conf.defaultAlertTimeInfo); + $scope.addAlert(alert, conf.defaultAlertTimeInfo); } }); - var addAlert = function (alert, timeout) { + $scope.addAlert = function (alert, timeout) { var alertNotExist = true; angular.forEach($scope.data.alerts, function (oneAlert, key) { if (angular.equals(oneAlert.msg, alert.msg) && angular.equals(oneAlert.type, alert.type)) { diff --git a/pollen-ui-angular/src/test/unit/alertControllersTest.js b/pollen-ui-angular/src/test/unit/alertControllersTest.js new file mode 100644 index 0000000..91b760a --- /dev/null +++ b/pollen-ui-angular/src/test/unit/alertControllersTest.js @@ -0,0 +1,78 @@ +'use strict'; + +/////////////////////////////// +//// TEST printAlertCtrl //// +/////////////////////////////// + +describe('Alert controller', function () { + var rootScope; + var $timeout; + var $scope = {}; + var ctrl = null; + + beforeEach(module('alertControllers')); + beforeEach(inject(function($rootScope, $controller) { + rootScope = $rootScope; + $scope = $rootScope.$new(); + ctrl = $controller('printAlertCtrl', {$scope: $scope}); + spyOn($rootScope, '$broadcast').andCallThrough(); + })); + + beforeEach(inject(function($injector) { + $timeout = $injector.get('$timeout'); + })); + + + it('should load printAlertCtrl', function () { + expect(ctrl).toBeDefined(); + expect(ctrl).not.toBeNull(); + }); + + it('should init alerts array', function () { + expect($scope.data.alerts.length).toBeGreaterThan(-1); + }); + + it('should can add an alert', function () { + var nbAlert = $scope.data.alerts.length; + var alert = {msg:'message alert', type:'type'}; + + $scope.addAlert(alert, -1); + + expect($scope.data.alerts.length).toEqual(nbAlert + 1); + }); + + it('should can delete my alert', function () { + var nbAlert = $scope.data.alerts.length; + var alert = {msg:'message alert', type:'type'}; + + $scope.addAlert(alert, -1); + $scope.hideAlert(alert); + + expect($scope.data.alerts.length).toEqual(nbAlert); + }); + + it('should can\'t duplicate alert ', function () { + var nbAlert = $scope.data.alerts.length; + var alert = {msg:'message alert', type:'type'}; + + $scope.addAlert(alert, -1); + $scope.addAlert(alert, -1); + + expect($scope.data.alerts.length).toEqual(nbAlert + 1); + }); + + it('should can hide an alert after timeout', function() { + var alert = {msg:'message alert', type:'type'}; + var nbAlert = $scope.data.alerts.length; + + $scope.addAlert(alert, 250); + + // check now is added + expect($scope.data.alerts.length).toEqual(nbAlert + 1); + + $timeout.flush(); + + // check now is hidden + expect($scope.data.alerts.length).toEqual(nbAlert); + }); +}); diff --git a/pollen-ui-angular/src/test/unit/pollControllersTest.js b/pollen-ui-angular/src/test/unit/pollControllersTest.js index d658764..3f23721 100644 --- a/pollen-ui-angular/src/test/unit/pollControllersTest.js +++ b/pollen-ui-angular/src/test/unit/pollControllersTest.js @@ -1,8 +1,8 @@ 'use strict'; -//////////////////////////// -///// TEST PollCtrl //// -//////////////////////////// +/////////////////////////////// +//// TEST PollCtrl //// +/////////////////////////////// describe('Global poll controller', function () { beforeEach(module('pollControllers')); @@ -177,6 +177,9 @@ describe('Global poll controller', function () { }); }); +/////////////////////////////// +//// TEST PollAdminCtrl //// +/////////////////////////////// describe('Admin poll controller', function () { beforeEach(module('pollControllers')); beforeEach(inject(function($controller) { @@ -258,6 +261,9 @@ describe('Admin poll controller', function () { }); +/////////////////////////////// +//// TEST PollCreateCtrl //// +/////////////////////////////// describe('Create poll Controller', function () { beforeEach(module('pollControllers')); beforeEach(inject(function($controller) { @@ -291,6 +297,9 @@ describe('Create poll Controller', function () { }); }); +/////////////////////////////// +//// TEST PollEditCtrl //// +/////////////////////////////// describe('Edit poll controller', function () { beforeEach(module('pollControllers')); beforeEach(inject(function($controller) { @@ -349,6 +358,9 @@ describe('Edit poll controller', function () { }); }); +/////////////////////////////// +//// TEST PollVoteCtrl //// +/////////////////////////////// describe('Vote poll controller', function () { beforeEach(module('pollControllers')); beforeEach(inject(function($controller) { @@ -406,6 +418,9 @@ describe('Vote poll controller', function () { }); }); +/////////////////////////////// +//// TEST PollCommentCtrl //// +/////////////////////////////// describe('Poll comment controller', function () { beforeEach(module('pollControllers')); beforeEach(inject(function($controller) { @@ -462,6 +477,9 @@ describe('Poll comment controller', function () { }); }); +/////////////////////////////// +//// TEST PollResultCtrl //// +/////////////////////////////// describe('Poll result controller', function () { beforeEach(module('pollControllers')); beforeEach(inject(function($controller) { @@ -484,6 +502,9 @@ describe('Poll result controller', function () { }); }); +/////////////////////////////// +//// TEST PollListCtrl //// +/////////////////////////////// describe('List of poll controller', function () { beforeEach(module('pollControllers')); beforeEach(inject(function($controller) { -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.
participants (1)
-
chorem.org scm