mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[ADF-1544] app config file management refactoring (#2331)
* application configuration service refactoring * fix demo shell * remove logging to console
This commit is contained in:
committed by
Eugenio Romano
parent
d9bd59833c
commit
e96f6aa481
@@ -70,18 +70,11 @@ import {
|
||||
WebscriptComponent
|
||||
} from './components/index';
|
||||
|
||||
let appConfigFile = 'app.config-dev.json';
|
||||
if (process.env.ENV === 'production') {
|
||||
appConfigFile = 'app.config-prod.json';
|
||||
}
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
BrowserModule,
|
||||
routing,
|
||||
CoreModule.forRoot({
|
||||
appConfigFile: appConfigFile
|
||||
}),
|
||||
CoreModule,
|
||||
MaterialModule,
|
||||
LoginModule.forRoot(),
|
||||
SearchModule.forRoot(),
|
||||
|
@@ -21,7 +21,7 @@ import { AlfrescoAuthenticationService, AppConfigService, BpmProductVersionModel
|
||||
import { ObjectDataTableAdapter } from 'ng2-alfresco-datatable';
|
||||
|
||||
@Component({
|
||||
selector: 'about-page',
|
||||
selector: 'adf-about-page',
|
||||
templateUrl: './about.component.html',
|
||||
styleUrls: ['./about.component.css']
|
||||
})
|
||||
@@ -30,7 +30,7 @@ export class AboutComponent implements OnInit {
|
||||
data: ObjectDataTableAdapter;
|
||||
githubUrlCommitAlpha: string = 'https://github.com/Alfresco/alfresco-ng2-components/commits/';
|
||||
|
||||
configFile: string = '';
|
||||
configFile: string = 'app.config.json';
|
||||
ecmHost: string = '';
|
||||
bpmHost: string = '';
|
||||
|
||||
@@ -85,7 +85,6 @@ export class AboutComponent implements OnInit {
|
||||
]);
|
||||
});
|
||||
|
||||
this.configFile = this.appConfig.configFile;
|
||||
this.ecmHost = this.appConfig.get<string>('ecmHost');
|
||||
this.bpmHost = this.appConfig.get<string>('bpmHost');
|
||||
}
|
||||
|
@@ -98,12 +98,6 @@ module.exports = {
|
||||
from: '**/*.json',
|
||||
to: 'resources/i18n'
|
||||
},
|
||||
{
|
||||
from: 'app.config-dev.json'
|
||||
},
|
||||
{
|
||||
from: 'app.config-prod.json'
|
||||
},
|
||||
{
|
||||
from: 'favicon-96x96.png'
|
||||
},
|
||||
|
@@ -5,7 +5,7 @@ const commonConfig = require('./webpack.common.js');
|
||||
const helpers = require('./helpers');
|
||||
const path = require('path');
|
||||
const CopyWebpackPlugin = require('copy-webpack-plugin');
|
||||
var HappyPack = require('happypack');
|
||||
const HappyPack = require('happypack');
|
||||
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
|
||||
|
||||
const alfrescoLibs = [
|
||||
@@ -131,7 +131,11 @@ module.exports = webpackMerge(commonConfig, {
|
||||
from: '**/*',
|
||||
to: `assets/${lib}/i18n/`
|
||||
}
|
||||
})
|
||||
}),
|
||||
{
|
||||
from: 'app.config-dev.json',
|
||||
to: 'app.config.json'
|
||||
}
|
||||
]),
|
||||
new CopyWebpackPlugin([
|
||||
{
|
||||
|
@@ -100,6 +100,10 @@ module.exports = webpackMerge(commonConfig, {
|
||||
context: `node_modules/ng2-alfresco-core/prebuilt-themes/`,
|
||||
from: '**/*.css',
|
||||
to: 'prebuilt-themes'
|
||||
},
|
||||
{
|
||||
from: 'app.config-prod.json',
|
||||
to: 'app.config.json'
|
||||
}
|
||||
]),
|
||||
new webpack.NoEmitOnErrorsPlugin(),
|
||||
|
@@ -18,7 +18,7 @@
|
||||
import { DebugElement } from '@angular/core';
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { ReportParametersModel } from 'ng2-activiti-diagrams';
|
||||
import { AlfrescoTranslationService, AppConfigModule, CoreModule } from 'ng2-alfresco-core';
|
||||
import { AlfrescoTranslationService, AppConfigService, CoreModule } from 'ng2-alfresco-core';
|
||||
import { Observable } from 'rxjs/Rx';
|
||||
import { AnalyticsReportListComponent } from '../components/analytics-report-list.component';
|
||||
import { AnalyticsService } from '../services/analytics.service';
|
||||
@@ -45,10 +45,7 @@ describe('AnalyticsReportListComponent', () => {
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
CoreModule.forRoot(),
|
||||
AppConfigModule.forRoot('app.config.json', {
|
||||
bpmHost: 'http://localhost:9876/bpm'
|
||||
})
|
||||
CoreModule
|
||||
],
|
||||
declarations: [
|
||||
AnalyticsReportListComponent
|
||||
@@ -66,6 +63,9 @@ describe('AnalyticsReportListComponent', () => {
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
let appConfig: AppConfigService = TestBed.get(AppConfigService);
|
||||
appConfig.config.bpmHost = 'http://localhost:9876/bpm';
|
||||
|
||||
fixture = TestBed.createComponent(AnalyticsReportListComponent);
|
||||
component = fixture.componentInstance;
|
||||
debug = fixture.debugElement;
|
||||
|
@@ -18,7 +18,7 @@
|
||||
import { DebugElement, SimpleChange } from '@angular/core';
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { ReportParametersModel } from 'ng2-activiti-diagrams';
|
||||
import { AlfrescoTranslationService, AppConfigModule, CoreModule } from 'ng2-alfresco-core';
|
||||
import { AlfrescoTranslationService, AppConfigService, CoreModule } from 'ng2-alfresco-core';
|
||||
import { Observable } from 'rxjs/Rx';
|
||||
import * as analyticParamsMock from '../assets/analyticsParamsReportComponent.mock';
|
||||
import { AnalyticsReportParametersComponent } from '../components/analytics-report-parameters.component';
|
||||
@@ -41,10 +41,7 @@ describe('AnalyticsReportParametersComponent', () => {
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
CoreModule.forRoot(),
|
||||
AppConfigModule.forRoot('app.config.json', {
|
||||
bpmHost: 'http://localhost:9876/bpm'
|
||||
}),
|
||||
CoreModule,
|
||||
MaterialModule
|
||||
],
|
||||
declarations: [
|
||||
@@ -70,6 +67,9 @@ describe('AnalyticsReportParametersComponent', () => {
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
let appConfig: AppConfigService = TestBed.get(AppConfigService);
|
||||
appConfig.config.bpmHost = 'http://localhost:9876/bpm';
|
||||
|
||||
fixture = TestBed.createComponent(AnalyticsReportParametersComponent);
|
||||
component = fixture.componentInstance;
|
||||
debug = fixture.debugElement;
|
||||
|
@@ -17,10 +17,9 @@
|
||||
|
||||
import { SimpleChange } from '@angular/core';
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { AppConfigModule, AppConfigService, CoreModule, TranslationService } from 'ng2-alfresco-core';
|
||||
import { AppConfigService, CoreModule, TranslationService } from 'ng2-alfresco-core';
|
||||
|
||||
import { Observable } from 'rxjs/Rx';
|
||||
import { AppConfigServiceMock } from '../assets/app-config.service.mock';
|
||||
import { TranslationMock } from '../assets/translation.service.mock';
|
||||
import { FilterParamsModel, FilterRepresentationModel } from '../models/filter.model';
|
||||
import { TaskListService } from '../services/tasklist.service';
|
||||
@@ -70,24 +69,23 @@ describe('TaskFiltersComponent', () => {
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
CoreModule.forRoot(),
|
||||
AppConfigModule.forRoot('app.config.json', {
|
||||
bpmHost: 'http://localhost:9876/bpm'
|
||||
})
|
||||
CoreModule
|
||||
],
|
||||
declarations: [
|
||||
TaskFiltersComponent
|
||||
],
|
||||
providers: [
|
||||
TaskListService,
|
||||
{ provide: TranslationService, useClass: TranslationMock },
|
||||
{ provide: AppConfigService, useClass: AppConfigServiceMock }
|
||||
{ provide: TranslationService, useClass: TranslationMock }
|
||||
]
|
||||
}).compileComponents();
|
||||
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
let appConfig: AppConfigService = TestBed.get(AppConfigService);
|
||||
appConfig.config.bpmHost = 'http://localhost:9876/bpm';
|
||||
|
||||
fixture = TestBed.createComponent(TaskFiltersComponent);
|
||||
component = fixture.componentInstance;
|
||||
|
||||
|
@@ -18,10 +18,9 @@
|
||||
import { SimpleChange } from '@angular/core';
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { MdProgressSpinnerModule } from '@angular/material';
|
||||
import { AppConfigModule, AppConfigService, CoreModule, TranslationService } from 'ng2-alfresco-core';
|
||||
import { AppConfigService, CoreModule, TranslationService } from 'ng2-alfresco-core';
|
||||
import { DataTableModule } from 'ng2-alfresco-datatable';
|
||||
import { DataRowEvent, ObjectDataRow, ObjectDataTableAdapter } from 'ng2-alfresco-datatable';
|
||||
import { AppConfigServiceMock } from '../assets/app-config.service.mock';
|
||||
import { TranslationMock } from '../assets/translation.service.mock';
|
||||
import { TaskListService } from '../services/tasklist.service';
|
||||
import { TaskListComponent } from './tasklist.component';
|
||||
@@ -93,10 +92,7 @@ describe('TaskListComponent', () => {
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
CoreModule.forRoot(),
|
||||
AppConfigModule.forRoot('app.config.json', {
|
||||
bpmHost: 'http://localhost:9876/bpm'
|
||||
}),
|
||||
CoreModule,
|
||||
DataTableModule,
|
||||
MdProgressSpinnerModule
|
||||
],
|
||||
@@ -105,14 +101,15 @@ describe('TaskListComponent', () => {
|
||||
],
|
||||
providers: [
|
||||
TaskListService,
|
||||
{provide: TranslationService, useClass: TranslationMock},
|
||||
{provide: AppConfigService, useClass: AppConfigServiceMock}
|
||||
{provide: TranslationService, useClass: TranslationMock}
|
||||
]
|
||||
}).compileComponents();
|
||||
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
let appConfig: AppConfigService = TestBed.get(AppConfigService);
|
||||
appConfig.config.bpmHost = 'http://localhost:9876/bpm';
|
||||
|
||||
fixture = TestBed.createComponent(TaskListComponent);
|
||||
component = fixture.componentInstance;
|
||||
|
@@ -808,22 +808,6 @@ Example of the default settings file content:
|
||||
Please note that settings above are default ones coming with the server.
|
||||
You can override the values in your custom `app.config.json` file if needed.
|
||||
|
||||
You can also change the path or name of the configuration file when importing the CoreModule in your main application.
|
||||
|
||||
```ts
|
||||
...
|
||||
@NgModule({
|
||||
imports: [
|
||||
...
|
||||
CoreModule.forRoot({
|
||||
appConfigFile: 'app.production.config.json'
|
||||
})
|
||||
],
|
||||
...
|
||||
}
|
||||
export class AppModule { }
|
||||
```
|
||||
|
||||
Below is a simple example of using the AppConfigService in practice.
|
||||
|
||||
**app.component.ts**
|
||||
@@ -849,28 +833,6 @@ export class AppComponent {
|
||||
Your custom components can also benefit from the `AppConfigService`,
|
||||
you can put an unlimited number of settings and optionally a nested JSON hierarchy.
|
||||
|
||||
#### Different configurations based on environment settings
|
||||
|
||||
The CoreModule allows you to provide custom application configuration path.
|
||||
That means you can evaluate the final file name based on conditions, for example environment settings:
|
||||
|
||||
```ts
|
||||
let appConfigFile = 'app.config-dev.json';
|
||||
if (process.env.ENV === 'production') {
|
||||
appConfigFile = 'app.config-prod.json';
|
||||
}
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
...
|
||||
CoreModule.forRoot({
|
||||
appConfigFile: appConfigFile
|
||||
}),
|
||||
...
|
||||
]
|
||||
})
|
||||
```
|
||||
|
||||
#### Variable substitution in configuration strings
|
||||
|
||||
The `AppConfigService` also supports a limited set of variable substitutions to greatly simplify certain scenarios.
|
||||
@@ -892,31 +854,6 @@ The supported variables are:
|
||||
| hostname | `location.hostname` |
|
||||
| port | `location.port` |
|
||||
|
||||
#### Unit testing
|
||||
|
||||
You can also provide custom values for the entire service.
|
||||
This might become handy when creating unit tests.
|
||||
|
||||
```ts
|
||||
describe('MyTest', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
CoreModule.forRoot(),
|
||||
AppConfigModule.forRoot('app.config.json', {
|
||||
ecmHost: 'http://localhost:9876/ecm'
|
||||
})
|
||||
]
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
```
|
||||
|
||||
In the example above custom values are applied on the top of all the values the `AppConfigService` has previously loaded.
|
||||
If there is an 'app.config.json' file loaded at unit test run time then your custom values will overwrite exiting values with the same keys if present.
|
||||
|
||||
## User Preferences Service
|
||||
|
||||
Stores preferences for components.
|
||||
|
@@ -36,8 +36,6 @@ import { DownloadZipDialogComponent } from './src/dialogs/download-zip.dialog';
|
||||
import { AlfrescoApiService } from './src/services/alfresco-api.service';
|
||||
import { AlfrescoContentService } from './src/services/alfresco-content.service';
|
||||
import { AlfrescoSettingsService } from './src/services/alfresco-settings.service';
|
||||
import { AppConfigService } from './src/services/app-config.service';
|
||||
import { InitAppConfigServiceProvider } from './src/services/app-config.service';
|
||||
import { AuthGuardBpm } from './src/services/auth-guard-bpm.service';
|
||||
import { AuthGuardEcm } from './src/services/auth-guard-ecm.service';
|
||||
import { AuthGuard } from './src/services/auth-guard.service';
|
||||
@@ -90,7 +88,6 @@ export { AuthenticationService } from './src/services/authentication.service';
|
||||
export { TranslationService, TRANSLATION_PROVIDER, TranslationProvider } from './src/services/translation.service';
|
||||
export { AlfrescoTranslateLoader } from './src/services/translate-loader.service';
|
||||
export { AppConfigService } from './src/services/app-config.service';
|
||||
export { InitAppConfigServiceProvider } from './src/services/app-config.service';
|
||||
export { ThumbnailService } from './src/services/thumbnail.service';
|
||||
export { UploadService } from './src/services/upload.service';
|
||||
export { CardViewUpdateService } from './src/services/card-view-update.service';
|
||||
@@ -279,6 +276,7 @@ export function createTranslateLoader(http: Http, logService: LogService) {
|
||||
}
|
||||
],
|
||||
exports: [
|
||||
AppConfigModule,
|
||||
BrowserAnimationsModule,
|
||||
CommonModule,
|
||||
FormsModule,
|
||||
@@ -313,16 +311,13 @@ export function createTranslateLoader(http: Http, logService: LogService) {
|
||||
]
|
||||
})
|
||||
export class CoreModule {
|
||||
/** @deprecated in 1.9.0 */
|
||||
static forRoot(opts: any = {}): ModuleWithProviders {
|
||||
|
||||
const appConfigFile = opts.appConfigFile || 'app.config.json';
|
||||
|
||||
console.log('CoreModule.forRoot is deprecated and will be removed in future versions');
|
||||
return {
|
||||
ngModule: CoreModule,
|
||||
providers: [
|
||||
...providers(),
|
||||
AppConfigService,
|
||||
InitAppConfigServiceProvider(appConfigFile)
|
||||
...providers()
|
||||
]
|
||||
};
|
||||
}
|
||||
|
@@ -20,7 +20,7 @@ import { CookieServiceMock } from './../assets/cookie.service.mock';
|
||||
import { AlfrescoApiService } from './alfresco-api.service';
|
||||
import { AlfrescoContentService } from './alfresco-content.service';
|
||||
import { AlfrescoSettingsService } from './alfresco-settings.service';
|
||||
import { AppConfigModule } from './app-config.service';
|
||||
import { AppConfigModule, AppConfigService } from './app-config.service';
|
||||
import { AuthenticationService } from './authentication.service';
|
||||
import { CookieService } from './cookie.service';
|
||||
import { LogService } from './log.service';
|
||||
@@ -72,6 +72,11 @@ describe('AlfrescoContentService', () => {
|
||||
};
|
||||
|
||||
jasmine.Ajax.install();
|
||||
|
||||
let appConfig: AppConfigService = TestBed.get(AppConfigService);
|
||||
appConfig.config = {
|
||||
ecmHost: 'http://localhost:9876/ecm'
|
||||
};
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
|
@@ -24,12 +24,12 @@ describe('AppConfigService', () => {
|
||||
|
||||
let appConfigService: AppConfigService;
|
||||
const mockResponse = {
|
||||
'ecmHost': 'http://localhost:4000/ecm',
|
||||
'bpmHost': 'http://localhost:4000/ecm',
|
||||
'application': {
|
||||
'name': 'Custom Name'
|
||||
ecmHost: 'http://localhost:4000/ecm',
|
||||
bpmHost: 'http://localhost:4000/ecm',
|
||||
application: {
|
||||
name: 'Custom Name'
|
||||
},
|
||||
'files': {
|
||||
files: {
|
||||
'excluded': ['exluded']
|
||||
}
|
||||
};
|
||||
@@ -76,27 +76,8 @@ describe('AppConfigService', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('should use default config file', () => {
|
||||
expect(appConfigService.configFile).toBeNull();
|
||||
appConfigService.load().then(() => {
|
||||
expect(appConfigService.configFile).toBe('app.config.json');
|
||||
});
|
||||
});
|
||||
|
||||
it('should take custom config file', () => {
|
||||
expect(appConfigService.configFile).toBeNull();
|
||||
|
||||
const name = 'custom.config.json';
|
||||
appConfigService.load(name).then(() => {
|
||||
expect(appConfigService.configFile).toBe(name);
|
||||
});
|
||||
});
|
||||
|
||||
it('should take excluded file list', () => {
|
||||
expect(appConfigService.configFile).toBeNull();
|
||||
|
||||
const name = 'custom.config.json';
|
||||
appConfigService.load(name).then(() => {
|
||||
appConfigService.load().then(() => {
|
||||
expect(appConfigService.get('files.excluded')[0]).toBe('exluded');
|
||||
});
|
||||
});
|
||||
|
@@ -15,20 +15,18 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { APP_INITIALIZER, Injectable, ModuleWithProviders, NgModule } from '@angular/core';
|
||||
import { APP_INITIALIZER, Injectable, NgModule } from '@angular/core';
|
||||
import { Http, HttpModule } from '@angular/http';
|
||||
import { ObjectUtils } from '../utils/object-utils';
|
||||
|
||||
@Injectable()
|
||||
export class AppConfigService {
|
||||
|
||||
private config: any = {
|
||||
'ecmHost': 'http://{hostname}:{port}/ecm',
|
||||
'bpmHost': 'http://{hostname}:{port}/bpm'
|
||||
config: any = {
|
||||
ecmHost: 'http://{hostname}:{port}/ecm',
|
||||
bpmHost: 'http://{hostname}:{port}/bpm'
|
||||
};
|
||||
|
||||
configFile: string = null;
|
||||
|
||||
constructor(private http: Http) {}
|
||||
|
||||
get<T>(key: string, defaultValue?: T): T {
|
||||
@@ -45,18 +43,14 @@ export class AppConfigService {
|
||||
return <T> result;
|
||||
}
|
||||
|
||||
load(resource: string = 'app.config.json', values?: {}): Promise<any> {
|
||||
this.configFile = resource;
|
||||
load(): Promise<any> {
|
||||
return new Promise(resolve => {
|
||||
this.config = Object.assign({}, values || {});
|
||||
this.http.get(resource).subscribe(
|
||||
this.http.get('app.config.json').subscribe(
|
||||
data => {
|
||||
this.config = Object.assign({}, this.config, data.json() || {});
|
||||
resolve(this.config);
|
||||
},
|
||||
() => {
|
||||
const errorMessage = `Error loading ${resource}`;
|
||||
console.log(errorMessage);
|
||||
resolve(this.config);
|
||||
}
|
||||
);
|
||||
@@ -75,17 +69,8 @@ export class AppConfigService {
|
||||
}
|
||||
}
|
||||
|
||||
export function InitAppConfigServiceProvider(resource: string, values?: {}): any {
|
||||
return {
|
||||
provide: APP_INITIALIZER,
|
||||
useFactory: (configService: AppConfigService) => {
|
||||
return () => configService.load(resource, values);
|
||||
},
|
||||
deps: [
|
||||
AppConfigService
|
||||
],
|
||||
multi: true
|
||||
};
|
||||
export function startupServiceFactory(configService: AppConfigService): Function {
|
||||
return () => configService.load();
|
||||
}
|
||||
|
||||
@NgModule({
|
||||
@@ -93,17 +78,15 @@ export function InitAppConfigServiceProvider(resource: string, values?: {}): any
|
||||
HttpModule
|
||||
],
|
||||
providers: [
|
||||
AppConfigService
|
||||
AppConfigService,
|
||||
{
|
||||
provide: APP_INITIALIZER,
|
||||
useFactory: startupServiceFactory,
|
||||
deps: [
|
||||
AppConfigService
|
||||
],
|
||||
multi: true
|
||||
}
|
||||
]
|
||||
})
|
||||
export class AppConfigModule {
|
||||
static forRoot(resource: string, values?: {}): ModuleWithProviders {
|
||||
return {
|
||||
ngModule: AppConfigModule,
|
||||
providers: [
|
||||
AppConfigService,
|
||||
InitAppConfigServiceProvider(resource, values)
|
||||
]
|
||||
};
|
||||
}
|
||||
}
|
||||
export class AppConfigModule {}
|
||||
|
@@ -19,7 +19,7 @@ import { async, TestBed } from '@angular/core/testing';
|
||||
import { BpmProductVersionModel, EcmProductVersionModel } from '../models/product-version.model';
|
||||
import { AlfrescoApiService } from './alfresco-api.service';
|
||||
import { AlfrescoSettingsService } from './alfresco-settings.service';
|
||||
import { AppConfigModule } from './app-config.service';
|
||||
import { AppConfigModule, AppConfigService } from './app-config.service';
|
||||
import { AuthenticationService } from './authentication.service';
|
||||
import { DiscoveryApiService } from './discovery-api.service';
|
||||
import { StorageService } from './storage.service';
|
||||
@@ -97,9 +97,7 @@ describe('Discovery Api Service', () => {
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
AppConfigModule.forRoot('app.config.json', {
|
||||
ecmHost: 'http://localhost:9876/ecm'
|
||||
})
|
||||
AppConfigModule
|
||||
],
|
||||
providers: [
|
||||
DiscoveryApiService,
|
||||
@@ -113,6 +111,10 @@ describe('Discovery Api Service', () => {
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
let appConfig: AppConfigService = TestBed.get(AppConfigService);
|
||||
appConfig.config = {
|
||||
ecmHost: 'http://localhost:9876/ecm'
|
||||
};
|
||||
service = TestBed.get(DiscoveryApiService);
|
||||
jasmine.Ajax.install();
|
||||
});
|
||||
|
@@ -1,169 +0,0 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright 2016 Alfresco Software, Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { async, inject, TestBed } from '@angular/core/testing';
|
||||
import { AlfrescoApiService } from './alfresco-api.service';
|
||||
import { AppConfigModule } from './app-config.service';
|
||||
import { SharedLinksApiService } from './shared-links-api.service';
|
||||
import { StorageService } from './storage.service';
|
||||
import { UserPreferencesService } from './user-preferences.service';
|
||||
|
||||
class TestConfig {
|
||||
service: any = null;
|
||||
setup: any = {
|
||||
rejectFindSharedLinks: false
|
||||
};
|
||||
|
||||
constructor(setup: any = {}) {
|
||||
Object.assign(this.setup, setup);
|
||||
|
||||
const { alfrescoApiServiceMock } = this;
|
||||
|
||||
const alfrescoApiServiceProvider = {
|
||||
provide: AlfrescoApiService,
|
||||
useValue: alfrescoApiServiceMock
|
||||
};
|
||||
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
AppConfigModule.forRoot('app.config.json', {
|
||||
pagination: {
|
||||
size: 20
|
||||
}
|
||||
})
|
||||
],
|
||||
providers: [
|
||||
alfrescoApiServiceProvider,
|
||||
SharedLinksApiService,
|
||||
StorageService,
|
||||
UserPreferencesService
|
||||
]
|
||||
});
|
||||
|
||||
inject([ SharedLinksApiService ], (service: SharedLinksApiService) => {
|
||||
this.service = service;
|
||||
})();
|
||||
}
|
||||
|
||||
private get alfrescoApiServiceMock(): any {
|
||||
const { setup } = this;
|
||||
|
||||
const nodePagingSample = {
|
||||
list: {
|
||||
entries: [
|
||||
{ entry: {} },
|
||||
{ entry: {} }
|
||||
],
|
||||
pagination: {}
|
||||
}
|
||||
};
|
||||
|
||||
const sharedLinksApiMock = {
|
||||
findSharedLinks: jasmine.createSpy('findSharedLinks').and.callFake(() => {
|
||||
return new Promise((resolve, reject) => {
|
||||
setup.rejectFindSharedLinks
|
||||
? reject()
|
||||
: resolve(nodePagingSample);
|
||||
});
|
||||
})
|
||||
};
|
||||
|
||||
return {
|
||||
getInstance: () => {
|
||||
return {
|
||||
core: { sharedlinksApi: sharedLinksApiMock }
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
get findSharedLinksSpy(): any {
|
||||
return this.service.sharedLinksApi.findSharedLinks;
|
||||
}
|
||||
|
||||
get findSharedLinksArgs(): any[] {
|
||||
return this.findSharedLinksSpy.calls.mostRecent().args;
|
||||
}
|
||||
}
|
||||
|
||||
describe('SharedLinks API', () => {
|
||||
describe('getSharedLinks', () => {
|
||||
describe('Provide a NodePaging', () => {
|
||||
beforeEach(() => {
|
||||
this.config = new TestConfig();
|
||||
});
|
||||
|
||||
it('provides a node paging with entries', async(() => {
|
||||
this.config.service.getSharedLinks().subscribe((paging) => {
|
||||
const { list: { entries, pagination } } = paging;
|
||||
|
||||
expect(entries).toEqual(jasmine.any(Array));
|
||||
expect(pagination).toEqual(jasmine.any(Object));
|
||||
expect(entries.length).toBe(2);
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
||||
describe('Manage query options', () => {
|
||||
beforeEach(() => {
|
||||
this.config = new TestConfig();
|
||||
|
||||
this.getCalledArgs = () => {
|
||||
return this.config.findSharedLinksArgs;
|
||||
};
|
||||
});
|
||||
|
||||
it('has default options', async(() => {
|
||||
this.config.service.getSharedLinks();
|
||||
|
||||
const [ { maxItems, skipCount } ] = this.getCalledArgs();
|
||||
|
||||
expect(maxItems).toBe(20);
|
||||
expect(skipCount).toBe(0);
|
||||
}));
|
||||
|
||||
it('combines custom and default options', async(() => {
|
||||
this.config.service.getSharedLinks({
|
||||
maxItems: 5
|
||||
});
|
||||
|
||||
const [ { maxItems, skipCount } ] = this.getCalledArgs();
|
||||
|
||||
expect(maxItems).toBe(5);
|
||||
expect(skipCount).toBe(0);
|
||||
}));
|
||||
});
|
||||
|
||||
describe('Error handling', () => {
|
||||
beforeEach(() => {
|
||||
const config = new TestConfig({
|
||||
rejectFindSharedLinks: true
|
||||
});
|
||||
|
||||
this.service = config.service;
|
||||
this.spy = spyOn(config.service, 'handleError')
|
||||
.and.callThrough();
|
||||
});
|
||||
|
||||
it('handles error on failure', async(() => {
|
||||
this.service.getSharedLinks().subscribe(() => {
|
||||
expect(this.spy).toHaveBeenCalled();
|
||||
});
|
||||
}));
|
||||
});
|
||||
});
|
||||
});
|
@@ -18,7 +18,7 @@
|
||||
import { async, TestBed } from '@angular/core/testing';
|
||||
import { AlfrescoApiService } from './alfresco-api.service';
|
||||
import { AlfrescoSettingsService } from './alfresco-settings.service';
|
||||
import { AppConfigModule } from './app-config.service';
|
||||
import { AppConfigModule, AppConfigService } from './app-config.service';
|
||||
import { AuthenticationService } from './authentication.service';
|
||||
import { SitesApiService } from './sites-api.service';
|
||||
import { StorageService } from './storage.service';
|
||||
@@ -33,12 +33,7 @@ describe('Sites service', () => {
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
AppConfigModule.forRoot('app.config.json', {
|
||||
ecmHost: 'http://localhost:9876/ecm',
|
||||
files: {
|
||||
excluded: ['.DS_Store', 'desktop.ini', '.git', '*.git']
|
||||
}
|
||||
})
|
||||
AppConfigModule
|
||||
],
|
||||
providers: [
|
||||
SitesApiService,
|
||||
@@ -52,6 +47,14 @@ describe('Sites service', () => {
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
let appConfig: AppConfigService = TestBed.get(AppConfigService);
|
||||
appConfig.config = {
|
||||
ecmHost: 'http://localhost:9876/ecm',
|
||||
files: {
|
||||
excluded: ['.DS_Store', 'desktop.ini', '.git', '*.git']
|
||||
}
|
||||
};
|
||||
|
||||
service = TestBed.get(SitesApiService);
|
||||
jasmine.Ajax.install();
|
||||
});
|
||||
|
@@ -16,11 +16,11 @@
|
||||
*/
|
||||
|
||||
import { EventEmitter } from '@angular/core';
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
import { async, TestBed } from '@angular/core/testing';
|
||||
import { FileModel, FileUploadOptions, FileUploadStatus } from '../models/file.model';
|
||||
import { AlfrescoApiService } from './alfresco-api.service';
|
||||
import { AlfrescoSettingsService } from './alfresco-settings.service';
|
||||
import { AppConfigModule } from './app-config.service';
|
||||
import { AppConfigModule, AppConfigService } from './app-config.service';
|
||||
import { AuthenticationService } from './authentication.service';
|
||||
import { StorageService } from './storage.service';
|
||||
import { UploadService } from './upload.service';
|
||||
@@ -30,15 +30,10 @@ declare let jasmine: any;
|
||||
describe('UploadService', () => {
|
||||
let service: UploadService;
|
||||
|
||||
beforeEach(() => {
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
AppConfigModule.forRoot('app.config.json', {
|
||||
ecmHost: 'http://localhost:9876/ecm',
|
||||
files: {
|
||||
excluded: ['.DS_Store', 'desktop.ini', '.git', '*.git']
|
||||
}
|
||||
})
|
||||
AppConfigModule
|
||||
],
|
||||
providers: [
|
||||
UploadService,
|
||||
@@ -47,7 +42,18 @@ describe('UploadService', () => {
|
||||
AuthenticationService,
|
||||
StorageService
|
||||
]
|
||||
});
|
||||
}).compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
let appConfig: AppConfigService = TestBed.get(AppConfigService);
|
||||
appConfig.config = {
|
||||
ecmHost: 'http://localhost:9876/ecm',
|
||||
files: {
|
||||
excluded: ['.DS_Store', 'desktop.ini', '.git', '*.git']
|
||||
}
|
||||
};
|
||||
|
||||
service = TestBed.get(UploadService);
|
||||
jasmine.Ajax.install();
|
||||
});
|
||||
|
@@ -17,7 +17,7 @@
|
||||
|
||||
import { async, TestBed } from '@angular/core/testing';
|
||||
import { AlfrescoApiService } from './alfresco-api.service';
|
||||
import { AppConfigModule } from './app-config.service';
|
||||
import { AppConfigModule, AppConfigService } from './app-config.service';
|
||||
import { StorageService } from './storage.service';
|
||||
import { UserPreferencesService } from './user-preferences.service';
|
||||
|
||||
@@ -30,11 +30,7 @@ describe('UserPreferencesService', () => {
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
AppConfigModule.forRoot('app.config.json', {
|
||||
'pagination': {
|
||||
'size': defaultPaginationSize
|
||||
}
|
||||
})
|
||||
AppConfigModule
|
||||
],
|
||||
providers: [
|
||||
AlfrescoApiService,
|
||||
@@ -45,6 +41,10 @@ describe('UserPreferencesService', () => {
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
let appConfig: AppConfigService = TestBed.get(AppConfigService);
|
||||
appConfig.config.pagination = {
|
||||
size: 10
|
||||
};
|
||||
preferences = TestBed.get(UserPreferencesService);
|
||||
storage = TestBed.get(StorageService);
|
||||
});
|
||||
|
@@ -16,7 +16,7 @@
|
||||
*/
|
||||
|
||||
import { async, TestBed } from '@angular/core/testing';
|
||||
import { AlfrescoTranslationService, AppConfigModule, CoreModule, NotificationService } from 'ng2-alfresco-core';
|
||||
import { AlfrescoTranslationService, AppConfigService, CoreModule, NotificationService } from 'ng2-alfresco-core';
|
||||
import { Observable } from 'rxjs/Rx';
|
||||
import { FileNode, FolderNode } from '../assets/document-library.model.mock';
|
||||
import { ContentActionHandler } from '../models/content-action.model';
|
||||
@@ -32,10 +32,7 @@ describe('FolderActionsService', () => {
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
CoreModule.forRoot(),
|
||||
AppConfigModule.forRoot('app.config.json', {
|
||||
ecmHost: 'http://localhost:9876/ecm'
|
||||
})
|
||||
CoreModule
|
||||
],
|
||||
providers: [
|
||||
DocumentListService,
|
||||
@@ -48,6 +45,9 @@ describe('FolderActionsService', () => {
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
let appConfig: AppConfigService = TestBed.get(AppConfigService);
|
||||
appConfig.config.ecmHost = 'http://localhost:9876/ecm';
|
||||
|
||||
service = TestBed.get(FolderActionsService);
|
||||
documentListService = TestBed.get(DocumentListService);
|
||||
});
|
||||
|
@@ -17,7 +17,7 @@
|
||||
|
||||
import { DebugElement } from '@angular/core';
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { AppConfigModule, CoreModule } from 'ng2-alfresco-core';
|
||||
import { AppConfigService, CoreModule } from 'ng2-alfresco-core';
|
||||
import { TagActionsComponent } from '../components/tag-actions.component';
|
||||
import { TagService } from '../services/tag.service';
|
||||
import { MaterialModule } from './material.module';
|
||||
@@ -35,10 +35,7 @@ describe('TagActionsComponent', () => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
MaterialModule,
|
||||
CoreModule.forRoot(),
|
||||
AppConfigModule.forRoot('app.config.json', {
|
||||
ecmHost: 'http://localhost:9876/ecm'
|
||||
})
|
||||
CoreModule
|
||||
],
|
||||
declarations: [
|
||||
TagActionsComponent
|
||||
@@ -50,6 +47,9 @@ describe('TagActionsComponent', () => {
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
let appConfig: AppConfigService = TestBed.get(AppConfigService);
|
||||
appConfig.config.ecmHost = 'http://localhost:9876/ecm';
|
||||
|
||||
fixture = TestBed.createComponent(TagActionsComponent);
|
||||
|
||||
debug = fixture.debugElement;
|
||||
|
@@ -17,7 +17,7 @@
|
||||
|
||||
import { DebugElement } from '@angular/core';
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { AppConfigModule, CoreModule } from 'ng2-alfresco-core';
|
||||
import { AppConfigService, CoreModule } from 'ng2-alfresco-core';
|
||||
import { TagService } from '../services/tag.service';
|
||||
import { TagListComponent } from './../components/tag-list.component';
|
||||
import { MaterialModule } from './material.module';
|
||||
@@ -52,10 +52,7 @@ describe('TagList', () => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
MaterialModule,
|
||||
CoreModule.forRoot(),
|
||||
AppConfigModule.forRoot('app.config.json', {
|
||||
ecmHost: 'http://localhost:9876/ecm'
|
||||
})
|
||||
CoreModule
|
||||
],
|
||||
declarations: [
|
||||
TagListComponent
|
||||
@@ -67,6 +64,9 @@ describe('TagList', () => {
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
let appConfig: AppConfigService = TestBed.get(AppConfigService);
|
||||
appConfig.config.ecmHost = 'http://localhost:9876/ecm';
|
||||
|
||||
fixture = TestBed.createComponent(TagListComponent);
|
||||
|
||||
debug = fixture.debugElement;
|
||||
|
@@ -17,7 +17,7 @@
|
||||
|
||||
import { DebugElement } from '@angular/core';
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { AppConfigModule, CoreModule } from 'ng2-alfresco-core';
|
||||
import { AppConfigService, CoreModule } from 'ng2-alfresco-core';
|
||||
import { TagNodeListComponent } from '../components/tag-node-list.component';
|
||||
import { TagService } from '../services/tag.service';
|
||||
import { MaterialModule } from './material.module';
|
||||
@@ -52,10 +52,7 @@ describe('TagNodeList', () => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
MaterialModule,
|
||||
CoreModule.forRoot(),
|
||||
AppConfigModule.forRoot('app.config.json', {
|
||||
ecmHost: 'http://localhost:9876/ecm'
|
||||
})
|
||||
CoreModule
|
||||
],
|
||||
declarations: [
|
||||
TagNodeListComponent
|
||||
@@ -67,6 +64,9 @@ describe('TagNodeList', () => {
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
let appConfig: AppConfigService = TestBed.get(AppConfigService);
|
||||
appConfig.config.ecmHost = 'http://localhost:9876/ecm';
|
||||
|
||||
fixture = TestBed.createComponent(TagNodeListComponent);
|
||||
|
||||
debug = fixture.debugElement;
|
||||
|
@@ -16,7 +16,7 @@
|
||||
*/
|
||||
|
||||
import { async, TestBed } from '@angular/core/testing';
|
||||
import { AppConfigModule, CoreModule } from 'ng2-alfresco-core';
|
||||
import { AppConfigService, CoreModule } from 'ng2-alfresco-core';
|
||||
import { TagService } from '../services/tag.service';
|
||||
|
||||
declare let jasmine: any;
|
||||
@@ -28,10 +28,7 @@ describe('TagService', () => {
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
CoreModule.forRoot(),
|
||||
AppConfigModule.forRoot('app.config.json', {
|
||||
ecmHost: 'http://localhost:9876/ecm'
|
||||
})
|
||||
CoreModule
|
||||
],
|
||||
providers: [
|
||||
TagService
|
||||
@@ -40,6 +37,9 @@ describe('TagService', () => {
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
let appConfig: AppConfigService = TestBed.get(AppConfigService);
|
||||
appConfig.config.ecmHost = 'http://localhost:9876/ecm';
|
||||
|
||||
service = TestBed.get(TagService);
|
||||
});
|
||||
|
||||
|
@@ -17,7 +17,7 @@
|
||||
|
||||
import { DebugElement } from '@angular/core';
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { AppConfigModule, CoreModule } from 'ng2-alfresco-core';
|
||||
import { AppConfigService, CoreModule } from 'ng2-alfresco-core';
|
||||
import { DataTableModule } from 'ng2-alfresco-datatable';
|
||||
import { WebscriptComponent } from '../src/webscript.component';
|
||||
|
||||
@@ -33,10 +33,7 @@ describe('WebscriptComponent', () => {
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
CoreModule.forRoot(),
|
||||
AppConfigModule.forRoot('app.config.json', {
|
||||
ecmHost: 'http://localhost:9876/ecm'
|
||||
}),
|
||||
CoreModule,
|
||||
DataTableModule
|
||||
],
|
||||
declarations: [
|
||||
@@ -46,6 +43,9 @@ describe('WebscriptComponent', () => {
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
let appConfig: AppConfigService = TestBed.get(AppConfigService);
|
||||
appConfig.config.ecmHost = 'http://localhost:9876/ecm';
|
||||
|
||||
fixture = TestBed.createComponent(WebscriptComponent);
|
||||
component = fixture.componentInstance;
|
||||
|
||||
|
Reference in New Issue
Block a user