Skip to content

Commit

Permalink
Fixed linting and js-api tests
Browse files Browse the repository at this point in the history
  • Loading branch information
VitoAlbano committed Nov 22, 2023
1 parent 651b236 commit 8cb6d20
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 49 deletions.
1 change: 1 addition & 0 deletions lib/core/src/lib/pipes/date-time.pipe.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { DateTimePipe } from './date-time.pipe';
import { addMinutes, isValid } from 'date-fns';

Expand Down
72 changes: 24 additions & 48 deletions lib/extensions/src/lib/services/extension-loader.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,14 @@
* limitations under the License.
*/

import { TestBed } from '@angular/core/testing';
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { TestBed, fakeAsync, flushMicrotasks, tick } from '@angular/core/testing';
import { HttpClientTestingModule, HttpTestingController } 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 httpMock: HttpTestingController;
let appExtensionsConfig: ExtensionConfig;
const pluginConfig1: ExtensionConfig = {
$id: 'test1',
Expand All @@ -34,33 +32,16 @@ describe('ExtensionLoaderService', () => {
$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);
httpMock = TestBed.inject(HttpTestingController);

appExtensionsConfig = {
$id: 'test',
Expand All @@ -72,35 +53,22 @@ describe('ExtensionLoaderService', () => {
$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(null);
});
afterEach(() => {
httpMock.verify();
});

it('should load default registered app extensions when no custom $references defined', (done) => {
it('should load default registered app extensions when no custom $references defined', fakeAsync(() => {
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']);
done();
});
});
httpMock.expectOne('assets/app.extensions.json').flush(appExtensionsConfig);
tick();
httpMock.expectOne('assets/plugins/test.extension.1.json').flush(pluginConfig1);
flushMicrotasks();
}));

it('should ignore default registered app extension if defined in $ignoreReferenceList', (done) => {
appExtensionsConfig.$ignoreReferenceList = ['test.extension.1.json'];
Expand All @@ -110,15 +78,23 @@ describe('ExtensionLoaderService', () => {
expect(pluginsReference).toEqual([]);
done();
});

httpMock.expectOne('assets/app.extensions.json').flush(appExtensionsConfig);
});

it('should load only extensions defined by $references', (done) => {
it('should load only extensions defined by $references', fakeAsync(() => {
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']);
done();
});
});

httpMock.expectOne('assets/app.extensions.json').flush(appExtensionsConfig);
tick();
httpMock.expectOne('assets/plugins/test.extension.1.json').flush(pluginConfig1);
httpMock.expectNone('assets/plugins/test.extension.2.json');
httpMock.expectNone('assets/plugins/test.extension.3.json');
flushMicrotasks();
}));
});
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ describe('CreateProcessAttachmentComponent', () => {
MatButtonModule,
MatIconModule
],
providers: [{ provide: AlfrescoApiService, useClass: AlfrescoApiServiceMock },]
providers: [{ provide: AlfrescoApiService, useClass: AlfrescoApiServiceMock }]
});
fixture = TestBed.createComponent(CreateProcessAttachmentComponent);
component = fixture.componentInstance;
Expand Down
31 changes: 31 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@
"@types/jasminewd2": "~2.0.2",
"@types/jsdom": "^21.1.5",
"@types/minimatch": "^3.0.3",
"@types/mocha": "^10.0.6",
"@types/node": "18.7.1",
"@types/pdfjs-dist": "^2.10.378",
"@types/selenium-webdriver": "^4.0.11",
Expand Down Expand Up @@ -176,6 +177,7 @@
"mocha": "^10.2.0",
"moment": "^2.29.4",
"ng-packagr": "15.2.2",
"nock": "^13.3.8",
"nx": "15.9.3",
"postcss": "^8.4.31",
"postcss-sass": "^0.5.0",
Expand Down

0 comments on commit 8cb6d20

Please sign in to comment.