Increase test coverage: Add unit tests to the login module part 1 13/21813/2
authorMaxime Millette-Coulombe <mmcoulombe@inocybe.com>
Wed, 3 Jun 2015 18:53:21 +0000 (14:53 -0400)
committerMaxime Millette-Coulombe <mmcoulombe@inocybe.com>
Wed, 3 Jun 2015 19:17:33 +0000 (19:17 +0000)
I found that some dependencies was obtained from a parent module.
Those dependencies were also not used.

Change-Id: Ia4bc1b39ff3871d1bfbc5178150c9b93bc91190e
Signed-off-by: Maxime Millette-Coulombe <mmcoulombe@inocybe.com>
modules/common-login-resources/src/main/resources/login/login.controller.js
modules/common-login-resources/src/main/resources/login/login.module.js
modules/common-login-resources/src/main/resources/login/login.spec.js [new file with mode: 0644]

index 4260ee225449d8a83a5bdf03bfefef316360072a..250d238010d8c8616b3ebb5fbe536f33d90d030a 100644 (file)
@@ -8,7 +8,7 @@
 
 define(['common/login/login.module', 'common/authentification/auth.services'], function(login) {
 
-  login.register.controller('LoginCtrl', function ($cookieStore, $scope, $http, $window, Auth, $location) {
+  login.register.controller('LoginCtrl', function ($scope, $http, $window, Auth, $location) {
         // default values
         $scope.login = {};
         $scope.login.username = "";
index b9d1e01e59bc314d8a47e262cb20bb02e64f065b..06b65c17843e1e078f81d47e1f64087dec8cccf5 100644 (file)
@@ -7,9 +7,10 @@
  */
 
 define(['angularAMD', 'jquery', 'common/authentification/auth.services', 'ocLazyLoad'], function(ng, $) {
-  var login = angular.module('app.common.login', ['ngCookies', 'app.common.auth', 'ui.router.state']);
+  var login = angular.module('app.common.login', ['app.common.auth', 'ui.router.state']);
+  login.register = login;
 
-  login.config(function($stateProvider, $compileProvider, $controllerProvider, $provide, $httpProvider, $translateProvider) {
+  login.config(function($stateProvider, $compileProvider, $controllerProvider, $provide, $httpProvider) {
 
     login.register = {
       controller : $controllerProvider.register,
diff --git a/modules/common-login-resources/src/main/resources/login/login.spec.js b/modules/common-login-resources/src/main/resources/login/login.spec.js
new file mode 100644 (file)
index 0000000..23ab183
--- /dev/null
@@ -0,0 +1,24 @@
+define(['common/login/login.controller'], function() {
+  describe('Login Module', function() {
+    var scope, state, controller, AuthMock;
+
+    beforeEach(module('ui.router'));
+    beforeEach(module('app.common.login', function($provide) {
+      AuthMock = jasmine.createSpyObj('AuthMock', ['isAuthed']);
+      $provide.value('Auth', AuthMock);
+    }));
+
+    beforeEach(inject( function($rootScope, $controller, $state) {
+      scope = $rootScope.$new();
+      controller = $controller;
+      state = $state;
+    }));
+
+    it('Should load the login state', function() {
+      var stateName = 'login';
+
+      controller('LoginCtrl', {$scope: scope, $state: state});
+      expect(state.href(stateName, {})).toBe('#/login');
+    });
+  });
+});