Matteo Scandolo | e0d71ea | 2016-12-19 11:56:12 -0800 | [diff] [blame] | 1 | /// <reference path="../../../../typings/index.d.ts" /> |
| 2 | |
| 3 | import * as $ from 'jquery'; |
| 4 | import 'jasmine-jquery'; |
| 5 | import * as angular from 'angular'; |
| 6 | import 'angular-mocks'; |
| 7 | import {IXosNavigationRoute} from '../services/navigation'; |
| 8 | import {xosNav} from './nav'; |
| 9 | |
| 10 | let element, scope: angular.IRootScopeService, compile: ng.ICompileService, isolatedScope; |
| 11 | |
| 12 | let baseRoutes: IXosNavigationRoute[] = [ |
| 13 | {label: 'Home', state: 'xos'}, |
| 14 | {label: 'Core', state: 'xos.core'} |
| 15 | ]; |
| 16 | |
| 17 | const NavigationService = function(){ |
| 18 | this.query = () => baseRoutes; |
| 19 | }; |
| 20 | |
| 21 | describe('Nav component', () => { |
| 22 | beforeEach(() => { |
| 23 | angular |
| 24 | .module('xosNav', ['app/core/nav/nav.html', 'ui.router']) |
| 25 | .component('xosNav', xosNav) |
| 26 | .service('NavigationService', NavigationService); |
| 27 | angular.mock.module('xosNav'); |
| 28 | }); |
| 29 | |
| 30 | beforeEach(angular.mock.inject(($rootScope: ng.IRootScopeService, $compile: ng.ICompileService) => { |
| 31 | scope = $rootScope; |
| 32 | compile = $compile; |
| 33 | element = $compile('<xos-nav></xos-nav>')($rootScope); |
| 34 | $rootScope.$digest(); |
| 35 | isolatedScope = element.isolateScope(); |
| 36 | |
| 37 | // clear routes |
| 38 | isolatedScope.routes = []; |
| 39 | })); |
| 40 | |
| 41 | it('should render a list of routes', () => { |
| 42 | const routes = $('.nav ul li', element); |
| 43 | expect(routes.length).toBe(2); |
| 44 | }); |
| 45 | |
| 46 | it('should render child routes', () => { |
| 47 | baseRoutes = [ |
| 48 | {label: 'Home', state: 'xos'}, |
| 49 | {label: 'Core', state: 'xos.core', children: [ |
| 50 | {label: 'Slices', state: 'xos.core.slices', parent: 'xos.core'} |
| 51 | ]} |
| 52 | ]; |
| 53 | scope.$apply(); |
| 54 | const childRouteContainer = $('.child-routes', element); |
| 55 | expect(childRouteContainer.length).toBe(1); |
| 56 | }); |
| 57 | }); |