1 define(['common/navigation/navigation.module', 'angular-ui-router',], function () {
2 describe('Navigation Module', function () {
3 var scope, NavHelperMock, EventMock, controller;
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;
24 getMenu: function () {
35 stopPropagation: function () {
38 preventDefault: function () {
45 it('Should have receive all menu items', function () {
46 spyOn(NavHelperMock, 'getMenu').andCallThrough();
47 controller('NavCtrl', {
49 NavHelper: NavHelperMock
52 expect(NavHelperMock.getMenu).toHaveBeenCalled();
53 expect(scope.navList).toBeDefined();
56 it('Should have create utility methods to show and hide submenu', function () {
57 controller('NavItemCtrl', {
59 NavHelper: NavHelperMock
62 expect(scope.display).toEqual('none');
63 expect(scope.isOpen).toBeFalsy();
65 expect(scope.isValid).toBeDefined();
66 expect(scope.updateTemplate).toBeDefined();
69 it('Should look if a item exist or not', function () {
70 controller('NavItemCtrl', {
72 NavHelper: NavHelperMock
76 expect(scope.isValid(item)).toBeTruthy();
77 expect(scope.isValid(null)).toBeFalsy();
80 it('Should toggle the status of the item scope', function () {
81 spyOn(EventMock, 'stopPropagation').andCallThrough();
82 spyOn(EventMock, 'preventDefault').andCallThrough();
83 controller('NavItemCtrl', {
85 NavHelper: NavHelperMock
88 var initOpen = scope.isOpen;
89 var initDisplay = scope.display;
91 scope.updateTemplate(EventMock, {});
92 expect(scope.isOpen).not.toEqual(initOpen);
93 expect(scope.display).not.toEqual(initDisplay);
95 scope.updateTemplate(EventMock, {});
96 expect(scope.isOpen).toEqual(initOpen);
97 expect(scope.display).toEqual(initDisplay);
99 expect(EventMock.stopPropagation.calls.length).toEqual(2);
100 expect(EventMock.preventDefault.calls.length).toEqual(2);