blob: 1096ec771bf9242464a2bb88afd84a83cd56d4c3 [file] [log] [blame]
Matteo Scandoloa4a47112016-12-16 10:06:13 -08001import * as angular from 'angular';
2import 'angular-mocks';
3import 'angular-ui-router';
4import {xosCore} from '../index';
5import {IXosNavigationService, IXosNavigationRoute} from './navigation';
6
7let service: IXosNavigationService;
8
9const defaultRoutes: IXosNavigationRoute[] = [
10 {label: 'Home', state: 'xos.dashboard'}
11];
12
13describe('The Navigation service', () => {
14
15 beforeEach(angular.mock.module(xosCore));
16
17 beforeEach(angular.mock.inject((
18 NavigationService: IXosNavigationService,
19 ) => {
20 service = NavigationService;
21 }));
22
23 it('should return navigation routes', () => {
24 expect(service.query()).toEqual(defaultRoutes);
25 });
26
27 it('should add a route', () => {
28 const testRoutes: IXosNavigationRoute[] = [
29 {label: 'TestState', state: 'xos.test'},
30 {label: 'TestUrl', url: 'test'}
31 ];
32 service.add(testRoutes[0]);
33 service.add(testRoutes[1]);
34 expect(service.query()).toEqual(defaultRoutes.concat(testRoutes));
35 });
36
37 it('should not add route that have both url and state', () => {
38 function wrapper() {
39 service.add({
40 label: 'Fail',
41 url: 'f',
42 state: 'f'
43 });
44 }
45 expect(wrapper).toThrowError('[XosNavigation] You can\'t provide both state and url');
46 });
47});