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 280bb61fac8049eb03b0748c3e558564bcfddfd4 Author: Adrien Garandel <a.garandel@dralagen.fr> Date: Tue Jul 15 16:35:34 2014 +0200 add test pollCtrl --- pollen-ui-angular/.gitignore | 2 + pollen-ui-angular/package.json | 19 ++ pollen-ui-angular/pom.xml | 27 +++ pollen-ui-angular/src/main/webapp/js/app.js | 4 +- .../src/main/webapp/js/controllers/alertCtrl.js | 1 + .../main/webapp/js/controllers/favoriteListCtrl.js | 2 + .../src/main/webapp/js/controllers/localeCtrl.js | 2 + .../src/main/webapp/js/controllers/mainCtrl.js | 4 +- .../src/main/webapp/js/controllers/pollCtrl.js | 135 +++++++------ .../src/main/webapp/js/controllers/userCtrl.js | 4 +- pollen-ui-angular/src/main/webapp/js/directives.js | 35 +--- pollen-ui-angular/src/main/webapp/js/services.js | 36 ++++ pollen-ui-angular/src/test/karma.conf.js | 97 ++++++++++ .../src/test/unit/pollControllersTest.js | 214 +++++++++++++++++++++ 14 files changed, 489 insertions(+), 93 deletions(-) diff --git a/pollen-ui-angular/.gitignore b/pollen-ui-angular/.gitignore index a3ec35a..1c7c2ba 100644 --- a/pollen-ui-angular/.gitignore +++ b/pollen-ui-angular/.gitignore @@ -1,4 +1,6 @@ *.iml +node_modules/* +test_out/* src/main/webapp/lib src/main/webapp/css/style.css src/main/webapp/js/conf.js diff --git a/pollen-ui-angular/package.json b/pollen-ui-angular/package.json new file mode 100644 index 0000000..5ff1f26 --- /dev/null +++ b/pollen-ui-angular/package.json @@ -0,0 +1,19 @@ +{ + "name": "Pollen-test", + "version": "2.0.0", + "description": "", + "main": "src/test/karma.conf.js", + "devDependencies": { + "karma": "^0.12.17", + "karma-chrome-launcher": "^0.1.4", + "karma-firefox-launcher": "^0.1.3", + "karma-jasmine": "^0.1.5", + "karma-junit-reporter": "^0.2.2", + "karma-phantomjs-launcher": "^0.1.4" + }, + "scripts": { + "test": "karma start src/test/karma.conf.js" + }, + "author": "garandel", + "license": "AGPL" +} diff --git a/pollen-ui-angular/pom.xml b/pollen-ui-angular/pom.xml index 3239320..ff50ec3 100644 --- a/pollen-ui-angular/pom.xml +++ b/pollen-ui-angular/pom.xml @@ -65,6 +65,33 @@ </execution> </executions> </plugin> + + <plugin> + <groupId>com.kelveden</groupId> + <artifactId>maven-karma-plugin</artifactId> + <version>1.6</version> + <executions> + <execution> + <phase>test</phase> + <goals> + <goal>start</goal> + </goals> + </execution> + </executions> + <configuration> + <karmaExecutable>${basedir}/node_modules/karma/bin/karma</karmaExecutable> + <configFile>src/test/karma.conf.js</configFile> + <reportsDirectory>${project.build.directory}/karma-reports</reportsDirectory> + <browsers>PhantomJS</browsers> + <autoWatch>false</autoWatch> + <singleRun>true</singleRun> + <colors>true</colors> + <skipKarma>false</skipKarma> + <skipTests>false</skipTests> + <karmaFailureIgnore>false</karmaFailureIgnore> + <reporters>dots,junit</reporters> + </configuration> + </plugin> </plugins> </build> diff --git a/pollen-ui-angular/src/main/webapp/js/app.js b/pollen-ui-angular/src/main/webapp/js/app.js index 28ff905..ef73d67 100644 --- a/pollen-ui-angular/src/main/webapp/js/app.js +++ b/pollen-ui-angular/src/main/webapp/js/app.js @@ -18,7 +18,9 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. * #L% */ -var pollen = angular.module('pollen', ['pollenDirective', 'pollenServices', 'ngRoute', 'pollControllers', 'userControllers', 'favoriteListControllers', 'localeControllers', 'alertControllers', 'ui.bootstrap', 'pascalprecht.translate', 'ngAnimate']) +'use strict'; + +angular.module('pollen', ['pollenDirective', 'pollenServices', 'ngRoute', 'PollenMainControllers', 'pollControllers', 'userControllers', 'favoriteListControllers', 'localeControllers', 'alertControllers', 'ui.bootstrap', 'pascalprecht.translate', 'ngAnimate']) .config(['$httpProvider', function($httpProvider) { // edit header for locale and sessionToken $httpProvider.interceptors.push('httpInterceptor'); 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 a6ea298..81a5802 100644 --- a/pollen-ui-angular/src/main/webapp/js/controllers/alertCtrl.js +++ b/pollen-ui-angular/src/main/webapp/js/controllers/alertCtrl.js @@ -18,6 +18,7 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. * #L% */ +'use strict'; angular.module('alertControllers', []) .controller('printAlertCtrl', ['$scope', '$timeout', diff --git a/pollen-ui-angular/src/main/webapp/js/controllers/favoriteListCtrl.js b/pollen-ui-angular/src/main/webapp/js/controllers/favoriteListCtrl.js index 932e82c..1477c4b 100644 --- a/pollen-ui-angular/src/main/webapp/js/controllers/favoriteListCtrl.js +++ b/pollen-ui-angular/src/main/webapp/js/controllers/favoriteListCtrl.js @@ -18,6 +18,8 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. * #L% */ +'use strict'; + angular.module('favoriteListControllers', []) .controller('FavoriteListCtrl', ['$scope', 'FavoriteList', 'FavoriteListMember', '$translate', '$routeParams', 'Page', function ($scope, FavoriteList, FavoriteListMember, $translate, $routeParams, Page) { diff --git a/pollen-ui-angular/src/main/webapp/js/controllers/localeCtrl.js b/pollen-ui-angular/src/main/webapp/js/controllers/localeCtrl.js index 524e3ef..47667e8 100644 --- a/pollen-ui-angular/src/main/webapp/js/controllers/localeCtrl.js +++ b/pollen-ui-angular/src/main/webapp/js/controllers/localeCtrl.js @@ -18,6 +18,8 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. * #L% */ +'use strict'; + angular.module('localeControllers', []) .controller('LocaleCtrl', ['$scope', '$rootScope', '$translate', 'SessionStorage', '$locale', function ($scope, $rootScope, $translate, SessionStorage, $locale) { $scope.debug = conf.debug; diff --git a/pollen-ui-angular/src/main/webapp/js/controllers/mainCtrl.js b/pollen-ui-angular/src/main/webapp/js/controllers/mainCtrl.js index d0ccb2a..38d47af 100644 --- a/pollen-ui-angular/src/main/webapp/js/controllers/mainCtrl.js +++ b/pollen-ui-angular/src/main/webapp/js/controllers/mainCtrl.js @@ -1,4 +1,6 @@ -pollen.controller('MainCtrl', ['$scope', 'Page', +'use strict'; + +angular.module('PollenMainControllers', ['pollenServices']).controller('MainCtrl', ['$scope', 'Page', function ($scope, Page) { $scope.$on('titleChange', function () { 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 4a691b1..dafeadf 100644 --- a/pollen-ui-angular/src/main/webapp/js/controllers/pollCtrl.js +++ b/pollen-ui-angular/src/main/webapp/js/controllers/pollCtrl.js @@ -18,7 +18,9 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. * #L% */ -angular.module('pollControllers', []) +'use strict'; + +angular.module('pollControllers', ['ngRoute', 'pollenServices', 'pascalprecht.translate', 'ui.bootstrap']) .controller('HomeCtrl', ['$scope', 'Poll', 'Page', function ($scope, Poll, Page) { Page.setTitle('title.home'); Poll.skeletonNew(); @@ -172,13 +174,22 @@ angular.module('pollControllers', []) }; initTemplateURL(); var lastRoute = $route.current; - $scope.$on('$locationChangeSuccess', function(event) { - if (lastRoute.$$route.controller == $route.current.$$route.controller) { - $route.current = lastRoute; - } + $timeout(function() { + $scope.$on('$locationChangeSuccess', function(event) { + if (lastRoute.$$route.controller == $route.current.$$route.controller) { + $route.current = lastRoute; + } + }); }); + $scope.voteCountingIsBoolean = function () { + if (angular.isDefined($scope.data.voteCountingType)) { + return $scope.data.voteCountingType.renderType == 'checkbox'; + } + return false; + } + $scope.getChoiceValue = function (choiceValue) { if ($scope.voteCountingIsBoolean()) { return (choiceValue)?true:false; @@ -198,7 +209,12 @@ angular.module('pollControllers', []) $scope.preSendChoice = function (choice) { if (choice.choiceType == 'DATE') { - choice.choiceValue = choice.choiceValue.getTime(); + if (angular.isDate(choice.choiceValue)) { + choice.choiceValue = choice.choiceValue.getTime(); + } + else { + choice.choiceValue = null; + } } else if (choice.choiceType == 'IMAGE') { try { @@ -216,7 +232,9 @@ angular.module('pollControllers', []) choice.choiceValue = new Date(Number(choice.choiceValue)); } else if (choice.choiceType == 'IMAGE') { - PollenResource.getMeta({resourceId : choice.choiceValue}, function (data) { + var resourceId = choice.choiceValue; + choice.choiceValue = {meta:{id:resourceId}, data:conf.restURL+'/resources/'+resourceId, id: resourceId}; + PollenResource.getMeta({resourceId : resourceId}, function (data) { choice.choiceValue = {meta:data, data : conf.restURL+'/resources/'+data.id, id : data.id}; }); } @@ -246,13 +264,6 @@ angular.module('pollControllers', []) }); }); - $scope.voteCountingIsBoolean = function () { - if (angular.isDefined($scope.data.voteCountingType)) { - return $scope.data.voteCountingType.renderType == 'checkbox'; - } - return false; - } - $scope.deletePoll = function () { if (angular.isDefined($scope.data.poll.id)) { var confirmMessage; @@ -299,7 +310,8 @@ angular.module('pollControllers', []) }]) -.controller('PollAdminCtrl', ['$scope', '$controller', '$modal', '$timeout', '$routeParams', 'Poll', function ($scope, $controller, $modal, $timeout, $routeParams, Poll) { +.controller('PollAdminCtrl', ['$scope', '$controller', '$modal', '$timeout', '$routeParams', 'Poll', + function ($scope, $controller, $modal, $timeout, $routeParams, Poll) { $controller('PollCtrl', {$scope:$scope}); $scope.tab = $scope.setTab('edit'); @@ -329,26 +341,28 @@ angular.module('pollControllers', []) $scope.data.voterList = []; $scope.data.voterList.push(newGroup()); - $scope.$watch('data.poll.pollType', function (newVal, oldVal) { - if (newVal != oldVal && newVal == 'RESTRICTED') { - var listMember = []; - for (var i = 0; i < $scope.data.voterList.length; i++) { - for (var j = 0; j < $scope.data.voterList[i].members.length; j++) { - // check if not a empty line - if ($scope.data.voterList[i].members[j].email != '' || $scope.data.voterList[i].members[j].name != '') { - listMember.push($scope.data.voterList[i].members[j]); + $timeout(function () { + $scope.$watch('data.poll.pollType', function (newVal, oldVal) { + if (newVal != oldVal && newVal == 'RESTRICTED') { + var listMember = []; + for (var i = 0; i < $scope.data.voterList.length; i++) { + for (var j = 0; j < $scope.data.voterList[i].members.length; j++) { + // check if not a empty line + if ($scope.data.voterList[i].members[j].email != '' || $scope.data.voterList[i].members[j].name != '') { + listMember.push($scope.data.voterList[i].members[j]); + } } } - } - // get the first group - $scope.data.voterList = $scope.data.voterList.splice(0,1); + // get the first group + $scope.data.voterList = $scope.data.voterList.splice(0,1); - // check if one voter is enter in one group - if (listMember.length > 0) { - $scope.data.voterList[0].members = listMember; + // check if one voter is enter in one group + if (listMember.length > 0) { + $scope.data.voterList[0].members = listMember; + } } - } + }); }); $scope.addVoter = function (index) { @@ -502,8 +516,10 @@ angular.module('pollControllers', []) }); }; - $scope.$on('switchLocale', function() { - initVoteCountingType(); + $timeout(function () { + $scope.$on('switchLocale', function() { + initVoteCountingType(); + }); }); $timeout(function () { @@ -527,7 +543,6 @@ angular.module('pollControllers', []) $scope.data.choices = []; $scope.data.vote = {}; $scope.data.vote.choices = $scope.data.choices; - $scope.restRequest = poll; }); } initPoll(); @@ -590,7 +605,7 @@ angular.module('pollControllers', []) //////////////////////////////// $scope.callBackAddChoice = function (choice) { - saveChoice = angular.copy(choice); + var saveChoice = angular.copy(choice); saveChoice = $scope.preSendChoice(saveChoice); @@ -604,7 +619,7 @@ angular.module('pollControllers', []) } $scope.callBackEditChoice = function (choice) { - saveChoice = angular.copy(choice); + var saveChoice = angular.copy(choice); saveChoice = $scope.preSendChoice(saveChoice); @@ -1072,8 +1087,8 @@ angular.module('pollControllers', []) }]) .controller('PollCommentCtrl', - ['$scope', '$rootScope', '$controller', '$routeParams', 'Poll', 'PollComment', '$translate', '$location', 'Page', - function ( $scope, $rootScope, $controller, $routeParams, Poll, PollComment, $translate, $location, Page) { + ['$scope', '$rootScope', '$controller', '$routeParams', 'Poll', 'PollComment', '$translate', '$timeout', '$location', 'Page', + function ( $scope, $rootScope, $controller, $routeParams, Poll, PollComment, $translate, $timeout, $location, Page) { $controller('PollCtrl', {$scope:$scope}); Page.setTitle('title.poll.comment'); @@ -1133,13 +1148,15 @@ angular.module('pollControllers', []) return commentPromise; }; initComments(); - $scope.$watch('data.commentsPagination.currentPage', function (newVal, oldVal) { - if (angular.isDefined(oldVal) && newVal != oldVal) { // Value change - if (paginationParameter.pageNumber != $scope.data.commentsPagination.currentPage) { // not same page - paginationParameter.pageNumber = $scope.data.commentsPagination.currentPage; - initComments(); + $timeout(function () { + $scope.$watch('data.commentsPagination.currentPage', function (newVal, oldVal) { + if (angular.isDefined(oldVal) && newVal != oldVal) { // Value change + if (paginationParameter.pageNumber != $scope.data.commentsPagination.currentPage) { // not same page + paginationParameter.pageNumber = $scope.data.commentsPagination.currentPage; + initComments(); + } } - } + }); }); $scope.postComment = function () { @@ -1225,8 +1242,8 @@ angular.module('pollControllers', []) }]) -.controller('PollResultCtrl', ['$scope', '$q', '$controller', '$route', '$routeParams', 'Poll', 'PollChoice', 'PollVote', '$translate', '$filter', 'Page', - function ($scope, $q, $controller, $route, $routeParams, Poll, PollChoice, PollVote, $translate, $filter, Page) { +.controller('PollResultCtrl', ['$scope', '$q', '$controller', '$route', '$routeParams', 'Poll', 'PollChoice', 'PollVote', '$translate', '$filter', '$timeout', 'Page', + function ($scope, $q, $controller, $route, $routeParams, Poll, PollChoice, PollVote, $translate, $filter, $timeout, Page) { $controller('PollCtrl', {$scope:$scope}); Page.setTitle('title.poll.result'); @@ -1240,9 +1257,11 @@ angular.module('pollControllers', []) $scope.tab = $scope.setTab('result'); $scope.plot = 'chart'; - $scope.$on('switchLocale', function() { - $route.reload(); - }) + $timeout(function () { + $scope.$on('switchLocale', function() { + $route.reload(); + }); + }); var choicesDeferred = $q.defer(); PollChoice.query({pollId:$routeParams.pollId}, function (choices) { @@ -1309,8 +1328,8 @@ angular.module('pollControllers', []) }]) .controller('PollListCtrl', - ['$scope', '$rootScope', '$controller', '$routeParams', '$location', 'Poll', 'Page', - function ($scope, $rootScope, $controller, $routeParams, $location, Poll, Page) { + ['$scope', '$rootScope', '$controller', '$routeParams', '$timeout', '$location', 'Poll', 'Page', + function ($scope, $rootScope, $controller, $routeParams, $timeout, $location, Poll, Page) { $scope.data = {}; Page.setTitle('title.poll.list'); @@ -1342,13 +1361,15 @@ angular.module('pollControllers', []) }); }; initPolls(); - $scope.$watch('data.pollsPagination.currentPage', function (newVal, oldVal) { - // check if the current page has changed - if (angular.isDefined(oldVal) && newVal != oldVal) { - paginationParameter.pageNumber = $scope.data.pollsPagination.currentPage; - initPolls(); - } - }); + $timeout(function () { + $scope.$watch('data.pollsPagination.currentPage', function (newVal, oldVal) { + // check if the current page has changed + if (angular.isDefined(oldVal) && newVal != oldVal) { + paginationParameter.pageNumber = $scope.data.pollsPagination.currentPage; + initPolls(); + } + }); + }) }]) diff --git a/pollen-ui-angular/src/main/webapp/js/controllers/userCtrl.js b/pollen-ui-angular/src/main/webapp/js/controllers/userCtrl.js index a64dad8..d93ee6a 100644 --- a/pollen-ui-angular/src/main/webapp/js/controllers/userCtrl.js +++ b/pollen-ui-angular/src/main/webapp/js/controllers/userCtrl.js @@ -18,7 +18,9 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. * #L% */ - angular.module('userControllers', []) +'use strict'; + +angular.module('userControllers', []) .controller('UserRegisterCtrl', ['$scope', '$rootScope', '$location', 'User', 'SessionStorage', 'Page', function ($scope, $rootScope, $location, User, SessionStorage, Page) { Page.setTitle('title.user.register'); diff --git a/pollen-ui-angular/src/main/webapp/js/directives.js b/pollen-ui-angular/src/main/webapp/js/directives.js index b5dd14c..478f369 100644 --- a/pollen-ui-angular/src/main/webapp/js/directives.js +++ b/pollen-ui-angular/src/main/webapp/js/directives.js @@ -18,40 +18,9 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. * #L% */ -angular.module('pollenDirective', []) - -////////////////////////////////////// -///// PAGE ///// -////////////////////////////////////// - -.factory('Page', ['$rootScope', '$filter', function ($rootScope, $filter) { - var title = ''; - var value; - return { - title : function () { - var makeTitle = "Pollen"; - if (title != '') { - makeTitle += " - " + $filter('translate')(title); - - } - - if (value !== undefined) { - makeTitle += " - " + value; - } +'use strict'; - return makeTitle; - }, - setTitle: function(newTitle, newValue) { - title = newTitle; - value = newValue; - $rootScope.$broadcast('titleChange'); - }, - setValue: function(newValue) { - value = newValue; - $rootScope.$broadcast('titleChange'); - } - }; -}]) +angular.module('pollenDirective', []) ////////////////////////////////////// ///// FOCUS ME ///// diff --git a/pollen-ui-angular/src/main/webapp/js/services.js b/pollen-ui-angular/src/main/webapp/js/services.js index 78b6ffa..fc4fef3 100644 --- a/pollen-ui-angular/src/main/webapp/js/services.js +++ b/pollen-ui-angular/src/main/webapp/js/services.js @@ -18,6 +18,8 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. * #L% */ +'use strict'; + angular.module('pollenServices', ['ngResource']) ////////////////////////////////////// @@ -417,4 +419,38 @@ angular.module('pollenServices', ['ngResource']) } } } +}]) + + +////////////////////////////////////// +///// PAGE ///// +////////////////////////////////////// + +.factory('Page', ['$rootScope', '$filter', function ($rootScope, $filter) { + var title = ''; + var value; + return { + title : function () { + var makeTitle = "Pollen"; + if (title != '') { + makeTitle += " - " + $filter('translate')(title); + + } + + if (value !== undefined) { + makeTitle += " - " + value; + } + + return makeTitle; + }, + setTitle: function(newTitle, newValue) { + title = newTitle; + value = newValue; + $rootScope.$broadcast('titleChange'); + }, + setValue: function(newValue) { + value = newValue; + $rootScope.$broadcast('titleChange'); + } + }; }]) \ No newline at end of file diff --git a/pollen-ui-angular/src/test/karma.conf.js b/pollen-ui-angular/src/test/karma.conf.js new file mode 100644 index 0000000..7274e8e --- /dev/null +++ b/pollen-ui-angular/src/test/karma.conf.js @@ -0,0 +1,97 @@ +// Karma configuration +// Generated on Tue Jul 15 2014 10:21:18 GMT+0200 (CEST) + +module.exports = function(config) { + config.set({ + + // base path that will be used to resolve all patterns (eg. files, exclude) + basePath: '../../', + + + // frameworks to use + // available frameworks: https://npmjs.org/browse/keyword/karma-adapter + frameworks: ['jasmine'], + + + // list of files / patterns to load in the browser + files: [ + 'src/main/webapp/lib/jquery/dist/jquery.min.js', + 'src/main/webapp/lib/jqplot/jquery.jqplot.min.js', + 'src/main/webapp/lib/jqplot/plugins/jqplot.barRenderer.min.js', + 'src/main/webapp/lib/jqplot/plugins/jqplot.pieRenderer.min.js', + 'src/main/webapp/lib/jqplot/plugins/jqplot.categoryAxisRenderer.min.js', + 'src/main/webapp/lib/jqplot/plugins/jqplot.pointLabels.min.js', + 'src/main/webapp/lib/jqplot/plugins/jqplot.highlighter.min.js', + 'src/main/webapp/lib/ckeditor/ckeditor.js', + 'src/main/webapp/lib/angular/angular.js', + 'src/main/webapp/lib/angular-mocks/angular-mocks.js', + 'src/main/webapp/lib/angular-bootstrap/ui-bootstrap-tpls.js', + 'src/main/webapp/lib/angular-resource/angular-resource.js', + 'src/main/webapp/lib/angular-route/angular-route.js', + 'src/main/webapp/lib/angular-translate/angular-translate.js', + 'src/main/webapp/lib/angular-animate/angular-animate.js', + 'src/main/webapp/js/*.js', + 'src/main/webapp/js/**/*.js', + 'src/main/webapp/i18n/*.js', + 'src/test/unit/**/*.js' + ], + + + // list of files to exclude + exclude: [ + ], + + + // preprocess matching files before serving them to the browser + // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor + preprocessors: { + + }, + + + // test results reporter to use + // possible values: 'dots', 'progress' + // available reporters: https://npmjs.org/browse/keyword/karma-reporter + reporters: ['progress'], + + + // web server port + port: 9876, + + + // enable / disable colors in the output (reporters and logs) + colors: true, + + + // level of logging + // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG + logLevel: config.LOG_INFO, + + + // enable / disable watching file and executing tests whenever any file changes + autoWatch: true, + + + // start these browsers + // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher + browsers: ['Chrome', 'Firefox', 'PhantomJS'], + + plugins : [ + 'karma-chrome-launcher', + 'karma-firefox-launcher', + 'karma-phantomjs-launcher', + 'karma-jasmine', + 'karma-junit-reporter' + ], + + junitReporter : { + outputFile: 'test_out/unit.xml', + suite: 'unit' + }, + + // Continuous Integration mode + // if true, Karma captures browsers, runs the tests and exits + singleRun: false + }); +}; + diff --git a/pollen-ui-angular/src/test/unit/pollControllersTest.js b/pollen-ui-angular/src/test/unit/pollControllersTest.js new file mode 100644 index 0000000..f4bb7b3 --- /dev/null +++ b/pollen-ui-angular/src/test/unit/pollControllersTest.js @@ -0,0 +1,214 @@ +'use strict'; + +//////////////////////////// +///// TEST PollCtrl //// +//////////////////////////// + +describe('Test pollCtrl', function () { + beforeEach(module('pollControllers')); + beforeEach(inject(function($controller) { + $scope = {}; + ctrl = $controller('PollCtrl', {$scope: $scope}); + })); + + var $scope = {}; + var ctrl = null; + it('should load PollCtrl', function () { + expect(ctrl).toBeDefined(); + expect(ctrl).not.toBeNull(); + + }); + + it('should set good default tab', function() { + + expect($scope.tab).toEqual('home'); + }); + + it('should set good default dateFormat', function() { + expect($scope.globalVariables.dateFormat).not.toBeNull(); + expect($scope.globalVariables.dateFormat).toBeDefined(); + + expect($scope.globalVariables.timeFormat).not.toBeNull(); + expect($scope.globalVariables.timeFormat).toBeDefined; + + expect($scope.globalVariables.dateTimeFormat).not.toBeNull(); + expect($scope.globalVariables.dateTimeFormat).toBeDefined(); + }); + + it('should set good template url', function () { + expect($scope.templateURL).toBeDefined(); + expect($scope.templateURL).not.toBeNull(); + }); + + + it('should get good voteCounting', function () { + // voteCounting boolean + runs(function () { + $scope.data.voteCountingType = {renderType:'checkbox'}; + expect($scope.voteCountingIsBoolean()).toBeTruthy(); + }); + + // voteCounting not boolean + runs(function () { + $scope.data.voteCountingType = {renderType: 'text'}; + expect($scope.voteCountingIsBoolean()).toBeFalsy(); + }); + }); + + it('should get good choiceValue', function () { + // voteCounting boolean + runs(function () { + $scope.data.voteCountingType = {renderType:'checkbox'}; + + var valueOf1 = $scope.getChoiceValue(1.0); + expect(valueOf1).toBeTruthy(); + var valueOf2 = $scope.getChoiceValue(2.0); + expect(valueOf2).toBeTruthy(); + + var valueOf0 = $scope.getChoiceValue(0.0); + expect(valueOf0).toBeFalsy(); + + var valueOfTrue = $scope.getChoiceValue(true); + expect(valueOfTrue).toBeTruthy(); + var valueOfFalse = $scope.getChoiceValue(false); + expect(valueOfFalse).toBeFalsy(); + + }); + + // voteCounting not boolean + runs(function () { + $scope.data.voteCountingType = {renderType: 'text'}; + + var valueOf1 = $scope.getChoiceValue(1.0); + expect(valueOf1).toEqual(1.0); + + var valueOf0 = $scope.getChoiceValue(0.0); + expect($scope.getChoiceValue(0.0)).toEqual(0.0); + + var valueOfTrue = $scope.getChoiceValue(true); + expect(valueOfTrue).toEqual(1.0); + + var valueOfFalse = $scope.getChoiceValue(false) + expect(valueOfFalse).toEqual(0.0); + + }); + }); + + it('should prepare good choice before send', function () { + // choice type text + runs(function () { + var makeChoice = {choiceType:'TEXT', choiceValue:'value of this choice'}; + var sendChoice = $scope.preSendChoice(makeChoice); + + expect(sendChoice).toEqual(makeChoice); + }); + + // choice type date + runs(function () { + var date = new Date(); + var makeChoice, sendChoice; + + makeChoice = {choiceType:'DATE', choiceValue: 'not a date'}; + sendChoice = $scope.preSendChoice(makeChoice); + + expect(sendChoice.choiceValue).toBeNull(); + expect(sendChoice.choiceType).toEqual('DATE'); + + makeChoice.choiceValue = date; + sendChoice = $scope.preSendChoice(makeChoice); + + expect(sendChoice.choiceValue).toEqual(date.getTime()); + expect(sendChoice.choiceType).toEqual('DATE'); + + }); + + // choice type image + runs(function () { + var makeChoice, sendChoice; + + makeChoice = {choiceType:'IMAGE', choiceValue:'not an image'}; + sendChoice = $scope.preSendChoice(makeChoice); + + expect(sendChoice.choiceValue).toBeNull(); + expect(sendChoice.choiceType).toEqual('IMAGE'); + + makeChoice.choiceValue = {meta:{name:'image.png', id:'shortTopiaId'}, data:'urlpicture', id:'shortTopiaId'}; + sendChoice = $scope.preSendChoice(makeChoice); + + expect(sendChoice.choiceValue).toEqual('shortTopiaId'); + expect(sendChoice.choiceType).toEqual('IMAGE'); + }); + }); + + it('should good receive choice', function () { + // choice type text + runs(function () { + var makeChoice = {choiceType:'TEXT', choiceValue:'value of this choice'}; + var receiveChoice = $scope.postReceiveChoice(makeChoice); + + expect(receiveChoice).toEqual(makeChoice); + }); + + // choice type date + runs(function () { + var date = new Date(1405461600000); + var makeChoice, receiveChoice; + + makeChoice = {choiceType:'DATE', choiceValue: "1405461600000"}; + receiveChoice = $scope.postReceiveChoice(makeChoice); + + expect(receiveChoice.choiceValue).toEqual(date);; + expect(receiveChoice.choiceType).toEqual('DATE'); + + }); + + // choice type image + runs(function () { + var makeChoice, receiveChoice; + + makeChoice = {choiceType:'IMAGE', choiceValue:'shortTopiaId'}; + receiveChoice = $scope.postReceiveChoice(makeChoice); + + expect(receiveChoice.choiceValue.id).toEqual('shortTopiaId'); + expect(receiveChoice.choiceValue.meta.id).toEqual('shortTopiaId'); + expect(receiveChoice.choiceValue.data).toEqual(conf.restURL+'/resources/shortTopiaId'); + expect(receiveChoice.choiceType).toEqual('IMAGE'); + }); + }); + +}); + +describe('load poll controllers', function () { + beforeEach(module('pollControllers')); + + it('should load PollCreateCtrl', inject(function($controller) { + var ctrl = $controller('PollCreateCtrl', {$scope:{}}); + expect(ctrl).toBeDefined(); + })); + + it('should load PollEditCtrl', inject(function($controller) { + var ctrl = $controller('PollEditCtrl', {$scope:{}}); + expect(ctrl).toBeDefined(); + })); + + it('should load PollVoteCtrl', inject(function($controller) { + var ctrl = $controller('PollVoteCtrl', {$scope:{}}); + expect(ctrl).toBeDefined(); + })); + + it('should load PollResultCtrl', inject(function($controller) { + var ctrl = $controller('PollResultCtrl', {$scope:{}}); + expect(ctrl).toBeDefined(); + })); + + it('should load PollCommentCtrl', inject(function($controller) { + var ctrl = $controller('PollCommentCtrl', {$scope:{}}); + expect(ctrl).toBeDefined(); + })); + + it('should load PollListCtrl', inject(function($controller) { + var ctrl = $controller('PollListCtrl', {$scope:{}}); + 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