mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[AAE-4966] Extensible app config (#6914)
* merge app config from the extensions * improved service injection in unit tests * extra unit test * fix content tests * update code as per review * fix lint * fix lint * update code and tests * update schema
This commit is contained in:
@@ -15,16 +15,25 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { HttpClientModule } from '@angular/common/http';
|
||||
import { async, inject, TestBed } from '@angular/core/testing';
|
||||
import { HttpClient, HttpClientModule } from '@angular/common/http';
|
||||
import { async, TestBed } from '@angular/core/testing';
|
||||
import { AppConfigService } from './app-config.service';
|
||||
import { AppConfigModule } from './app-config.module';
|
||||
import { ExtensionConfig, ExtensionService } from '@alfresco/adf-extensions';
|
||||
import { of } from 'rxjs';
|
||||
|
||||
declare let jasmine: any;
|
||||
class TestExtensionService extends ExtensionService {
|
||||
|
||||
onSetup(config: ExtensionConfig) {
|
||||
this.onSetup$.next(config);
|
||||
}
|
||||
}
|
||||
|
||||
describe('AppConfigService', () => {
|
||||
|
||||
let appConfigService: AppConfigService;
|
||||
let extensionService: ExtensionService;
|
||||
let httpClient: HttpClient;
|
||||
|
||||
const mockResponse = {
|
||||
ecmHost: 'http://localhost:4000/ecm',
|
||||
@@ -46,32 +55,60 @@ describe('AppConfigService', () => {
|
||||
AppConfigModule
|
||||
],
|
||||
providers: [
|
||||
{ provide: AppConfigService, useClass: AppConfigService }
|
||||
{ provide: ExtensionService, useClass: TestExtensionService }
|
||||
]
|
||||
});
|
||||
|
||||
jasmine.Ajax.install();
|
||||
});
|
||||
|
||||
beforeEach(
|
||||
inject([AppConfigService], (appConfig: AppConfigService) => {
|
||||
appConfigService = appConfig;
|
||||
appConfigService.load();
|
||||
beforeEach(() => {
|
||||
httpClient = TestBed.inject(HttpClient);
|
||||
spyOn(httpClient, 'get').and.returnValue(of(mockResponse));
|
||||
|
||||
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||
'status': 200,
|
||||
contentType: 'application/json',
|
||||
responseText: JSON.stringify(mockResponse)
|
||||
});
|
||||
})
|
||||
);
|
||||
extensionService = TestBed.inject(ExtensionService);
|
||||
|
||||
afterEach(() => {
|
||||
jasmine.Ajax.uninstall();
|
||||
appConfigService = TestBed.inject(AppConfigService);
|
||||
appConfigService.load();
|
||||
});
|
||||
|
||||
it('should export service in the module', () => {
|
||||
expect(appConfigService).toBeDefined();
|
||||
it('should merge the configs from extensions', () => {
|
||||
appConfigService.config = {
|
||||
application: {
|
||||
name: 'application name'
|
||||
}
|
||||
};
|
||||
|
||||
(extensionService as TestExtensionService).onSetup({
|
||||
appConfig: {
|
||||
application: {
|
||||
name: 'custom name'
|
||||
}
|
||||
}
|
||||
} as any);
|
||||
|
||||
expect(appConfigService.get('application.name')).toEqual('custom name');
|
||||
});
|
||||
|
||||
it('should merge the configs upon new data loaded', async (done) => {
|
||||
appConfigService.config = {
|
||||
application: {
|
||||
name: 'application name'
|
||||
}
|
||||
};
|
||||
|
||||
(extensionService as TestExtensionService).onSetup({
|
||||
appConfig: {
|
||||
application: {
|
||||
name: 'custom name'
|
||||
}
|
||||
}
|
||||
} as any);
|
||||
|
||||
expect(appConfigService.get('application.name')).toEqual('custom name');
|
||||
|
||||
await appConfigService.load();
|
||||
|
||||
expect(appConfigService.get('application.name')).toEqual('custom name');
|
||||
done();
|
||||
});
|
||||
|
||||
it('should stream only the selected attribute changes when using select', async(() => {
|
||||
|
Reference in New Issue
Block a user