blob: 6a70f4c5a62d1a9947fc176e12f63549188bf842 [file] [log] [blame]
Matteo Scandoloe0d71ea2016-12-19 11:56:12 -08001/// <reference path="../../../../typings/index.d.ts" />
2
3import * as $ from 'jquery';
4import 'jasmine-jquery';
5import * as angular from 'angular';
6import 'angular-mocks';
7import {IXosNavigationRoute} from '../services/navigation';
8import {xosNav} from './nav';
9
10let element, scope: angular.IRootScopeService, compile: ng.ICompileService, isolatedScope;
11
12let baseRoutes: IXosNavigationRoute[] = [
13 {label: 'Home', state: 'xos'},
14 {label: 'Core', state: 'xos.core'}
15];
16
17const NavigationService = function(){
18 this.query = () => baseRoutes;
19};
20
21describe('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', () => {
Matteo Scandolo266907e2016-12-20 13:41:42 -080042 const routes = $('.nav li:not(.nav-info)', element);
Matteo Scandoloe0d71ea2016-12-19 11:56:12 -080043 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();
Matteo Scandolo266907e2016-12-20 13:41:42 -080054 const childRouteContainer = $('.nav-second li', element);
Matteo Scandoloe0d71ea2016-12-19 11:56:12 -080055 expect(childRouteContainer.length).toBe(1);
56 });
57});