-
Notifications
You must be signed in to change notification settings - Fork 261
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* add $ignoreReferenceList to ExtensionConfig interface * update schema * change type * load registered extensions * filter out ignored extensions * tests * conditionally load plugins * update tests
- Loading branch information
Showing
5 changed files
with
150 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
121 changes: 121 additions & 0 deletions
121
lib/extensions/src/lib/services/extension-loader.service.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
/*! | ||
* @license | ||
* Copyright 2019 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, TestBed } from '@angular/core/testing'; | ||
import { HttpClientTestingModule } from '@angular/common/http/testing'; | ||
import { ExtensionConfig } from '../config/extension.config'; | ||
import { ExtensionLoaderService } from './extension-loader.service'; | ||
import { HttpClient } from '@angular/common/http'; | ||
import { of } from 'rxjs'; | ||
|
||
describe('ExtensionLoaderService', () => { | ||
let extensionLoaderService: ExtensionLoaderService; | ||
let httpClient: HttpClient; | ||
let appExtensionsConfig: ExtensionConfig; | ||
const pluginConfig1: ExtensionConfig = { | ||
$id: 'test1', | ||
$name: 'test.extension.1', | ||
$version: '1.0.0', | ||
$vendor: 'Alfresco', | ||
$license: 'MIT', | ||
$runtime: '2.6.1' | ||
}; | ||
const pluginConfig2: ExtensionConfig = { | ||
$id: 'test2', | ||
$name: 'test.extension.2', | ||
$version: '1.0.0', | ||
$vendor: 'Alfresco', | ||
$license: 'MIT', | ||
$runtime: '2.6.1' | ||
}; | ||
const pluginConfig3: ExtensionConfig = { | ||
$id: 'test3', | ||
$name: 'test.extension.3', | ||
$version: '1.0.0', | ||
$vendor: 'Alfresco', | ||
$license: 'MIT', | ||
$runtime: '2.6.1' | ||
}; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [HttpClientTestingModule], | ||
providers: [ | ||
HttpClient, | ||
ExtensionLoaderService | ||
] | ||
}); | ||
extensionLoaderService = TestBed.inject(ExtensionLoaderService); | ||
httpClient = TestBed.inject(HttpClient); | ||
|
||
appExtensionsConfig = { | ||
$id: 'test', | ||
$name: 'test.config', | ||
$version: '1.0.0', | ||
$vendor: 'Alfresco', | ||
$license: 'MIT', | ||
$runtime: '2.6.1', | ||
$references: [], | ||
$ignoreReferenceList: [] | ||
}; | ||
|
||
spyOn(httpClient, 'get').and.callFake((url: string) => { | ||
if (url === 'assets/app.extensions.json') { | ||
return of(appExtensionsConfig); | ||
} | ||
|
||
if (url === 'assets/plugins/test.extension.1.json') { | ||
return of(pluginConfig1); | ||
} | ||
|
||
if (url === 'assets/plugins/test.extension.2.json') { | ||
return of(pluginConfig2); | ||
} | ||
|
||
if (url === 'assets/plugins/test.extension.3.json') { | ||
return of(pluginConfig3); | ||
} | ||
|
||
return of({}); | ||
}); | ||
}); | ||
|
||
it('should load default registered app extensions when no custom $references defined', async(() => { | ||
extensionLoaderService.load('assets/app.extensions.json', 'assets/plugins', ['test.extension.1.json']).then((config: ExtensionConfig) => { | ||
const pluginsReference = config.$references.map((entry: ExtensionConfig) => entry.$name); | ||
expect(pluginsReference).toEqual(['test.extension.1']); | ||
}); | ||
})); | ||
|
||
it('should ignore default registered app extension if defined in $ignoreReferenceList', async(() => { | ||
appExtensionsConfig.$ignoreReferenceList = ['test.extension.1.json']; | ||
|
||
extensionLoaderService.load('assets/app.extensions.json', 'assets/plugins', ['test.extension.1.json']).then((config: ExtensionConfig) => { | ||
const pluginsReference = config.$references.map((entry: ExtensionConfig) => entry.$name); | ||
expect(pluginsReference).toEqual([]); | ||
}); | ||
})); | ||
|
||
it('should load only extensions defined by $references', async(() => { | ||
appExtensionsConfig.$references = ['test.extension.1.json']; | ||
|
||
extensionLoaderService.load('assets/app.extensions.json', 'assets/plugins', ['test.extension.2.json, test.extension.3.json']).then((config: ExtensionConfig) => { | ||
const pluginsReference = config.$references.map((entry: ExtensionConfig) => entry.$name); | ||
expect(pluginsReference).toEqual(['test.extension.1']); | ||
}); | ||
})); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters