Added tests
Change-Id: I493675212f4b1548b32a6d92ce3664d184bc0e04
diff --git a/src/app/core/services/navigation.spec.ts b/src/app/core/services/navigation.spec.ts
new file mode 100644
index 0000000..1096ec7
--- /dev/null
+++ b/src/app/core/services/navigation.spec.ts
@@ -0,0 +1,47 @@
+import * as angular from 'angular';
+import 'angular-mocks';
+import 'angular-ui-router';
+import {xosCore} from '../index';
+import {IXosNavigationService, IXosNavigationRoute} from './navigation';
+
+let service: IXosNavigationService;
+
+const defaultRoutes: IXosNavigationRoute[] = [
+ {label: 'Home', state: 'xos.dashboard'}
+];
+
+describe('The Navigation service', () => {
+
+ beforeEach(angular.mock.module(xosCore));
+
+ beforeEach(angular.mock.inject((
+ NavigationService: IXosNavigationService,
+ ) => {
+ service = NavigationService;
+ }));
+
+ it('should return navigation routes', () => {
+ expect(service.query()).toEqual(defaultRoutes);
+ });
+
+ it('should add a route', () => {
+ const testRoutes: IXosNavigationRoute[] = [
+ {label: 'TestState', state: 'xos.test'},
+ {label: 'TestUrl', url: 'test'}
+ ];
+ service.add(testRoutes[0]);
+ service.add(testRoutes[1]);
+ expect(service.query()).toEqual(defaultRoutes.concat(testRoutes));
+ });
+
+ it('should not add route that have both url and state', () => {
+ function wrapper() {
+ service.add({
+ label: 'Fail',
+ url: 'f',
+ state: 'f'
+ });
+ }
+ expect(wrapper).toThrowError('[XosNavigation] You can\'t provide both state and url');
+ });
+});
diff --git a/src/app/core/services/navigation.ts b/src/app/core/services/navigation.ts
index 8cb3b66..04eb575 100644
--- a/src/app/core/services/navigation.ts
+++ b/src/app/core/services/navigation.ts
@@ -26,6 +26,9 @@
}
add(route: IXosNavigationRoute) {
+ if (angular.isDefined(route.state) && angular.isDefined(route.url)) {
+ throw new Error('[XosNavigation] You can\'t provide both state and url');
+ }
this.routes.push(route);
}
}
diff --git a/src/app/core/services/page-title.spec.ts b/src/app/core/services/page-title.spec.ts
new file mode 100644
index 0000000..4ff2be6
--- /dev/null
+++ b/src/app/core/services/page-title.spec.ts
@@ -0,0 +1,31 @@
+import * as angular from 'angular';
+import 'angular-mocks';
+import 'angular-ui-router';
+import {xosCore} from '../index';
+import {IXosPageTitleService} from './page-title';
+import IWindowService = angular.IWindowService;
+import {StyleConfig} from '../../config/style.config';
+
+let service: IXosPageTitleService, $window: IWindowService;
+describe('The PageTitle service', () => {
+
+ beforeEach(angular.mock.module(xosCore));
+
+ beforeEach(angular.mock.inject((
+ PageTitle: IXosPageTitleService,
+ _$window_: IWindowService
+ ) => {
+ service = PageTitle;
+ $window = _$window_;
+ }));
+
+ it('should get the page title', () => {
+ $window.document.title = 'test';
+ expect(service.get()).toEqual('test');
+ });
+
+ it('should set a page title', () => {
+ service.set('sample');
+ expect($window.document.title).toEqual(`${StyleConfig.projectName} - sample`);
+ });
+});
diff --git a/src/app/core/services/page-title.ts b/src/app/core/services/page-title.ts
index 6f7e0c3..fb1e5a7 100644
--- a/src/app/core/services/page-title.ts
+++ b/src/app/core/services/page-title.ts
@@ -11,7 +11,6 @@
private $window: angular.IWindowService,
private $transitions: any // missing definition
) {
- console.log('page title');
this.$transitions.onSuccess({ to: '**' }, (transtion) => {
this.set(this.formatStateName(transtion.$to().name));
});
diff --git a/src/app/core/services/runtime-states.spec.ts b/src/app/core/services/runtime-states.spec.ts
new file mode 100644
index 0000000..5dd44db
--- /dev/null
+++ b/src/app/core/services/runtime-states.spec.ts
@@ -0,0 +1,30 @@
+import * as angular from 'angular';
+import 'angular-mocks';
+import 'angular-ui-router';
+import {xosCore} from '../index';
+import {IRuntimeStatesService} from './runtime-states';
+
+let service: IRuntimeStatesService, $state: ng.ui.IStateService;
+
+describe('The Navigation service', () => {
+
+ beforeEach(angular.mock.module(xosCore));
+
+ beforeEach(angular.mock.inject((
+ RuntimeStates: IRuntimeStatesService,
+ _$state_: ng.ui.IStateService
+ ) => {
+ service = RuntimeStates;
+ $state = _$state_;
+ }));
+
+ it('should add a state', () => {
+ service.addState('testState', {
+ url: 'test-state',
+ template: 'test-state'
+ });
+
+ expect($state.get('testState').url).toEqual('test-state');
+ expect($state.get('testState').template).toEqual('test-state');
+ });
+});