[AAE-12288] remove mock barrel import and remove code duplication

This commit is contained in:
Diogo Bastos
2023-04-03 12:35:41 +01:00
parent a4f652edc6
commit 15dedc2365
9 changed files with 35 additions and 73 deletions
@@ -15,7 +15,7 @@
* limitations under the License.
*/
import { fakeEnvironmentList } from '../../common';
import { fakeEnvironmentList } from '../../common/mock/environment.mock';
import { ApplicationInstanceModel } from '../models/application-instance.model';
export const fakeApplicationInstance: ApplicationInstanceModel[] = [
@@ -20,9 +20,10 @@ import { throwError } from 'rxjs';
import { setupTestBed, AppConfigService, AlfrescoApiService, CoreTestingModule } from '@alfresco/adf-core';
import { HttpErrorResponse } from '@angular/common/http';
import { AppsProcessCloudService } from './apps-process-cloud.service';
import { fakeApplicationInstance } from '../mock/app-model.mock';
import { fakeApplicationInstance, fakeApplicationInstanceWithEnvironment } from '../mock/app-model.mock';
import { ProcessServiceCloudTestingModule } from '../../testing/process-service-cloud.testing.module';
import { TranslateModule } from '@ngx-translate/core';
import { fakeEnvironmentList } from '../../common/mock/environment.mock';
describe('AppsProcessCloudService', () => {
@@ -103,4 +104,15 @@ describe('AppsProcessCloudService', () => {
}
);
});
it('should return label with application name', () => {
const applicationLabel = service.getApplicationLabel(fakeApplicationInstance[0]);
expect(applicationLabel).toBe('application-new-1');
});
it('should return label with application name and environment name', () => {
const applicationLabel = service.getApplicationLabel(fakeApplicationInstanceWithEnvironment[0], fakeEnvironmentList);
expect(applicationLabel).toBe('application-new-1 (test-env-name-1)');
});
});
@@ -21,6 +21,7 @@ import { map, catchError } from 'rxjs/operators';
import { AlfrescoApiService, AppConfigService, LogService } from '@alfresco/adf-core';
import { Oauth2Auth } from '@alfresco/js-api';
import { ApplicationInstanceModel } from '../models/application-instance.model';
import { Environment } from '../../common/interface/environment.interface';
@Injectable({ providedIn: 'root' })
export class AppsProcessCloudService {
@@ -58,6 +59,16 @@ export class AppsProcessCloudService {
this.deployedApps = apps;
}
getApplicationLabel(application: ApplicationInstanceModel, environmentList?: Environment[]): string {
const envName = environmentList?.find((env: Environment) => env.id === application.environmentId)?.name;
if (application.environmentId && environmentList && envName) {
return `${application.name} (${envName})`;
} else {
return application.name;
}
}
private getApplicationsByStatus(status: string, role?: string): Observable<ApplicationInstanceModel[]> {
if (status === '') {
return of([]);
@@ -1,18 +0,0 @@
/*!
* @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.
*/
export * from './public-api';
@@ -1,19 +0,0 @@
/*!
* @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.
*/
export * from './date-range-filter.mock';
export * from './environment.mock';
@@ -16,4 +16,3 @@
*/
export * from './interface/index';
export * from './mock/index';
@@ -413,21 +413,12 @@ export class EditProcessFilterCloudComponent implements OnInit, OnChanges, OnDes
.subscribe((applications) => {
if (applications && applications.length > 0) {
applications.map((application) => {
if (application.environmentId) {
this.applicationNames.push({ label: `${application.name} (${this.getEnvironmentName(application.environmentId)})`, value: application.name });
} else {
this.applicationNames.push({ label: application.name, value: application.name });
}
this.applicationNames.push({ label: this.appsProcessCloudService.getApplicationLabel(application, this.environmentList), value: application.name });
});
}
});
}
private getEnvironmentName(environmentId: string): string {
return this.environmentList.find((env: any) => env['id'] === environmentId)?.name;
}
getProcessDefinitions() {
this.processDefinitionNames = [];
@@ -68,10 +68,6 @@ export abstract class BaseEditTaskFilterCloudComponent<T> implements OnInit, OnC
@Input()
id: string;
/** Environment ID of the application. */
@Input()
environmentId: string;
/** List of environments. */
@Input()
environmentList: Environment[] = [];
@@ -108,14 +104,6 @@ export abstract class BaseEditTaskFilterCloudComponent<T> implements OnInit, OnC
@Input()
sortProperties: string[] = [];
/** Task Filter to use*/
@Input()
taskFilter: T;
/** Emitted when a task filter property changes. */
@Output()
filterChange = new EventEmitter<T>();
/** Emitted when a filter action occurs (i.e Save, Save As, Delete). */
@Output()
action = new EventEmitter<TaskFilterAction>();
@@ -138,8 +126,15 @@ export abstract class BaseEditTaskFilterCloudComponent<T> implements OnInit, OnC
label: 'ADF_CLOUD_TASK_FILTERS.STATUS.ALL'
};
@Input()
taskFilter: T;
changedTaskFilter: T;
/** Emitted when a task filter property changes. */
@Output()
filterChange = new EventEmitter<T>();
protected onDestroy$ = new Subject<boolean>();
isLoading: boolean = false;
@@ -253,20 +248,12 @@ export abstract class BaseEditTaskFilterCloudComponent<T> implements OnInit, OnC
.subscribe((applications) => {
if (applications && applications.length > 0) {
applications.map((application) => {
if (application.environmentId) {
this.applicationNames.push({ label: `${application.name} (${this.getEnvironmentName(application.environmentId)})`, value: application.name });
} else {
this.applicationNames.push({ label: application.name, value: application.name });
}
this.applicationNames.push({ label: this.appsProcessCloudService.getApplicationLabel(application, this.environmentList), value: application.name });
});
}
});
}
private getEnvironmentName(environmentId: string): string {
return this.environmentList.find((env: any) => env['id'] === environmentId)?.name;
}
getProcessDefinitions() {
this.taskCloudService.getProcessDefinitions(this.appName)
.subscribe((processDefinitions) => {
@@ -36,7 +36,7 @@ import { EditServiceTaskFilterCloudComponent } from './edit-service-task-filter-
import { MatIconTestingModule } from '@angular/material/icon/testing';
import { ProcessDefinitionCloud } from '../../../../models/process-definition-cloud.model';
import { TaskFilterDialogCloudComponent } from '../task-filter-dialog/task-filter-dialog-cloud.component';
import { fakeEnvironmentList } from 'lib/process-services-cloud/src/lib/common/mock/environment.mock';
import { fakeEnvironmentList } from '../../../../common/mock/environment.mock';
import { mockApplicationTaskFilterProperties } from '../../mock/edit-task-filter-cloud.mock';
describe('EditServiceTaskFilterCloudComponent', () => {
@@ -756,7 +756,6 @@ describe('EditServiceTaskFilterCloudComponent', () => {
it('should add environment name to each application selector option label', () => {
component.appName = fakeApplicationInstance[0].name;
component.environmentList = fakeEnvironmentList;
component.environmentId = fakeEnvironmentList[0].id;
getRunningApplicationsSpy.and.returnValue(of(fakeApplicationInstanceWithEnvironment));
spyOn(component, 'createTaskFilterProperties').and.returnValue(mockApplicationTaskFilterProperties);