Matteo Scandolo | a4a4711 | 2016-12-16 10:06:13 -0800 | [diff] [blame^] | 1 | import * as angular from 'angular'; |
| 2 | import 'angular-mocks'; |
| 3 | import 'angular-ui-router'; |
| 4 | import {xosCore} from '../index'; |
| 5 | import {IXosNavigationService, IXosNavigationRoute} from './navigation'; |
| 6 | |
| 7 | let service: IXosNavigationService; |
| 8 | |
| 9 | const defaultRoutes: IXosNavigationRoute[] = [ |
| 10 | {label: 'Home', state: 'xos.dashboard'} |
| 11 | ]; |
| 12 | |
| 13 | describe('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 | }); |