1 define(['common/navigation/navigation.controller'], function() {
2 describe('Navigation Module', function(){
3 var scope, NavHelperMock, EventMock, controller, NavHelperProviderMock;
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();
14 $provide.provider('NavHelper', NavHelperProvider);
17 beforeEach(module('app.common.nav'));
19 beforeEach(inject(function($rootScope, $controller){
20 scope = $rootScope.$new();
21 controller = $controller;
35 stopPropagation: function() {
38 preventDefault: function() {
45 it('Should have receive all menu items', function() {
46 spyOn(NavHelperMock, 'getMenu').andCallThrough();
47 controller('NavCtrl', {$scope: scope, NavHelper:NavHelperMock });
49 expect(NavHelperMock.getMenu).toHaveBeenCalled();
50 expect(scope.navList).toBeDefined();
53 it('Should have create utility methods to show and hide submenu', function() {
54 controller('navItemCtrl', {$scope: scope, NavHelper:NavHelperMock });
56 expect(scope.display).toEqual('none');
57 expect(scope.isOpen).toBeFalsy();
59 expect(scope.isValid).toBeDefined();
60 expect(scope.updateTemplate).toBeDefined();
63 it('Should look if a item exist or not', function(){
64 controller('navItemCtrl', {$scope: scope, NavHelper:NavHelperMock });
67 expect(scope.isValid(item)).toBeTruthy();
68 expect(scope.isValid(null)).toBeFalsy();
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 });
76 var initOpen = scope.isOpen;
77 var initDisplay = scope.display;
79 scope.updateTemplate(EventMock, { });
80 expect(scope.isOpen).not.toEqual(initOpen);
81 expect(scope.display).not.toEqual(initDisplay);
83 scope.updateTemplate(EventMock, { });
84 expect(scope.isOpen).toEqual(initOpen);
85 expect(scope.display).toEqual(initDisplay);
87 expect(EventMock.stopPropagation.calls.length).toEqual(2);
88 expect(EventMock.preventDefault.calls.length).toEqual(2);