workarounds for jasmine.ajax in unit tests

This commit is contained in:
Denys Vuika 2024-09-13 14:30:55 -04:00
parent d72a3d2096
commit 40a9b37f63
14 changed files with 79 additions and 24 deletions

View File

@ -18,6 +18,7 @@
import { DocumentListService } from './document-list.service'; import { DocumentListService } from './document-list.service';
import { fakeAsync, TestBed } from '@angular/core/testing'; import { fakeAsync, TestBed } from '@angular/core/testing';
import { ContentTestingModule } from '../../testing/content.testing.module'; import { ContentTestingModule } from '../../testing/content.testing.module';
import { AdfHttpClient } from '@alfresco/adf-core/api';
declare let jasmine: any; declare let jasmine: any;
@ -68,7 +69,11 @@ describe('DocumentListService', () => {
beforeEach(() => { beforeEach(() => {
TestBed.configureTestingModule({ TestBed.configureTestingModule({
imports: [ContentTestingModule] imports: [ContentTestingModule],
providers: [
// TODO: remove this as soon as unit test not using jasmine.Ajax
{ provide: AdfHttpClient, useValue: null }
]
}); });
service = TestBed.inject(DocumentListService); service = TestBed.inject(DocumentListService);
jasmine.Ajax.install(); jasmine.Ajax.install();

View File

@ -31,7 +31,7 @@ export class AlfrescoApiService {
protected appConfig = inject(AppConfigService); protected appConfig = inject(AppConfigService);
protected storageService = inject(StorageService); protected storageService = inject(StorageService);
protected alfrescoApiFactory = inject<AlfrescoApiFactory>(ALFRESCO_API_FACTORY, { optional: true }); protected alfrescoApiFactory = inject<AlfrescoApiFactory>(ALFRESCO_API_FACTORY, { optional: true });
protected adfHttpClient = inject(AdfHttpClient); protected adfHttpClient = inject(AdfHttpClient, { optional: true });
alfrescoApiInitialized: ReplaySubject<boolean> = new ReplaySubject(1); alfrescoApiInitialized: ReplaySubject<boolean> = new ReplaySubject(1);

View File

@ -71,12 +71,23 @@ export class AdfHttpClient implements ee.Emitter, JsApiHttpClient {
ee(this); ee(this);
} }
/** @deprecated not used anywhere */ /**
* Update the default security options
*
* @param options security options
* @deprecated not used anywhere
*/
setDefaultSecurityOption(options: any) { setDefaultSecurityOption(options: any) {
this.defaultSecurityOptions = this.merge(this.defaultSecurityOptions, options); this.defaultSecurityOptions = this.merge(this.defaultSecurityOptions, options);
} }
/** @deprecated not used anywhere */ /**
* Merge objects
*
* @param objects objects to merge
* @deprecated not used anywhere
* @returns merged object
*/
merge(...objects): any { merge(...objects): any {
const result = {}; const result = {};
@ -228,6 +239,7 @@ export class AdfHttpClient implements ee.Emitter, JsApiHttpClient {
) )
.toPromise(); .toPromise();
/* eslint-disable @typescript-eslint/space-before-function-paren */
(promise as any).abort = function () { (promise as any).abort = function () {
eventEmitter.emit('abort'); eventEmitter.emit('abort');
abort$.next(); abort$.next();

View File

@ -16,7 +16,7 @@
*/ */
import { HttpClient } from '@angular/common/http'; import { HttpClient } from '@angular/common/http';
import { inject, Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { ObjectUtils } from '../common/utils/object-utils'; import { ObjectUtils } from '../common/utils/object-utils';
import { Observable, ReplaySubject } from 'rxjs'; import { Observable, ReplaySubject } from 'rxjs';
import { map, distinctUntilChanged, take } from 'rxjs/operators'; import { map, distinctUntilChanged, take } from 'rxjs/operators';
@ -76,17 +76,14 @@ export class AppConfigService {
}; };
status: Status = Status.INIT; status: Status = Status.INIT;
protected onLoadSubject: ReplaySubject<any>; protected readonly onLoadSubject = new ReplaySubject<any>();
onLoad: Observable<any>; onLoad = this.onLoadSubject.asObservable();
get isLoaded() { get isLoaded() {
return this.status === Status.LOADED; return this.status === Status.LOADED;
} }
constructor() { constructor() {
this.onLoadSubject = new ReplaySubject();
this.onLoad = this.onLoadSubject.asObservable();
this.extensionService.setup$.subscribe((config) => { this.extensionService.setup$.subscribe((config) => {
this.onExtensionsLoaded(config); this.onExtensionsLoaded(config);
}); });

View File

@ -15,15 +15,13 @@
* limitations under the License. * limitations under the License.
*/ */
import { Injectable } from '@angular/core'; import { inject, Injectable } from '@angular/core';
import { StorageService } from '../common/services/storage.service'; import { StorageService } from '../common/services/storage.service';
import { AppConfigService, AppConfigValues } from './app-config.service'; import { AppConfigService, AppConfigValues } from './app-config.service';
@Injectable() @Injectable()
export class DebugAppConfigService extends AppConfigService { export class DebugAppConfigService extends AppConfigService {
constructor(private storage: StorageService) { private storage = inject(StorageService);
super();
}
/** @override */ /** @override */
get<T>(key: string, defaultValue?: T): T { get<T>(key: string, defaultValue?: T): T {

View File

@ -20,6 +20,7 @@ import { ComponentFixture, TestBed } from '@angular/core/testing';
import { CreateProcessAttachmentComponent } from './create-process-attachment.component'; import { CreateProcessAttachmentComponent } from './create-process-attachment.component';
import { ProcessTestingModule } from '../../testing/process.testing.module'; import { ProcessTestingModule } from '../../testing/process.testing.module';
import { AlfrescoApiService, AlfrescoApiServiceMock } from '@alfresco/adf-content-services'; import { AlfrescoApiService, AlfrescoApiServiceMock } from '@alfresco/adf-content-services';
import { AdfHttpClient } from '@alfresco/adf-core/api';
declare let jasmine: any; declare let jasmine: any;
@ -49,7 +50,11 @@ describe('CreateProcessAttachmentComponent', () => {
beforeEach(() => { beforeEach(() => {
TestBed.configureTestingModule({ TestBed.configureTestingModule({
imports: [ProcessTestingModule, CreateProcessAttachmentComponent], imports: [ProcessTestingModule, CreateProcessAttachmentComponent],
providers: [{ provide: AlfrescoApiService, useClass: AlfrescoApiServiceMock }] providers: [
{ provide: AlfrescoApiService, useClass: AlfrescoApiServiceMock },
// TODO: remove this as soon as unit test not using jasmine.Ajax
{ provide: AdfHttpClient, useValue: null }
]
}); });
fixture = TestBed.createComponent(CreateProcessAttachmentComponent); fixture = TestBed.createComponent(CreateProcessAttachmentComponent);
component = fixture.componentInstance; component = fixture.componentInstance;

View File

@ -20,6 +20,7 @@ import { FormModel, CoreTestingModule } from '@alfresco/adf-core';
import { EcmModelService } from './ecm-model.service'; import { EcmModelService } from './ecm-model.service';
import { TestBed } from '@angular/core/testing'; import { TestBed } from '@angular/core/testing';
import { AlfrescoApiService, AlfrescoApiServiceMock } from '@alfresco/adf-content-services'; import { AlfrescoApiService, AlfrescoApiServiceMock } from '@alfresco/adf-content-services';
import { AdfHttpClient } from '@alfresco/adf-core/api';
declare let jasmine: any; declare let jasmine: any;
@ -29,7 +30,11 @@ describe('EcmModelService', () => {
beforeEach(() => { beforeEach(() => {
TestBed.configureTestingModule({ TestBed.configureTestingModule({
imports: [CoreTestingModule], imports: [CoreTestingModule],
providers: [{ provide: AlfrescoApiService, useClass: AlfrescoApiServiceMock }] providers: [
{ provide: AlfrescoApiService, useClass: AlfrescoApiServiceMock },
// TODO: remove this as soon as unit test not using jasmine.Ajax
{ provide: AdfHttpClient, useValue: null }
]
}); });
service = TestBed.inject(EcmModelService); service = TestBed.inject(EcmModelService);
jasmine.Ajax.install(); jasmine.Ajax.install();

View File

@ -20,6 +20,7 @@ import { of } from 'rxjs';
import { ProcessContentService } from './process-content.service'; import { ProcessContentService } from './process-content.service';
import { CoreTestingModule } from '@alfresco/adf-core'; import { CoreTestingModule } from '@alfresco/adf-core';
import { AlfrescoApiService, AlfrescoApiServiceMock } from '@alfresco/adf-content-services'; import { AlfrescoApiService, AlfrescoApiServiceMock } from '@alfresco/adf-content-services';
import { AdfHttpClient } from '@alfresco/adf-core/api';
declare let jasmine: any; declare let jasmine: any;
@ -68,7 +69,11 @@ describe('ProcessContentService', () => {
beforeEach(() => { beforeEach(() => {
TestBed.configureTestingModule({ TestBed.configureTestingModule({
imports: [CoreTestingModule], imports: [CoreTestingModule],
providers: [{ provide: AlfrescoApiService, useClass: AlfrescoApiServiceMock }] providers: [
{ provide: AlfrescoApiService, useClass: AlfrescoApiServiceMock },
// TODO: remove this as soon as unit test not using jasmine.Ajax
{ provide: AdfHttpClient, useValue: null }
]
}); });
service = TestBed.inject(ProcessContentService); service = TestBed.inject(ProcessContentService);
}); });

View File

@ -23,6 +23,7 @@ import { of } from 'rxjs';
import { ContentWidgetComponent } from './content.widget'; import { ContentWidgetComponent } from './content.widget';
import { ProcessContentService } from '../../services/process-content.service'; import { ProcessContentService } from '../../services/process-content.service';
import { AlfrescoApiService, AlfrescoApiServiceMock } from '@alfresco/adf-content-services'; import { AlfrescoApiService, AlfrescoApiServiceMock } from '@alfresco/adf-content-services';
import { AdfHttpClient } from '@alfresco/adf-core/api';
declare let jasmine: any; declare let jasmine: any;
@ -61,7 +62,11 @@ describe('ContentWidgetComponent', () => {
beforeEach(() => { beforeEach(() => {
TestBed.configureTestingModule({ TestBed.configureTestingModule({
imports: [CoreTestingModule, ContentWidgetComponent], imports: [CoreTestingModule, ContentWidgetComponent],
providers: [{ provide: AlfrescoApiService, useClass: AlfrescoApiServiceMock }] providers: [
{ provide: AlfrescoApiService, useClass: AlfrescoApiServiceMock },
// TODO: remove this as soon as unit test not using jasmine.Ajax
{ provide: AdfHttpClient, useValue: null }
]
}); });
downloadService = TestBed.inject(DownloadService); downloadService = TestBed.inject(DownloadService);
processContentService = TestBed.inject(ProcessContentService); processContentService = TestBed.inject(ProcessContentService);

View File

@ -20,6 +20,7 @@ import { of } from 'rxjs';
import { PeopleSearchComponent } from './people-search.component'; import { PeopleSearchComponent } from './people-search.component';
import { ProcessTestingModule } from '../../../testing/process.testing.module'; import { ProcessTestingModule } from '../../../testing/process.testing.module';
import { LightUserRepresentation } from '@alfresco/js-api'; import { LightUserRepresentation } from '@alfresco/js-api';
import { AdfHttpClient } from '@alfresco/adf-core/api';
const fakeUser: LightUserRepresentation = { const fakeUser: LightUserRepresentation = {
id: 1, id: 1,
@ -44,7 +45,11 @@ describe('PeopleSearchComponent', () => {
beforeEach(() => { beforeEach(() => {
TestBed.configureTestingModule({ TestBed.configureTestingModule({
imports: [ProcessTestingModule, PeopleSearchComponent] imports: [ProcessTestingModule, PeopleSearchComponent],
providers: [
// TODO: remove this as soon as unit test not using jasmine.Ajax
{ provide: AdfHttpClient, useValue: null }
]
}); });
fixture = TestBed.createComponent(PeopleSearchComponent); fixture = TestBed.createComponent(PeopleSearchComponent);
peopleSearchComponent = fixture.componentInstance; peopleSearchComponent = fixture.componentInstance;

View File

@ -19,8 +19,9 @@ import { ComponentFixture, TestBed } from '@angular/core/testing';
import { PeopleComponent } from './people.component'; import { PeopleComponent } from './people.component';
import { ProcessTestingModule } from '../../../testing/process.testing.module'; import { ProcessTestingModule } from '../../../testing/process.testing.module';
import { LightUserRepresentation } from '@alfresco/js-api'; import { LightUserRepresentation } from '@alfresco/js-api';
import { PeopleProcessService } from '@alfresco/adf-process-services'; import { AdfHttpClient } from '@alfresco/adf-core/api';
import { of, throwError } from 'rxjs'; import { of, throwError } from 'rxjs';
import { PeopleProcessService } from '@alfresco/adf-process-services';
const fakeUser: LightUserRepresentation = { const fakeUser: LightUserRepresentation = {
id: 0, id: 0,
@ -45,7 +46,11 @@ describe('PeopleComponent', () => {
beforeEach(() => { beforeEach(() => {
TestBed.configureTestingModule({ TestBed.configureTestingModule({
imports: [ProcessTestingModule, PeopleComponent] imports: [ProcessTestingModule, PeopleComponent],
providers: [
// TODO: remove this as soon as unit test not using jasmine.Ajax
{ provide: AdfHttpClient, useValue: null }
]
}); });
fixture = TestBed.createComponent(PeopleComponent); fixture = TestBed.createComponent(PeopleComponent);
peopleProcessService = fixture.debugElement.injector.get(PeopleProcessService); peopleProcessService = fixture.debugElement.injector.get(PeopleProcessService);

View File

@ -21,6 +21,7 @@ import { CoreTestingModule } from '@alfresco/adf-core';
import { ProcessInstanceFilterRepresentation, UserProcessInstanceFilterRepresentation } from '@alfresco/js-api'; import { ProcessInstanceFilterRepresentation, UserProcessInstanceFilterRepresentation } from '@alfresco/js-api';
import { of } from 'rxjs'; import { of } from 'rxjs';
import { AlfrescoApiService, AlfrescoApiServiceMock } from '@alfresco/adf-content-services'; import { AlfrescoApiService, AlfrescoApiServiceMock } from '@alfresco/adf-content-services';
import { AdfHttpClient } from '@alfresco/adf-core/api';
declare let jasmine: any; declare let jasmine: any;
@ -51,7 +52,11 @@ describe('Process filter', () => {
beforeEach(() => { beforeEach(() => {
TestBed.configureTestingModule({ TestBed.configureTestingModule({
imports: [CoreTestingModule], imports: [CoreTestingModule],
providers: [{ provide: AlfrescoApiService, useClass: AlfrescoApiServiceMock }] providers: [
{ provide: AlfrescoApiService, useClass: AlfrescoApiServiceMock },
// TODO: remove this as soon as unit test not using jasmine.Ajax
{ provide: AdfHttpClient, useValue: null }
]
}); });
service = TestBed.inject(ProcessFilterService); service = TestBed.inject(ProcessFilterService);
}); });

View File

@ -20,6 +20,7 @@ import { PeopleProcessService } from './people-process.service';
import { CoreTestingModule } from '@alfresco/adf-core'; import { CoreTestingModule } from '@alfresco/adf-core';
import { LightUserRepresentation } from '@alfresco/js-api'; import { LightUserRepresentation } from '@alfresco/js-api';
import { AlfrescoApiService, AlfrescoApiServiceMock } from '@alfresco/adf-content-services'; import { AlfrescoApiService, AlfrescoApiServiceMock } from '@alfresco/adf-content-services';
import { AdfHttpClient } from '@alfresco/adf-core/api';
declare let jasmine: any; declare let jasmine: any;
@ -47,7 +48,11 @@ describe('PeopleProcessService', () => {
beforeEach(() => { beforeEach(() => {
TestBed.configureTestingModule({ TestBed.configureTestingModule({
imports: [CoreTestingModule], imports: [CoreTestingModule],
providers: [{ provide: AlfrescoApiService, useClass: AlfrescoApiServiceMock }] providers: [
{ provide: AlfrescoApiService, useClass: AlfrescoApiServiceMock },
// TODO: remove this as soon as unit test not using jasmine.Ajax
{ provide: AdfHttpClient, useValue: null }
]
}); });
service = TestBed.inject(PeopleProcessService); service = TestBed.inject(PeopleProcessService);
}); });

View File

@ -44,6 +44,7 @@ import { MatMenuItemHarness } from '@angular/material/menu/testing';
import { NoopAnimationsModule } from '@angular/platform-browser/animations'; import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { AlfrescoApiService, AlfrescoApiServiceMock } from '@alfresco/adf-content-services'; import { AlfrescoApiService, AlfrescoApiServiceMock } from '@alfresco/adf-content-services';
import { CommonModule } from '@angular/common'; import { CommonModule } from '@angular/common';
import { AdfHttpClient } from '@alfresco/adf-core/api';
declare let jasmine: any; declare let jasmine: any;
@ -112,7 +113,9 @@ describe('TaskListComponent', () => {
providers: [ providers: [
TaskListService, TaskListService,
{ provide: AlfrescoApiService, useClass: AlfrescoApiServiceMock }, { provide: AlfrescoApiService, useClass: AlfrescoApiServiceMock },
{ provide: AppConfigService, useClass: AppConfigServiceMock } { provide: AppConfigService, useClass: AppConfigServiceMock },
// TODO: remove this as soon as unit test not using jasmine.Ajax
{ provide: AdfHttpClient, useValue: null }
] ]
}); });
appConfig = TestBed.inject(AppConfigService); appConfig = TestBed.inject(AppConfigService);