Commit 682b0f3e75a63a2411d8871ec948e889a454e8aa

Authored by Victor Costa
1 parent 052d904e
Exists in master and in 1 other branch dev-fixes

Clean karma tests

src/app/components/navbar/navbar.directive.js
@@ -10,9 +10,7 @@ @@ -10,9 +10,7 @@
10 var directive = { 10 var directive = {
11 restrict: 'E', 11 restrict: 'E',
12 templateUrl: 'app/components/navbar/navbar.html', 12 templateUrl: 'app/components/navbar/navbar.html',
13 - scope: {  
14 - creationDate: '='  
15 - }, 13 + scope: {},
16 controller: NavbarController, 14 controller: NavbarController,
17 controllerAs: 'vm', 15 controllerAs: 'vm',
18 bindToController: true 16 bindToController: true
@@ -24,8 +22,6 @@ @@ -24,8 +22,6 @@
24 function NavbarController(moment, $modal, AuthService, Session, $scope, $state, AUTH_EVENTS) { 22 function NavbarController(moment, $modal, AuthService, Session, $scope, $state, AUTH_EVENTS) {
25 var vm = this; 23 var vm = this;
26 24
27 - // "vm.creation" is avaible by directive option "bindToController: true"  
28 - vm.relativeDate = moment(vm.creationDate).fromNow();  
29 vm.currentUser = Session.getCurrentUser(); 25 vm.currentUser = Session.getCurrentUser();
30 vm.modalInstance = null; 26 vm.modalInstance = null;
31 27
src/app/components/navbar/navbar.directive.spec.js
1 (function() { 1 (function() {
2 'use strict'; 2 'use strict';
3 3
4 - /**  
5 - * @todo Complete the test  
6 - * This example is not perfect.  
7 - * Test should check if MomentJS have been called  
8 - */  
9 describe('directive navbar', function() { 4 describe('directive navbar', function() {
10 - // var $window;  
11 var vm; 5 var vm;
12 var el; 6 var el;
13 - var timeInMs;  
14 7
15 beforeEach(module('angular')); 8 beforeEach(module('angular'));
16 - beforeEach(inject(function($compile, $rootScope) {  
17 - // spyOn(_$window_, 'moment').and.callThrough();  
18 - // $window = _$window_; 9 + beforeEach(inject(function($compile, $rootScope, $httpBackend) {
  10 + $httpBackend.when('POST','/api/v1/login_from_cookie').respond({});
19 11
20 - timeInMs = new Date();  
21 - timeInMs = timeInMs.setHours(timeInMs.getHours() - 24);  
22 -  
23 - el = angular.element('<acme-navbar creation-date="' + timeInMs + '"></acme-navbar>'); 12 + el = angular.element('<acme-navbar></acme-navbar>');
24 13
25 $compile(el)($rootScope.$new()); 14 $compile(el)($rootScope.$new());
26 $rootScope.$digest(); 15 $rootScope.$digest();
27 vm = el.isolateScope().vm; 16 vm = el.isolateScope().vm;
28 - // ctrl = el.controller('acmeNavbar');  
29 })); 17 }));
30 18
31 it('should be compiled', function() { 19 it('should be compiled', function() {
@@ -34,17 +22,8 @@ @@ -34,17 +22,8 @@
34 22
35 it('should have isolate scope object with instanciate members', function() { 23 it('should have isolate scope object with instanciate members', function() {
36 expect(vm).toEqual(jasmine.any(Object)); 24 expect(vm).toEqual(jasmine.any(Object));
37 -  
38 - expect(vm.creationDate).toEqual(jasmine.any(Number));  
39 - expect(vm.creationDate).toEqual(timeInMs);  
40 -  
41 - expect(vm.relativeDate).toEqual(jasmine.any(String));  
42 - expect(vm.relativeDate).toEqual('a day ago'); 25 + expect(vm.currentUser).toEqual(undefined);
43 }); 26 });
44 27
45 - // it('should call Moment', function() {  
46 - // console.log($window.moment)  
47 - // expect($window.moment).toHaveBeenCalled();  
48 - // });  
49 }); 28 });
50 })(); 29 })();
src/app/components/noosfero/profile-image/profile-image.directive.js
@@ -24,7 +24,7 @@ @@ -24,7 +24,7 @@
24 function ProfileImageController() { 24 function ProfileImageController() {
25 var vm = this; 25 var vm = this;
26 vm.defaultIcon = 'fa-users'; 26 vm.defaultIcon = 'fa-users';
27 - if(vm.profile.type==='Person') vm.defaultIcon = 'fa-user'; 27 + if(vm.profile && vm.profile.type==='Person') vm.defaultIcon = 'fa-user';
28 } 28 }
29 } 29 }
30 30
src/app/profile/profile.controller.spec.js
@@ -3,36 +3,10 @@ @@ -3,36 +3,10 @@
3 3
4 describe('controllers', function(){ 4 describe('controllers', function(){
5 var vm; 5 var vm;
6 - var $timeout;  
7 - var toastr;  
8 6
9 beforeEach(module('angular')); 7 beforeEach(module('angular'));
10 - beforeEach(inject(function(_$controller_, _$timeout_, _toastr_) {  
11 - spyOn(_toastr_, 'info').and.callThrough();  
12 - 8 + beforeEach(inject(function(_$controller_) {
13 vm = _$controller_('MainController'); 9 vm = _$controller_('MainController');
14 - $timeout = _$timeout_;  
15 - toastr = _toastr_;  
16 })); 10 }));
17 -  
18 - it('should have a timestamp creation date', function() {  
19 - expect(vm.creationDate).toEqual(jasmine.any(Number));  
20 - });  
21 -  
22 - it('should define animate class after delaying timeout ', function() {  
23 - $timeout.flush();  
24 - expect(vm.classAnimation).toEqual('rubberBand');  
25 - });  
26 -  
27 - it('should show a Toastr info and stop animation when invoke showToastr()', function() {  
28 - vm.showToastr();  
29 - expect(toastr.info).toHaveBeenCalled();  
30 - expect(vm.classAnimation).toEqual('');  
31 - });  
32 -  
33 - it('should define more than 5 awesome things', function() {  
34 - expect(angular.isArray(vm.awesomeThings)).toBeTruthy();  
35 - expect(vm.awesomeThings.length === 5).toBeTruthy();  
36 - });  
37 }); 11 });
38 })(); 12 })();