blob: c5fb85df03b1523d0a102c37863080f2f924372f [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
Matteo Scandoloe0d71ea2016-12-19 11:56:12 -08009let defaultRoutes: IXosNavigationRoute[];
Matteo Scandoloa4a47112016-12-16 10:06:13 -080010
11describe('The Navigation service', () => {
12
13 beforeEach(angular.mock.module(xosCore));
14
15 beforeEach(angular.mock.inject((
16 NavigationService: IXosNavigationService,
17 ) => {
18 service = NavigationService;
Matteo Scandoloe0d71ea2016-12-19 11:56:12 -080019 defaultRoutes = angular.copy(service.query());
Matteo Scandoloa4a47112016-12-16 10:06:13 -080020 }));
21
22 it('should return navigation routes', () => {
23 expect(service.query()).toEqual(defaultRoutes);
24 });
25
26 it('should add a route', () => {
27 const testRoutes: IXosNavigationRoute[] = [
28 {label: 'TestState', state: 'xos.test'},
29 {label: 'TestUrl', url: 'test'}
30 ];
31 service.add(testRoutes[0]);
32 service.add(testRoutes[1]);
Matteo Scandoloe0d71ea2016-12-19 11:56:12 -080033 const serviceRoutes = service.query();
34 expect(serviceRoutes).toEqual(defaultRoutes.concat(testRoutes));
35 });
36
37 it('should add a child route', () => {
38 const testRoute: IXosNavigationRoute = {
39 label: 'TestState', state: 'xos.test', parent: 'xos.core'
40 };
41 service.add(testRoute);
42 defaultRoutes[1].children = [testRoute];
43 expect(service.query()).toEqual(defaultRoutes);
Matteo Scandoloa4a47112016-12-16 10:06:13 -080044 });
45
46 it('should not add route that have both url and state', () => {
47 function wrapper() {
48 service.add({
49 label: 'Fail',
50 url: 'f',
51 state: 'f'
52 });
53 }
54 expect(wrapper).toThrowError('[XosNavigation] You can\'t provide both state and url');
55 });
56});