Merge "Increase test coverage: Add unit tests to the login module part 1"
[dlux.git] / modules / common-navigation-resources / src / main / resources / navigation / navigation.spec.js
1 define(['common/navigation/navigation.controller'], function() {
2   describe('Navigation Module', function(){
3     var scope, NavHelperMock, EventMock, controller, NavHelperProviderMock;
4
5     beforeEach(angular.mock.module('ui.router'));
6     beforeEach(module('app.core', function($provide) {
7       function NavHelperProvider() {
8         this.addToView = function(url) {};
9         this.addControllerUrl = function(url) {};
10         this.$get =  function NavHelperFactory() {
11           return new NavHelperProvider();
12         };
13       }
14       $provide.provider('NavHelper', NavHelperProvider);
15     }));
16
17     beforeEach(module('app.common.nav'));
18
19     beforeEach(inject(function($rootScope, $controller){
20       scope = $rootScope.$new();
21       controller = $controller;
22
23       NavHelperMock = {
24         getMenu: function() {
25           return {
26             "id" : "",
27             "title" : "",
28             "active" : "",
29             "submenu" : ""
30           };
31         }
32       };
33
34       EventMock = {
35         stopPropagation: function() {
36           return null;
37         },
38         preventDefault: function() {
39           return null;
40         }
41       };
42
43     }));
44
45     it('Should have receive all menu items', function() {
46       spyOn(NavHelperMock, 'getMenu').andCallThrough();
47       controller('NavCtrl', {$scope: scope, NavHelper:NavHelperMock });
48
49       expect(NavHelperMock.getMenu).toHaveBeenCalled();
50       expect(scope.navList).toBeDefined();
51     });
52
53     it('Should have create utility methods to show and hide submenu', function() {
54       controller('navItemCtrl', {$scope: scope, NavHelper:NavHelperMock });
55
56       expect(scope.display).toEqual('none');
57       expect(scope.isOpen).toBeFalsy();
58
59       expect(scope.isValid).toBeDefined();
60       expect(scope.updateTemplate).toBeDefined();
61     });
62
63     it('Should look if a item exist or not', function(){
64       controller('navItemCtrl', {$scope: scope, NavHelper:NavHelperMock });
65       var item = {};
66
67       expect(scope.isValid(item)).toBeTruthy();
68       expect(scope.isValid(null)).toBeFalsy();
69     });
70
71     it('Should toggle the status of the item scope', function() {
72       spyOn(EventMock, 'stopPropagation').andCallThrough();
73       spyOn(EventMock, 'preventDefault').andCallThrough();
74       controller('navItemCtrl', {$scope: scope, NavHelper:NavHelperMock });
75
76       var initOpen = scope.isOpen;
77       var initDisplay = scope.display;
78
79       scope.updateTemplate(EventMock, { });
80       expect(scope.isOpen).not.toEqual(initOpen);
81       expect(scope.display).not.toEqual(initDisplay);
82
83       scope.updateTemplate(EventMock, { });
84       expect(scope.isOpen).toEqual(initOpen);
85       expect(scope.display).toEqual(initDisplay);
86
87       expect(EventMock.stopPropagation.calls.length).toEqual(2);
88       expect(EventMock.preventDefault.calls.length).toEqual(2);
89     });
90   });
91 });