ACS-8652: Noop Translation Module for better unit testing ergonomics (#10118)

This commit is contained in:
Denys Vuika
2024-08-29 11:02:12 -04:00
committed by GitHub
parent f6e72f8a6f
commit 54ab9575d3
68 changed files with 369 additions and 528 deletions

View File

@@ -16,9 +16,7 @@
*/
import { Component, ViewEncapsulation, Input, Inject, OnDestroy } from '@angular/core';
import {
AppConfigService, UserPreferencesService
} from '@alfresco/adf-core';
import { AppConfigService, UserPreferencesService } from '@alfresco/adf-core';
import { ServiceTaskQueryCloudRequestModel } from '../models/service-task-cloud.model';
import { BaseTaskListCloudComponent } from './base-task-list-cloud.component';
import { ServiceTaskListCloudService } from '../services/service-task-list-cloud.service';
@@ -42,19 +40,17 @@ export class ServiceTaskListCloudComponent extends BaseTaskListCloudComponent im
private onDestroyServiceTaskList$ = new Subject<boolean>();
private isReloadingSubject$ = new BehaviorSubject<boolean>(false);
isLoading$ = combineLatest([
this.isLoadingPreferences$,
this.isReloadingSubject$
]).pipe(
isLoading$ = combineLatest([this.isLoadingPreferences$, this.isReloadingSubject$]).pipe(
map(([isLoadingPreferences, isReloading]) => isLoadingPreferences || isReloading)
);
constructor(private serviceTaskListCloudService: ServiceTaskListCloudService,
appConfigService: AppConfigService,
taskCloudService: TaskCloudService,
userPreferences: UserPreferencesService,
@Inject(TASK_LIST_PREFERENCES_SERVICE_TOKEN) cloudPreferenceService: PreferenceCloudServiceInterface
) {
constructor(
private serviceTaskListCloudService: ServiceTaskListCloudService,
appConfigService: AppConfigService,
taskCloudService: TaskCloudService,
userPreferences: UserPreferencesService,
@Inject(TASK_LIST_PREFERENCES_SERVICE_TOKEN) cloudPreferenceService: PreferenceCloudServiceInterface
) {
super(appConfigService, taskCloudService, userPreferences, PRESET_KEY, cloudPreferenceService);
}
@@ -69,22 +65,20 @@ export class ServiceTaskListCloudComponent extends BaseTaskListCloudComponent im
this.requestNode = this.createRequestNode();
if (this.requestNode.appName || this.requestNode.appName === '') {
combineLatest([
this.serviceTaskListCloudService.getServiceTaskByRequest(this.requestNode),
this.isColumnSchemaCreated$
]).pipe(
takeUntil(this.onDestroyServiceTaskList$)
).subscribe(
([tasks]) => {
this.rows = tasks.list.entries;
this.success.emit(tasks);
this.pagination.next(tasks.list.pagination);
this.isReloadingSubject$.next(false);
}, (error) => {
this.error.emit(error);
this.isReloadingSubject$.next(false);
});
combineLatest([this.serviceTaskListCloudService.getServiceTaskByRequest(this.requestNode), this.isColumnSchemaCreated$])
.pipe(takeUntil(this.onDestroyServiceTaskList$))
.subscribe(
([tasks]) => {
this.rows = tasks.list.entries;
this.success.emit(tasks);
this.pagination.next(tasks.list.pagination);
this.isReloadingSubject$.next(false);
},
(error) => {
this.error.emit(error);
this.isReloadingSubject$.next(false);
}
);
} else {
this.rows = [];
}

View File

@@ -151,20 +151,18 @@ export class TaskListCloudComponent extends BaseTaskListCloudComponent<ProcessLi
dataAdapter: TasksListDatatableAdapter | undefined;
private isReloadingSubject$ = new BehaviorSubject<boolean>(false);
isLoading$ = combineLatest([
this.isLoadingPreferences$,
this.isReloadingSubject$
]).pipe(
isLoading$ = combineLatest([this.isLoadingPreferences$, this.isReloadingSubject$]).pipe(
map(([isLoadingPreferences, isReloading]) => isLoadingPreferences || isReloading)
);
constructor(@Inject(TASK_LIST_CLOUD_TOKEN) public taskListCloudService: TaskListCloudServiceInterface,
appConfigService: AppConfigService,
taskCloudService: TaskCloudService,
userPreferences: UserPreferencesService,
@Inject(TASK_LIST_PREFERENCES_SERVICE_TOKEN) cloudPreferenceService: PreferenceCloudServiceInterface,
private viewModelCreator: VariableMapperService
) {
constructor(
@Inject(TASK_LIST_CLOUD_TOKEN) public taskListCloudService: TaskListCloudServiceInterface,
appConfigService: AppConfigService,
taskCloudService: TaskCloudService,
userPreferences: UserPreferencesService,
@Inject(TASK_LIST_PREFERENCES_SERVICE_TOKEN) cloudPreferenceService: PreferenceCloudServiceInterface,
private viewModelCreator: VariableMapperService
) {
super(appConfigService, taskCloudService, userPreferences, PRESET_KEY, cloudPreferenceService);
}
@@ -176,31 +174,33 @@ export class TaskListCloudComponent extends BaseTaskListCloudComponent<ProcessLi
reload() {
this.isReloadingSubject$.next(true);
this.isColumnSchemaCreated$.pipe(
switchMap(() => of(this.createRequestNode())),
tap((requestNode) => this.requestNode = requestNode),
switchMap((requestNode) => this.taskListCloudService.getTaskByRequest(requestNode)),
takeUntil(this.onDestroyTaskList$)
).subscribe((tasks: { list: PaginatedEntries<TaskCloudModel> }) => {
const tasksWithVariables = tasks.list.entries.map((task) => ({
...task,
variables: task.processVariables
}));
this.isColumnSchemaCreated$
.pipe(
switchMap(() => of(this.createRequestNode())),
tap((requestNode) => (this.requestNode = requestNode)),
switchMap((requestNode) => this.taskListCloudService.getTaskByRequest(requestNode)),
takeUntil(this.onDestroyTaskList$)
)
.subscribe(
(tasks: { list: PaginatedEntries<TaskCloudModel> }) => {
const tasksWithVariables = tasks.list.entries.map((task) => ({
...task,
variables: task.processVariables
}));
this.rows = this.viewModelCreator.mapVariablesByColumnTitle(
tasksWithVariables,
this.columns
this.rows = this.viewModelCreator.mapVariablesByColumnTitle(tasksWithVariables, this.columns);
this.dataAdapter = new TasksListDatatableAdapter(this.rows, this.columns);
this.success.emit(tasks);
this.isReloadingSubject$.next(false);
this.pagination.next(tasks.list.pagination);
},
(error) => {
this.error.emit(error);
this.isReloadingSubject$.next(false);
}
);
this.dataAdapter = new TasksListDatatableAdapter(this.rows, this.columns);
this.success.emit(tasks);
this.isReloadingSubject$.next(false);
this.pagination.next(tasks.list.pagination);
}, (error) => {
this.error.emit(error);
this.isReloadingSubject$.next(false);
});
}
createRequestNode(): TaskQueryCloudRequestModel {
@@ -242,11 +242,8 @@ export class TaskListCloudComponent extends BaseTaskListCloudComponent<ProcessLi
private getRequestNodeVariables(): string[] | undefined {
const displayedVariableColumns: string[] = (this.columns ?? [])
.filter(column =>
column.customData?.columnType === 'process-variable-column' &&
column.isHidden !== true
)
.map(column => {
.filter((column) => column.customData?.columnType === 'process-variable-column' && column.isHidden !== true)
.map((column) => {
const variableDefinitionsPayload = column.customData.variableDefinitionsPayload;
return variableDefinitionsPayload;
})

View File

@@ -1,30 +0,0 @@
/*!
* @license
* Copyright © 2005-2024 Hyland Software, Inc. and its affiliates. All rights reserved.
*
* 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 { TaskListCloudModule } from './task-list-cloud.module';
describe('TaskListCloudModule', () => {
let taskListCloudModule: TaskListCloudModule;
beforeEach(() => {
taskListCloudModule = new TaskListCloudModule();
});
it('should create an instance', () => {
expect(taskListCloudModule).toBeTruthy();
});
});

View File

@@ -26,19 +26,9 @@ import { TaskListCloudService } from './services/task-list-cloud.service';
import { LocalPreferenceCloudService } from '../../services/local-preference-cloud.service';
@NgModule({
imports: [
CommonModule,
MaterialModule,
CoreModule
],
declarations: [
TaskListCloudComponent,
ServiceTaskListCloudComponent
],
exports: [
TaskListCloudComponent,
ServiceTaskListCloudComponent
],
imports: [CommonModule, MaterialModule, CoreModule],
declarations: [TaskListCloudComponent, ServiceTaskListCloudComponent],
exports: [TaskListCloudComponent, ServiceTaskListCloudComponent],
providers: [
{
provide: TASK_LIST_CLOUD_TOKEN,
@@ -50,4 +40,4 @@ import { LocalPreferenceCloudService } from '../../services/local-preference-clo
}
]
})
export class TaskListCloudModule { }
export class TaskListCloudModule {}

View File

@@ -25,7 +25,8 @@ import {
AppConfigServiceMock,
TranslationService,
TranslationMock,
CoreModule, AuthModule
CoreModule,
AuthModule
} from '@alfresco/adf-core';
import { TranslateModule } from '@ngx-translate/core';
import { ProcessServicesCloudModule } from '../process-services-cloud.module';
@@ -46,11 +47,6 @@ import { RouterTestingModule } from '@angular/router/testing';
{ provide: AppConfigService, useClass: AppConfigServiceMock },
{ provide: TranslationService, useClass: TranslationMock }
],
exports: [
NoopAnimationsModule,
TranslateModule,
CoreModule,
ProcessServicesCloudModule
]
exports: [NoopAnimationsModule, TranslateModule, CoreModule, ProcessServicesCloudModule]
})
export class ProcessServiceCloudTestingModule {}