From 77801e458e96965d47f306b23e1a98b0e68e9736 Mon Sep 17 00:00:00 2001 From: Andrew Bloomgarden Date: Sun, 12 Jan 2014 15:00:47 -0800 Subject: [PATCH] Change static module name to habitrpgStatic. The way the tests are written now, the habitrpg module definition in static.js was clobbering the one in app.js. In other words, most of the tests weren't testing what they thought they were testing. --- karma.conf.js | 12 +++ public/js/app.js | 4 +- public/js/controllers/authCtrl.js | 167 +++++++++++++++--------------- public/js/static.js | 4 +- test/spec/authCtrlSpec.js | 4 +- views/static/front.jade | 2 +- 6 files changed, 103 insertions(+), 90 deletions(-) diff --git a/karma.conf.js b/karma.conf.js index a97bbe6c48..38f0411d5e 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -11,10 +11,22 @@ module.exports = function(config) { // list of files / patterns to load in the browser files: [ + 'public/bower_components/jquery/jquery.js', 'public/bower_components/angular/angular.js', 'public/bower_components/angular-loading-bar/build/loading-bar.min.js', 'public/bower_components/angular-resource/angular-resource.min.js', + 'public/bower_components/angular-sanitize/angular-sanitize.js', + 'public/bower_components/bootstrap/docs/assets/js/bootstrap.js', + 'public/bower_components/angular-bootstrap/ui-bootstrap.js', + 'public/bower_components/angular-bootstrap/ui-bootstrap-tpls.js', + 'public/bower_components/angular-ui-router/release/angular-ui-router.js', + 'public/bower_components/angular-ui/build/angular-ui.js', + 'public/bower_components/angular-ui-utils/ui-utils.min.js', + 'public/bower_components/Angular-At-Directive/src/at.js', + 'public/bower_components/Angular-At-Directive/src/caret.js', 'public/bower_components/angular-mocks/angular-mocks.js', + 'public/bower_components/angular-bindonce/bindonce.js', + 'public/bower_components/ngInfiniteScroll/ng-infinite-scroll.js', 'public/bower_components/marked/lib/marked.js', 'public/bower_components/js-emoji/emoji.js', 'public/bower_components/habitrpg-shared/dist/habitrpg-shared.js', diff --git a/public/js/app.js b/public/js/app.js index f65ace1d79..ed3d79b8e8 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -17,7 +17,7 @@ window.env.t = function(string){ window.habitrpg = angular.module('habitrpg', ['ngResource', 'ngSanitize', 'userServices', 'groupServices', 'memberServices', 'challengeServices', - 'authServices', 'notificationServices', 'guideServices', + 'authServices', 'notificationServices', 'guideServices', 'authCtrl', 'ui.bootstrap', 'ui.keypress', 'ui.router', 'chieffancypants.loadingBar', 'At', 'pasvaz.bindonce', 'infinite-scroll']) // @see https://github.com/angular-ui/ui-router/issues/110 and https://github.com/HabitRPG/habitrpg/issues/1705 @@ -231,4 +231,4 @@ window.habitrpg = angular.module('habitrpg', } }]; $httpProvider.responseInterceptors.push(interceptor); - }]) \ No newline at end of file + }]) diff --git a/public/js/controllers/authCtrl.js b/public/js/controllers/authCtrl.js index b4e195d893..58ae4bc23c 100644 --- a/public/js/controllers/authCtrl.js +++ b/public/js/controllers/authCtrl.js @@ -4,93 +4,94 @@ The authentication controller (login & facebook) */ -habitrpg.controller("AuthCtrl", ['$scope', '$rootScope', 'User', '$http', '$location', '$window','API_URL', - function($scope, $rootScope, User, $http, $location, $window, API_URL) { - var runAuth; - var showedFacebookMessage; +angular.module('authCtrl', []) + .controller("AuthCtrl", ['$scope', '$rootScope', 'User', '$http', '$location', '$window','API_URL', + function($scope, $rootScope, User, $http, $location, $window, API_URL) { + var runAuth; + var showedFacebookMessage; - $scope.useUUID = false; - $scope.toggleUUID = function() { - if (showedFacebookMessage === false) { - alert("Until we add Facebook, use your UUID and API Token to log in (found at https://habitrpg.com > Options > Settings)."); - showedFacebookMessage = true; - } - $scope.useUUID = !$scope.useUUID; - }; - - $scope.logout = function() { - localStorage.clear(); - window.location.href = '/logout'; - }; - - runAuth = function(id, token) { - User.authenticate(id, token, function(err) { - $window.location.href = '/'; - //$rootScope.modals.login = false; - }); - }; - - $scope.register = function() { - /*TODO highlight invalid inputs - we have this as a workaround for https://github.com/HabitRPG/habitrpg-mobile/issues/64 - */ - if ($scope.registrationForm.$invalid) { - return; - } - $http.post(API_URL + "/api/v2/register", $scope.registerVals).success(function(data, status, headers, config) { - runAuth(data.id, data.apiToken); - }).error(function(data, status, headers, config) { - if (status === 0) { - $window.alert("Server not currently reachable, try again later"); - } else if (!!data && !!data.err) { - $window.alert(data.err); - } else { - $window.alert("ERROR: " + status); - } - }); - }; - - function errorAlert(data, status, headers, config) { - if (status === 0) { - $window.alert("Server not currently reachable, try again later"); - } else if (!!data && !!data.err) { - $window.alert(data.err); - } else { - $window.alert("ERROR: " + status); - } - } - - $scope.auth = function() { - var data = { - username: $scope.loginUsername, - password: $scope.loginPassword + $scope.useUUID = false; + $scope.toggleUUID = function() { + if (showedFacebookMessage === false) { + alert("Until we add Facebook, use your UUID and API Token to log in (found at https://habitrpg.com > Options > Settings)."); + showedFacebookMessage = true; + } + $scope.useUUID = !$scope.useUUID; }; - if ($scope.useUUID) { - runAuth($scope.loginUsername, $scope.loginPassword); - } else { - $http.post(API_URL + "/api/v2/user/auth/local", data) - .success(function(data, status, headers, config) { - runAuth(data.id, data.token); - }).error(errorAlert); - } - }; - $scope.playButtonClick = function(){ - if (User.authenticated()) { - window.location.href = '/#/tasks'; - } else { - $('#login-modal').modal('show'); - } - } + $scope.logout = function() { + localStorage.clear(); + window.location.href = '/logout'; + }; - $scope.passwordReset = function(email){ - $http.post(API_URL + '/api/v2/user/reset-password', {email:email}) - .success(function(){ - alert('New password sent.'); - }) - .error(function(data){ - alert(data.err); + runAuth = function(id, token) { + User.authenticate(id, token, function(err) { + $window.location.href = '/'; + //$rootScope.modals.login = false; }); + }; + + $scope.register = function() { + /*TODO highlight invalid inputs + we have this as a workaround for https://github.com/HabitRPG/habitrpg-mobile/issues/64 + */ + if ($scope.registrationForm.$invalid) { + return; + } + $http.post(API_URL + "/api/v2/register", $scope.registerVals).success(function(data, status, headers, config) { + runAuth(data.id, data.apiToken); + }).error(function(data, status, headers, config) { + if (status === 0) { + $window.alert("Server not currently reachable, try again later"); + } else if (!!data && !!data.err) { + $window.alert(data.err); + } else { + $window.alert("ERROR: " + status); + } + }); + }; + + function errorAlert(data, status, headers, config) { + if (status === 0) { + $window.alert("Server not currently reachable, try again later"); + } else if (!!data && !!data.err) { + $window.alert(data.err); + } else { + $window.alert("ERROR: " + status); + } + } + + $scope.auth = function() { + var data = { + username: $scope.loginUsername, + password: $scope.loginPassword + }; + if ($scope.useUUID) { + runAuth($scope.loginUsername, $scope.loginPassword); + } else { + $http.post(API_URL + "/api/v2/user/auth/local", data) + .success(function(data, status, headers, config) { + runAuth(data.id, data.token); + }).error(errorAlert); + } + }; + + $scope.playButtonClick = function(){ + if (User.authenticated()) { + window.location.href = '/#/tasks'; + } else { + $('#login-modal').modal('show'); + } + } + + $scope.passwordReset = function(email){ + $http.post(API_URL + '/api/v2/user/reset-password', {email:email}) + .success(function(){ + alert('New password sent.'); + }) + .error(function(data){ + alert(data.err); + }); + } } - } ]); diff --git a/public/js/static.js b/public/js/static.js index fa38902ee6..ef7e61c195 100644 --- a/public/js/static.js +++ b/public/js/static.js @@ -1,7 +1,7 @@ "use strict"; -window.habitrpg = angular.module('habitrpg', ['notificationServices', 'userServices', 'chieffancypants.loadingBar']) +window.habitrpgStatic = angular.module('habitrpgStatic', ['notificationServices', 'userServices', 'chieffancypants.loadingBar', 'authCtrl']) .constant("API_URL", "") .constant("STORAGE_USER_ID", 'habitrpg-user') .constant("STORAGE_SETTINGS_ID", 'habit-mobile-settings') - .constant("MOBILE_APP", false) \ No newline at end of file + .constant("MOBILE_APP", false) diff --git a/test/spec/authCtrlSpec.js b/test/spec/authCtrlSpec.js index f36a72ea58..9c630e186c 100644 --- a/test/spec/authCtrlSpec.js +++ b/test/spec/authCtrlSpec.js @@ -2,7 +2,7 @@ describe('Auth Controller', function() { - beforeEach(module('habitrpg')); + beforeEach(module('habitrpgStatic')); describe('AuthCtrl', function(){ var scope, ctrl, user, $httpBackend, $window; @@ -35,4 +35,4 @@ describe('Auth Controller', function() { }); }); -}); \ No newline at end of file +}); diff --git a/views/static/front.jade b/views/static/front.jade index c11c381054..6683ccc6bc 100644 --- a/views/static/front.jade +++ b/views/static/front.jade @@ -7,7 +7,7 @@ block title title=env.t('titleFront') block content - div(ng-app='habitrpg') + div(ng-app='habitrpgStatic') #wrap(ng-controller='AuthCtrl') //-include ./header .jumbotron.masthead