Moved config to ngConstant to mount that from outside the container
Change-Id: I23169cdeeae9034ea97e94089dcdbca3179bbb23
diff --git a/src/app/core/footer/footer.spec.ts b/src/app/core/footer/footer.spec.ts
index 06c1044..4193bc9 100644
--- a/src/app/core/footer/footer.spec.ts
+++ b/src/app/core/footer/footer.spec.ts
@@ -3,13 +3,18 @@
import * as angular from 'angular';
import 'angular-mocks';
import {xosFooter} from './footer';
-import {StyleConfig} from '../../config/style.config';
+
+const MockStyleConfig = {
+ projectName: 'CORD'
+};
describe('footer component', () => {
beforeEach(() => {
angular
.module('xosFooter', ['app/core/footer/footer.html'])
- .component('xosFooter', xosFooter);
+ .component('xosFooter', xosFooter)
+ .constant('StyleConfig', MockStyleConfig);
+
angular.mock.module('xosFooter');
});
@@ -17,6 +22,6 @@
const element = $compile('<xos-footer></xos-footer>')($rootScope);
$rootScope.$digest();
const footer = element.find('a');
- expect(footer.html().trim()).toEqual(`${StyleConfig.projectName} Team`);
+ expect(footer.html().trim()).toEqual(`${MockStyleConfig.projectName} Team`);
}));
});
diff --git a/src/app/core/footer/footer.ts b/src/app/core/footer/footer.ts
index 77a223b..e5fbe3f 100644
--- a/src/app/core/footer/footer.ts
+++ b/src/app/core/footer/footer.ts
@@ -1,11 +1,15 @@
-import {StyleConfig} from '../../config/style.config';
-
+import {IXosStyleConfig} from '../../../index';
class FooterCtrl {
+
+ static $inject = ['StyleConfig'];
+
public brand: string;
/** @ngInject */
- constructor() {
- this.brand = StyleConfig.projectName;
+ constructor(
+ private StyleConfig: IXosStyleConfig
+ ) {
+ this.brand = this.StyleConfig.projectName;
}
}
diff --git a/src/app/core/header/header.spec.ts b/src/app/core/header/header.spec.ts
index 864c5a4..62fa368 100644
--- a/src/app/core/header/header.spec.ts
+++ b/src/app/core/header/header.spec.ts
@@ -51,7 +51,11 @@
.value('toastr', MockToastr)
.value('toastrConfig', MockToastrConfig)
.value('AuthService', MockAuth)
- .value('NavigationService', {});
+ .value('NavigationService', {})
+ .value('StyleConfig', {
+ logo: 'cord-logo.png',
+ });
+
angular.mock.module('xosHeader');
});
diff --git a/src/app/core/header/header.ts b/src/app/core/header/header.ts
index 88562ea..0a98494 100644
--- a/src/app/core/header/header.ts
+++ b/src/app/core/header/header.ts
@@ -1,5 +1,4 @@
import './header.scss';
-import {StyleConfig} from '../../config/style.config';
import {IWSEvent} from '../../datasources/websocket/global';
import {IStoreService} from '../../datasources/stores/synchronizer.store';
import {IXosAuthService} from '../../datasources/rest/auth.rest';
@@ -7,13 +6,14 @@
import {IStateService} from 'angular-ui-router';
import * as _ from 'lodash';
import * as $ from 'jquery';
+import {IXosStyleConfig} from '../../../index';
export interface INotification extends IWSEvent {
viewed?: boolean;
}
class HeaderController {
- static $inject = ['$scope', '$rootScope', '$state', 'AuthService', 'SynchronizerStore', 'toastr', 'toastrConfig', 'NavigationService'];
+ static $inject = ['$scope', '$rootScope', '$state', 'AuthService', 'SynchronizerStore', 'toastr', 'toastrConfig', 'NavigationService', 'StyleConfig'];
public notifications: INotification[] = [];
public newNotifications: INotification[] = [];
public version: string;
@@ -30,7 +30,8 @@
private syncStore: IStoreService,
private toastr: ng.toastr.IToastrService,
private toastrConfig: ng.toastr.IToastrConfig,
- private NavigationService: IXosNavigationService
+ private NavigationService: IXosNavigationService,
+ private StyleConfig: IXosStyleConfig
) {
this.version = require('../../../../package.json').version;
angular.extend(this.toastrConfig, {
@@ -107,7 +108,7 @@
}
public getLogo(): string {
- return require(`../../images/brand/${StyleConfig.logo}`);
+ return require(`../../images/brand/${this.StyleConfig.logo}`);
}
// TODO display a list of notification in the template (if it make sense)
diff --git a/src/app/core/login/login.ts b/src/app/core/login/login.ts
index ac0da82..2dcabe9 100644
--- a/src/app/core/login/login.ts
+++ b/src/app/core/login/login.ts
@@ -1,27 +1,28 @@
import {AuthService} from '../../datasources/rest/auth.rest';
-import {StyleConfig} from '../../config/style.config';
import './login.scss';
import {IXosModelSetupService} from '../services/helpers/model-setup.helpers';
+import {IXosStyleConfig} from '../../../index';
class LoginCtrl {
- static $inject = ['AuthService', '$state', 'ModelSetup'];
+ static $inject = ['AuthService', '$state', 'ModelSetup', 'StyleConfig'];
public loginStyle: any;
public img: string;
/** @ngInject */
constructor(
private authService: AuthService,
private $state: angular.ui.IStateService,
- private ModelSetup: IXosModelSetupService
+ private ModelSetup: IXosModelSetupService,
+ private StyleConfig: IXosStyleConfig
) {
if (this.authService.isAuthenticated()) {
this.$state.go('xos.dashboard');
}
- this.img = this.getImg(StyleConfig.background);
+ this.img = this.getImg(this.StyleConfig.background);
this.loginStyle = {
- 'background-image': `url('${this.getImg(StyleConfig.background)}')`
+ 'background-image': `url('${this.getImg(this.StyleConfig.background)}')`
};
}
diff --git a/src/app/core/nav/nav.spec.ts b/src/app/core/nav/nav.spec.ts
index 28cd3e1..fafec7d 100644
--- a/src/app/core/nav/nav.spec.ts
+++ b/src/app/core/nav/nav.spec.ts
@@ -30,7 +30,8 @@
.module('xosNav', ['app/core/nav/nav.html', 'ui.router'])
.component('xosNav', xosNav)
.service('NavigationService', NavigationService)
- .value('AuthService', AuthMock);
+ .value('AuthService', AuthMock)
+ .value('StyleConfig', {});
angular.mock.module('xosNav');
});
diff --git a/src/app/core/nav/nav.ts b/src/app/core/nav/nav.ts
index 6c26635..c100c42 100644
--- a/src/app/core/nav/nav.ts
+++ b/src/app/core/nav/nav.ts
@@ -1,10 +1,10 @@
import './nav.scss';
import {IXosNavigationService, IXosNavigationRoute} from '../services/navigation';
-import {StyleConfig} from '../../config/style.config';
import {IXosAuthService} from '../../datasources/rest/auth.rest';
+import {IXosStyleConfig} from '../../../index';
class NavCtrl {
- static $inject = ['$scope', '$state', 'NavigationService', 'AuthService'];
+ static $inject = ['$scope', '$state', 'NavigationService', 'AuthService', 'StyleConfig'];
public routes: IXosNavigationRoute[];
public navSelected: string;
public appName: string;
@@ -14,7 +14,8 @@
private $scope: ng.IScope,
private $state: angular.ui.IStateService,
private navigationService: IXosNavigationService,
- private authService: IXosAuthService
+ private authService: IXosAuthService,
+ private StyleConfig: IXosStyleConfig
) {
// NOTE we'll need to have:
// - Base routes (defined from configuration based on BRAND)
@@ -24,8 +25,8 @@
this.$scope.$watch(() => this.navigationService.query(), (routes) => {
this.routes = routes;
});
- this.appName = StyleConfig.projectName;
- this.payoff = StyleConfig.payoff;
+ this.appName = this.StyleConfig.projectName;
+ this.payoff = this.StyleConfig.payoff;
}
activateRoute(route: IXosNavigationRoute) {
diff --git a/src/app/core/services/navigation.spec.ts b/src/app/core/services/navigation.spec.ts
index c5fb85d..62e8d3c 100644
--- a/src/app/core/services/navigation.spec.ts
+++ b/src/app/core/services/navigation.spec.ts
@@ -8,15 +8,46 @@
let defaultRoutes: IXosNavigationRoute[];
+const mockRoutes = [
+ {
+ label: 'Slices',
+ state: 'xos.core.slices'
+ },
+ {
+ label: 'Instances',
+ state: 'xos.core.instances'
+ },
+ {
+ label: 'Nodes',
+ state: 'xos.core.nodes'
+ }
+];
+
describe('The Navigation service', () => {
- beforeEach(angular.mock.module(xosCore));
+ beforeEach(() => {
+ angular.module(xosCore)
+ .value('StyleConfig', {
+ routes: mockRoutes
+ });
+
+ angular.mock.module(xosCore);
+ });
beforeEach(angular.mock.inject((
NavigationService: IXosNavigationService,
) => {
service = NavigationService;
- defaultRoutes = angular.copy(service.query());
+ defaultRoutes = [
+ {
+ label: 'Home',
+ state: 'xos.dashboard'
+ },
+ {
+ label: 'Core',
+ state: 'xos.core'
+ }
+ ].concat(mockRoutes);
}));
it('should return navigation routes', () => {
diff --git a/src/app/core/services/navigation.ts b/src/app/core/services/navigation.ts
index d184fc2..31f2b4e 100644
--- a/src/app/core/services/navigation.ts
+++ b/src/app/core/services/navigation.ts
@@ -1,7 +1,7 @@
/// <reference path="../../../../typings/index.d.ts" />
import * as _ from 'lodash';
-import {StyleConfig} from '../../config/style.config';
+import {IXosStyleConfig} from '../../../index';
export interface IXosNavigationRoute {
label: string;
@@ -18,9 +18,12 @@
}
export class NavigationService {
+ static $inject = ['StyleConfig'];
private routes: IXosNavigationRoute[];
- constructor() {
+ constructor(
+ private StyleConfig: IXosStyleConfig
+ ) {
const defaultRoutes = [
{
label: 'Home',
@@ -34,7 +37,7 @@
// adding configuration defined routes
// this.routes = StyleConfig.routes.concat(defaultRoutes).reverse();
this.routes = defaultRoutes;
- StyleConfig.routes.forEach(r => {
+ this.StyleConfig.routes.forEach(r => {
this.add(r);
});
}
diff --git a/src/app/core/services/page-title.spec.ts b/src/app/core/services/page-title.spec.ts
index 0959e57..9e6f519 100644
--- a/src/app/core/services/page-title.spec.ts
+++ b/src/app/core/services/page-title.spec.ts
@@ -4,12 +4,20 @@
import {xosCore} from '../index';
import {IXosPageTitleService} from './page-title';
import IWindowService = angular.IWindowService;
-import {StyleConfig} from '../../config/style.config';
let service: IXosPageTitleService, $window: IWindowService;
+
+const MockStyleConfig = {
+ projectName: 'CORD'
+};
+
describe('The PageTitle service', () => {
- beforeEach(angular.mock.module(xosCore));
+ beforeEach(() => {
+ angular.module(xosCore)
+ .constant('StyleConfig', MockStyleConfig);
+ angular.mock.module(xosCore);
+ });
beforeEach(angular.mock.inject((
PageTitle: IXosPageTitleService,
@@ -26,11 +34,11 @@
it('should set a page title', () => {
service.set('sample');
- expect($window.document.title).toEqual(`${StyleConfig.projectName} - sample`);
+ expect($window.document.title).toEqual(`${MockStyleConfig.projectName} - sample`);
});
it('should convert dots to >', () => {
service.set('core.sample.bread.crumb');
- expect($window.document.title).toEqual(`${StyleConfig.projectName} - core > sample > bread > crumb`);
+ expect($window.document.title).toEqual(`${MockStyleConfig.projectName} - core > sample > bread > crumb`);
});
});
diff --git a/src/app/core/services/page-title.ts b/src/app/core/services/page-title.ts
index 865149d..e3b8d42 100644
--- a/src/app/core/services/page-title.ts
+++ b/src/app/core/services/page-title.ts
@@ -1,4 +1,4 @@
-import {StyleConfig} from '../../config/style.config';
+import {IXosStyleConfig} from '../../../index';
export interface IXosPageTitleService {
get(): string;
set(title: string): void;
@@ -6,10 +6,11 @@
}
export class PageTitle {
- static $inject = ['$window', '$transitions'];
+ static $inject = ['$window', '$transitions', 'StyleConfig'];
constructor(
private $window: angular.IWindowService,
- private $transitions: any // missing definition
+ private $transitions: any, // missing definition
+ private StyleConfig: IXosStyleConfig
) {
this.$transitions.onSuccess({ to: '**' }, (transtion) => {
this.set(transtion.$to().name);
@@ -21,7 +22,7 @@
}
set(title: string) {
- this.$window.document.title = `${StyleConfig.projectName} - ${this.formatStateName(title)}`;
+ this.$window.document.title = `${this.StyleConfig.projectName} - ${this.formatStateName(title)}`;
}
private formatStateName(stateName: string): string {