From 54c3e12ad869397902c2ab12cde1ad7c2acfd1e8 Mon Sep 17 00:00:00 2001 From: Denys Vuika Date: Fri, 19 Apr 2024 12:14:33 -0400 Subject: [PATCH] [ACS-7688] Reduce the usage of LogService and TranslateModule (tests) (#9567) --- .../settings/settings.component.html | 2 +- .../components/settings/settings.component.ts | 10 +- .../app/services/in-memory-form.service.ts | 20 +- .../components/people.component.md | 4 + .../services/aspect-list.service.ts | 34 +- .../lib/common/services/rendition.service.ts | 123 ++-- .../services/rendition.services.spec.ts | 19 +- .../site-dropdown/sites-dropdown.component.ts | 8 +- .../components/upload-button.component.ts | 3 +- .../components/alfresco-viewer.component.ts | 10 +- .../about-github-link.component.spec.ts | 3 +- .../about-server-settings.component.spec.ts | 6 +- .../basic-auth/basic-alfresco-auth.service.ts | 92 +-- .../auth/guard/auth-guard-bpm.service.spec.ts | 27 +- .../auth/guard/auth-guard-ecm.service.spec.ts | 39 +- .../guard/auth-guard-sso-role.service.spec.ts | 8 +- .../lib/auth/guard/auth-guard.service.spec.ts | 23 +- .../services/authentication.service.spec.ts | 31 +- .../services/base-authentication.service.ts | 10 +- .../services/identity-group.service.spec.ts | 298 +++++----- .../auth/services/identity-role.service.ts | 53 +- .../services/identity-user.service.spec.ts | 539 +++++++++--------- .../services/oidc-authentication.service.ts | 15 +- .../buttons-menu.component.spec.ts | 44 +- .../card-view-arrayitem.component.spec.ts | 3 +- .../card-view-boolitem.component.spec.ts | 25 +- .../card-view-dateitem.component.spec.ts | 8 + ...d-view-keyvaluepairsitem.component.spec.ts | 10 +- .../card-view-mapitem.component.spec.ts | 6 +- .../card-view-selectitem.component.spec.ts | 3 +- .../select-filter-input.component.spec.ts | 3 +- .../card-view-textitem.component.spec.ts | 7 +- .../card-view/card-view.component.spec.ts | 3 +- .../lib/clipboard/clipboard.directive.spec.ts | 47 +- .../lib/clipboard/clipboard.service.spec.ts | 10 +- .../src/lib/clipboard/clipboard.service.ts | 18 +- .../comment-list.component.spec.ts | 18 +- .../lib/comments/comments.component.spec.ts | 25 +- .../directionality-config.service.spec.ts | 8 +- .../src/lib/common/services/log.service.ts | 11 +- .../common/services/storage.service.spec.ts | 11 +- .../services/user-preferences.service.spec.ts | 8 +- .../context-menu-overlay.service.spec.ts | 13 +- .../src/lib/context-menu/context-menu.spec.ts | 32 +- .../columns-selector.component.spec.ts | 71 +-- .../datatable/datatable.component.spec.ts | 11 +- .../empty-list/empty-list.component.spec.ts | 6 +- .../json-cell/json-cell.component.spec.ts | 3 +- .../data-column/data-column.component.spec.ts | 6 +- .../header-filter-template.directive.spec.ts | 7 +- .../loading-template.directive.spec.ts | 7 +- .../no-content-template.directive.spec.ts | 7 +- .../no-permission-template.directive.spec.ts | 7 +- .../directives/highlight.directive.spec.ts | 19 +- .../lib/directives/logout.directive.spec.ts | 37 +- .../dynamic-chip-list.component.spec.ts | 64 ++- .../form-field/form-field.component.spec.ts | 8 +- .../form-renderer.component.spec.ts | 7 +- .../inplace-form-input.component.spec.ts | 18 +- .../widgets/amount/amount.widget.spec.ts | 7 +- .../base-viewer/base-viewer.widget.spec.ts | 22 +- .../widgets/checkbox/checkbox.widget.spec.ts | 4 +- .../date-time/date-time.widget.spec.ts | 3 +- .../widgets/date/date.widget.spec.ts | 12 +- .../widgets/decimal/decimal.component.spec.ts | 8 +- .../hyperlink/hyperlink.widget.spec.ts | 14 +- .../multiline-text.widget.spec.ts | 3 +- .../widgets/number/number.widget.spec.ts | 3 +- .../widgets/text/text.widget.spec.ts | 3 +- .../widgets/widget.component.spec.ts | 16 +- .../components/widgets/widget.component.ts | 5 +- .../lib/form/models/form-rules.model.spec.ts | 15 +- .../lib/form/services/form.service.spec.ts | 8 +- .../widget-visibility-cloud.service.spec.ts | 75 ++- .../widget-visibility.service.spec.ts | 231 ++++---- .../identity-user-info.component.spec.ts | 26 +- .../info-drawer/info-drawer.component.spec.ts | 49 +- .../language-menu.component.spec.ts | 9 +- .../header/header.component.spec.ts | 11 +- .../sidebar-action-menu.component.spec.ts | 16 +- .../login-dialog-panel.component.spec.ts | 10 +- .../components/login/login.component.spec.ts | 77 +-- .../directives/login-footer.directive.spec.ts | 9 +- .../directives/login-header.directive.spec.ts | 10 +- .../notification-history.component.spec.ts | 39 +- .../services/notification.service.spec.ts | 3 +- .../infinite-pagination.component.spec.ts | 34 +- .../pagination/pagination.component.spec.ts | 38 +- lib/core/src/lib/pipes/date-time.pipe.spec.ts | 3 +- .../src/lib/pipes/decimal-number.pipe.spec.ts | 7 +- .../src/lib/pipes/localized-date.pipe.spec.ts | 7 +- lib/core/src/lib/pipes/time-ago.pipe.spec.ts | 10 +- .../search-text-input.component.spec.ts | 13 +- .../snackbar-content.component.spec.ts | 30 +- .../empty-content.component.spec.ts | 17 +- .../error-content.component.spec.ts | 11 +- .../src/lib/toolbar/toolbar.component.spec.ts | 7 +- .../download-prompt-dialog.component.spec.ts | 10 +- .../components/img-viewer.component.spec.ts | 22 +- .../pdf-viewer-password-dialog.spec.ts | 6 +- .../pdf-viewer-thumb.component.spec.ts | 21 +- .../pdf-viewer-thumbnails.component.spec.ts | 46 +- .../components/pdf-viewer.component.spec.ts | 149 ++--- .../components/txt-viewer.component.spec.ts | 12 +- .../viewer-render.component.spec.ts | 35 +- .../components/viewer.component.spec.ts | 72 +-- .../viewer-extension.directive.spec.ts | 8 +- .../analytics-generator.component.spec.ts | 3 +- ...nalytics-report-heat-map.component.spec.ts | 10 +- .../analytics-report-list.component.spec.ts | 3 +- ...lytics-report-parameters.component.spec.ts | 163 +++--- .../analytics-report-parameters.component.ts | 12 +- .../date-range/date-range.widget.spec.ts | 8 +- .../diagram.component.activities.spec.ts | 111 ++-- .../diagram.component.boundary.spec.ts | 111 ++-- .../diagram.component.catching.events.spec.ts | 123 ++-- .../diagram.component.events.spec.ts | 127 +++-- .../diagram.component.flows.spec.ts | 11 +- .../diagram.component.gateways.spec.ts | 43 +- .../diagram.component.structural.spec.ts | 11 +- .../components/diagram.component.swim.spec.ts | 11 +- .../diagram.component.throw.spec.ts | 109 ++-- .../lib/testing/insights.testing.module.ts | 18 +- .../app-details-cloud.component.spec.ts | 3 +- .../app-list-cloud.component.spec.ts | 4 +- .../apps-process-cloud.service.spec.ts | 70 +-- .../date-range-filter.component.spec.ts | 22 +- ...rm-cloud-custom-outcomes.component.spec.ts | 39 +- ...efinition-selector-cloud.component.spec.ts | 9 +- ...attach-file-cloud-widget.component.spec.ts | 5 +- .../attach-file-cloud-widget.component.ts | 55 +- ...e-properties-table-cloud.component.spec.ts | 56 +- .../attach-file/upload-cloud.widget.ts | 12 +- .../data-table/data-table.widget.spec.ts | 22 +- .../widgets/data-table/data-table.widget.ts | 7 +- .../widgets/date/date-cloud.widget.spec.ts | 3 +- .../display-external-property.widget.spec.ts | 25 +- .../display-external-property.widget.ts | 25 +- .../dropdown/dropdown-cloud.widget.spec.ts | 251 ++++---- .../widgets/dropdown/dropdown-cloud.widget.ts | 83 +-- .../widgets/group/group-cloud.widget.spec.ts | 42 +- .../people/people-cloud.widget.spec.ts | 44 +- .../properties-viewer.widget.spec.ts | 11 +- .../properties-viewer.widget.spec.ts | 11 +- .../radio-buttons-cloud.widget.spec.ts | 11 +- .../radio-buttons-cloud.widget.ts | 11 +- ...ontent-cloud-node-selector.service.spec.ts | 3 +- .../content-cloud-node-selector.service.ts | 31 +- .../form/services/form-cloud.service.spec.ts | 155 +++-- ...-definition-selector-cloud.service.spec.ts | 7 +- .../components/group-cloud.component.spec.ts | 3 +- .../group/components/group-cloud.component.ts | 5 +- .../services/identity-group.service.spec.ts | 169 +++--- .../components/people-cloud.component.spec.ts | 3 +- .../components/people-cloud.component.ts | 6 +- .../services/identity-user.service.spec.ts | 266 ++++----- .../lib/pipes/process-name-cloud.pipe.spec.ts | 8 +- .../cancel-process.directive.spec.ts | 14 +- .../mock/process-cloud.service.mock.ts | 10 - ...dit-process-filter-cloud.component.spec.ts | 3 +- ...cess-filter-dialog-cloud.component.spec.ts | 41 +- .../process-filters-cloud.component.spec.ts | 26 +- .../process-filter-cloud.service.spec.ts | 18 +- .../process-header-cloud.component.spec.ts | 9 +- .../process-list-cloud.component.spec.ts | 9 +- .../services/process-list-cloud.service.ts | 7 +- .../process-task-list-cloud.service.ts | 7 +- .../process/services/process-cloud.service.ts | 24 +- .../start-process-cloud.component.spec.ts | 2 - .../services/start-process-cloud.service.ts | 11 +- .../src/lib/services/base-cloud.service.ts | 77 +-- .../notification-cloud.service.spec.ts | 6 +- .../user-preference-cloud.service.spec.ts | 296 +++++----- .../services/user-preference-cloud.service.ts | 140 +++-- .../claim-task-cloud.directive.spec.ts | 38 +- .../complete-task.directive.spec.ts | 48 +- .../unclaim-task-cloud.directive.spec.ts | 38 +- .../lib/task/mock/task-cloud.service.mock.ts | 16 +- .../task/services/task-cloud.service.spec.ts | 127 +++-- .../lib/task/services/task-cloud.service.ts | 86 +-- .../start-task-cloud.component.spec.ts | 16 +- .../components/start-task-cloud.component.ts | 53 +- .../services/start-task-cloud.service.spec.ts | 47 +- ...ervice-task-filter-cloud.component.spec.ts | 3 +- .../edit-task-filter-cloud.component.spec.ts | 3 +- ...rvice-task-filters-cloud.component.spec.ts | 13 +- .../task-assignment-filter.component.spec.ts | 28 +- ...task-filter-dialog-cloud.component.spec.ts | 9 +- .../task-form-cloud.component.spec.ts | 3 +- .../task-header-cloud.component.spec.ts | 45 +- .../service-task-list-cloud.component.spec.ts | 7 +- .../task-list-cloud.component.spec.ts | 30 +- .../service-task-list-cloud.service.spec.ts | 76 +-- .../service-task-list-cloud.service.ts | 13 +- .../services/task-list-cloud.service.spec.ts | 21 +- .../services/task-list-cloud.service.ts | 1 - .../lib/app-list/apps-list.component.spec.ts | 3 +- .../select-apps-dialog.component.spec.ts | 23 +- .../services/apps-process.service.spec.ts | 63 +- ...reate-process-attachment.component.spec.ts | 7 +- .../create-task-attachment.component.spec.ts | 3 +- .../process-attachment-list.component.spec.ts | 5 +- .../task-attachment-list.component.spec.ts | 63 +- .../services/people-process.service.spec.ts | 99 ++-- .../src/lib/form/form.component.spec.ts | 232 ++++---- .../form/form.component.visibility.spec.ts | 3 +- .../services/activiti-alfresco.service.ts | 22 +- .../form/services/ecm-model.service.spec.ts | 219 ++++--- .../lib/form/services/ecm-model.service.ts | 21 +- .../src/lib/form/services/editor.service.ts | 24 +- .../src/lib/form/services/model.service.ts | 5 +- .../services/process-content.service.spec.ts | 10 +- .../services/process-definition.service.ts | 5 +- .../lib/form/services/task-form.service.ts | 5 +- .../src/lib/form/services/task.service.ts | 21 +- .../src/lib/form/start-form.component.spec.ts | 74 ++- ...ttach-file-widget-dialog.component.spec.ts | 33 +- .../attach-file-widget-dialog.service.spec.ts | 9 +- .../attach-file-widget.component.spec.ts | 3 +- .../attach-file-widget.component.ts | 14 +- .../attach-folder-widget.component.spec.ts | 3 +- .../widgets/document/content.widget.spec.ts | 63 +- .../widgets/dropdown/dropdown.widget.spec.ts | 3 +- .../form/widgets/dropdown/dropdown.widget.ts | 41 +- .../dynamic-table.widget.spec.ts | 52 +- .../dynamic-table/dynamic-table.widget.ts | 9 +- .../editors/date/date.editor.spec.ts | 13 +- .../editors/datetime/datetime.editor.spec.ts | 10 +- .../editors/dropdown/dropdown.editor.spec.ts | 44 +- .../editors/dropdown/dropdown.editor.ts | 31 +- .../editors/row-editor/row.editor.spec.ts | 23 +- .../functional-group.widget.spec.ts | 29 +- .../form/widgets/people/people.widget.spec.ts | 42 +- .../radio-buttons.widget.spec.ts | 5 +- .../radio-buttons/radio-buttons.widget.ts | 29 +- .../typeahead/typeahead.widget.spec.ts | 177 +++--- .../widgets/typeahead/typeahead.widget.ts | 49 +- .../form/widgets/upload/upload.widget.spec.ts | 43 +- .../lib/form/widgets/upload/upload.widget.ts | 25 +- .../people-list/people-list.component.spec.ts | 7 +- .../people-search-field.component.spec.ts | 7 +- .../people-search.component.spec.ts | 7 +- .../people-selector.component.spec.ts | 30 +- .../people-selector.component.ts | 11 +- .../people/people.component.spec.ts | 77 +-- .../components/people/people.component.ts | 53 +- .../src/lib/pipes/process-name.pipe.spec.ts | 10 +- .../process-comments.component.spec.ts | 9 +- .../process-audit.directive.spec.ts | 90 +-- .../process-filters.component.spec.ts | 20 +- ...process-instance-details.component.spec.ts | 10 +- .../process-instance-details.component.ts | 7 +- .../process-instance-header.component.spec.ts | 12 +- .../process-instance-tasks.component.spec.ts | 3 +- .../process-instance-tasks.component.ts | 10 +- .../components/process-list.component.spec.ts | 177 +++--- .../start-process.component.spec.ts | 7 +- .../process-user-info.component.spec.ts | 15 +- .../services/task-comments.service.spec.ts | 48 +- .../components/attach-form.component.spec.ts | 14 +- .../components/attach-form.component.ts | 43 +- .../components/checklist.component.spec.ts | 126 ++-- .../no-task-detail-template.directive.spec.ts | 3 +- .../components/start-task.component.spec.ts | 15 +- .../components/start-task.component.ts | 38 +- .../components/task-audit.directive.spec.ts | 55 +- .../components/task-details.component.spec.ts | 3 +- .../components/task-details.component.ts | 14 +- .../components/task-filters.component.spec.ts | 39 +- .../task-form/claim-task.directive.ts | 23 +- .../task-form/task-form.component.spec.ts | 3 +- .../task-form/unclaim-task.directive.ts | 21 +- .../components/task-header.component.spec.ts | 3 +- .../components/task-list.component.spec.ts | 10 +- .../task-standalone.component.spec.ts | 6 +- 275 files changed, 4104 insertions(+), 5565 deletions(-) diff --git a/demo-shell/src/app/components/settings/settings.component.html b/demo-shell/src/app/components/settings/settings.component.html index 1e45f7c65c8..ab701c3f09d 100644 --- a/demo-shell/src/app/components/settings/settings.component.html +++ b/demo-shell/src/app/components/settings/settings.component.html @@ -1 +1 @@ - + diff --git a/demo-shell/src/app/components/settings/settings.component.ts b/demo-shell/src/app/components/settings/settings.component.ts index 6d4642a9e96..3ba506d76cc 100644 --- a/demo-shell/src/app/components/settings/settings.component.ts +++ b/demo-shell/src/app/components/settings/settings.component.ts @@ -16,7 +16,6 @@ */ import { Component } from '@angular/core'; -import { LogService } from '@alfresco/adf-core'; import { Router } from '@angular/router'; @Component({ @@ -24,14 +23,7 @@ import { Router } from '@angular/router'; templateUrl: './settings.component.html' }) export class SettingsComponent { - - constructor(private router: Router, - public logService: LogService) { - } - - onError(error: string) { - this.logService.log(error); - } + constructor(private router: Router) {} onCancel() { this.router.navigate(['/login']); diff --git a/demo-shell/src/app/services/in-memory-form.service.ts b/demo-shell/src/app/services/in-memory-form.service.ts index 823f34f0aa5..57c3dd2113e 100644 --- a/demo-shell/src/app/services/in-memory-form.service.ts +++ b/demo-shell/src/app/services/in-memory-form.service.ts @@ -16,9 +16,7 @@ */ import { Injectable } from '@angular/core'; -import { AppConfigService, LogService, - FormFieldOption, FormService, FormValues, FormModel, - FormOutcomeModel, FormOutcomeEvent } from '@alfresco/adf-core'; +import { AppConfigService, FormFieldOption, FormService, FormValues, FormModel, FormOutcomeModel, FormOutcomeEvent } from '@alfresco/adf-core'; import { Observable, Subject } from 'rxjs'; interface ProcessServiceData { @@ -37,13 +35,11 @@ interface ProcessServiceData { // @Injectable() export class InMemoryFormService extends FormService { - private data: ProcessServiceData; executeOutcome = new Subject(); - constructor(appConfig: AppConfigService, - protected logService: LogService) { + constructor(appConfig: AppConfigService) { super(); this.data = appConfig.get('activiti'); } @@ -53,14 +49,10 @@ export class InMemoryFormService extends FormService { // Uncomment this to use original call // return super.getRestFieldValues(taskId, fieldId); - this.logService.log(`getRestFieldValues: ${taskId} => ${field}`); return new Observable((observer) => { - const currentField = this.data.rest.fields.find( - (f) => f.taskId === taskId && f.fieldId === field - ); - if ( currentField ) { + const currentField = this.data.rest.fields.find((f) => f.taskId === taskId && f.fieldId === field); + if (currentField) { const values: FormFieldOption[] = currentField.values || []; - this.logService.log(values); observer.next(values); } }); @@ -75,7 +67,7 @@ export class InMemoryFormService extends FormService { delete flattenForm.formDefinition; const formValues: FormValues = {}; - (data || []).forEach(variable => { + (data || []).forEach((variable) => { formValues[variable.name] = variable.value; }); @@ -99,13 +91,11 @@ export class InMemoryFormService extends FormService { // Uncomment this to use original call // return super.getRestFieldValuesByProcessId(processDefinitionId, fieldId); - this.logService.log(`getRestFieldValuesByProcessId: ${processDefinitionId} => ${fieldId}`); return new Observable((observer) => { const field = this.data.rest.fields.find( (currentField) => currentField.processId === processDefinitionId && currentField.fieldId === fieldId ); const values: FormFieldOption[] = field.values || []; - this.logService.log(values); observer.next(values); }); } diff --git a/docs/process-services/components/people.component.md b/docs/process-services/components/people.component.md index dd61cfc886e..d6620946c9a 100644 --- a/docs/process-services/components/people.component.md +++ b/docs/process-services/components/people.component.md @@ -43,6 +43,10 @@ Displays users involved with a specified task | readOnly | `boolean` | false | Should the data be read-only? | | taskId | `string` | "" | The numeric ID of the task. | +### Events + +- `error`: Emitted when an error occurs. + ## Details ### How to customize the people component behavior diff --git a/lib/content-services/src/lib/aspect-list/services/aspect-list.service.ts b/lib/content-services/src/lib/aspect-list/services/aspect-list.service.ts index 289d5ceedad..fd54837029f 100644 --- a/lib/content-services/src/lib/aspect-list/services/aspect-list.service.ts +++ b/lib/content-services/src/lib/aspect-list/services/aspect-list.service.ts @@ -16,7 +16,7 @@ */ import { Injectable } from '@angular/core'; -import { AlfrescoApiService, AppConfigService, LogService } from '@alfresco/adf-core'; +import { AlfrescoApiService, AppConfigService } from '@alfresco/adf-core'; import { from, Observable, of, zip } from 'rxjs'; import { catchError, map } from 'rxjs/operators'; import { AspectEntry, AspectPaging, AspectsApi } from '@alfresco/js-api'; @@ -25,17 +25,13 @@ import { AspectEntry, AspectPaging, AspectsApi } from '@alfresco/js-api'; providedIn: 'root' }) export class AspectListService { - private _aspectsApi: AspectsApi; get aspectsApi(): AspectsApi { this._aspectsApi = this._aspectsApi ?? new AspectsApi(this.alfrescoApiService.getInstance()); return this._aspectsApi; } - constructor(private alfrescoApiService: AlfrescoApiService, - private appConfigService: AppConfigService, - private logService: LogService) { - } + constructor(private alfrescoApiService: AlfrescoApiService, private appConfigService: AppConfigService) {} getAspects(): Observable { const visibleAspectList = this.getVisibleAspects(); @@ -52,14 +48,11 @@ export class AspectListService { where, include: ['properties'] }; - return from(this.aspectsApi.listAspects(opts)) - .pipe( - map((result: AspectPaging) => this.filterAspectByConfig(whiteList, result?.list?.entries)), - catchError((error) => { - this.logService.error(error); - return of([]); - }) - ); + + return from(this.aspectsApi.listAspects(opts)).pipe( + map((result: AspectPaging) => this.filterAspectByConfig(whiteList, result?.list?.entries)), + catchError(() => of([])) + ); } getCustomAspects(whiteList?: string[]): Observable { @@ -68,14 +61,10 @@ export class AspectListService { where, include: ['properties'] }; - return from(this.aspectsApi.listAspects(opts)) - .pipe( - map((result: AspectPaging) => this.filterAspectByConfig(whiteList, result?.list?.entries)), - catchError((error) => { - this.logService.error(error); - return of([]); - }) - ); + return from(this.aspectsApi.listAspects(opts)).pipe( + map((result: AspectPaging) => this.filterAspectByConfig(whiteList, result?.list?.entries)), + catchError(() => of([])) + ); } private filterAspectByConfig(visibleAspectList: string[], aspectEntries: AspectEntry[]): AspectEntry[] { @@ -96,5 +85,4 @@ export class AspectListService { } return visibleAspectList; } - } diff --git a/lib/content-services/src/lib/common/services/rendition.service.ts b/lib/content-services/src/lib/common/services/rendition.service.ts index 07557b04fc1..b0edfaf3ae9 100644 --- a/lib/content-services/src/lib/common/services/rendition.service.ts +++ b/lib/content-services/src/lib/common/services/rendition.service.ts @@ -17,13 +17,12 @@ import { Injectable } from '@angular/core'; import { ContentApi, RenditionEntry, RenditionPaging, RenditionsApi, VersionsApi } from '@alfresco/js-api'; -import { AlfrescoApiService , LogService, Track,TranslationService, ViewUtilService } from '@alfresco/adf-core'; +import { AlfrescoApiService, Track, TranslationService, ViewUtilService } from '@alfresco/adf-core'; @Injectable({ providedIn: 'root' }) export class RenditionService { - static TARGET = '_new'; /** @@ -53,7 +52,6 @@ export class RenditionService { */ private TRY_TIMEOUT: number = 10000; - _renditionsApi: RenditionsApi; get renditionsApi(): RenditionsApi { this._renditionsApi = this._renditionsApi ?? new RenditionsApi(this.apiService.getInstance()); @@ -74,17 +72,12 @@ export class RenditionService { return this._versionsApi; } - constructor(private apiService: AlfrescoApiService, - private logService: LogService, - private translateService: TranslationService, - private viewUtilsService: ViewUtilService) { - } - + constructor(private apiService: AlfrescoApiService, private translateService: TranslationService, private viewUtilsService: ViewUtilService) {} getRenditionUrl(nodeId: string, type: string, renditionExists: boolean): string { - return (renditionExists && type !== RenditionService.ContentGroup.IMAGE) ? - this.contentApi.getRenditionUrl(nodeId, RenditionService.ContentGroup.PDF) : - this.contentApi.getContentUrl(nodeId, false); + return renditionExists && type !== RenditionService.ContentGroup.IMAGE + ? this.contentApi.getRenditionUrl(nodeId, RenditionService.ContentGroup.PDF) + : this.contentApi.getContentUrl(nodeId, false); } private async waitRendition(nodeId: string, renditionId: string, retries: number): Promise { @@ -110,18 +103,18 @@ export class RenditionService { async getRendition(nodeId: string, renditionId: string): Promise { const renditionPaging: RenditionPaging = await this.renditionsApi.listRenditions(nodeId); - let rendition: RenditionEntry = renditionPaging.list.entries.find((renditionEntry: RenditionEntry) => renditionEntry.entry.id.toLowerCase() === renditionId); + let rendition: RenditionEntry = renditionPaging.list.entries.find( + (renditionEntry: RenditionEntry) => renditionEntry.entry.id.toLowerCase() === renditionId + ); if (rendition) { const status = rendition.entry.status.toString(); if (status === 'NOT_CREATED') { try { - await this.renditionsApi.createRendition(nodeId, {id: renditionId}); + await this.renditionsApi.createRendition(nodeId, { id: renditionId }); rendition = await this.waitRendition(nodeId, renditionId, 0); - } catch (err) { - this.logService.error(err); - } + } catch {} } } return new Promise((resolve) => resolve(rendition)); @@ -129,10 +122,8 @@ export class RenditionService { async getNodeRendition(nodeId: string, versionId?: string): Promise<{ url: string; mimeType: string }> { try { - return versionId ? await this.resolveNodeRendition(nodeId, 'pdf', versionId) : - await this.resolveNodeRendition(nodeId, 'pdf'); - } catch (err) { - this.logService.error(err); + return versionId ? await this.resolveNodeRendition(nodeId, 'pdf', versionId) : await this.resolveNodeRendition(nodeId, 'pdf'); + } catch { return null; } } @@ -140,8 +131,9 @@ export class RenditionService { private async resolveNodeRendition(nodeId: string, renditionId: string, versionId?: string): Promise<{ url: string; mimeType: string }> { renditionId = renditionId.toLowerCase(); - const supportedRendition: RenditionPaging = versionId ? await this.versionsApi.listVersionRenditions(nodeId, versionId) : - await this.renditionsApi.listRenditions(nodeId); + const supportedRendition: RenditionPaging = versionId + ? await this.versionsApi.listVersionRenditions(nodeId, versionId) + : await this.renditionsApi.listRenditions(nodeId); let rendition = this.findRenditionById(supportedRendition, renditionId); if (!rendition) { @@ -154,9 +146,9 @@ export class RenditionService { const mimeType: string = rendition.entry.content.mimeType; if (status === 'NOT_CREATED') { - return {url: await this.requestCreateRendition(nodeId, renditionId, versionId), mimeType}; + return { url: await this.requestCreateRendition(nodeId, renditionId, versionId), mimeType }; } else { - return {url: await this.handleNodeRendition(nodeId, renditionId, versionId), mimeType}; + return { url: await this.handleNodeRendition(nodeId, renditionId, versionId), mimeType }; } } @@ -166,25 +158,22 @@ export class RenditionService { private async requestCreateRendition(nodeId: string, renditionId: string, versionId: string): Promise { try { if (versionId) { - await this.versionsApi.createVersionRendition(nodeId, versionId, {id: renditionId}); + await this.versionsApi.createVersionRendition(nodeId, versionId, { id: renditionId }); } else { - await this.renditionsApi.createRendition(nodeId, {id: renditionId}); + await this.renditionsApi.createRendition(nodeId, { id: renditionId }); } try { return versionId ? await this.waitNodeRendition(nodeId, renditionId, versionId) : await this.waitNodeRendition(nodeId, renditionId); } catch (e) { return null; } - - } catch (err) { - this.logService.error(err); + } catch { return null; } } private findRenditionById(supportedRendition: RenditionPaging, renditionId: string) { - const rendition: RenditionEntry = supportedRendition.list.entries.find((renditionEntry: RenditionEntry) => renditionEntry.entry.id.toLowerCase() === renditionId); - return rendition; + return supportedRendition.list.entries.find((renditionEntry: RenditionEntry) => renditionEntry.entry.id.toLowerCase() === renditionId); } private async waitNodeRendition(nodeId: string, renditionId: string, versionId?: string): Promise { @@ -194,23 +183,29 @@ export class RenditionService { currentRetry++; if (this.maxRetries >= currentRetry) { if (versionId) { - this.versionsApi.getVersionRendition(nodeId, versionId, renditionId).then((rendition: RenditionEntry) => { - const status: string = rendition.entry.status.toString(); - - if (status === 'CREATED') { - clearInterval(intervalId); - return resolve(this.handleNodeRendition(nodeId, rendition.entry.content.mimeType, versionId)); - } - }, () => reject(new Error('Error geting version rendition'))); + this.versionsApi.getVersionRendition(nodeId, versionId, renditionId).then( + (rendition: RenditionEntry) => { + const status: string = rendition.entry.status.toString(); + + if (status === 'CREATED') { + clearInterval(intervalId); + return resolve(this.handleNodeRendition(nodeId, rendition.entry.content.mimeType, versionId)); + } + }, + () => reject(new Error('Error geting version rendition')) + ); } else { - this.renditionsApi.getRendition(nodeId, renditionId).then((rendition: RenditionEntry) => { - const status: string = rendition.entry.status.toString(); - - if (status === 'CREATED') { - clearInterval(intervalId); - return resolve(this.handleNodeRendition(nodeId, renditionId, versionId)); - } - }, () => reject(new Error('Error getting rendition'))); + this.renditionsApi.getRendition(nodeId, renditionId).then( + (rendition: RenditionEntry) => { + const status: string = rendition.entry.status.toString(); + + if (status === 'CREATED') { + clearInterval(intervalId); + return resolve(this.handleNodeRendition(nodeId, renditionId, versionId)); + } + }, + () => reject(new Error('Error getting rendition')) + ); } } else { clearInterval(intervalId); @@ -221,11 +216,9 @@ export class RenditionService { } private async handleNodeRendition(nodeId: string, renditionId: string, versionId?: string): Promise { - - const url = versionId ? this.contentApi.getVersionRenditionUrl(nodeId, versionId, renditionId) : - this.contentApi.getRenditionUrl(nodeId, renditionId); - - return url; + return versionId + ? this.contentApi.getVersionRenditionUrl(nodeId, versionId, renditionId) + : this.contentApi.getRenditionUrl(nodeId, renditionId); } async generateMediaTracksRendition(nodeId: string): Promise { @@ -241,16 +234,14 @@ export class RenditionService { } return tracks; }) - .catch((err) => { - this.logService.error('Error while retrieving ' + RenditionService.SUBTITLES_RENDITION_NAME + ' rendition'); - this.logService.error(err); - return []; - }); + .catch(() => []); } private async isRenditionAvailable(nodeId: string, renditionId: string): Promise { const renditionPaging: RenditionPaging = await this.renditionsApi.listRenditions(nodeId); - const rendition: RenditionEntry = renditionPaging.list.entries.find((renditionEntry: RenditionEntry) => renditionEntry.entry.id.toLowerCase() === renditionId); + const rendition: RenditionEntry = renditionPaging.list.entries.find( + (renditionEntry: RenditionEntry) => renditionEntry.entry.id.toLowerCase() === renditionId + ); return rendition?.entry?.status?.toString() === 'CREATED' || false; } @@ -297,15 +288,13 @@ export class RenditionService { this.getRendition(nodeId, RenditionService.ContentGroup.PDF) .then((value) => { - const url: string = this.getRenditionUrl(nodeId, type, (!!value)); - const printType = (type === RenditionService.ContentGroup.PDF - || type === RenditionService.ContentGroup.TEXT) - ? RenditionService.ContentGroup.PDF : type; + const url: string = this.getRenditionUrl(nodeId, type, !!value); + const printType = + type === RenditionService.ContentGroup.PDF || type === RenditionService.ContentGroup.TEXT + ? RenditionService.ContentGroup.PDF + : type; this.printFile(url, printType); }) - .catch((err) => { - this.logService.error('Error with Printing'); - this.logService.error(err); - }); + .catch(() => {}); } } diff --git a/lib/content-services/src/lib/common/services/rendition.services.spec.ts b/lib/content-services/src/lib/common/services/rendition.services.spec.ts index 713a387a03e..8462276ee7a 100644 --- a/lib/content-services/src/lib/common/services/rendition.services.spec.ts +++ b/lib/content-services/src/lib/common/services/rendition.services.spec.ts @@ -16,7 +16,7 @@ */ import { TestBed } from '@angular/core/testing'; -import { AlfrescoApiService, LogService, TranslationService, ViewUtilService } from '@alfresco/adf-core'; +import { AlfrescoApiService, TranslationService, ViewUtilService } from '@alfresco/adf-core'; import { Rendition, RenditionEntry, RenditionPaging, RenditionsApi } from '@alfresco/js-api'; import { RenditionService } from '@alfresco/adf-content-services'; @@ -28,7 +28,7 @@ const getRenditionEntry = (status: Rendition.StatusEnum): RenditionEntry => ({ } }); -const getRenditionPaging = (status: Rendition.StatusEnum): RenditionPaging => ({ +const getRenditionPaging = (status: Rendition.StatusEnum): RenditionPaging => ({ list: { entries: [getRenditionEntry(status)] } @@ -43,14 +43,16 @@ describe('RenditionService', () => { providers: [ RenditionService, { provide: AlfrescoApiService, useValue: {} }, - { provide: LogService, useValue: { error: jasmine.createSpy('error') } }, { provide: TranslationService, useValue: {} }, { provide: ViewUtilService, useValue: {} }, - { provide: RenditionsApi, useValue: { + { + provide: RenditionsApi, + useValue: { listRenditions: jasmine.createSpy('listRenditions'), getRendition: jasmine.createSpy('getRendition'), createRendition: jasmine.createSpy('createRendition') - } } + } + } ] }); renditionService = TestBed.inject(RenditionService); @@ -77,9 +79,9 @@ describe('RenditionService', () => { renditionsApi.listRenditions.and.returnValue(Promise.resolve(mockRenditionPaging)); renditionsApi.getRendition.and.returnValues( - Promise.resolve(getRenditionEntry(Rendition.StatusEnum.NOTCREATED)), - Promise.resolve(getRenditionEntry(Rendition.StatusEnum.NOTCREATED)), - Promise.resolve(mockRenditionEntry) + Promise.resolve(getRenditionEntry(Rendition.StatusEnum.NOTCREATED)), + Promise.resolve(getRenditionEntry(Rendition.StatusEnum.NOTCREATED)), + Promise.resolve(mockRenditionEntry) ); const result = await renditionService.getRendition('nodeId', 'pdf'); @@ -98,5 +100,4 @@ describe('RenditionService', () => { expect(result).toEqual(mockRenditionPaging.list.entries[0]); expect(renditionsApi.getRendition).not.toHaveBeenCalled(); }); - }); diff --git a/lib/content-services/src/lib/site-dropdown/sites-dropdown.component.ts b/lib/content-services/src/lib/site-dropdown/sites-dropdown.component.ts index 0d8d2d2a585..8537ee0efaa 100644 --- a/lib/content-services/src/lib/site-dropdown/sites-dropdown.component.ts +++ b/lib/content-services/src/lib/site-dropdown/sites-dropdown.component.ts @@ -16,7 +16,7 @@ */ import { Component, EventEmitter, Input, OnInit, Output, ViewEncapsulation } from '@angular/core'; -import { LogService, InfiniteSelectScrollDirective, AuthenticationService } from '@alfresco/adf-core'; +import { InfiniteSelectScrollDirective, AuthenticationService } from '@alfresco/adf-core'; import { SitePaging, SiteEntry, Site } from '@alfresco/js-api'; import { MatSelectChange } from '@angular/material/select'; import { LiveAnnouncer } from '@angular/cdk/a11y'; @@ -77,6 +77,9 @@ export class DropdownSitesComponent implements OnInit { @Output() change: EventEmitter = new EventEmitter(); + @Output() + error = new EventEmitter(); + private loading = true; private skipCount = 0; @@ -86,7 +89,6 @@ export class DropdownSitesComponent implements OnInit { constructor( private authService: AuthenticationService, private sitesService: SitesService, - private logService: LogService, private liveAnnouncer: LiveAnnouncer, private translateService: TranslateService ) {} @@ -158,7 +160,7 @@ export class DropdownSitesComponent implements OnInit { this.loading = false; }, (error) => { - this.logService.error(error); + this.error.emit(error); } ); } diff --git a/lib/content-services/src/lib/upload/components/upload-button.component.ts b/lib/content-services/src/lib/upload/components/upload-button.component.ts index fbd5ffd3390..6d5cb24e102 100644 --- a/lib/content-services/src/lib/upload/components/upload-button.component.ts +++ b/lib/content-services/src/lib/upload/components/upload-button.component.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { EXTENDIBLE_COMPONENT, FileUtils, LogService } from '@alfresco/adf-core'; +import { EXTENDIBLE_COMPONENT, FileUtils } from '@alfresco/adf-core'; import { Component, EventEmitter, forwardRef, Input, OnChanges, OnInit, Output, SimpleChanges, ViewEncapsulation, inject } from '@angular/core'; import { NodesApiService } from '../../common/services/nodes-api.service'; import { ContentService } from '../../common/services/content.service'; @@ -36,7 +36,6 @@ import { NodeAllowableOperationSubject } from '../../interfaces/node-allowable-o export class UploadButtonComponent extends UploadBase implements OnInit, OnChanges, NodeAllowableOperationSubject { private contentService = inject(ContentService); private nodesApiService = inject(NodesApiService); - protected logService = inject(LogService); /** Allows/disallows upload folders (only for Chrome). */ @Input() diff --git a/lib/content-services/src/lib/viewer/components/alfresco-viewer.component.ts b/lib/content-services/src/lib/viewer/components/alfresco-viewer.component.ts index 12959a50b00..bf914cb835a 100644 --- a/lib/content-services/src/lib/viewer/components/alfresco-viewer.component.ts +++ b/lib/content-services/src/lib/viewer/components/alfresco-viewer.component.ts @@ -32,7 +32,6 @@ import { import { AlfrescoApiService, CloseButtonPosition, - LogService, Track, ViewerComponent, ViewerMoreActionsComponent, @@ -241,7 +240,6 @@ export class AlfrescoViewerComponent implements OnChanges, OnInit, OnDestroy { private nodesApiService: NodesApiService, private renditionService: RenditionService, private viewUtilService: ViewUtilService, - private logService: LogService, private contentService: ContentService, private uploadService: UploadService, public dialog: MatDialog, @@ -256,9 +254,7 @@ export class AlfrescoViewerComponent implements OnChanges, OnInit, OnDestroy { .pipe( filter( (node) => - node && - node.id === this.nodeId && - this.getNodeVersionProperty(this.nodeEntry.entry) !== this.getNodeVersionProperty(node) + node && node.id === this.nodeId && this.getNodeVersionProperty(this.nodeEntry.entry) !== this.getNodeVersionProperty(node) ), takeUntil(this.onDestroy$) ) @@ -284,7 +280,6 @@ export class AlfrescoViewerComponent implements OnChanges, OnInit, OnDestroy { const sharedLinkEntry = await this.sharedLinksApi.getSharedLink(this.sharedLinkId); await this.setUpSharedLinkFile(sharedLinkEntry); } catch (error) { - this.logService.error('This sharedLink does not exist'); this.invalidSharedLink.next(undefined); this.mimeType = 'invalid-link'; this.urlFileContent = 'invalid-file'; @@ -303,7 +298,6 @@ export class AlfrescoViewerComponent implements OnChanges, OnInit, OnDestroy { } } catch (error) { this.urlFileContent = 'invalid-node'; - this.logService.error('This node does not exist'); } } @@ -373,7 +367,6 @@ export class AlfrescoViewerComponent implements OnChanges, OnInit, OnDestroy { return { url: urlFileContent, mimeType: 'application/pdf' }; } } catch (error) { - this.logService.error(error); try { const rendition: RenditionEntry = await this.sharedLinksApi.getSharedLinkRendition(sharedId, 'imgpreview'); if (rendition.entry.status.toString() === 'CREATED') { @@ -381,7 +374,6 @@ export class AlfrescoViewerComponent implements OnChanges, OnInit, OnDestroy { return { url: urlFileContent, mimeType: 'image/png' }; } } catch (renditionError) { - this.logService.error(renditionError); return null; } } diff --git a/lib/core/src/lib/about/about-github-link/about-github-link.component.spec.ts b/lib/core/src/lib/about/about-github-link/about-github-link.component.spec.ts index 2539f00158c..a268562f5cd 100644 --- a/lib/core/src/lib/about/about-github-link/about-github-link.component.spec.ts +++ b/lib/core/src/lib/about/about-github-link/about-github-link.component.spec.ts @@ -19,7 +19,6 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; import { CoreTestingModule } from '../../testing/core.testing.module'; import { AboutGithubLinkComponent } from './about-github-link.component'; import { aboutGithubDetails } from '../about.mock'; -import { TranslateModule } from '@ngx-translate/core'; describe('AboutGithubLinkComponent', () => { let fixture: ComponentFixture; @@ -27,7 +26,7 @@ describe('AboutGithubLinkComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [TranslateModule.forRoot(), CoreTestingModule] + imports: [CoreTestingModule] }); fixture = TestBed.createComponent(AboutGithubLinkComponent); component = fixture.componentInstance; diff --git a/lib/core/src/lib/about/about-server-settings/about-server-settings.component.spec.ts b/lib/core/src/lib/about/about-server-settings/about-server-settings.component.spec.ts index c3f4ba67871..8013b351748 100644 --- a/lib/core/src/lib/about/about-server-settings/about-server-settings.component.spec.ts +++ b/lib/core/src/lib/about/about-server-settings/about-server-settings.component.spec.ts @@ -20,7 +20,6 @@ import { CoreTestingModule } from '../../testing/core.testing.module'; import { AboutServerSettingsComponent } from './about-server-settings.component'; import { AppConfigService } from '../../app-config/app-config.service'; import { aboutGithubDetails } from '../about.mock'; -import { TranslateModule } from '@ngx-translate/core'; describe('AboutServerSettingsComponent', () => { let fixture: ComponentFixture; @@ -29,10 +28,7 @@ describe('AboutServerSettingsComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - CoreTestingModule - ] + imports: [CoreTestingModule] }); fixture = TestBed.createComponent(AboutServerSettingsComponent); component = fixture.componentInstance; diff --git a/lib/core/src/lib/auth/basic-auth/basic-alfresco-auth.service.ts b/lib/core/src/lib/auth/basic-auth/basic-alfresco-auth.service.ts index 74761ee40dc..56f1a2a0e7c 100644 --- a/lib/core/src/lib/auth/basic-auth/basic-alfresco-auth.service.ts +++ b/lib/core/src/lib/auth/basic-auth/basic-alfresco-auth.service.ts @@ -25,7 +25,6 @@ import { catchError, map } from 'rxjs/operators'; import { from, Observable } from 'rxjs'; import { RedirectionModel } from '../models/redirection.model'; import { BaseAuthenticationService } from '../services/base-authentication.service'; -import { LogService } from '../../common'; import { HttpHeaders } from '@angular/common/http'; const REMEMBER_ME_COOKIE_KEY = 'ALFRESCO_REMEMBER_ME'; @@ -35,7 +34,6 @@ const REMEMBER_ME_UNTIL = 1000 * 60 * 60 * 24 * 30; providedIn: 'root' }) export class BasicAlfrescoAuthService extends BaseAuthenticationService { - protected redirectUrl: RedirectionModel = null; authentications: Authentication = { @@ -45,45 +43,52 @@ export class BasicAlfrescoAuthService extends BaseAuthenticationService { type: 'basic' }; - constructor( - logService: LogService, - appConfig: AppConfigService, - cookie: CookieService, - private contentAuth: ContentAuth, - private processAuth: ProcessAuth - ) { - super(appConfig, cookie, logService); - - this.appConfig.onLoad - .subscribe(() => { - if (!this.isOauth() && this.isLoggedIn()) { - this.requireAlfTicket().then(() => { + constructor(appConfig: AppConfigService, cookie: CookieService, private contentAuth: ContentAuth, private processAuth: ProcessAuth) { + super(appConfig, cookie); + + this.appConfig.onLoad.subscribe(() => { + if (!this.isOauth() && this.isLoggedIn()) { + this.requireAlfTicket() + .then(() => { this.onLogin.next('logged-in'); - }).catch(() => { + }) + .catch(() => { this.contentAuth.invalidateSession(); this.onLogout.next('logout'); }); - } - }); - - this.contentAuth.onLogout.pipe(map((event) => { - this.onLogout.next(event); - })); - this.contentAuth.onLogin.pipe(map((event) => { - this.onLogin.next(event); - })); - this.contentAuth.onError.pipe(map((event) => { - this.onError.next(event); - })); - this.processAuth.onLogout.pipe(map((event) => { - this.onLogout.next(event); - })); - this.processAuth.onLogin.pipe(map((event) => { - this.onLogin.next(event); - })); - this.processAuth.onError.pipe(map((event) => { - this.onError.next(event); - })); + } + }); + + this.contentAuth.onLogout.pipe( + map((event) => { + this.onLogout.next(event); + }) + ); + this.contentAuth.onLogin.pipe( + map((event) => { + this.onLogin.next(event); + }) + ); + this.contentAuth.onError.pipe( + map((event) => { + this.onError.next(event); + }) + ); + this.processAuth.onLogout.pipe( + map((event) => { + this.onLogout.next(event); + }) + ); + this.processAuth.onLogin.pipe( + map((event) => { + this.onLogin.next(event); + }) + ); + this.processAuth.onError.pipe( + map((event) => { + this.onError.next(event); + }) + ); } /** @@ -130,20 +135,17 @@ export class BasicAlfrescoAuthService extends BaseAuthenticationService { } catch (e) { return Promise.reject(e); } - } else if (this.isECMProvider()) { try { return await this.contentAuth.login(username, password); } catch (e) { return Promise.reject(e); } - } else if (this.isALLProvider()) { return this.loginBPMECM(username, password); } else { return Promise.reject(new Error('Unknown configuration')); } - } private loginBPMECM(username: string, password: string): Promise { @@ -165,7 +167,8 @@ export class BasicAlfrescoAuthService extends BaseAuthenticationService { } this.onError.next('error'); reject(error); - }); + } + ); }); } @@ -243,7 +246,7 @@ export class BasicAlfrescoAuthService extends BaseAuthenticationService { } else if (this.isECMProvider()) { return authWithCredentials ? true : this.contentAuth.isLoggedIn(); } else if (this.isALLProvider()) { - return authWithCredentials ? true : (this.contentAuth.isLoggedIn() && this.processAuth.isLoggedIn()); + return authWithCredentials ? true : this.contentAuth.isLoggedIn() && this.processAuth.isLoggedIn(); } else { return false; } @@ -281,12 +284,13 @@ export class BasicAlfrescoAuthService extends BaseAuthenticationService { } this.onError.next('error'); reject(error); - }); + } + ); }); - } reset(): void { + // do nothing } /** diff --git a/lib/core/src/lib/auth/guard/auth-guard-bpm.service.spec.ts b/lib/core/src/lib/auth/guard/auth-guard-bpm.service.spec.ts index 810d13e9641..c6e4cb64d97 100644 --- a/lib/core/src/lib/auth/guard/auth-guard-bpm.service.spec.ts +++ b/lib/core/src/lib/auth/guard/auth-guard-bpm.service.spec.ts @@ -22,12 +22,10 @@ import { AuthenticationService } from '../services/authentication.service'; import { RouterStateSnapshot, Router } from '@angular/router'; import { CoreTestingModule } from '../../testing/core.testing.module'; import { MatDialog } from '@angular/material/dialog'; -import { TranslateModule } from '@ngx-translate/core'; import { BasicAlfrescoAuthService } from '../basic-auth/basic-alfresco-auth.service'; import { OidcAuthenticationService } from '../services/oidc-authentication.service'; describe('AuthGuardService BPM', () => { - let authGuard: AuthGuardBpm; let authService: AuthenticationService; let basicAlfrescoAuthService: BasicAlfrescoAuthService; @@ -38,14 +36,12 @@ describe('AuthGuardService BPM', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - CoreTestingModule - ], + imports: [CoreTestingModule], providers: [ { - provide: OidcAuthenticationService, useValue: { - ssoLogin: () => { }, + provide: OidcAuthenticationService, + useValue: { + ssoLogin: () => {}, isPublicUrl: () => false, hasValidIdToken: () => false, isLoggedIn: () => false @@ -154,7 +150,8 @@ describe('AuthGuardService BPM', () => { authGuard.canActivate(null, route); expect(basicAlfrescoAuthService.setRedirect).toHaveBeenCalledWith({ - provider: 'BPM', url: 'some-url' + provider: 'BPM', + url: 'some-url' }); expect(basicAlfrescoAuthService.getRedirect()).toEqual('some-url'); }); @@ -167,7 +164,8 @@ describe('AuthGuardService BPM', () => { authGuard.canActivate(null, route); expect(basicAlfrescoAuthService.setRedirect).toHaveBeenCalledWith({ - provider: 'BPM', url: 'some-url;q=123' + provider: 'BPM', + url: 'some-url;q=123' }); expect(basicAlfrescoAuthService.getRedirect()).toEqual('some-url;q=123'); }); @@ -180,7 +178,8 @@ describe('AuthGuardService BPM', () => { authGuard.canActivate(null, route); expect(basicAlfrescoAuthService.setRedirect).toHaveBeenCalledWith({ - provider: 'BPM', url: '/' + provider: 'BPM', + url: '/' }); expect(basicAlfrescoAuthService.getRedirect()).toEqual('/'); }); @@ -194,7 +193,8 @@ describe('AuthGuardService BPM', () => { authGuard.canActivate(null, route); expect(basicAlfrescoAuthService.setRedirect).toHaveBeenCalledWith({ - provider: 'BPM', url: 'some-url' + provider: 'BPM', + url: 'some-url' }); expect(router.navigateByUrl).toHaveBeenCalledWith(router.parseUrl('/fakeLoginRoute?redirectUrl=some-url')); }); @@ -211,7 +211,8 @@ describe('AuthGuardService BPM', () => { authGuard.canActivate(null, route); expect(basicAlfrescoAuthService.setRedirect).toHaveBeenCalledWith({ - provider: 'BPM', url: 'some-url' + provider: 'BPM', + url: 'some-url' }); expect(materialDialog.closeAll).toHaveBeenCalled(); diff --git a/lib/core/src/lib/auth/guard/auth-guard-ecm.service.spec.ts b/lib/core/src/lib/auth/guard/auth-guard-ecm.service.spec.ts index e865954443a..55d180b8891 100644 --- a/lib/core/src/lib/auth/guard/auth-guard-ecm.service.spec.ts +++ b/lib/core/src/lib/auth/guard/auth-guard-ecm.service.spec.ts @@ -22,12 +22,10 @@ import { AuthenticationService } from '../services/authentication.service'; import { RouterStateSnapshot, Router } from '@angular/router'; import { CoreTestingModule } from '../../testing/core.testing.module'; import { MatDialog } from '@angular/material/dialog'; -import { TranslateModule } from '@ngx-translate/core'; import { OidcAuthenticationService } from '../services/oidc-authentication.service'; import { BasicAlfrescoAuthService } from '../basic-auth/basic-alfresco-auth.service'; describe('AuthGuardService ECM', () => { - let authGuard: AuthGuardEcm; let authService: AuthenticationService; let basicAlfrescoAuthService: BasicAlfrescoAuthService; @@ -37,14 +35,12 @@ describe('AuthGuardService ECM', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - CoreTestingModule - ], + imports: [CoreTestingModule], providers: [ { - provide: OidcAuthenticationService, useValue: { - ssoLogin: () => { }, + provide: OidcAuthenticationService, + useValue: { + ssoLogin: () => {}, isPublicUrl: () => false, hasValidIdToken: () => false, isLoggedIn: () => false @@ -67,7 +63,7 @@ describe('AuthGuardService ECM', () => { it('if the alfresco js api is logged in should canActivate be true', async () => { spyOn(authService, 'isEcmLoggedIn').and.returnValue(true); - const route = {url : 'some-url'} as RouterStateSnapshot; + const route = { url: 'some-url' } as RouterStateSnapshot; expect(await authGuard.canActivate(null, route)).toBeTruthy(); }); @@ -76,7 +72,7 @@ describe('AuthGuardService ECM', () => { spyOn(authService, 'isBpmLoggedIn').and.returnValue(true); appConfigService.config.auth.withCredentials = true; - const route = {url : 'some-url'} as RouterStateSnapshot; + const route = { url: 'some-url' } as RouterStateSnapshot; expect(await authGuard.canActivate(null, route)).toBeTruthy(); }); @@ -94,7 +90,7 @@ describe('AuthGuardService ECM', () => { spyOn(router, 'navigateByUrl'); spyOn(authService, 'isEcmLoggedIn').and.returnValue(false); - const route = {url : 'some-url'} as RouterStateSnapshot; + const route = { url: 'some-url' } as RouterStateSnapshot; expect(await authGuard.canActivate(null, route)).toBeFalsy(); expect(router.navigateByUrl).toHaveBeenCalledWith(router.parseUrl('/login?redirectUrl=some-url')); @@ -105,7 +101,7 @@ describe('AuthGuardService ECM', () => { spyOn(authService, 'isEcmLoggedIn').and.returnValue(false); spyOn(authService, 'isOauth').and.returnValue(true); appConfigService.config.oauth2.silentLogin = false; - const route = {url : 'some-url'} as RouterStateSnapshot; + const route = { url: 'some-url' } as RouterStateSnapshot; expect(await authGuard.canActivate(null, route)).toBeFalsy(); expect(router.navigateByUrl).toHaveBeenCalled(); @@ -126,7 +122,7 @@ describe('AuthGuardService ECM', () => { scope: 'openid' }; - const route = {url : 'abc'} as RouterStateSnapshot; + const route = { url: 'abc' } as RouterStateSnapshot; expect(await authGuard.canActivate(null, route)).toBeFalsy(); expect(oidcAuthenticationService.ssoLogin).toHaveBeenCalledTimes(1); @@ -137,7 +133,7 @@ describe('AuthGuardService ECM', () => { spyOn(authService, 'isEcmLoggedIn').and.returnValue(false); spyOn(authService, 'isOauth').and.returnValue(true); appConfigService.config.oauth2.silentLogin = undefined; - const route = {url : 'some-url'} as RouterStateSnapshot; + const route = { url: 'some-url' } as RouterStateSnapshot; expect(await authGuard.canActivate(null, route)).toBeFalsy(); expect(router.navigateByUrl).toHaveBeenCalled(); @@ -151,7 +147,8 @@ describe('AuthGuardService ECM', () => { authGuard.canActivate(null, route); expect(basicAlfrescoAuthService.setRedirect).toHaveBeenCalledWith({ - provider: 'ECM', url: 'some-url' + provider: 'ECM', + url: 'some-url' }); expect(basicAlfrescoAuthService.getRedirect()).toEqual('some-url'); }); @@ -164,7 +161,8 @@ describe('AuthGuardService ECM', () => { authGuard.canActivate(null, route); expect(basicAlfrescoAuthService.setRedirect).toHaveBeenCalledWith({ - provider: 'ECM', url: 'some-url;q=123' + provider: 'ECM', + url: 'some-url;q=123' }); expect(basicAlfrescoAuthService.getRedirect()).toEqual('some-url;q=123'); }); @@ -177,7 +175,8 @@ describe('AuthGuardService ECM', () => { authGuard.canActivate(null, route); expect(basicAlfrescoAuthService.setRedirect).toHaveBeenCalledWith({ - provider: 'ECM', url: '/' + provider: 'ECM', + url: '/' }); expect(basicAlfrescoAuthService.getRedirect()).toEqual('/'); }); @@ -191,7 +190,8 @@ describe('AuthGuardService ECM', () => { authGuard.canActivate(null, route); expect(basicAlfrescoAuthService.setRedirect).toHaveBeenCalledWith({ - provider: 'ECM', url: 'some-url' + provider: 'ECM', + url: 'some-url' }); expect(router.navigateByUrl).toHaveBeenCalledWith(router.parseUrl('/fakeLoginRoute?redirectUrl=some-url')); }); @@ -208,7 +208,8 @@ describe('AuthGuardService ECM', () => { authGuard.canActivate(null, route); expect(basicAlfrescoAuthService.setRedirect).toHaveBeenCalledWith({ - provider: 'ECM', url: 'some-url' + provider: 'ECM', + url: 'some-url' }); expect(materialDialog.closeAll).toHaveBeenCalled(); diff --git a/lib/core/src/lib/auth/guard/auth-guard-sso-role.service.spec.ts b/lib/core/src/lib/auth/guard/auth-guard-sso-role.service.spec.ts index 31e3440c607..9fd8b30d47e 100644 --- a/lib/core/src/lib/auth/guard/auth-guard-sso-role.service.spec.ts +++ b/lib/core/src/lib/auth/guard/auth-guard-sso-role.service.spec.ts @@ -21,20 +21,15 @@ import { CoreTestingModule } from '../../testing/core.testing.module'; import { AuthGuardSsoRoleService } from './auth-guard-sso-role.service'; import { JwtHelperService } from '../services/jwt-helper.service'; import { MatDialog } from '@angular/material/dialog'; -import { TranslateModule } from '@ngx-translate/core'; describe('Auth Guard SSO role service', () => { - let authGuard: AuthGuardSsoRoleService; let jwtHelperService: JwtHelperService; let routerService: Router; beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - CoreTestingModule - ] + imports: [CoreTestingModule] }); localStorage.clear(); authGuard = TestBed.inject(AuthGuardSsoRoleService); @@ -192,6 +187,5 @@ describe('Auth Guard SSO role service', () => { router.data = { roles: ['MOCK_USER_ROLE', 'MOCK_ADMIN_ROLE'], excludedRoles: ['MOCK_ROOT_USER_ROLE'] }; expect(authGuard.canActivate(router)).toBeTruthy(); }); - }); }); diff --git a/lib/core/src/lib/auth/guard/auth-guard.service.spec.ts b/lib/core/src/lib/auth/guard/auth-guard.service.spec.ts index 062d4e708fc..f10a9ee8459 100644 --- a/lib/core/src/lib/auth/guard/auth-guard.service.spec.ts +++ b/lib/core/src/lib/auth/guard/auth-guard.service.spec.ts @@ -21,7 +21,6 @@ import { AppConfigService } from '../../app-config/app-config.service'; import { AuthGuard } from './auth-guard.service'; import { AuthenticationService } from '../services/authentication.service'; import { CoreTestingModule } from '../../testing/core.testing.module'; -import { TranslateModule } from '@ngx-translate/core'; import { StorageService } from '../../common/services/storage.service'; import { OidcAuthenticationService } from '../services/oidc-authentication.service'; import { BasicAlfrescoAuthService } from '../basic-auth/basic-alfresco-auth.service'; @@ -38,14 +37,12 @@ describe('AuthGuardService', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - CoreTestingModule - ], + imports: [CoreTestingModule], providers: [ { - provide: OidcAuthenticationService, useValue: { - ssoLogin: () => { }, + provide: OidcAuthenticationService, + useValue: { + ssoLogin: () => {}, isPublicUrl: () => false, hasValidIdToken: () => false } @@ -144,7 +141,8 @@ describe('AuthGuardService', () => { await authGuard.canActivate(null, state); expect(basicAlfrescoAuthService.setRedirect).toHaveBeenCalledWith({ - provider: 'ALL', url: 'some-url' + provider: 'ALL', + url: 'some-url' }); expect(router.navigateByUrl).toHaveBeenCalledWith(router.parseUrl('/login?redirectUrl=some-url')); }); @@ -160,7 +158,8 @@ describe('AuthGuardService', () => { await authGuard.canActivate(null, state); expect(basicAlfrescoAuthService.setRedirect).toHaveBeenCalledWith({ - provider: 'ALL', url: 'some-url;q=query' + provider: 'ALL', + url: 'some-url;q=query' }); expect(router.navigateByUrl).toHaveBeenCalledWith(router.parseUrl('/login?redirectUrl=some-url;q=query')); }); @@ -175,7 +174,8 @@ describe('AuthGuardService', () => { await authGuard.canActivate(null, state); expect(basicAlfrescoAuthService.setRedirect).toHaveBeenCalledWith({ - provider: 'ALL', url: 'some-url' + provider: 'ALL', + url: 'some-url' }); expect(router.navigateByUrl).toHaveBeenCalledWith(router.parseUrl('/fakeLoginRoute?redirectUrl=some-url')); }); @@ -189,7 +189,8 @@ describe('AuthGuardService', () => { await authGuard.canActivate(null, state); expect(basicAlfrescoAuthService.setRedirect).toHaveBeenCalledWith({ - provider: 'ALL', url: '/' + provider: 'ALL', + url: '/' }); }); }); diff --git a/lib/core/src/lib/auth/services/authentication.service.spec.ts b/lib/core/src/lib/auth/services/authentication.service.spec.ts index 23747588a35..357cd499ad1 100644 --- a/lib/core/src/lib/auth/services/authentication.service.spec.ts +++ b/lib/core/src/lib/auth/services/authentication.service.spec.ts @@ -21,7 +21,6 @@ import { CookieService } from '../../common/services/cookie.service'; import { AppConfigService } from '../../app-config/app-config.service'; import { setupTestBed } from '../../testing/setup-test-bed'; import { CoreTestingModule } from '../../testing/core.testing.module'; -import { TranslateModule } from '@ngx-translate/core'; import { BasicAlfrescoAuthService } from '../basic-auth/basic-alfresco-auth.service'; import { OidcAuthenticationService } from './oidc-authentication.service'; @@ -35,10 +34,7 @@ describe('AuthenticationService', () => { let oidcAuthenticationService: OidcAuthenticationService; setupTestBed({ - imports: [ - TranslateModule.forRoot(), - CoreTestingModule - ] + imports: [CoreTestingModule] }); beforeEach(() => { @@ -69,7 +65,7 @@ describe('AuthenticationService', () => { appConfigService.config.auth = { withCredentials: true }; }); - it('should emit login event for kerberos', (done) => { + it('should emit login event for kerberos', (done) => { spyOn(basicAlfrescoAuthService, 'requireAlfTicket').and.returnValue(Promise.resolve()); const disposableLogin = authService.onLogin.subscribe(() => { disposableLogin.unsubscribe(); @@ -97,7 +93,6 @@ describe('AuthenticationService', () => { }); describe('when the setting is ECM', () => { - const fakeECMLoginResponse = { type: 'ECM', ticket: 'fake-post-ticket' }; beforeEach(() => { @@ -216,7 +211,6 @@ describe('AuthenticationService', () => { }); describe('when the setting is BPM', () => { - beforeEach(() => { appConfigService.config.providers = 'BPM'; appConfigService.load(); @@ -278,13 +272,13 @@ describe('AuthenticationService', () => { it('[BPM] should return an error when the logout return error', (done) => { authService.logout().subscribe( - () => { - }, + () => {}, (err: any) => { expect(err).toBeDefined(); expect(authService.getToken()).toBe(null); done(); - }); + } + ); jasmine.Ajax.requests.mostRecent().respondWith({ status: 403 @@ -323,7 +317,6 @@ describe('AuthenticationService', () => { }); describe('remember me', () => { - beforeEach(() => { appConfigService.config.providers = 'ECM'; appConfigService.load(); @@ -367,7 +360,8 @@ describe('AuthenticationService', () => { expect(cookie['ALFRESCO_REMEMBER_ME']).toBeUndefined(); disposableLogin.unsubscribe(); done(); - }); + } + ); jasmine.Ajax.requests.mostRecent().respondWith({ status: 403, @@ -386,7 +380,6 @@ describe('AuthenticationService', () => { }); describe('when the setting is both ECM and BPM ', () => { - beforeEach(() => { appConfigService.config.providers = 'ALL'; appConfigService.load(); @@ -426,7 +419,8 @@ describe('AuthenticationService', () => { expect(authService.isEcmLoggedIn()).toBe(false, 'isEcmLoggedIn'); disposableLogin.unsubscribe(); done(); - }); + } + ); jasmine.Ajax.requests.at(0).respondWith({ status: 403 @@ -447,7 +441,8 @@ describe('AuthenticationService', () => { expect(authService.isBpmLoggedIn()).toBe(false); disposableLogin.unsubscribe(); done(); - }); + } + ); jasmine.Ajax.requests.at(0).respondWith({ status: 201, @@ -471,7 +466,8 @@ describe('AuthenticationService', () => { expect(authService.isEcmLoggedIn()).toBe(false); disposableLogin.unsubscribe(); done(); - }); + } + ); jasmine.Ajax.requests.at(0).respondWith({ status: 403 @@ -510,6 +506,5 @@ describe('AuthenticationService', () => { const username = authService.getUsername(); expect(username).toEqual('john.petrucci'); }); - }); }); diff --git a/lib/core/src/lib/auth/services/base-authentication.service.ts b/lib/core/src/lib/auth/services/base-authentication.service.ts index eaa548b20c2..e2f43f3e04a 100644 --- a/lib/core/src/lib/auth/services/base-authentication.service.ts +++ b/lib/core/src/lib/auth/services/base-authentication.service.ts @@ -20,12 +20,10 @@ import { RedirectionModel } from '../models/redirection.model'; import { Observable, Observer, ReplaySubject, throwError } from 'rxjs'; import { AppConfigService, AppConfigValues } from '../../app-config/app-config.service'; import { CookieService } from '../../common/services/cookie.service'; -import { LogService } from '../../common/services/log.service'; import { AuthenticationServiceInterface } from '../interfaces/authentication-service.interface'; import ee from 'event-emitter'; export abstract class BaseAuthenticationService implements AuthenticationServiceInterface, ee.Emitter { - on: ee.EmitterMethod; off: ee.EmitterMethod; once: ee.EmitterMethod; @@ -37,11 +35,7 @@ export abstract class BaseAuthenticationService implements AuthenticationService onLogin = new ReplaySubject(1); onLogout = new ReplaySubject(1); - constructor( - protected appConfig: AppConfigService, - protected cookie: CookieService, - private logService: LogService - ) { + protected constructor(protected appConfig: AppConfigService, protected cookie: CookieService) { ee(this); } @@ -77,7 +71,6 @@ export abstract class BaseAuthenticationService implements AuthenticationService headers = new HttpHeaders(); } try { - const header = this.getAuthHeaders(requestUrl, headers); observer.next(header); @@ -130,7 +123,6 @@ export abstract class BaseAuthenticationService implements AuthenticationService */ handleError(error: any): Observable { this.onError.next(error || 'Server error'); - this.logService.error('Error when logging in', error); return throwError(error || 'Server error'); } diff --git a/lib/core/src/lib/auth/services/identity-group.service.spec.ts b/lib/core/src/lib/auth/services/identity-group.service.spec.ts index 2f1fcad3a0e..cca4df1057c 100644 --- a/lib/core/src/lib/auth/services/identity-group.service.spec.ts +++ b/lib/core/src/lib/auth/services/identity-group.service.spec.ts @@ -28,7 +28,6 @@ import { roleMappingMock } from '../mock/identity-group.mock'; import { CoreTestingModule } from '../../testing/core.testing.module'; -import { TranslateModule } from '@ngx-translate/core'; import { AdfHttpClient } from '../../../../api/src'; describe('IdentityGroupService', () => { @@ -38,10 +37,7 @@ describe('IdentityGroupService', () => { beforeEach(fakeAsync(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - CoreTestingModule - ] + imports: [CoreTestingModule] }); service = TestBed.inject(IdentityGroupService); adfHttpClient = TestBed.inject(AdfHttpClient); @@ -50,7 +46,7 @@ describe('IdentityGroupService', () => { it('should be able to fetch groups based on group name', (done) => { requestSpy.and.returnValue(Promise.resolve(mockIdentityGroups)); - service.findGroupsByName({name: 'mock'}).subscribe((res) => { + service.findGroupsByName({ name: 'mock' }).subscribe((res) => { expect(res).toBeDefined(); expect(res).not.toBeNull(); expect(res.length).toBe(5); @@ -84,142 +80,126 @@ describe('IdentityGroupService', () => { it('should able to fetch group roles by groupId', (done) => { spyOn(service, 'getGroupRoles').and.returnValue(of(mockIdentityRoles)); - service.getGroupRoles('mock-group-id').subscribe( - (res: any) => { - expect(res).toBeDefined(); - expect(res.length).toEqual(3); - expect(res[0].name).toEqual('MOCK-ADMIN-ROLE'); - expect(res[1].name).toEqual('MOCK-USER-ROLE'); - expect(res[2].name).toEqual('MOCK-ROLE-1'); - done(); - } - ); + service.getGroupRoles('mock-group-id').subscribe((res: any) => { + expect(res).toBeDefined(); + expect(res.length).toEqual(3); + expect(res[0].name).toEqual('MOCK-ADMIN-ROLE'); + expect(res[1].name).toEqual('MOCK-USER-ROLE'); + expect(res[2].name).toEqual('MOCK-ROLE-1'); + done(); + }); }); it('Should not able to fetch group roles if error occurred', (done) => { const errorResponse = new HttpErrorResponse({ error: 'Mock Error', - status: 404, statusText: 'Not Found' + status: 404, + statusText: 'Not Found' }); spyOn(service, 'getGroupRoles').and.returnValue(throwError(errorResponse)); - service.getGroupRoles('mock-group-id') - .subscribe( - () => { - fail('expected an error, not group roles'); - }, - (error) => { - expect(error.status).toEqual(404); - expect(error.statusText).toEqual('Not Found'); - expect(error.error).toEqual('Mock Error'); - done(); - } - ); + service.getGroupRoles('mock-group-id').subscribe( + () => { + fail('expected an error, not group roles'); + }, + (error) => { + expect(error.status).toEqual(404); + expect(error.statusText).toEqual('Not Found'); + expect(error.error).toEqual('Mock Error'); + done(); + } + ); }); it('should return true if group has given role', (done) => { spyOn(service, 'getGroupRoles').and.returnValue(of(mockIdentityRoles)); - service.checkGroupHasRole('mock-group-id', ['MOCK-ADMIN-ROLE']).subscribe( - (res: boolean) => { - expect(res).toBeDefined(); - expect(res).toBeTruthy(); - done(); - } - ); + service.checkGroupHasRole('mock-group-id', ['MOCK-ADMIN-ROLE']).subscribe((res: boolean) => { + expect(res).toBeDefined(); + expect(res).toBeTruthy(); + done(); + }); }); it('should return false if group does not have given role', (done) => { spyOn(service, 'getGroupRoles').and.returnValue(of(mockIdentityRoles)); - service.checkGroupHasRole('mock-group-id', ['MOCK-ADMIN-MODELER']).subscribe( - (res: boolean) => { - expect(res).toBeDefined(); - expect(res).toBeFalsy(); - done(); - } - ); + service.checkGroupHasRole('mock-group-id', ['MOCK-ADMIN-MODELER']).subscribe((res: boolean) => { + expect(res).toBeDefined(); + expect(res).toBeFalsy(); + done(); + }); }); it('should fetch client roles by groupId and clientId', (done) => { spyOn(service, 'getClientRoles').and.returnValue(of(clientRoles)); - service.getClientRoles('mock-group-id', 'mock-client-id').subscribe( - (res: any) => { - expect(res).toBeDefined(); - expect(res.length).toEqual(2); - expect(res).toEqual(clientRoles); - done(); - } - ); + service.getClientRoles('mock-group-id', 'mock-client-id').subscribe((res: any) => { + expect(res).toBeDefined(); + expect(res.length).toEqual(2); + expect(res).toEqual(clientRoles); + done(); + }); }); it('Should not fetch client roles if error occurred', (done) => { const errorResponse = new HttpErrorResponse({ error: 'Mock Error', - status: 404, statusText: 'Not Found' + status: 404, + statusText: 'Not Found' }); spyOn(service, 'getClientRoles').and.returnValue(throwError(errorResponse)); - service.getClientRoles('mock-group-id', 'mock-client-id') - .subscribe( - () => { - fail('expected an error, not client roles'); - }, - (error) => { - expect(error.status).toEqual(404); - expect(error.statusText).toEqual('Not Found'); - expect(error.error).toEqual('Mock Error'); - done(); - } - ); + service.getClientRoles('mock-group-id', 'mock-client-id').subscribe( + () => { + fail('expected an error, not client roles'); + }, + (error) => { + expect(error.status).toEqual(404); + expect(error.statusText).toEqual('Not Found'); + expect(error.error).toEqual('Mock Error'); + done(); + } + ); }); it('should return true if group has client access', (done) => { spyOn(service, 'getClientRoles').and.returnValue(of(clientRoles)); - service.checkGroupHasClientApp('mock-group-id', 'mock-client-id').subscribe( - (res: boolean) => { - expect(res).toBeDefined(); - expect(res).toBeTruthy(); - done(); - } - ); + service.checkGroupHasClientApp('mock-group-id', 'mock-client-id').subscribe((res: boolean) => { + expect(res).toBeDefined(); + expect(res).toBeTruthy(); + done(); + }); }); it('should return false if group does not have client access', (done) => { spyOn(service, 'getClientRoles').and.returnValue(of([])); - service.checkGroupHasClientApp('mock-group-id', 'mock-client-id').subscribe( - (res: boolean) => { - expect(res).toBeDefined(); - expect(res).toBeFalsy(); - done(); - } - ); + service.checkGroupHasClientApp('mock-group-id', 'mock-client-id').subscribe((res: boolean) => { + expect(res).toBeDefined(); + expect(res).toBeFalsy(); + done(); + }); }); it('should return true if group has any client role', (done) => { spyOn(service, 'checkGroupHasAnyClientAppRole').and.returnValue(of(true)); - service.checkGroupHasAnyClientAppRole('mock-group-id', 'mock-client-id', ['MOCK-USER-ROLE']).subscribe( - (res: boolean) => { - expect(res).toBeDefined(); - expect(res).toBeTruthy(); - done(); - } - ); + service.checkGroupHasAnyClientAppRole('mock-group-id', 'mock-client-id', ['MOCK-USER-ROLE']).subscribe((res: boolean) => { + expect(res).toBeDefined(); + expect(res).toBeTruthy(); + done(); + }); }); it('should return false if group does not have any client role', (done) => { spyOn(service, 'getClientRoles').and.returnValue(of([])); - service.checkGroupHasAnyClientAppRole('mock-group-id', 'mock-client-id', ['MOCK-ADMIN-MODELER']).subscribe( - (res: boolean) => { - expect(res).toBeDefined(); - expect(res).toBeFalsy(); - done(); - } - ); + service.checkGroupHasAnyClientAppRole('mock-group-id', 'mock-client-id', ['MOCK-ADMIN-MODELER']).subscribe((res: boolean) => { + expect(res).toBeDefined(); + expect(res).toBeFalsy(); + done(); + }); }); it('should be able to fetch the client id', (done) => { - requestSpy.and.returnValue(Promise.resolve([{id: 'mock-app-id', name: 'mock-app-name'}])); + requestSpy.and.returnValue(Promise.resolve([{ id: 'mock-app-id', name: 'mock-app-name' }])); service.getClientIdByApplicationName('mock-app-name').subscribe((clientId) => { expect(clientId).toBeDefined(); expect(clientId).not.toBeNull(); @@ -245,29 +225,29 @@ describe('IdentityGroupService', () => { it('Should not able to fetch all group if error occurred', (done) => { const errorResponse = new HttpErrorResponse({ error: 'Mock Error', - status: 404, statusText: 'Not Found' + status: 404, + statusText: 'Not Found' }); spyOn(service, 'getGroups').and.returnValue(throwError(errorResponse)); - service.getGroups() - .subscribe( - () => { - fail('expected an error, not groups'); - }, - (error) => { - expect(error.status).toEqual(404); - expect(error.statusText).toEqual('Not Found'); - expect(error.error).toEqual('Mock Error'); - done(); - } - ); + service.getGroups().subscribe( + () => { + fail('expected an error, not groups'); + }, + (error) => { + expect(error.status).toEqual(404); + expect(error.statusText).toEqual('Not Found'); + expect(error.error).toEqual('Mock Error'); + done(); + } + ); }); it('should be able to query groups based on first & max params', (done) => { spyOn(service, 'getTotalGroupsCount').and.returnValue(of(mockIdentityGroupsCount)); requestSpy.and.returnValue(Promise.resolve(mockIdentityGroups)); - service.queryGroups({first: 0, max: 5}).subscribe((res) => { + service.queryGroups({ first: 0, max: 5 }).subscribe((res) => { expect(res).toBeDefined(); expect(res).not.toBeNull(); expect(res.entries.length).toBe(5); @@ -287,23 +267,23 @@ describe('IdentityGroupService', () => { it('Should not able to query groups if error occurred', (done) => { const errorResponse = new HttpErrorResponse({ error: 'Mock Error', - status: 404, statusText: 'Not Found' + status: 404, + statusText: 'Not Found' }); spyOn(service, 'queryGroups').and.returnValue(throwError(errorResponse)); - service.queryGroups({first: 0, max: 5}) - .subscribe( - () => { - fail('expected an error, not query groups'); - }, - (error) => { - expect(error.status).toEqual(404); - expect(error.statusText).toEqual('Not Found'); - expect(error.error).toEqual('Mock Error'); - done(); - } - ); + service.queryGroups({ first: 0, max: 5 }).subscribe( + () => { + fail('expected an error, not query groups'); + }, + (error) => { + expect(error.status).toEqual(404); + expect(error.statusText).toEqual('Not Found'); + expect(error.error).toEqual('Mock Error'); + done(); + } + ); }); it('should be able to create group', (done) => { @@ -317,23 +297,23 @@ describe('IdentityGroupService', () => { it('Should not able to create group if error occurred', (done) => { const errorResponse = new HttpErrorResponse({ error: 'Mock Error', - status: 404, statusText: 'Not Found' + status: 404, + statusText: 'Not Found' }); spyOn(service, 'createGroup').and.returnValue(throwError(errorResponse)); - service.createGroup(mockIdentityGroup1) - .subscribe( - () => { - fail('expected an error, not to create group'); - }, - (error) => { - expect(error.status).toEqual(404); - expect(error.statusText).toEqual('Not Found'); - expect(error.error).toEqual('Mock Error'); - done(); - } - ); + service.createGroup(mockIdentityGroup1).subscribe( + () => { + fail('expected an error, not to create group'); + }, + (error) => { + expect(error.status).toEqual(404); + expect(error.statusText).toEqual('Not Found'); + expect(error.error).toEqual('Mock Error'); + done(); + } + ); }); it('should be able to update group', (done) => { @@ -347,23 +327,23 @@ describe('IdentityGroupService', () => { it('Should not able to update group if error occurred', (done) => { const errorResponse = new HttpErrorResponse({ error: 'Mock Error', - status: 404, statusText: 'Not Found' + status: 404, + statusText: 'Not Found' }); spyOn(service, 'updateGroup').and.returnValue(throwError(errorResponse)); - service.updateGroup('mock-group-id', mockIdentityGroup1) - .subscribe( - () => { - fail('expected an error, not to update group'); - }, - (error) => { - expect(error.status).toEqual(404); - expect(error.statusText).toEqual('Not Found'); - expect(error.error).toEqual('Mock Error'); - done(); - } - ); + service.updateGroup('mock-group-id', mockIdentityGroup1).subscribe( + () => { + fail('expected an error, not to update group'); + }, + (error) => { + expect(error.status).toEqual(404); + expect(error.statusText).toEqual('Not Found'); + expect(error.error).toEqual('Mock Error'); + done(); + } + ); }); it('should be able to delete group', (done) => { @@ -377,22 +357,22 @@ describe('IdentityGroupService', () => { it('Should not able to delete group if error occurred', (done) => { const errorResponse = new HttpErrorResponse({ error: 'Mock Error', - status: 404, statusText: 'Not Found' + status: 404, + statusText: 'Not Found' }); spyOn(service, 'deleteGroup').and.returnValue(throwError(errorResponse)); - service.deleteGroup('mock-group-id') - .subscribe( - () => { - fail('expected an error, not to delete group'); - }, - (error) => { - expect(error.status).toEqual(404); - expect(error.statusText).toEqual('Not Found'); - expect(error.error).toEqual('Mock Error'); - done(); - } - ); + service.deleteGroup('mock-group-id').subscribe( + () => { + fail('expected an error, not to delete group'); + }, + (error) => { + expect(error.status).toEqual(404); + expect(error.statusText).toEqual('Not Found'); + expect(error.error).toEqual('Mock Error'); + done(); + } + ); }); }); diff --git a/lib/core/src/lib/auth/services/identity-role.service.ts b/lib/core/src/lib/auth/services/identity-role.service.ts index 765718390c5..1158e63d34f 100644 --- a/lib/core/src/lib/auth/services/identity-role.service.ts +++ b/lib/core/src/lib/auth/services/identity-role.service.ts @@ -17,17 +17,16 @@ import { Injectable } from '@angular/core'; import { HttpClient } from '@angular/common/http'; -import { throwError as observableThrowError, Observable, of } from 'rxjs'; -import { catchError, map } from 'rxjs/operators'; +import { Observable, of } from 'rxjs'; +import { map } from 'rxjs/operators'; import { PaginationModel } from '../../models/pagination.model'; import { IdentityRoleModel } from '../models/identity-role.model'; import { AppConfigService } from '../../app-config/app-config.service'; -import { LogService } from '../../common/services/log.service'; export interface IdentityRoleResponseModel { entries: IdentityRoleModel[]; pagination: PaginationModel; - } +} @Injectable({ providedIn: 'root' @@ -36,11 +35,7 @@ export class IdentityRoleService { contextRoot = ''; identityHost = ''; - constructor( - protected http: HttpClient, - protected appConfig: AppConfigService, - protected logService: LogService - ) { + constructor(protected http: HttpClient, protected appConfig: AppConfigService) { this.contextRoot = this.appConfig.get('apiHost', ''); this.identityHost = this.appConfig.get('identityHost'); } @@ -52,21 +47,11 @@ export class IdentityRoleService { * @param size page size * @returns List of roles */ - getRoles( - skipCount: number = 0, - size: number = 5 - ): Observable { - return this.http.get(`${this.identityHost}/roles`).pipe( - map(res => this.preparePaginationWithRoles(res, skipCount, size)), - catchError(error => this.handleError(error)) - ); + getRoles(skipCount: number = 0, size: number = 5): Observable { + return this.http.get(`${this.identityHost}/roles`).pipe(map((res) => this.preparePaginationWithRoles(res, skipCount, size))); } - private preparePaginationWithRoles( - roles: IdentityRoleModel[], - skipCount: number = 0, - size: number = 5 - ): IdentityRoleResponseModel { + private preparePaginationWithRoles(roles: IdentityRoleModel[], skipCount: number = 0, size: number = 5): IdentityRoleResponseModel { return { entries: roles.slice(skipCount, skipCount + size), pagination: { @@ -87,10 +72,7 @@ export class IdentityRoleService { */ addRole(newRole: IdentityRoleModel): Observable { if (newRole) { - const request = newRole; - return this.http - .post(`${this.identityHost}/roles`, request) - .pipe(catchError(error => this.handleError(error))); + return this.http.post(`${this.identityHost}/roles`, newRole); } return of(); } @@ -102,9 +84,7 @@ export class IdentityRoleService { * @returns Server result payload */ deleteRole(deletedRole: IdentityRoleModel): Observable { - return this.http - .delete(`${this.identityHost}/roles-by-id/${deletedRole.id}`) - .pipe(catchError(error => this.handleError(error))); + return this.http.delete(`${this.identityHost}/roles-by-id/${deletedRole.id}`); } /** @@ -114,21 +94,10 @@ export class IdentityRoleService { * @param roleId Role id * @returns Server result payload */ - updateRole( - updatedRole: IdentityRoleModel, - roleId: string - ): Observable { + updateRole(updatedRole: IdentityRoleModel, roleId: string): Observable { if (updatedRole && roleId) { - const request = updatedRole; - return this.http - .put(`${this.identityHost}/roles-by-id/${roleId}`, request) - .pipe(catchError(error => this.handleError(error))); + return this.http.put(`${this.identityHost}/roles-by-id/${roleId}`, updatedRole); } return of(); } - - private handleError(error: any) { - this.logService.error(error); - return observableThrowError(error || 'Server error'); - } } diff --git a/lib/core/src/lib/auth/services/identity-user.service.spec.ts b/lib/core/src/lib/auth/services/identity-user.service.spec.ts index 62dce422454..c2abd94b069 100644 --- a/lib/core/src/lib/auth/services/identity-user.service.spec.ts +++ b/lib/core/src/lib/auth/services/identity-user.service.spec.ts @@ -33,18 +33,16 @@ import { JwtHelperService } from './jwt-helper.service'; import { mockToken } from '../mock/jwt-helper.service.spec'; import { IdentityRoleModel } from '../models/identity-role.model'; import { CoreTestingModule } from '../../testing/core.testing.module'; -import { TranslateModule } from '@ngx-translate/core'; import { AdfHttpClient } from '../../../../api/src'; import { StorageService } from '../../common/services/storage.service'; describe('IdentityUserService', () => { - const mockRoles = [ - { id: 'id-1', name: 'MOCK-ADMIN-ROLE'}, - { id: 'id-2', name: 'MOCK-USER-ROLE'}, + { id: 'id-1', name: 'MOCK-ADMIN-ROLE' }, + { id: 'id-2', name: 'MOCK-USER-ROLE' }, { id: 'id-3', name: 'MOCK_MODELER-ROLE' }, { id: 'id-4', name: 'MOCK-ROLE-1' }, - { id: 'id-5', name: 'MOCK-ROLE-2'} + { id: 'id-5', name: 'MOCK-ROLE-2' } ]; let storageService: StorageService; @@ -54,10 +52,7 @@ describe('IdentityUserService', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - CoreTestingModule - ] + imports: [CoreTestingModule] }); storageService = TestBed.inject(StorageService); service = TestBed.inject(IdentityUserService); @@ -87,111 +82,103 @@ describe('IdentityUserService', () => { it('should fetch users ', (done) => { spyOn(service, 'getUsers').and.returnValue(of(mockIdentityUsers)); - service.getUsers().subscribe( - res => { - expect(res).toBeDefined(); - expect(res[0].id).toEqual('mock-user-id-1'); - expect(res[0].username).toEqual('userName1'); - expect(res[1].id).toEqual('mock-user-id-2'); - expect(res[1].username).toEqual('userName2'); - expect(res[2].id).toEqual('mock-user-id-3'); - expect(res[2].username).toEqual('userName3'); - done(); - } - ); + service.getUsers().subscribe((res) => { + expect(res).toBeDefined(); + expect(res[0].id).toEqual('mock-user-id-1'); + expect(res[0].username).toEqual('userName1'); + expect(res[1].id).toEqual('mock-user-id-2'); + expect(res[1].username).toEqual('userName2'); + expect(res[2].id).toEqual('mock-user-id-3'); + expect(res[2].username).toEqual('userName3'); + done(); + }); }); it('Should not fetch users if error occurred', (done) => { const errorResponse = new HttpErrorResponse({ error: 'Mock Error', - status: 404, statusText: 'Not Found' + status: 404, + statusText: 'Not Found' }); spyOn(service, 'getUsers').and.returnValue(throwError(errorResponse)); - service.getUsers() - .subscribe( - () => { - fail('expected an error, not users'); - }, - (error) => { - expect(error.status).toEqual(404); - expect(error.statusText).toEqual('Not Found'); - expect(error.error).toEqual('Mock Error'); - done(); - } - ); + service.getUsers().subscribe( + () => { + fail('expected an error, not users'); + }, + (error) => { + expect(error.status).toEqual(404); + expect(error.statusText).toEqual('Not Found'); + expect(error.error).toEqual('Mock Error'); + done(); + } + ); }); it('should fetch roles by userId', (done) => { spyOn(service, 'getUserRoles').and.returnValue(of(mockRoles)); - service.getUserRoles('mock-user-id').subscribe( - (res: IdentityRoleModel[]) => { - expect(res).toBeDefined(); - expect(res[0].name).toEqual('MOCK-ADMIN-ROLE'); - expect(res[1].name).toEqual('MOCK-USER-ROLE'); - expect(res[4].name).toEqual('MOCK-ROLE-2'); - done(); - } - ); + service.getUserRoles('mock-user-id').subscribe((res: IdentityRoleModel[]) => { + expect(res).toBeDefined(); + expect(res[0].name).toEqual('MOCK-ADMIN-ROLE'); + expect(res[1].name).toEqual('MOCK-USER-ROLE'); + expect(res[4].name).toEqual('MOCK-ROLE-2'); + done(); + }); }); it('Should not fetch roles if error occurred', (done) => { const errorResponse = new HttpErrorResponse({ error: 'Mock Error', - status: 404, statusText: 'Not Found' + status: 404, + statusText: 'Not Found' }); spyOn(service, 'getUserRoles').and.returnValue(throwError(errorResponse)); - service.getUserRoles('mock-user-id') - .subscribe( - () => { - fail('expected an error, not users'); - }, - (error) => { - expect(error.status).toEqual(404); - expect(error.statusText).toEqual('Not Found'); - expect(error.error).toEqual('Mock Error'); - done(); - } - ); + service.getUserRoles('mock-user-id').subscribe( + () => { + fail('expected an error, not users'); + }, + (error) => { + expect(error.status).toEqual(404); + expect(error.statusText).toEqual('Not Found'); + expect(error.error).toEqual('Mock Error'); + done(); + } + ); }); it('should fetch users by roles', (done) => { spyOn(service, 'getUsers').and.returnValue(of(mockIdentityUsers)); spyOn(service, 'getUserRoles').and.returnValue(of(mockRoles)); - service.getUsersByRolesWithCurrentUser([mockRoles[0].name]).then( - res => { - expect(res).toBeDefined(); - expect(res[0].id).toEqual('mock-user-id-1'); - expect(res[0].username).toEqual('userName1'); - expect(res[1].id).toEqual('mock-user-id-2'); - expect(res[1].username).toEqual('userName2'); - expect(res[2].id).toEqual('mock-user-id-3'); - expect(res[2].username).toEqual('userName3'); - done(); - } - ); + service.getUsersByRolesWithCurrentUser([mockRoles[0].name]).then((res) => { + expect(res).toBeDefined(); + expect(res[0].id).toEqual('mock-user-id-1'); + expect(res[0].username).toEqual('userName1'); + expect(res[1].id).toEqual('mock-user-id-2'); + expect(res[1].username).toEqual('userName2'); + expect(res[2].id).toEqual('mock-user-id-3'); + expect(res[2].username).toEqual('userName3'); + done(); + }); }); it('Should not fetch users by roles if error occurred', (done) => { const errorResponse = new HttpErrorResponse({ error: 'Mock Error', - status: 404, statusText: 'Not Found' + status: 404, + statusText: 'Not Found' }); spyOn(service, 'getUsers').and.returnValue(throwError(errorResponse)); - service.getUsersByRolesWithCurrentUser([mockRoles[0].name]) - .catch( - (error) => { - expect(error.status).toEqual(404); - expect(error.statusText).toEqual('Not Found'); - expect(error.error).toEqual('Mock Error'); - done(); - } - ); + service.getUsersByRolesWithCurrentUser([mockRoles[0].name]).catch((error) => { + expect(error.status).toEqual(404); + expect(error.statusText).toEqual('Not Found'); + expect(error.error).toEqual('Mock Error'); + done(); + }); }); it('should fetch users by roles without current user', (done) => { @@ -199,91 +186,77 @@ describe('IdentityUserService', () => { spyOn(service, 'getUserRoles').and.returnValue(of(mockRoles)); spyOn(service, 'getCurrentUserInfo').and.returnValue(mockIdentityUsers[0]); - service.getUsersByRolesWithoutCurrentUser([mockRoles[0].name]).then( - res => { - expect(res).toBeDefined(); - expect(res[0].id).toEqual('mock-user-id-2'); - expect(res[0].username).toEqual('userName2'); - expect(res[1].id).toEqual('mock-user-id-3'); - expect(res[1].username).toEqual('userName3'); - done(); - } - ); + service.getUsersByRolesWithoutCurrentUser([mockRoles[0].name]).then((res) => { + expect(res).toBeDefined(); + expect(res[0].id).toEqual('mock-user-id-2'); + expect(res[0].username).toEqual('userName2'); + expect(res[1].id).toEqual('mock-user-id-3'); + expect(res[1].username).toEqual('userName3'); + done(); + }); }); it('should return true when user has access to an application', (done) => { spyOn(service, 'getClientIdByApplicationName').and.returnValue(of('mock-client')); spyOn(service, 'getClientRoles').and.returnValue(of(mockRoles)); - service.checkUserHasClientApp('user-id', 'app-name').subscribe( - (res: boolean) => { - expect(res).toBeTruthy(); - done(); - } - ); + service.checkUserHasClientApp('user-id', 'app-name').subscribe((res: boolean) => { + expect(res).toBeTruthy(); + done(); + }); }); it('should return false when user does not have access to an application', (done) => { spyOn(service, 'getClientIdByApplicationName').and.returnValue(of('mock-client')); spyOn(service, 'getClientRoles').and.returnValue(of([])); - service.checkUserHasClientApp('user-id', 'app-name').subscribe( - (res: boolean) => { - expect(res).toBeFalsy(); - done(); - } - ); + service.checkUserHasClientApp('user-id', 'app-name').subscribe((res: boolean) => { + expect(res).toBeFalsy(); + done(); + }); }); it('should return true when user has any given application role', (done) => { spyOn(service, 'getClientIdByApplicationName').and.returnValue(of('mock-client')); spyOn(service, 'getClientRoles').and.returnValue(of(mockRoles)); - service.checkUserHasAnyClientAppRole('user-id', 'app-name', [mockRoles[1].name] ).subscribe( - (res: boolean) => { - expect(res).toBeTruthy(); - done(); - } - ); + service.checkUserHasAnyClientAppRole('user-id', 'app-name', [mockRoles[1].name]).subscribe((res: boolean) => { + expect(res).toBeTruthy(); + done(); + }); }); it('should return false when user does not have any given application role', (done) => { spyOn(service, 'getClientIdByApplicationName').and.returnValue(of('mock-client')); spyOn(service, 'getClientRoles').and.returnValue(of([])); - service.checkUserHasAnyClientAppRole('user-id', 'app-name', [mockRoles[1].name]).subscribe( - (res: boolean) => { - expect(res).toBeFalsy(); - done(); - } - ); + service.checkUserHasAnyClientAppRole('user-id', 'app-name', [mockRoles[1].name]).subscribe((res: boolean) => { + expect(res).toBeFalsy(); + done(); + }); }); it('should return true if user has given role', (done) => { spyOn(service, 'getUserRoles').and.returnValue(of(mockRoles)); - service.checkUserHasRole('mock-user-id', ['MOCK-ROLE-1']).subscribe( - (res: boolean) => { - expect(res).toBeDefined(); - expect(res).toBeTruthy(); - done(); - } - ); + service.checkUserHasRole('mock-user-id', ['MOCK-ROLE-1']).subscribe((res: boolean) => { + expect(res).toBeDefined(); + expect(res).toBeTruthy(); + done(); + }); }); it('should return false if user does not have given role', (done) => { spyOn(service, 'getUserRoles').and.returnValue(of(mockRoles)); - service.checkUserHasRole('mock-user-id', ['MOCK-ROLE-10']).subscribe( - (res: boolean) => { - expect(res).toBeDefined(); - expect(res).toBeFalsy(); - done(); - } - ); + service.checkUserHasRole('mock-user-id', ['MOCK-ROLE-10']).subscribe((res: boolean) => { + expect(res).toBeDefined(); + expect(res).toBeFalsy(); + done(); + }); }); it('should be able to query users based on query params (first & max params)', (done) => { requestSpy.and.returnValue(Promise.resolve(mockIdentityUsers)); - service.queryUsers({first: 0, max: 5}).subscribe((res) => { + service.queryUsers({ first: 0, max: 5 }).subscribe((res) => { expect(res).toBeDefined(); expect(res).not.toBeNull(); expect(res.entries.length).toBe(5); @@ -300,23 +273,23 @@ describe('IdentityUserService', () => { it('Should not be able to query users if error occurred', (done) => { const errorResponse = new HttpErrorResponse({ error: 'Mock Error', - status: 404, statusText: 'Not Found' + status: 404, + statusText: 'Not Found' }); spyOn(service, 'queryUsers').and.returnValue(throwError(errorResponse)); - service.queryUsers({first: 0, max: 5}) - .subscribe( - () => { - fail('expected an error, not users'); - }, - (error) => { - expect(error.status).toEqual(404); - expect(error.statusText).toEqual('Not Found'); - expect(error.error).toEqual('Mock Error'); - done(); - } - ); + service.queryUsers({ first: 0, max: 5 }).subscribe( + () => { + fail('expected an error, not users'); + }, + (error) => { + expect(error.status).toEqual(404); + expect(error.statusText).toEqual('Not Found'); + expect(error.error).toEqual('Mock Error'); + done(); + } + ); }); it('should be able to create user', (done) => { @@ -330,23 +303,23 @@ describe('IdentityUserService', () => { it('Should not able to create user if error occurred', (done) => { const errorResponse = new HttpErrorResponse({ error: 'Mock Error', - status: 404, statusText: 'Not Found' + status: 404, + statusText: 'Not Found' }); spyOn(service, 'createUser').and.returnValue(throwError(errorResponse)); - service.createUser(mockIdentityUser1) - .subscribe( - () => { - fail('expected an error, not to create user'); - }, - (error) => { - expect(error.status).toEqual(404); - expect(error.statusText).toEqual('Not Found'); - expect(error.error).toEqual('Mock Error'); - done(); - } - ); + service.createUser(mockIdentityUser1).subscribe( + () => { + fail('expected an error, not to create user'); + }, + (error) => { + expect(error.status).toEqual(404); + expect(error.statusText).toEqual('Not Found'); + expect(error.error).toEqual('Mock Error'); + done(); + } + ); }); it('should be able to update user', (done) => { @@ -360,23 +333,23 @@ describe('IdentityUserService', () => { it('Should not able to update user if error occurred', (done) => { const errorResponse = new HttpErrorResponse({ error: 'Mock Error', - status: 404, statusText: 'Not Found' + status: 404, + statusText: 'Not Found' }); spyOn(service, 'updateUser').and.returnValue(throwError(errorResponse)); - service.updateUser('mock-id-2', mockIdentityUser2) - .subscribe( - () => { - fail('expected an error, not to update user'); - }, - (error) => { - expect(error.status).toEqual(404); - expect(error.statusText).toEqual('Not Found'); - expect(error.error).toEqual('Mock Error'); - done(); - } - ); + service.updateUser('mock-id-2', mockIdentityUser2).subscribe( + () => { + fail('expected an error, not to update user'); + }, + (error) => { + expect(error.status).toEqual(404); + expect(error.statusText).toEqual('Not Found'); + expect(error.error).toEqual('Mock Error'); + done(); + } + ); }); it('should be able to delete group', (done) => { @@ -390,23 +363,23 @@ describe('IdentityUserService', () => { it('Should not able to delete user if error occurred', (done) => { const errorResponse = new HttpErrorResponse({ error: 'Mock Error', - status: 404, statusText: 'Not Found' + status: 404, + statusText: 'Not Found' }); spyOn(service, 'deleteUser').and.returnValue(throwError(errorResponse)); - service.deleteUser('mock-user-id') - .subscribe( - () => { - fail('expected an error, not to delete user'); - }, - (error) => { - expect(error.status).toEqual(404); - expect(error.statusText).toEqual('Not Found'); - expect(error.error).toEqual('Mock Error'); - done(); - } - ); + service.deleteUser('mock-user-id').subscribe( + () => { + fail('expected an error, not to delete user'); + }, + (error) => { + expect(error.status).toEqual(404); + expect(error.statusText).toEqual('Not Found'); + expect(error.error).toEqual('Mock Error'); + done(); + } + ); }); it('should be able to fetch involved groups based on user id', (done) => { @@ -426,23 +399,23 @@ describe('IdentityUserService', () => { it('Should not be able to fetch involved groups if error occurred', (done) => { const errorResponse = new HttpErrorResponse({ error: 'Mock Error', - status: 404, statusText: 'Not Found' + status: 404, + statusText: 'Not Found' }); spyOn(service, 'getInvolvedGroups').and.returnValue(throwError(errorResponse)); - service.getInvolvedGroups('mock-user-id') - .subscribe( - () => { - fail('expected an error, not involved groups'); - }, - (error) => { - expect(error.status).toEqual(404); - expect(error.statusText).toEqual('Not Found'); - expect(error.error).toEqual('Mock Error'); - done(); - } - ); + service.getInvolvedGroups('mock-user-id').subscribe( + () => { + fail('expected an error, not involved groups'); + }, + (error) => { + expect(error.status).toEqual(404); + expect(error.statusText).toEqual('Not Found'); + expect(error.error).toEqual('Mock Error'); + done(); + } + ); }); it('should be able to join the group', (done) => { @@ -456,23 +429,23 @@ describe('IdentityUserService', () => { it('Should not able to join group if error occurred', (done) => { const errorResponse = new HttpErrorResponse({ error: 'Mock Error', - status: 404, statusText: 'Not Found' + status: 404, + statusText: 'Not Found' }); spyOn(service, 'joinGroup').and.returnValue(throwError(errorResponse)); - service.joinGroup(mockJoinGroupRequest) - .subscribe( - () => { - fail('expected an error, not to join group'); - }, - (error) => { - expect(error.status).toEqual(404); - expect(error.statusText).toEqual('Not Found'); - expect(error.error).toEqual('Mock Error'); - done(); - } - ); + service.joinGroup(mockJoinGroupRequest).subscribe( + () => { + fail('expected an error, not to join group'); + }, + (error) => { + expect(error.status).toEqual(404); + expect(error.statusText).toEqual('Not Found'); + expect(error.error).toEqual('Mock Error'); + done(); + } + ); }); it('should be able to leave the group', (done) => { @@ -486,23 +459,23 @@ describe('IdentityUserService', () => { it('Should not able to leave group if error occurred', (done) => { const errorResponse = new HttpErrorResponse({ error: 'Mock Error', - status: 404, statusText: 'Not Found' + status: 404, + statusText: 'Not Found' }); spyOn(service, 'leaveGroup').and.returnValue(throwError(errorResponse)); - service.leaveGroup('mock-user-id', 'mock-group-id') - .subscribe( - () => { - fail('expected an error, not to leave group'); - }, - (error) => { - expect(error.status).toEqual(404); - expect(error.statusText).toEqual('Not Found'); - expect(error.error).toEqual('Mock Error'); - done(); - } - ); + service.leaveGroup('mock-user-id', 'mock-group-id').subscribe( + () => { + fail('expected an error, not to leave group'); + }, + (error) => { + expect(error.status).toEqual(404); + expect(error.statusText).toEqual('Not Found'); + expect(error.error).toEqual('Mock Error'); + done(); + } + ); }); it('should be able to fetch available roles based on user id', (done) => { @@ -524,23 +497,23 @@ describe('IdentityUserService', () => { it('Should not be able to fetch available roles based on user id if error occurred', (done) => { const errorResponse = new HttpErrorResponse({ error: 'Mock Error', - status: 404, statusText: 'Not Found' + status: 404, + statusText: 'Not Found' }); spyOn(service, 'getAvailableRoles').and.returnValue(throwError(errorResponse)); - service.getAvailableRoles('mock-user-id') - .subscribe( - () => { - fail('expected an error, not available roles'); - }, - (error) => { - expect(error.status).toEqual(404); - expect(error.statusText).toEqual('Not Found'); - expect(error.error).toEqual('Mock Error'); - done(); - } - ); + service.getAvailableRoles('mock-user-id').subscribe( + () => { + fail('expected an error, not available roles'); + }, + (error) => { + expect(error.status).toEqual(404); + expect(error.statusText).toEqual('Not Found'); + expect(error.error).toEqual('Mock Error'); + done(); + } + ); }); it('should be able to fetch assigned roles based on user id', (done) => { @@ -562,23 +535,23 @@ describe('IdentityUserService', () => { it('Should not be able to fetch assigned roles based on user id if error occurred', (done) => { const errorResponse = new HttpErrorResponse({ error: 'Mock Error', - status: 404, statusText: 'Not Found' + status: 404, + statusText: 'Not Found' }); spyOn(service, 'getAssignedRoles').and.returnValue(throwError(errorResponse)); - service.getAssignedRoles('mock-user-id') - .subscribe( - () => { - fail('expected an error, not assigned roles'); - }, - (error) => { - expect(error.status).toEqual(404); - expect(error.statusText).toEqual('Not Found'); - expect(error.error).toEqual('Mock Error'); - done(); - } - ); + service.getAssignedRoles('mock-user-id').subscribe( + () => { + fail('expected an error, not assigned roles'); + }, + (error) => { + expect(error.status).toEqual(404); + expect(error.statusText).toEqual('Not Found'); + expect(error.error).toEqual('Mock Error'); + done(); + } + ); }); it('should be able to fetch effective roles based on user id', (done) => { @@ -600,23 +573,23 @@ describe('IdentityUserService', () => { it('Should not be able to fetch effective roles based on user id if error occurred', (done) => { const errorResponse = new HttpErrorResponse({ error: 'Mock Error', - status: 404, statusText: 'Not Found' + status: 404, + statusText: 'Not Found' }); spyOn(service, 'getEffectiveRoles').and.returnValue(throwError(errorResponse)); - service.getEffectiveRoles('mock-user-id') - .subscribe( - () => { - fail('expected an error, not effective roles'); - }, - (error) => { - expect(error.status).toEqual(404); - expect(error.statusText).toEqual('Not Found'); - expect(error.error).toEqual('Mock Error'); - done(); - } - ); + service.getEffectiveRoles('mock-user-id').subscribe( + () => { + fail('expected an error, not effective roles'); + }, + (error) => { + expect(error.status).toEqual(404); + expect(error.statusText).toEqual('Not Found'); + expect(error.error).toEqual('Mock Error'); + done(); + } + ); }); it('should be able to assign roles to the user', (done) => { @@ -630,23 +603,23 @@ describe('IdentityUserService', () => { it('Should not able to assign roles to the user if error occurred', (done) => { const errorResponse = new HttpErrorResponse({ error: 'Mock Error', - status: 404, statusText: 'Not Found' + status: 404, + statusText: 'Not Found' }); spyOn(service, 'assignRoles').and.returnValue(throwError(errorResponse)); - service.assignRoles('mock-user-id', [mockIdentityRole]) - .subscribe( - () => { - fail('expected an error, not to assigen roles to the user'); - }, - (error) => { - expect(error.status).toEqual(404); - expect(error.statusText).toEqual('Not Found'); - expect(error.error).toEqual('Mock Error'); - done(); - } - ); + service.assignRoles('mock-user-id', [mockIdentityRole]).subscribe( + () => { + fail('expected an error, not to assigen roles to the user'); + }, + (error) => { + expect(error.status).toEqual(404); + expect(error.statusText).toEqual('Not Found'); + expect(error.error).toEqual('Mock Error'); + done(); + } + ); }); it('should be able to remove roles', (done) => { @@ -660,22 +633,22 @@ describe('IdentityUserService', () => { it('Should not able to remove roles if error occurred', (done) => { const errorResponse = new HttpErrorResponse({ error: 'Mock Error', - status: 404, statusText: 'Not Found' + status: 404, + statusText: 'Not Found' }); spyOn(service, 'removeRoles').and.returnValue(throwError(errorResponse)); - service.removeRoles('mock-user-id', [mockIdentityRole]) - .subscribe( - () => { - fail('expected an error, not to remove roles'); - }, - (error) => { - expect(error.status).toEqual(404); - expect(error.statusText).toEqual('Not Found'); - expect(error.error).toEqual('Mock Error'); - done(); - } - ); + service.removeRoles('mock-user-id', [mockIdentityRole]).subscribe( + () => { + fail('expected an error, not to remove roles'); + }, + (error) => { + expect(error.status).toEqual(404); + expect(error.statusText).toEqual('Not Found'); + expect(error.error).toEqual('Mock Error'); + done(); + } + ); }); }); diff --git a/lib/core/src/lib/auth/services/oidc-authentication.service.ts b/lib/core/src/lib/auth/services/oidc-authentication.service.ts index 320d63e4f61..7504253629c 100644 --- a/lib/core/src/lib/auth/services/oidc-authentication.service.ts +++ b/lib/core/src/lib/auth/services/oidc-authentication.service.ts @@ -24,7 +24,6 @@ import { OauthConfigModel } from '../models/oauth-config.model'; import { BaseAuthenticationService } from './base-authentication.service'; import { CookieService } from '../../common/services/cookie.service'; import { JwtHelperService } from './jwt-helper.service'; -import { LogService } from '../../common/services/log.service'; import { AuthConfigService } from '../oidc/auth-config.service'; import { AuthService } from '../oidc/auth.service'; import { Minimatch } from 'minimatch'; @@ -34,18 +33,16 @@ import { HttpHeaders } from '@angular/common/http'; providedIn: 'root' }) export class OidcAuthenticationService extends BaseAuthenticationService { - constructor( appConfig: AppConfigService, cookie: CookieService, - logService: LogService, private jwtHelperService: JwtHelperService, private authStorage: OAuthStorage, private oauthService: OAuthService, private readonly authConfig: AuthConfigService, private readonly auth: AuthService ) { - super(appConfig, cookie, logService); + super(appConfig, cookie); } isEcmLoggedIn(): boolean { @@ -53,7 +50,6 @@ export class OidcAuthenticationService extends BaseAuthenticationService { return this.isLoggedIn(); } return false; - } isBpmLoggedIn(): boolean { @@ -118,7 +114,7 @@ export class OidcAuthenticationService extends BaseAuthenticationService { }); } - getUsername(){ + getUsername() { return this.jwtHelperService.getValueFromLocalToken(JwtHelperService.USER_PREFERRED_USERNAME); } @@ -169,11 +165,13 @@ export class OidcAuthenticationService extends BaseAuthenticationService { const oauth2 = this.appConfig.get(AppConfigValues.OAUTHCONFIG, null); if (Array.isArray(oauth2.publicUrls)) { - return oauth2.publicUrls.length > 0 && + return ( + oauth2.publicUrls.length > 0 && oauth2.publicUrls.some((urlPattern: string) => { const minimatch = new Minimatch(urlPattern); return minimatch.match(window.location.href); - }); + }) + ); } return false; } @@ -219,5 +217,4 @@ export class OidcAuthenticationService extends BaseAuthenticationService { return undefined; } } - } diff --git a/lib/core/src/lib/buttons-menu/buttons-menu.component.spec.ts b/lib/core/src/lib/buttons-menu/buttons-menu.component.spec.ts index c10388801e2..5907db638d9 100644 --- a/lib/core/src/lib/buttons-menu/buttons-menu.component.spec.ts +++ b/lib/core/src/lib/buttons-menu/buttons-menu.component.spec.ts @@ -19,20 +19,16 @@ import { TestBed, ComponentFixture } from '@angular/core/testing'; import { MaterialModule } from '../material.module'; import { CoreTestingModule } from '../testing/core.testing.module'; import { CUSTOM_ELEMENTS_SCHEMA, Component } from '@angular/core'; -import { TranslateModule } from '@ngx-translate/core'; @Component({ selector: 'adf-custom-container', template: ` - + ` }) export class CustomContainerComponent { - value: number; assignValue() { @@ -42,35 +38,21 @@ export class CustomContainerComponent { @Component({ selector: 'adf-custom-empty-container', - template: ` - - - ` + template: `` }) -export class CustomEmptyContainerComponent { -} +export class CustomEmptyContainerComponent {} describe('ButtonsMenuComponent', () => { - describe('When Buttons are injected', () => { - let fixture: ComponentFixture; let component: CustomContainerComponent; let element: HTMLElement; beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - CoreTestingModule, - MaterialModule - ], - declarations: [ - CustomContainerComponent - ], - schemas: [ - CUSTOM_ELEMENTS_SCHEMA - ] + imports: [CoreTestingModule, MaterialModule], + declarations: [CustomContainerComponent], + schemas: [CUSTOM_ELEMENTS_SCHEMA] }); fixture = TestBed.createComponent(CustomContainerComponent); element = fixture.debugElement.nativeElement; @@ -111,17 +93,9 @@ describe('ButtonsMenuComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - CoreTestingModule, - MaterialModule - ], - declarations: [ - CustomEmptyContainerComponent - ], - schemas: [ - CUSTOM_ELEMENTS_SCHEMA - ] + imports: [CoreTestingModule, MaterialModule], + declarations: [CustomEmptyContainerComponent], + schemas: [CUSTOM_ELEMENTS_SCHEMA] }); fixture = TestBed.createComponent(CustomEmptyContainerComponent); element = fixture.nativeElement; diff --git a/lib/core/src/lib/card-view/components/card-view-arrayitem/card-view-arrayitem.component.spec.ts b/lib/core/src/lib/card-view/components/card-view-arrayitem/card-view-arrayitem.component.spec.ts index 8eba3158bef..e5aa5b3986b 100644 --- a/lib/core/src/lib/card-view/components/card-view-arrayitem/card-view-arrayitem.component.spec.ts +++ b/lib/core/src/lib/card-view/components/card-view-arrayitem/card-view-arrayitem.component.spec.ts @@ -21,7 +21,6 @@ import { CoreTestingModule } from '../../../testing/core.testing.module'; import { CardViewArrayItemComponent } from './card-view-arrayitem.component'; import { CardViewArrayItemModel, CardViewArrayItem } from '../../models/card-view-arrayitem.model'; import { By } from '@angular/platform-browser'; -import { TranslateModule } from '@ngx-translate/core'; import { CardViewUpdateService } from '../../services/card-view-update.service'; import { HarnessLoader } from '@angular/cdk/testing'; import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed'; @@ -52,7 +51,7 @@ describe('CardViewArrayItemComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [TranslateModule.forRoot(), CoreTestingModule] + imports: [CoreTestingModule] }); fixture = TestBed.createComponent(CardViewArrayItemComponent); service = TestBed.inject(CardViewUpdateService); diff --git a/lib/core/src/lib/card-view/components/card-view-boolitem/card-view-boolitem.component.spec.ts b/lib/core/src/lib/card-view/components/card-view-boolitem/card-view-boolitem.component.spec.ts index 5dd121da2a1..d70c8451bc4 100644 --- a/lib/core/src/lib/card-view/components/card-view-boolitem/card-view-boolitem.component.spec.ts +++ b/lib/core/src/lib/card-view/components/card-view-boolitem/card-view-boolitem.component.spec.ts @@ -22,19 +22,14 @@ import { CardViewUpdateService } from '../../services/card-view-update.service'; import { CardViewBoolItemComponent } from './card-view-boolitem.component'; import { CardViewBoolItemModel } from '../../models/card-view-boolitem.model'; import { CoreTestingModule } from '../../../testing/core.testing.module'; -import { TranslateModule } from '@ngx-translate/core'; describe('CardViewBoolItemComponent', () => { - let fixture: ComponentFixture; let component: CardViewBoolItemComponent; beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - CoreTestingModule - ] + imports: [CoreTestingModule] }); fixture = TestBed.createComponent(CardViewBoolItemComponent); component = fixture.componentInstance; @@ -52,7 +47,6 @@ describe('CardViewBoolItemComponent', () => { }); describe('Rendering', () => { - it('should render the label and value if the property is editable', () => { component.editable = true; component.property.editable = true; @@ -169,7 +163,6 @@ describe('CardViewBoolItemComponent', () => { }); describe('Update', () => { - beforeEach(() => { component.editable = true; component.property.editable = true; @@ -180,7 +173,7 @@ describe('CardViewBoolItemComponent', () => { it('should trigger the update event when changing the checkbox', () => { const cardViewUpdateService = TestBed.inject(CardViewUpdateService); spyOn(cardViewUpdateService, 'update'); - const property = { ... component.property }; + const property = { ...component.property }; component.changed({ checked: true } as MatCheckboxChange); @@ -204,14 +197,12 @@ describe('CardViewBoolItemComponent', () => { fixture.detectChanges(); const property = { ...component.property }; - const disposableUpdate = cardViewUpdateService.itemUpdated$.subscribe( - (updateNotification) => { - expect(updateNotification.target).toEqual(property); - expect(updateNotification.changed).toEqual({ boolKey: true }); - disposableUpdate.unsubscribe(); - done(); - } - ); + const disposableUpdate = cardViewUpdateService.itemUpdated$.subscribe((updateNotification) => { + expect(updateNotification.target).toEqual(property); + expect(updateNotification.changed).toEqual({ boolKey: true }); + disposableUpdate.unsubscribe(); + done(); + }); const labelElement = fixture.debugElement.query(By.directive(MatCheckbox)).nativeElement.querySelector('label'); labelElement.click(); diff --git a/lib/core/src/lib/card-view/components/card-view-dateitem/card-view-dateitem.component.spec.ts b/lib/core/src/lib/card-view/components/card-view-dateitem/card-view-dateitem.component.spec.ts index 9f74b605fec..4f727d1cd6d 100644 --- a/lib/core/src/lib/card-view/components/card-view-dateitem/card-view-dateitem.component.spec.ts +++ b/lib/core/src/lib/card-view/components/card-view-dateitem/card-view-dateitem.component.spec.ts @@ -24,6 +24,7 @@ import { CoreTestingModule } from '../../../testing/core.testing.module'; import { ClipboardService } from '../../../clipboard/clipboard.service'; import { CardViewDatetimeItemModel } from '../../models/card-view-datetimeitem.model'; import { TranslateModule } from '@ngx-translate/core'; +import { AppConfigService } from '../../../app-config/app-config.service'; import { MatDatetimepickerInputEvent } from '@mat-datetimepicker/core'; import { HarnessLoader } from '@angular/cdk/testing'; import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed'; @@ -33,11 +34,18 @@ describe('CardViewDateItemComponent', () => { let loader: HarnessLoader; let fixture: ComponentFixture; let component: CardViewDateItemComponent; + let appConfigService: AppConfigService; beforeEach(() => { TestBed.configureTestingModule({ imports: [TranslateModule.forRoot(), CoreTestingModule] }); + appConfigService = TestBed.inject(AppConfigService); + appConfigService.config.dateValues = { + defaultDateFormat: 'shortDate', + defaultDateTimeFormat: 'M/d/yy, h:mm a', + defaultLocale: 'uk' + }; fixture = TestBed.createComponent(CardViewDateItemComponent); component = fixture.componentInstance; diff --git a/lib/core/src/lib/card-view/components/card-view-keyvaluepairsitem/card-view-keyvaluepairsitem.component.spec.ts b/lib/core/src/lib/card-view/components/card-view-keyvaluepairsitem/card-view-keyvaluepairsitem.component.spec.ts index 7ef53d3bdc4..60eaf79d9b3 100644 --- a/lib/core/src/lib/card-view/components/card-view-keyvaluepairsitem/card-view-keyvaluepairsitem.component.spec.ts +++ b/lib/core/src/lib/card-view/components/card-view-keyvaluepairsitem/card-view-keyvaluepairsitem.component.spec.ts @@ -21,10 +21,8 @@ import { CardViewKeyValuePairsItemModel } from '../../models/card-view-keyvaluep import { CardViewKeyValuePairsItemComponent } from './card-view-keyvaluepairsitem.component'; import { CoreTestingModule } from '../../../testing/core.testing.module'; import { CardViewUpdateService } from '../../services/card-view-update.service'; -import { TranslateModule } from '@ngx-translate/core'; describe('CardViewKeyValuePairsItemComponent', () => { - let fixture: ComponentFixture; let component: CardViewKeyValuePairsItemComponent; let cardViewUpdateService: CardViewUpdateService; @@ -33,10 +31,7 @@ describe('CardViewKeyValuePairsItemComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - CoreTestingModule - ] + imports: [CoreTestingModule] }); fixture = TestBed.createComponent(CardViewKeyValuePairsItemComponent); cardViewUpdateService = TestBed.inject(CardViewUpdateService); @@ -55,7 +50,6 @@ describe('CardViewKeyValuePairsItemComponent', () => { }); describe('Component', () => { - it('should render the label', () => { fixture.detectChanges(); @@ -122,5 +116,5 @@ describe('CardViewKeyValuePairsItemComponent', () => { expect(cardViewUpdateService.update).toHaveBeenCalled(); expect(component.property.value.length).toBe(0); }); - }); + }); }); diff --git a/lib/core/src/lib/card-view/components/card-view-mapitem/card-view-mapitem.component.spec.ts b/lib/core/src/lib/card-view/components/card-view-mapitem/card-view-mapitem.component.spec.ts index ab1111ce37d..d7e3e0864b8 100644 --- a/lib/core/src/lib/card-view/components/card-view-mapitem/card-view-mapitem.component.spec.ts +++ b/lib/core/src/lib/card-view/components/card-view-mapitem/card-view-mapitem.component.spec.ts @@ -22,7 +22,6 @@ import { CardViewMapItemModel } from '../../models/card-view-mapitem.model'; import { CardViewUpdateService } from '../../services/card-view-update.service'; import { CardViewMapItemComponent } from './card-view-mapitem.component'; import { CoreTestingModule } from '../../../testing/core.testing.module'; -import { TranslateModule } from '@ngx-translate/core'; describe('CardViewMapItemComponent', () => { let service: CardViewUpdateService; @@ -34,10 +33,7 @@ describe('CardViewMapItemComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - CoreTestingModule - ] + imports: [CoreTestingModule] }); fixture = TestBed.createComponent(CardViewMapItemComponent); service = TestBed.inject(CardViewUpdateService); diff --git a/lib/core/src/lib/card-view/components/card-view-selectitem/card-view-selectitem.component.spec.ts b/lib/core/src/lib/card-view/components/card-view-selectitem/card-view-selectitem.component.spec.ts index 4c5521aee5f..5670533db68 100644 --- a/lib/core/src/lib/card-view/components/card-view-selectitem/card-view-selectitem.component.spec.ts +++ b/lib/core/src/lib/card-view/components/card-view-selectitem/card-view-selectitem.component.spec.ts @@ -21,7 +21,6 @@ import { CardViewSelectItemModel } from '../../models/card-view-selectitem.model import { CardViewSelectItemComponent } from './card-view-selectitem.component'; import { CoreTestingModule } from '../../../testing/core.testing.module'; import { of } from 'rxjs'; -import { TranslateModule } from '@ngx-translate/core'; import { AppConfigService } from '../../../app-config/app-config.service'; import { HarnessLoader } from '@angular/cdk/testing'; import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed'; @@ -60,7 +59,7 @@ describe('CardViewSelectItemComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [TranslateModule.forRoot(), CoreTestingModule] + imports: [CoreTestingModule] }); fixture = TestBed.createComponent(CardViewSelectItemComponent); component = fixture.componentInstance; diff --git a/lib/core/src/lib/card-view/components/card-view-selectitem/select-filter-input/select-filter-input.component.spec.ts b/lib/core/src/lib/card-view/components/card-view-selectitem/select-filter-input/select-filter-input.component.spec.ts index be3d2fcc105..e9ec1643763 100644 --- a/lib/core/src/lib/card-view/components/card-view-selectitem/select-filter-input/select-filter-input.component.spec.ts +++ b/lib/core/src/lib/card-view/components/card-view-selectitem/select-filter-input/select-filter-input.component.spec.ts @@ -17,7 +17,6 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; import { CoreTestingModule } from '../../../../testing/core.testing.module'; -import { TranslateModule } from '@ngx-translate/core'; import { SelectFilterInputComponent } from './select-filter-input.component'; import { MatSelect } from '@angular/material/select'; @@ -28,7 +27,7 @@ describe('SelectFilterInputComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [TranslateModule.forRoot(), CoreTestingModule], + imports: [CoreTestingModule], providers: [MatSelect] }); diff --git a/lib/core/src/lib/card-view/components/card-view-textitem/card-view-textitem.component.spec.ts b/lib/core/src/lib/card-view/components/card-view-textitem/card-view-textitem.component.spec.ts index 427fb77353e..f59f3fa6ab5 100644 --- a/lib/core/src/lib/card-view/components/card-view-textitem/card-view-textitem.component.spec.ts +++ b/lib/core/src/lib/card-view/components/card-view-textitem/card-view-textitem.component.spec.ts @@ -28,7 +28,6 @@ import { CardViewFloatItemModel } from '../../models/card-view-floatitem.model'; import { MatChipInputEvent, MatChipsModule } from '@angular/material/chips'; import { ClipboardService } from '../../../clipboard/clipboard.service'; import { DebugElement, SimpleChange } from '@angular/core'; -import { TranslateModule } from '@ngx-translate/core'; import { CardViewItemValidator } from '../../interfaces/card-view-item-validator.interface'; import { HarnessLoader } from '@angular/cdk/testing'; import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed'; @@ -113,7 +112,7 @@ describe('CardViewTextItemComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [TranslateModule.forRoot(), CoreTestingModule, MatChipsModule] + imports: [CoreTestingModule, MatChipsModule] }); fixture = TestBed.createComponent(CardViewTextItemComponent); component = fixture.componentInstance; @@ -536,7 +535,9 @@ describe('CardViewTextItemComponent', () => { component.ngOnChanges({}); loader = TestbedHarnessEnvironment.loader(fixture); - const inputHarness = await loader.getHarness(MatInputHarness.with({selector: `[data-automation-id="card-textitem-value-${component.property.key}"]`})); + const inputHarness = await loader.getHarness( + MatInputHarness.with({ selector: `[data-automation-id="card-textitem-value-${component.property.key}"]` }) + ); expect(component.isEditable).toBe(false); expect(await inputHarness.isReadonly()).toBe(true); diff --git a/lib/core/src/lib/card-view/components/card-view/card-view.component.spec.ts b/lib/core/src/lib/card-view/components/card-view/card-view.component.spec.ts index 4b6e81b81ba..20c548be760 100644 --- a/lib/core/src/lib/card-view/components/card-view/card-view.component.spec.ts +++ b/lib/core/src/lib/card-view/components/card-view/card-view.component.spec.ts @@ -21,7 +21,6 @@ import { CardViewDateItemModel } from '../../models/card-view-dateitem.model'; import { CardViewTextItemModel } from '../../models/card-view-textitem.model'; import { CardViewComponent } from './card-view.component'; import { CoreTestingModule } from '../../../testing/core.testing.module'; -import { TranslateModule } from '@ngx-translate/core'; import { CardViewSelectItemModel } from '../../models/card-view-selectitem.model'; import { of } from 'rxjs'; import { CardViewSelectItemOption } from '../../interfaces/card-view-selectitem-properties.interface'; @@ -38,7 +37,7 @@ describe('CardViewComponent', () => { beforeEach(async () => { await TestBed.configureTestingModule({ - imports: [TranslateModule.forRoot(), CoreTestingModule] + imports: [CoreTestingModule] }).compileComponents(); fixture = TestBed.createComponent(CardViewComponent); diff --git a/lib/core/src/lib/clipboard/clipboard.directive.spec.ts b/lib/core/src/lib/clipboard/clipboard.directive.spec.ts index 1dd16662642..bae94b14526 100644 --- a/lib/core/src/lib/clipboard/clipboard.directive.spec.ts +++ b/lib/core/src/lib/clipboard/clipboard.directive.spec.ts @@ -20,19 +20,14 @@ import { ComponentFixture, TestBed, tick, fakeAsync } from '@angular/core/testin import { ClipboardService } from './clipboard.service'; import { ClipboardDirective } from './clipboard.directive'; import { CoreTestingModule } from '../testing/core.testing.module'; -import { TranslateModule } from '@ngx-translate/core'; @Component({ - selector: 'adf-test-component', - template: ` - + selector: 'adf-test-component', + template: ` + - ` + ` }) class TestTargetClipboardComponent {} @@ -42,13 +37,8 @@ describe('ClipboardDirective', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - CoreTestingModule - ], - declarations: [ - TestTargetClipboardComponent - ] + imports: [CoreTestingModule], + declarations: [TestTargetClipboardComponent] }); fixture = TestBed.createComponent(TestTargetClipboardComponent); clipboardService = TestBed.inject(ClipboardService); @@ -66,20 +56,18 @@ describe('ClipboardDirective', () => { it('should notify copy target value on keydown event', () => { spyOn(clipboardService, 'copyToClipboard'); fixture.nativeElement.querySelector('input').value = 'some value'; - fixture.nativeElement.querySelector('button').dispatchEvent(new KeyboardEvent('keydown', {code: 'Enter', key: 'Enter'})); + fixture.nativeElement.querySelector('button').dispatchEvent(new KeyboardEvent('keydown', { code: 'Enter', key: 'Enter' })); expect(clipboardService.copyToClipboard).toHaveBeenCalled(); }); }); describe('CopyClipboardDirective', () => { - @Component({ - selector: 'adf-copy-conent-test-component', + selector: 'adf-copy-conent-test-component', template: `{{ mockText }}` }) class TestCopyClipboardComponent { - mockText = 'text to copy'; placeholder = 'copy text'; @@ -92,27 +80,22 @@ describe('CopyClipboardDirective', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - CoreTestingModule - ], - declarations: [ - TestCopyClipboardComponent - ] + imports: [CoreTestingModule], + declarations: [TestCopyClipboardComponent] }); fixture = TestBed.createComponent(TestCopyClipboardComponent); element = fixture.debugElement.nativeElement; fixture.detectChanges(); }); - it('should show tooltip when hover element', (() => { + it('should show tooltip when hover element', () => { const spanHTMLElement = element.querySelector('span'); spanHTMLElement.dispatchEvent(new Event('mouseenter')); fixture.detectChanges(); expect(fixture.debugElement.nativeElement.querySelector('.adf-copy-tooltip')).not.toBeNull(); - })); + }); - it('should not show tooltip when element it is not hovered', (() => { + it('should not show tooltip when element it is not hovered', () => { const spanHTMLElement = element.querySelector('span'); spanHTMLElement.dispatchEvent(new Event('mouseenter')); fixture.detectChanges(); @@ -121,7 +104,7 @@ describe('CopyClipboardDirective', () => { spanHTMLElement.dispatchEvent(new Event('mouseleave')); fixture.detectChanges(); expect(fixture.debugElement.nativeElement.querySelector('.adf-copy-tooltip')).toBeNull(); - })); + }); it('should copy the content of element when click it', fakeAsync(() => { const spanHTMLElement = element.querySelector('span'); @@ -137,7 +120,7 @@ describe('CopyClipboardDirective', () => { const spanHTMLElement = element.querySelector('span'); fixture.detectChanges(); spyOn(navigator.clipboard, 'writeText'); - spanHTMLElement.dispatchEvent(new KeyboardEvent('keydown', {code: 'Enter', key: 'Enter'})); + spanHTMLElement.dispatchEvent(new KeyboardEvent('keydown', { code: 'Enter', key: 'Enter' })); tick(); fixture.detectChanges(); expect(navigator.clipboard.writeText).toHaveBeenCalledWith('text to copy'); diff --git a/lib/core/src/lib/clipboard/clipboard.service.spec.ts b/lib/core/src/lib/clipboard/clipboard.service.spec.ts index cd5ee501f99..47f78e3127a 100644 --- a/lib/core/src/lib/clipboard/clipboard.service.spec.ts +++ b/lib/core/src/lib/clipboard/clipboard.service.spec.ts @@ -20,7 +20,6 @@ import { TestBed } from '@angular/core/testing'; import { ClipboardService } from './clipboard.service'; import { MatSnackBarModule } from '@angular/material/snack-bar'; import { CoreTestingModule } from '../testing'; -import { TranslateModule } from '@ngx-translate/core'; describe('ClipboardService', () => { let clipboardService: ClipboardService; @@ -29,11 +28,7 @@ describe('ClipboardService', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - CoreTestingModule, - MatSnackBarModule - ] + imports: [CoreTestingModule, MatSnackBarModule] }); clipboardService = TestBed.inject(ClipboardService); notificationService = TestBed.inject(NotificationService); @@ -61,8 +56,7 @@ describe('ClipboardService', () => { clipboardService.copyToClipboard(inputElement); expect(inputElement.select).toHaveBeenCalledWith(); - expect(inputElement.setSelectionRange) - .toHaveBeenCalledWith(0, inputElement.value.length); + expect(inputElement.setSelectionRange).toHaveBeenCalledWith(0, inputElement.value.length); expect(navigator.clipboard.writeText).toHaveBeenCalledWith('some text'); }); diff --git a/lib/core/src/lib/clipboard/clipboard.service.ts b/lib/core/src/lib/clipboard/clipboard.service.ts index fbaa932e3b1..c5df2ec2253 100644 --- a/lib/core/src/lib/clipboard/clipboard.service.ts +++ b/lib/core/src/lib/clipboard/clipboard.service.ts @@ -17,16 +17,11 @@ import { Injectable, Inject } from '@angular/core'; import { DOCUMENT } from '@angular/common'; -import { LogService } from '../common/services/log.service'; import { NotificationService } from '../notifications/services/notification.service'; @Injectable({ providedIn: 'root' }) export class ClipboardService { - - constructor( - @Inject(DOCUMENT) private document: any, - private logService: LogService, - private notificationService: NotificationService) { } + constructor(@Inject(DOCUMENT) private document: any, private notificationService: NotificationService) {} /** * Checks if the target element can have its text copied. @@ -58,9 +53,7 @@ export class ClipboardService { this.document.execCommand('copy'); } this.notify(message); - } catch (error) { - this.logService.error(error); - } + } catch {} } } @@ -76,16 +69,14 @@ export class ClipboardService { navigator.clipboard.writeText(content); } else { document.addEventListener('copy', (e: ClipboardEvent) => { - e.clipboardData.setData('text/plain', (content)); + e.clipboardData.setData('text/plain', content); e.preventDefault(); document.removeEventListener('copy', null); }); document.execCommand('copy'); } this.notify(message); - } catch (error) { - this.logService.error(error); - } + } catch {} } private notify(message) { @@ -93,5 +84,4 @@ export class ClipboardService { this.notificationService.openSnackMessage(message); } } - } diff --git a/lib/core/src/lib/comments/comment-list/comment-list.component.spec.ts b/lib/core/src/lib/comments/comment-list/comment-list.component.spec.ts index 207278046b8..5a874763af7 100644 --- a/lib/core/src/lib/comments/comment-list/comment-list.component.spec.ts +++ b/lib/core/src/lib/comments/comment-list/comment-list.component.spec.ts @@ -20,28 +20,18 @@ import { CommentModel } from '../../models/comment.model'; import { CommentListComponent } from './comment-list.component'; import { By } from '@angular/platform-browser'; import { CoreTestingModule } from '../../testing/core.testing.module'; -import { TranslateModule } from '@ngx-translate/core'; -import { - commentUserNoPictureDefined, - commentUserPictureDefined, - mockCommentOne, - testUser -} from './mocks/comment-list.mock'; +import { commentUserNoPictureDefined, commentUserPictureDefined, mockCommentOne, testUser } from './mocks/comment-list.mock'; import { CommentListServiceMock } from './mocks/comment-list.service.mock'; import { ADF_COMMENTS_SERVICE } from '../interfaces/comments.token'; describe('CommentListComponent', () => { - let commentList: CommentListComponent; let fixture: ComponentFixture; let element: HTMLElement; beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - CoreTestingModule - ], + imports: [CoreTestingModule], providers: [ { provide: ADF_COMMENTS_SERVICE, @@ -123,7 +113,7 @@ describe('CommentListComponent', () => { it('comment date time should start with Yesterday when comment date is yesterday', async () => { const commentOld = new CommentModel(mockCommentOne); - commentOld.created = new Date((Date.now() - 24 * 3600 * 1000)); + commentOld.created = new Date(Date.now() - 24 * 3600 * 1000); commentList.comments = [commentOld]; fixture.detectChanges(); @@ -135,7 +125,7 @@ describe('CommentListComponent', () => { it('comment date time should not start with Today/Yesterday when comment date is before yesterday', async () => { const commentOld = new CommentModel(mockCommentOne); - commentOld.created = new Date((Date.now() - 24 * 3600 * 1000 * 2)); + commentOld.created = new Date(Date.now() - 24 * 3600 * 1000 * 2); commentList.comments = [commentOld]; fixture.detectChanges(); diff --git a/lib/core/src/lib/comments/comments.component.spec.ts b/lib/core/src/lib/comments/comments.component.spec.ts index f75416afad4..ac616faa969 100644 --- a/lib/core/src/lib/comments/comments.component.spec.ts +++ b/lib/core/src/lib/comments/comments.component.spec.ts @@ -19,7 +19,6 @@ import { SimpleChange } from '@angular/core'; import { ComponentFixture, TestBed } from '@angular/core/testing'; import { CommentsComponent } from './comments.component'; import { CoreTestingModule } from '../testing/core.testing.module'; -import { TranslateModule } from '@ngx-translate/core'; import { CommentsServiceMock, commentsResponseMock } from './mocks/comments.service.mock'; import { of, throwError } from 'rxjs'; import { ADF_COMMENTS_SERVICE } from './interfaces/comments.token'; @@ -34,10 +33,7 @@ describe('CommentsComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - CoreTestingModule - ], + imports: [CoreTestingModule], providers: [ { provide: ADF_COMMENTS_SERVICE, @@ -60,7 +56,7 @@ describe('CommentsComponent', () => { it('should load comments when id specified', () => { const change = new SimpleChange(null, '123', true); - component.ngOnChanges({id: change}); + component.ngOnChanges({ id: change }); expect(getCommentSpy).toHaveBeenCalled(); }); @@ -70,7 +66,7 @@ describe('CommentsComponent', () => { getCommentSpy.and.returnValue(throwError({})); const change = new SimpleChange(null, '123', true); - component.ngOnChanges({id: change}); + component.ngOnChanges({ id: change }); expect(emitSpy).toHaveBeenCalled(); }); @@ -82,7 +78,7 @@ describe('CommentsComponent', () => { it('should display comments when the entity has comments', async () => { const change = new SimpleChange(null, '123', true); - component.ngOnChanges({id: change}); + component.ngOnChanges({ id: change }); fixture.detectChanges(); await fixture.whenStable(); @@ -93,7 +89,7 @@ describe('CommentsComponent', () => { it('should display comments count when the entity has comments', async () => { const change = new SimpleChange(null, '123', true); - component.ngOnChanges({id: change}); + component.ngOnChanges({ id: change }); fixture.detectChanges(); await fixture.whenStable(); @@ -114,7 +110,7 @@ describe('CommentsComponent', () => { it('should display comments input by default', async () => { const change = new SimpleChange(null, '123', true); - component.ngOnChanges({id: change}); + component.ngOnChanges({ id: change }); fixture.detectChanges(); await fixture.whenStable(); @@ -141,7 +137,7 @@ describe('CommentsComponent', () => { }); it('should fetch new comments when id changed', () => { - component.ngOnChanges({id: change}); + component.ngOnChanges({ id: change }); expect(getCommentSpy).toHaveBeenCalledWith('456'); }); @@ -151,13 +147,12 @@ describe('CommentsComponent', () => { }); it('should not fetch new comments when id changed to null', () => { - component.ngOnChanges({id: nullChange}); + component.ngOnChanges({ id: nullChange }); expect(getCommentSpy).not.toHaveBeenCalled(); }); }); describe('Add comment', () => { - beforeEach(() => { component.id = '123'; fixture.detectChanges(); @@ -229,7 +224,7 @@ describe('CommentsComponent', () => { }); it('should clear comment when escape key is pressed', async () => { - const event = new KeyboardEvent('keydown', {key: 'Escape'}); + const event = new KeyboardEvent('keydown', { key: 'Escape' }); let element = fixture.nativeElement.querySelector('#comment-input'); element.dispatchEvent(event); @@ -271,5 +266,5 @@ describe('CommentsComponent', () => { component.addComment(); expect(addCommentSpy).not.toHaveBeenCalled(); }); - }); + }); }); diff --git a/lib/core/src/lib/common/services/directionality-config.service.spec.ts b/lib/core/src/lib/common/services/directionality-config.service.spec.ts index 91a7ca0cb2b..4130b238266 100644 --- a/lib/core/src/lib/common/services/directionality-config.service.spec.ts +++ b/lib/core/src/lib/common/services/directionality-config.service.spec.ts @@ -18,19 +18,13 @@ import { TestBed } from '@angular/core/testing'; import { CoreTestingModule } from '../../testing/core.testing.module'; import { UserPreferencesService } from './user-preferences.service'; -import { TranslateModule } from '@ngx-translate/core'; -import { CoreModule } from '../../core.module'; describe('DirectionalityConfigService', () => { let userPreferencesService: UserPreferencesService; beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - CoreModule.forRoot(), - CoreTestingModule - ] + imports: [CoreTestingModule] }); userPreferencesService = TestBed.inject(UserPreferencesService); }); diff --git a/lib/core/src/lib/common/services/log.service.ts b/lib/core/src/lib/common/services/log.service.ts index 8169868bd8a..fae5dbc2164 100644 --- a/lib/core/src/lib/common/services/log.service.ts +++ b/lib/core/src/lib/common/services/log.service.ts @@ -22,11 +22,13 @@ import { AppConfigService, AppConfigValues } from '../../app-config/app-config.s import { logLevels, LogLevelsEnum } from '../models/log-levels.model'; import { Subject } from 'rxjs'; +/** + * @deprecated This service is deprecated and will be removed in future versions. + */ @Injectable({ providedIn: 'root' }) export class LogService { - get currentLogLevel() { const configLevel: string = this.appConfig.get(AppConfigValues.LOG_LEVEL); @@ -51,7 +53,6 @@ export class LogService { */ error(message?: any, ...optionalParams: any[]) { if (this.currentLogLevel >= LogLevelsEnum.ERROR) { - this.messageBus(message, 'ERROR'); console.error(message, ...optionalParams); @@ -66,7 +67,6 @@ export class LogService { */ debug(message?: any, ...optionalParams: any[]) { if (this.currentLogLevel >= LogLevelsEnum.DEBUG) { - this.messageBus(message, 'DEBUG'); console.debug(message, ...optionalParams); @@ -81,7 +81,6 @@ export class LogService { */ info(message?: any, ...optionalParams: any[]) { if (this.currentLogLevel >= LogLevelsEnum.INFO) { - this.messageBus(message, 'INFO'); console.info(message, ...optionalParams); @@ -96,7 +95,6 @@ export class LogService { */ log(message?: any, ...optionalParams: any[]) { if (this.currentLogLevel >= LogLevelsEnum.TRACE) { - this.messageBus(message, 'LOG'); console.log(message, ...optionalParams); @@ -111,7 +109,6 @@ export class LogService { */ trace(message?: any, ...optionalParams: any[]) { if (this.currentLogLevel >= LogLevelsEnum.TRACE) { - this.messageBus(message, 'TRACE'); console.trace(message, ...optionalParams); @@ -126,7 +123,6 @@ export class LogService { */ warn(message?: any, ...optionalParams: any[]) { if (this.currentLogLevel >= LogLevelsEnum.WARN) { - this.messageBus(message, 'WARN'); console.warn(message, ...optionalParams); @@ -142,7 +138,6 @@ export class LogService { */ assert(test?: boolean, message?: string, ...optionalParams: any[]) { if (this.currentLogLevel !== LogLevelsEnum.SILENT) { - this.messageBus(message, 'ASSERT'); console.assert(test, message, ...optionalParams); diff --git a/lib/core/src/lib/common/services/storage.service.spec.ts b/lib/core/src/lib/common/services/storage.service.spec.ts index 755c8f1d567..03d4b167605 100644 --- a/lib/core/src/lib/common/services/storage.service.spec.ts +++ b/lib/core/src/lib/common/services/storage.service.spec.ts @@ -20,10 +20,8 @@ import { AppConfigService } from '../../app-config/app-config.service'; import { StorageService } from '../../common/services/storage.service'; import { CoreTestingModule } from '../../testing/core.testing.module'; import { AppConfigServiceMock } from '../mock/app-config.service.mock'; -import { TranslateModule } from '@ngx-translate/core'; describe('StorageService', () => { - let storage: StorageService; let appConfig: AppConfigServiceMock; const key = 'test_key'; @@ -32,9 +30,7 @@ describe('StorageService', () => { describe('StorageService', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - CoreTestingModule - ] + imports: [CoreTestingModule] }); appConfig = TestBed.inject(AppConfigService); appConfig.config = { @@ -78,10 +74,7 @@ describe('StorageService', () => { describe('StorageService', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - CoreTestingModule - ] + imports: [CoreTestingModule] }); appConfig = TestBed.inject(AppConfigService); diff --git a/lib/core/src/lib/common/services/user-preferences.service.spec.ts b/lib/core/src/lib/common/services/user-preferences.service.spec.ts index 0e7a3964ea6..f3c4758bbd3 100644 --- a/lib/core/src/lib/common/services/user-preferences.service.spec.ts +++ b/lib/core/src/lib/common/services/user-preferences.service.spec.ts @@ -16,7 +16,7 @@ */ import { TestBed } from '@angular/core/testing'; -import { TranslateService, TranslateModule } from '@ngx-translate/core'; +import { TranslateService } from '@ngx-translate/core'; import { AppConfigService } from '../../app-config/app-config.service'; import { StorageService } from '../../common/services/storage.service'; import { UserPreferencesService, UserPreferenceValues } from '../../common/services/user-preferences.service'; @@ -26,7 +26,6 @@ import { AlfrescoApiService } from '../../services/alfresco-api.service'; import { AlfrescoApiServiceMock } from '../../mock'; describe('UserPreferencesService', () => { - const supportedPaginationSize = [5, 10, 15, 20]; let preferences: UserPreferencesService; let storage: StorageService; @@ -36,10 +35,7 @@ describe('UserPreferencesService', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - CoreTestingModule - ] + imports: [CoreTestingModule] }); appConfig = TestBed.inject(AppConfigService); appConfig.config = { diff --git a/lib/core/src/lib/context-menu/context-menu-overlay.service.spec.ts b/lib/core/src/lib/context-menu/context-menu-overlay.service.spec.ts index e14a3fda70d..4b09eedfdba 100644 --- a/lib/core/src/lib/context-menu/context-menu-overlay.service.spec.ts +++ b/lib/core/src/lib/context-menu/context-menu-overlay.service.spec.ts @@ -20,7 +20,6 @@ import { CoreTestingModule } from '../testing/core.testing.module'; import { ContextMenuOverlayService } from './context-menu-overlay.service'; import { Injector } from '@angular/core'; import { TestBed } from '@angular/core/testing'; -import { TranslateModule } from '@ngx-translate/core'; describe('ContextMenuOverlayService', () => { let contextMenuOverlayService: ContextMenuOverlayService; @@ -36,11 +35,8 @@ describe('ContextMenuOverlayService', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - CoreTestingModule - ], - providers: [ Overlay ] + imports: [CoreTestingModule], + providers: [Overlay] }); overlay = TestBed.inject(Overlay); injector = TestBed.inject(Injector); @@ -48,10 +44,7 @@ describe('ContextMenuOverlayService', () => { describe('Overlay', () => { beforeEach(() => { - contextMenuOverlayService = new ContextMenuOverlayService( - injector, - overlay - ); + contextMenuOverlayService = new ContextMenuOverlayService(injector, overlay); }); it('should create a custom overlay', () => { diff --git a/lib/core/src/lib/context-menu/context-menu.spec.ts b/lib/core/src/lib/context-menu/context-menu.spec.ts index 13a88d2f2a3..c0ddf755577 100644 --- a/lib/core/src/lib/context-menu/context-menu.spec.ts +++ b/lib/core/src/lib/context-menu/context-menu.spec.ts @@ -19,16 +19,13 @@ import { Component } from '@angular/core'; import { TestBed, ComponentFixture } from '@angular/core/testing'; import { ContextMenuModule } from './context-menu.module'; import { CoreTestingModule } from '../testing/core.testing.module'; -import { TranslateModule } from '@ngx-translate/core'; import { HarnessLoader } from '@angular/cdk/testing'; import { MatIconHarness } from '@angular/material/icon/testing'; import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed'; @Component({ selector: 'adf-test-component', - template: ` -
- ` + template: `
` }) class TestComponent { actions; @@ -83,14 +80,8 @@ describe('ContextMenuDirective', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - CoreTestingModule, - ContextMenuModule - ], - declarations: [ - TestComponent - ] + imports: [CoreTestingModule, ContextMenuModule], + declarations: [TestComponent] }); fixture = TestBed.createComponent(TestComponent); fixture.componentInstance.actions = actions; @@ -118,7 +109,9 @@ describe('ContextMenuDirective', () => { it('should reset DOM element reference on Escape event', () => { const event = new KeyboardEvent('keydown', { - bubbles : true, cancelable : true, key : 'Escape' + bubbles: true, + cancelable: true, + key: 'Escape' }); document.querySelector('.cdk-overlay-backdrop')?.dispatchEvent(event); @@ -169,9 +162,16 @@ describe('ContextMenuDirective', () => { }); it('should not render item icon if not set', async () => { - expect((await loader.getAllHarnesses(MatIconHarness.with({ - ancestor: 'adf-context-menu', name: 'Action 1' - }))).length).toBe(0); + expect( + ( + await loader.getAllHarnesses( + MatIconHarness.with({ + ancestor: 'adf-context-menu', + name: 'Action 1' + }) + ) + ).length + ).toBe(0); }); }); }); diff --git a/lib/core/src/lib/datatable/components/columns-selector/columns-selector.component.spec.ts b/lib/core/src/lib/datatable/components/columns-selector/columns-selector.component.spec.ts index 790fbf17666..e28c1839c69 100644 --- a/lib/core/src/lib/datatable/components/columns-selector/columns-selector.component.spec.ts +++ b/lib/core/src/lib/datatable/components/columns-selector/columns-selector.component.spec.ts @@ -21,7 +21,6 @@ import { DataColumn } from '../../data/data-column.model'; import { Observable, Subject } from 'rxjs'; import { MatMenuTrigger } from '@angular/material/menu'; import { CoreTestingModule } from '../../../testing'; -import { TranslateModule } from '@ngx-translate/core'; import { By } from '@angular/platform-browser'; import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed'; import { HarnessLoader } from '@angular/cdk/testing'; @@ -41,10 +40,7 @@ describe('ColumnsSelectorComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - CoreTestingModule - ], + imports: [CoreTestingModule], declarations: [ColumnsSelectorComponent] }).compileComponents(); @@ -52,32 +48,38 @@ describe('ColumnsSelectorComponent', () => { loader = TestbedHarnessEnvironment.loader(fixture); component = fixture.componentInstance; - inputColumns = [{ - id: 'id0', - key: 'key0', - title: 'title0', - type: 'text' - }, { - id: 'id1', - key: 'key1', - title: 'title1', - type: 'text' - }, { - id: 'id2', - key: 'key2', - title: 'title2', - type: 'text' - }, { - id: 'id3', - key: 'NoTitle', - type: 'text' - }, { - id: 'id4', - key: 'IsHidden', - type: 'text', - title: 'title4', - isHidden: true - }]; + inputColumns = [ + { + id: 'id0', + key: 'key0', + title: 'title0', + type: 'text' + }, + { + id: 'id1', + key: 'key1', + title: 'title1', + type: 'text' + }, + { + id: 'id2', + key: 'key2', + title: 'title2', + type: 'text' + }, + { + id: 'id3', + key: 'NoTitle', + type: 'text' + }, + { + id: 'id4', + key: 'IsHidden', + type: 'text', + title: 'title4', + isHidden: true + } + ]; mainMenuTrigger = { menuOpened: menuOpenedTrigger.asObservable(), @@ -114,13 +116,13 @@ describe('ColumnsSelectorComponent', () => { const checkboxes = await loader.getAllHarnesses(MatCheckboxHarness); - const inputColumnsWithTitle = inputColumns.filter(column => !!column.title); + const inputColumnsWithTitle = inputColumns.filter((column) => !!column.title); expect(checkboxes.length).toBe(inputColumnsWithTitle.length); for await (const checkbox of checkboxes) { const checkboxLabel = await checkbox.getLabelText(); - const inputColumn = inputColumnsWithTitle.find(inputColumnWithTitle => inputColumnWithTitle.title === checkboxLabel); + const inputColumn = inputColumnsWithTitle.find((inputColumnWithTitle) => inputColumnWithTitle.title === checkboxLabel); expect(inputColumn).toBeTruthy('Should have all columns with title'); } }); @@ -149,14 +151,13 @@ describe('ColumnsSelectorComponent', () => { const firstColumnCheckbox = await loader.getHarness(MatCheckboxHarness); const checkBoxName = await firstColumnCheckbox.getLabelText(); - const toggledColumnItem = component.columnItems.find(item => item.title === checkBoxName); + const toggledColumnItem = component.columnItems.find((item) => item.title === checkBoxName); expect(toggledColumnItem.isHidden).toBeFalsy(); await firstColumnCheckbox.toggle(); expect(toggledColumnItem.isHidden).toBe(true); }); - describe('checkboxes', () => { it('should have set proper default state', async () => { menuOpenedTrigger.next(); diff --git a/lib/core/src/lib/datatable/components/datatable/datatable.component.spec.ts b/lib/core/src/lib/datatable/components/datatable/datatable.component.spec.ts index 4af2931618d..de0bcf3db47 100644 --- a/lib/core/src/lib/datatable/components/datatable/datatable.component.spec.ts +++ b/lib/core/src/lib/datatable/components/datatable/datatable.component.spec.ts @@ -27,7 +27,6 @@ import { DataTableComponent, ShowHeaderMode } from './datatable.component'; import { CoreTestingModule } from '../../../testing/core.testing.module'; import { DataColumnListComponent } from '../../data-column/data-column-list.component'; import { DataColumnComponent } from '../../data-column/data-column.component'; -import { TranslateModule } from '@ngx-translate/core'; import { domSanitizerMock } from '../../../mock/dom-sanitizer-mock'; import { matIconRegistryMock } from '../../../mock/mat-icon-registry-mock'; import { CdkDrag, CdkDragDrop, CdkDropList } from '@angular/cdk/drag-drop'; @@ -140,7 +139,7 @@ describe('DataTable', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [TranslateModule.forRoot(), CoreTestingModule], + imports: [CoreTestingModule], declarations: [CustomColumnHeaderComponent] }); fixture = TestBed.createComponent(DataTableComponent); @@ -1280,7 +1279,7 @@ describe('Accesibility', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [TranslateModule.forRoot(), CoreTestingModule], + imports: [CoreTestingModule], declarations: [CustomColumnTemplateComponent], schemas: [NO_ERRORS_SCHEMA] }); @@ -1483,7 +1482,7 @@ describe('Drag&Drop column header', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [TranslateModule.forRoot(), CoreTestingModule], + imports: [CoreTestingModule], declarations: [CustomColumnTemplateComponent], schemas: [NO_ERRORS_SCHEMA] }); @@ -1584,7 +1583,7 @@ describe('Show/hide columns', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [TranslateModule.forRoot(), CoreTestingModule], + imports: [CoreTestingModule], declarations: [CustomColumnTemplateComponent], schemas: [NO_ERRORS_SCHEMA] }); @@ -1691,7 +1690,7 @@ describe('Column Resizing', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [TranslateModule.forRoot(), CoreTestingModule], + imports: [CoreTestingModule], declarations: [CustomColumnTemplateComponent], schemas: [NO_ERRORS_SCHEMA] }); diff --git a/lib/core/src/lib/datatable/components/empty-list/empty-list.component.spec.ts b/lib/core/src/lib/datatable/components/empty-list/empty-list.component.spec.ts index 900c485a534..229e095da7f 100644 --- a/lib/core/src/lib/datatable/components/empty-list/empty-list.component.spec.ts +++ b/lib/core/src/lib/datatable/components/empty-list/empty-list.component.spec.ts @@ -18,17 +18,13 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; import { EmptyListComponent } from './empty-list.component'; import { CoreTestingModule } from '../../../testing/core.testing.module'; -import { TranslateModule } from '@ngx-translate/core'; describe('EmptyListComponentComponent', () => { let fixture: ComponentFixture; beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - CoreTestingModule - ] + imports: [CoreTestingModule] }); fixture = TestBed.createComponent(EmptyListComponent); }); diff --git a/lib/core/src/lib/datatable/components/json-cell/json-cell.component.spec.ts b/lib/core/src/lib/datatable/components/json-cell/json-cell.component.spec.ts index 0a943730b50..dae62cf29b5 100644 --- a/lib/core/src/lib/datatable/components/json-cell/json-cell.component.spec.ts +++ b/lib/core/src/lib/datatable/components/json-cell/json-cell.component.spec.ts @@ -20,7 +20,6 @@ import { ObjectDataTableAdapter } from '../../data/object-datatable-adapter'; import { ObjectDataColumn } from '../../data/object-datacolumn.model'; import { CoreTestingModule } from '../../../testing/core.testing.module'; import { JsonCellComponent } from './json-cell.component'; -import { TranslateModule } from '@ngx-translate/core'; import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed'; import { HarnessLoader } from '@angular/cdk/testing'; import { MatButtonHarness } from '@angular/material/button/testing'; @@ -35,7 +34,7 @@ describe('JsonCellComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [TranslateModule.forRoot(), CoreTestingModule] + imports: [CoreTestingModule] }); fixture = TestBed.createComponent(JsonCellComponent); component = fixture.componentInstance; diff --git a/lib/core/src/lib/datatable/data-column/data-column.component.spec.ts b/lib/core/src/lib/datatable/data-column/data-column.component.spec.ts index 1386966e97b..8a25efa866d 100644 --- a/lib/core/src/lib/datatable/data-column/data-column.component.spec.ts +++ b/lib/core/src/lib/datatable/data-column/data-column.component.spec.ts @@ -17,16 +17,12 @@ import { DataColumnComponent } from './data-column.component'; import { CoreTestingModule } from '../../testing/core.testing.module'; -import { TranslateModule } from '@ngx-translate/core'; import { TestBed } from '@angular/core/testing'; describe('DataColumnListComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - CoreTestingModule - ] + imports: [CoreTestingModule] }); }); diff --git a/lib/core/src/lib/datatable/directives/header-filter-template.directive.spec.ts b/lib/core/src/lib/datatable/directives/header-filter-template.directive.spec.ts index 820c734966e..65f98df458f 100644 --- a/lib/core/src/lib/datatable/directives/header-filter-template.directive.spec.ts +++ b/lib/core/src/lib/datatable/directives/header-filter-template.directive.spec.ts @@ -19,20 +19,15 @@ import { TestBed, ComponentFixture } from '@angular/core/testing'; import { DataTableComponent } from '../components/datatable/datatable.component'; import { HeaderFilterTemplateDirective } from './header-filter-template.directive'; import { CoreTestingModule } from '../../testing/core.testing.module'; -import { TranslateModule } from '@ngx-translate/core'; describe('HeaderFilterTemplateDirective', () => { - let fixture: ComponentFixture; let dataTable: DataTableComponent; let directive: HeaderFilterTemplateDirective; beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - CoreTestingModule - ] + imports: [CoreTestingModule] }); fixture = TestBed.createComponent(DataTableComponent); dataTable = fixture.componentInstance; diff --git a/lib/core/src/lib/datatable/directives/loading-template.directive.spec.ts b/lib/core/src/lib/datatable/directives/loading-template.directive.spec.ts index 96fb35b29c0..06e8cacc03d 100644 --- a/lib/core/src/lib/datatable/directives/loading-template.directive.spec.ts +++ b/lib/core/src/lib/datatable/directives/loading-template.directive.spec.ts @@ -19,20 +19,15 @@ import { TestBed, ComponentFixture } from '@angular/core/testing'; import { DataTableComponent } from '../components/datatable/datatable.component'; import { LoadingContentTemplateDirective } from './loading-template.directive'; import { CoreTestingModule } from '../../testing/core.testing.module'; -import { TranslateModule } from '@ngx-translate/core'; describe('LoadingContentTemplateDirective', () => { - let fixture: ComponentFixture; let dataTable: DataTableComponent; let directive: LoadingContentTemplateDirective; beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - CoreTestingModule - ] + imports: [CoreTestingModule] }); fixture = TestBed.createComponent(DataTableComponent); dataTable = fixture.componentInstance; diff --git a/lib/core/src/lib/datatable/directives/no-content-template.directive.spec.ts b/lib/core/src/lib/datatable/directives/no-content-template.directive.spec.ts index c55f09cd05e..f2413f15826 100644 --- a/lib/core/src/lib/datatable/directives/no-content-template.directive.spec.ts +++ b/lib/core/src/lib/datatable/directives/no-content-template.directive.spec.ts @@ -19,20 +19,15 @@ import { TestBed, ComponentFixture } from '@angular/core/testing'; import { DataTableComponent } from '../components/datatable/datatable.component'; import { NoContentTemplateDirective } from './no-content-template.directive'; import { CoreTestingModule } from '../../testing/core.testing.module'; -import { TranslateModule } from '@ngx-translate/core'; describe('NoContentTemplateDirective', () => { - let fixture: ComponentFixture; let dataTable: DataTableComponent; let directive: NoContentTemplateDirective; beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - CoreTestingModule - ] + imports: [CoreTestingModule] }); fixture = TestBed.createComponent(DataTableComponent); dataTable = fixture.componentInstance; diff --git a/lib/core/src/lib/datatable/directives/no-permission-template.directive.spec.ts b/lib/core/src/lib/datatable/directives/no-permission-template.directive.spec.ts index 6afaf680778..2023f0e24f5 100644 --- a/lib/core/src/lib/datatable/directives/no-permission-template.directive.spec.ts +++ b/lib/core/src/lib/datatable/directives/no-permission-template.directive.spec.ts @@ -19,20 +19,15 @@ import { TestBed, ComponentFixture } from '@angular/core/testing'; import { DataTableComponent } from '../components/datatable/datatable.component'; import { NoPermissionTemplateDirective } from './no-permission-template.directive'; import { CoreTestingModule } from '../../testing/core.testing.module'; -import { TranslateModule } from '@ngx-translate/core'; describe('NoPermissionTemplateDirective', () => { - let fixture: ComponentFixture; let dataTable: DataTableComponent; let directive: NoPermissionTemplateDirective; beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - CoreTestingModule - ] + imports: [CoreTestingModule] }); fixture = TestBed.createComponent(DataTableComponent); dataTable = fixture.componentInstance; diff --git a/lib/core/src/lib/directives/highlight.directive.spec.ts b/lib/core/src/lib/directives/highlight.directive.spec.ts index bc586d36afb..20924a03949 100644 --- a/lib/core/src/lib/directives/highlight.directive.spec.ts +++ b/lib/core/src/lib/directives/highlight.directive.spec.ts @@ -21,7 +21,6 @@ import { By } from '@angular/platform-browser'; import { HighlightTransformService } from '../common/services/highlight-transform.service'; import { HighlightDirective } from './highlight.directive'; import { CoreTestingModule } from '../testing/core.testing.module'; -import { TranslateModule } from '@ngx-translate/core'; /* spellchecker: disable */ const template: string = ` @@ -41,19 +40,13 @@ class TestComponent { } describe('HighlightDirective', () => { - let fixture: ComponentFixture; let component: TestComponent; beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - CoreTestingModule - ], - declarations: [ - TestComponent - ] + imports: [CoreTestingModule], + declarations: [TestComponent] }); fixture = TestBed.createComponent(TestComponent); component = fixture.componentInstance; @@ -77,8 +70,12 @@ describe('HighlightDirective', () => { const containerElement2 = fixture.debugElement.query(By.css('#innerDiv14')); expect(containerElement1).not.toBeNull(); expect(containerElement2).not.toBeNull(); - expect(containerElement1.nativeElement.innerHTML).toBe('Lorem ipsum salana-eyong-aysis dolor sit amet'); - expect(containerElement2.nativeElement.innerHTML).toBe('sed do eiusmod salana-eyong-aysis tempor incididunt'); + expect(containerElement1.nativeElement.innerHTML).toBe( + 'Lorem ipsum salana-eyong-aysis dolor sit amet' + ); + expect(containerElement2.nativeElement.innerHTML).toBe( + 'sed do eiusmod salana-eyong-aysis tempor incididunt' + ); }); it('should NOT replace the searched text in an element without the proper selector class', () => { diff --git a/lib/core/src/lib/directives/logout.directive.spec.ts b/lib/core/src/lib/directives/logout.directive.spec.ts index 705f150aefa..a944d4352da 100644 --- a/lib/core/src/lib/directives/logout.directive.spec.ts +++ b/lib/core/src/lib/directives/logout.directive.spec.ts @@ -23,12 +23,9 @@ import { AuthenticationService } from '../auth/services/authentication.service'; import { AppConfigService } from '../app-config/app-config.service'; import { LogoutDirective } from './logout.directive'; import { CoreTestingModule } from '../testing/core.testing.module'; -import { TranslateModule } from '@ngx-translate/core'; describe('LogoutDirective', () => { - describe('No input', () => { - @Component({ selector: 'adf-test-component', template: '' @@ -45,13 +42,8 @@ describe('LogoutDirective', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - CoreTestingModule - ], - declarations: [ - TestComponent - ] + imports: [CoreTestingModule], + declarations: [TestComponent] }); router = TestBed.inject(Router); authService = TestBed.inject(AuthenticationService); @@ -107,10 +99,9 @@ describe('LogoutDirective', () => { expect(authService.logout).toHaveBeenCalled(); expect(router.navigate).toHaveBeenCalledWith(['/login']); }); - }); + }); describe('redirectUri', () => { - @Component({ selector: 'adf-test-component', template: '' @@ -126,13 +117,8 @@ describe('LogoutDirective', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - CoreTestingModule - ], - declarations: [ - TestComponent - ] + imports: [CoreTestingModule], + declarations: [TestComponent] }); router = TestBed.inject(Router); authService = TestBed.inject(AuthenticationService); @@ -150,10 +136,9 @@ describe('LogoutDirective', () => { expect(authService.logout).toHaveBeenCalled(); expect(router.navigate).toHaveBeenCalledWith(['/myCustomUri']); }); - }); + }); describe('enableRedirect', () => { - @Component({ selector: 'adf-test-component', template: '' @@ -169,13 +154,8 @@ describe('LogoutDirective', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - CoreTestingModule - ], - declarations: [ - TestComponent - ] + imports: [CoreTestingModule], + declarations: [TestComponent] }); router = TestBed.inject(Router); authService = TestBed.inject(AuthenticationService); @@ -192,6 +172,5 @@ describe('LogoutDirective', () => { expect(authService.logout).toHaveBeenCalled(); expect(router.navigate).not.toHaveBeenCalled(); }); - }); }); diff --git a/lib/core/src/lib/dynamic-chip-list/dynamic-chip-list.component.spec.ts b/lib/core/src/lib/dynamic-chip-list/dynamic-chip-list.component.spec.ts index a4fc46bdfdf..fe59e184391 100644 --- a/lib/core/src/lib/dynamic-chip-list/dynamic-chip-list.component.spec.ts +++ b/lib/core/src/lib/dynamic-chip-list/dynamic-chip-list.component.spec.ts @@ -16,24 +16,28 @@ */ import { ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing'; -import { TranslateModule } from '@ngx-translate/core'; import { Chip, CoreTestingModule, DynamicChipListComponent } from '@alfresco/adf-core'; import { SimpleChange } from '@angular/core'; describe('DynamicChipListComponent', () => { - let chips: Chip[] = [{ - name: 'test1', - id: '0ee933fa-57fc-4587-8a77-b787e814f1d2' - }, { - name: 'test2', - id: 'fcb92659-1f10-41b4-9b17-851b72a3b597' - }, { - name: 'test3', - id: 'fb4213c0-729d-466c-9a6c-ee2e937273bf' - }, { - name: 'test4', - id: 'as4213c0-729d-466c-9a6c-ee2e937273as' - }]; + let chips: Chip[] = [ + { + name: 'test1', + id: '0ee933fa-57fc-4587-8a77-b787e814f1d2' + }, + { + name: 'test2', + id: 'fcb92659-1f10-41b4-9b17-851b72a3b597' + }, + { + name: 'test3', + id: 'fb4213c0-729d-466c-9a6c-ee2e937273bf' + }, + { + name: 'test4', + id: 'as4213c0-729d-466c-9a6c-ee2e937273as' + } + ]; let component: DynamicChipListComponent; let fixture: ComponentFixture; let element: HTMLElement; @@ -59,10 +63,7 @@ describe('DynamicChipListComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - CoreTestingModule - ] + imports: [CoreTestingModule] }); const resizeObserverSpy = spyOn(window, 'ResizeObserver').and.callThrough(); fixture = TestBed.createComponent(DynamicChipListComponent); @@ -210,10 +211,12 @@ describe('DynamicChipListComponent', () => { })); it('should not render view more button when chip takes more than one line and there are no more chips', fakeAsync(() => { - renderChips([{ - name: 'VeryLongTag VeryLongTag VeryLongTag VeryLongTag VeryLongTag VeryLongTag VeryLongTag VeryLongTag', - id: '0ee933fa-57fc-4587-8a77-b787e814f1d2' - }]); + renderChips([ + { + name: 'VeryLongTag VeryLongTag VeryLongTag VeryLongTag VeryLongTag VeryLongTag VeryLongTag VeryLongTag', + id: '0ee933fa-57fc-4587-8a77-b787e814f1d2' + } + ]); component.ngOnChanges({ chips: new SimpleChange(undefined, component.chips, true) }); @@ -225,13 +228,16 @@ describe('DynamicChipListComponent', () => { })); it('should render view more button when chip takes more than one line and there are more chips', fakeAsync(() => { - renderChips([{ - name: 'VeryLongTag VeryLongTag VeryLongTag VeryLongTag VeryLongTag VeryLongTag VeryLongTag VeryLongTag', - id: '0ee933fa-57fc-4587-8a77-b787e814f1d2' - }, { - name: 'Some other tag', - id: '0ee933fa-57fc-4587-8a77-b787e814f1d3' - }]); + renderChips([ + { + name: 'VeryLongTag VeryLongTag VeryLongTag VeryLongTag VeryLongTag VeryLongTag VeryLongTag VeryLongTag', + id: '0ee933fa-57fc-4587-8a77-b787e814f1d2' + }, + { + name: 'Some other tag', + id: '0ee933fa-57fc-4587-8a77-b787e814f1d3' + } + ]); component.ngOnChanges({ chips: new SimpleChange(undefined, component.chips, true) }); diff --git a/lib/core/src/lib/form/components/form-field/form-field.component.spec.ts b/lib/core/src/lib/form/components/form-field/form-field.component.spec.ts index 7cd79802edb..d0508c5d4de 100644 --- a/lib/core/src/lib/form/components/form-field/form-field.component.spec.ts +++ b/lib/core/src/lib/form/components/form-field/form-field.component.spec.ts @@ -22,10 +22,8 @@ import { TextWidgetComponent, CheckboxWidgetComponent } from '../widgets'; import { FormFieldComponent } from './form-field.component'; import { FormBaseModule } from '../../form-base.module'; import { CoreTestingModule } from '../../../testing'; -import { TranslateModule } from '@ngx-translate/core'; describe('FormFieldComponent', () => { - let fixture: ComponentFixture; let component: FormFieldComponent; let form: FormModel; @@ -34,11 +32,7 @@ describe('FormFieldComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - CoreTestingModule, - FormBaseModule - ] + imports: [CoreTestingModule, FormBaseModule] }); fixture = TestBed.createComponent(FormFieldComponent); component = fixture.componentInstance; diff --git a/lib/core/src/lib/form/components/form-renderer.component.spec.ts b/lib/core/src/lib/form/components/form-renderer.component.spec.ts index f1225820f83..d07d9bd09f6 100644 --- a/lib/core/src/lib/form/components/form-renderer.component.spec.ts +++ b/lib/core/src/lib/form/components/form-renderer.component.spec.ts @@ -43,7 +43,6 @@ import { } from './mock/form-renderer.component.mock'; import { FormService } from '../services/form.service'; import { CoreTestingModule } from '../../testing'; -import { TranslateModule } from '@ngx-translate/core'; import { FormRenderingService } from '../services/form-rendering.service'; import { TextWidgetComponent } from './widgets'; import { FormRulesManager } from '../models/form-rules.model'; @@ -88,7 +87,7 @@ describe('Form Renderer Component', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [TranslateModule.forRoot(), CoreTestingModule, FormBaseModule] + imports: [CoreTestingModule, FormBaseModule] }); fixture = TestBed.createComponent(FormRendererComponent); formRendererComponent = fixture.componentInstance; @@ -430,9 +429,7 @@ describe('Form Renderer Component', () => { const twoSpanTextWidgetContainerId = '#field-1ff21afc-7df4-4607-8363-1dc8576e1c8e-container'; const oneSpanTextWidgetContainerId = '#field-f4285ad-g123-1a73-521d-7nm4a7231aul0-container'; - const formSizedElement = fixture.nativeElement.querySelector( - `${oneSpanTextWidgetContainerId} section.adf-grid-list-column-view` - ); + const formSizedElement = fixture.nativeElement.querySelector(`${oneSpanTextWidgetContainerId} section.adf-grid-list-column-view`); expectElementToBeVisible(formSizedElement); const sectionGridElement: HTMLElement[] = fixture.nativeElement.querySelectorAll( `${oneSpanTextWidgetContainerId} section .adf-grid-list-single-column` diff --git a/lib/core/src/lib/form/components/inplace-form-input/inplace-form-input.component.spec.ts b/lib/core/src/lib/form/components/inplace-form-input/inplace-form-input.component.spec.ts index 7c2ca33f3d7..2b2e372c44b 100644 --- a/lib/core/src/lib/form/components/inplace-form-input/inplace-form-input.component.spec.ts +++ b/lib/core/src/lib/form/components/inplace-form-input/inplace-form-input.component.spec.ts @@ -17,7 +17,6 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; import { UntypedFormControl } from '@angular/forms'; -import { TranslateModule } from '@ngx-translate/core'; import { CoreTestingModule } from '../../../testing/core.testing.module'; import { InplaceFormInputComponent } from './inplace-form-input.component'; @@ -28,10 +27,7 @@ describe('InplaceFormInputComponent', () => { beforeEach(async () => { await TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - CoreTestingModule - ], + imports: [CoreTestingModule], declarations: [InplaceFormInputComponent] }).compileComponents(); }); @@ -48,9 +44,7 @@ describe('InplaceFormInputComponent', () => { formControl.setValue('New Value'); fixture.detectChanges(); - const input = fixture.nativeElement.querySelector( - '[data-automation-id="adf-inplace-input"]' - ); + const input = fixture.nativeElement.querySelector('[data-automation-id="adf-inplace-input"]'); expect(input.value).toBe('New Value'); }); @@ -63,9 +57,7 @@ describe('InplaceFormInputComponent', () => { fixture.detectChanges(); - const error = fixture.nativeElement.querySelector( - '[data-automation-id="adf-inplace-input-error"]' - ); + const error = fixture.nativeElement.querySelector('[data-automation-id="adf-inplace-input-error"]'); expect(error).toBeTruthy(); }); @@ -75,9 +67,7 @@ describe('InplaceFormInputComponent', () => { fixture.detectChanges(); - const error = fixture.nativeElement.querySelector( - '[data-automation-id="adf-inplace-input-label"]' - ); + const error = fixture.nativeElement.querySelector('[data-automation-id="adf-inplace-input-label"]'); expect(error).toBeTruthy(); }); diff --git a/lib/core/src/lib/form/components/widgets/amount/amount.widget.spec.ts b/lib/core/src/lib/form/components/widgets/amount/amount.widget.spec.ts index db9040c8d03..14add4be431 100644 --- a/lib/core/src/lib/form/components/widgets/amount/amount.widget.spec.ts +++ b/lib/core/src/lib/form/components/widgets/amount/amount.widget.spec.ts @@ -21,7 +21,6 @@ import { AmountWidgetComponent, ADF_AMOUNT_SETTINGS } from './amount.widget'; import { FormBaseModule } from '../../../form-base.module'; import { FormFieldTypes } from '../core/form-field-types'; import { CoreTestingModule } from '../../../../testing/core.testing.module'; -import { TranslateModule } from '@ngx-translate/core'; import { FormModel } from '../core/form.model'; import { HarnessLoader } from '@angular/cdk/testing'; import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed'; @@ -37,7 +36,7 @@ describe('AmountWidgetComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [TranslateModule.forRoot(), CoreTestingModule, FormBaseModule] + imports: [CoreTestingModule, FormBaseModule] }); fixture = TestBed.createComponent(AmountWidgetComponent); widget = fixture.componentInstance; @@ -145,7 +144,7 @@ describe('AmountWidgetComponent - rendering', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [TranslateModule.forRoot(), CoreTestingModule, FormBaseModule] + imports: [CoreTestingModule, FormBaseModule] }); fixture = TestBed.createComponent(AmountWidgetComponent); widget = fixture.componentInstance; @@ -340,7 +339,7 @@ describe('AmountWidgetComponent settings', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [TranslateModule.forRoot(), CoreTestingModule, FormBaseModule], + imports: [CoreTestingModule, FormBaseModule], providers: [ { provide: ADF_AMOUNT_SETTINGS, diff --git a/lib/core/src/lib/form/components/widgets/base-viewer/base-viewer.widget.spec.ts b/lib/core/src/lib/form/components/widgets/base-viewer/base-viewer.widget.spec.ts index 92c8247cba6..054270a5ad6 100644 --- a/lib/core/src/lib/form/components/widgets/base-viewer/base-viewer.widget.spec.ts +++ b/lib/core/src/lib/form/components/widgets/base-viewer/base-viewer.widget.spec.ts @@ -16,7 +16,6 @@ */ import { FormModel } from '../core/form.model'; -import { TranslateModule } from '@ngx-translate/core'; import { FormFieldModel } from '../core/form-field.model'; import { FormService } from '../../../services/form.service'; import { CoreTestingModule } from '../../../../testing/core.testing.module'; @@ -46,13 +45,10 @@ describe('BaseViewerWidgetComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - CoreTestingModule, - TranslateModule.forRoot() - ], - declarations: [ BaseViewerWidgetComponent ], - providers: [ { provide: FormService, useValue: formServiceStub } ] - }); + imports: [CoreTestingModule], + declarations: [BaseViewerWidgetComponent], + providers: [{ provide: FormService, useValue: formServiceStub }] + }); formServiceStub = TestBed.inject(FormService); fixture = TestBed.createComponent(BaseViewerWidgetComponent); @@ -82,7 +78,14 @@ describe('BaseViewerWidgetComponent', () => { * @param fixture test fixture * @param done callback */ -function assertFileId(value: any, expectedFileId: string, fakeForm: FormModel, widget: BaseViewerWidgetComponent, fixture: ComponentFixture, done: DoneFn) { +function assertFileId( + value: any, + expectedFileId: string, + fakeForm: FormModel, + widget: BaseViewerWidgetComponent, + fixture: ComponentFixture, + done: DoneFn +) { const fakeField = new FormFieldModel(fakeForm, { id: 'fakeField', value }); widget.field = fakeField; @@ -93,4 +96,3 @@ function assertFileId(value: any, expectedFileId: string, fakeForm: FormModel, w done(); }); } - diff --git a/lib/core/src/lib/form/components/widgets/checkbox/checkbox.widget.spec.ts b/lib/core/src/lib/form/components/widgets/checkbox/checkbox.widget.spec.ts index db2ea903846..5986499c4d5 100644 --- a/lib/core/src/lib/form/components/widgets/checkbox/checkbox.widget.spec.ts +++ b/lib/core/src/lib/form/components/widgets/checkbox/checkbox.widget.spec.ts @@ -21,7 +21,7 @@ import { FormFieldModel } from '../core/form-field.model'; import { FormModel } from '../core/form.model'; import { CheckboxWidgetComponent } from './checkbox.widget'; import { FormBaseModule } from '../../../form-base.module'; -import { TranslateLoader, TranslateModule } from '@ngx-translate/core'; +import { TranslateLoader } from '@ngx-translate/core'; import { TranslateLoaderService } from '../../../../translation/translate-loader.service'; import { MatCheckboxModule } from '@angular/material/checkbox'; import { CoreTestingModule } from '../../../../testing'; @@ -39,7 +39,7 @@ describe('CheckboxWidgetComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [TranslateModule.forRoot(), CoreTestingModule, FormBaseModule, MatCheckboxModule, MatTooltipModule], + imports: [CoreTestingModule, FormBaseModule, MatCheckboxModule, MatTooltipModule], providers: [{ provide: TranslateLoader, useClass: TranslateLoaderService }] }); fixture = TestBed.createComponent(CheckboxWidgetComponent); diff --git a/lib/core/src/lib/form/components/widgets/date-time/date-time.widget.spec.ts b/lib/core/src/lib/form/components/widgets/date-time/date-time.widget.spec.ts index 0838c79b4ec..38133b28428 100644 --- a/lib/core/src/lib/form/components/widgets/date-time/date-time.widget.spec.ts +++ b/lib/core/src/lib/form/components/widgets/date-time/date-time.widget.spec.ts @@ -20,7 +20,6 @@ import { FormFieldModel } from '../core/form-field.model'; import { FormModel } from '../core/form.model'; import { DateTimeWidgetComponent } from './date-time.widget'; import { CoreTestingModule } from '../../../../testing/core.testing.module'; -import { TranslateModule } from '@ngx-translate/core'; import { MatTooltipModule } from '@angular/material/tooltip'; import { FormFieldTypes } from '../core/form-field-types'; import { DateFieldValidator, DateTimeFieldValidator } from '../core'; @@ -38,7 +37,7 @@ describe('DateTimeWidgetComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [TranslateModule.forRoot(), CoreTestingModule, MatTooltipModule] + imports: [CoreTestingModule, MatTooltipModule] }); fixture = TestBed.createComponent(DateTimeWidgetComponent); diff --git a/lib/core/src/lib/form/components/widgets/date/date.widget.spec.ts b/lib/core/src/lib/form/components/widgets/date/date.widget.spec.ts index 98bb017c23d..761a09fa15e 100644 --- a/lib/core/src/lib/form/components/widgets/date/date.widget.spec.ts +++ b/lib/core/src/lib/form/components/widgets/date/date.widget.spec.ts @@ -21,7 +21,6 @@ import { FormFieldModel } from '../core/form-field.model'; import { FormModel } from '../core/form.model'; import { DateWidgetComponent } from './date.widget'; import { CoreTestingModule } from '../../../../testing/core.testing.module'; -import { TranslateModule } from '@ngx-translate/core'; import { FormFieldTypes } from '../core/form-field-types'; import { DateFieldValidator, MaxDateFieldValidator, MinDateFieldValidator } from '../core/form-field-validator'; @@ -34,10 +33,7 @@ describe('DateWidgetComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - CoreTestingModule - ] + imports: [CoreTestingModule] }); form = new FormModel(); @@ -168,9 +164,8 @@ describe('DateWidgetComponent', () => { }); describe('when is required', () => { - beforeEach(() => { - widget.field = new FormFieldModel( new FormModel({ taskId: '' }), { + widget.field = new FormFieldModel(new FormModel({ taskId: '' }), { type: FormFieldTypes.DATE, required: true }); @@ -190,7 +185,6 @@ describe('DateWidgetComponent', () => { }); describe('template check', () => { - afterEach(() => { fixture.destroy(); TestBed.resetTestingModule(); @@ -217,7 +211,7 @@ describe('DateWidgetComponent', () => { widget.field = new FormFieldModel(form, { id: 'date-field-id', name: 'date-name', - value: '30-12-9999', + value: '30-12-9999', type: 'date', dateDisplayFormat: 'MM-DD-YYYY' }); diff --git a/lib/core/src/lib/form/components/widgets/decimal/decimal.component.spec.ts b/lib/core/src/lib/form/components/widgets/decimal/decimal.component.spec.ts index b1f91c2df8c..c64ddc47c2a 100644 --- a/lib/core/src/lib/form/components/widgets/decimal/decimal.component.spec.ts +++ b/lib/core/src/lib/form/components/widgets/decimal/decimal.component.spec.ts @@ -25,7 +25,6 @@ import { FormFieldModel, FormFieldTypes, FormModel } from '../core'; import { MatInputHarness } from '@angular/material/input/testing'; import { MatTooltipHarness } from '@angular/material/tooltip/testing'; import { MatInputModule } from '@angular/material/input'; -import { TranslateModule } from '@ngx-translate/core'; import { CoreTestingModule } from '../../../../testing'; import { FormsModule } from '@angular/forms'; @@ -37,12 +36,7 @@ describe('DecimalComponent', () => { beforeEach(async () => { await TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - CoreTestingModule, - MatInputModule, - FormsModule - ], + imports: [CoreTestingModule, MatInputModule, FormsModule], declarations: [DecimalWidgetComponent], providers: [FormService] }).compileComponents(); diff --git a/lib/core/src/lib/form/components/widgets/hyperlink/hyperlink.widget.spec.ts b/lib/core/src/lib/form/components/widgets/hyperlink/hyperlink.widget.spec.ts index 9b9e2b2f92c..20ca2833bf5 100644 --- a/lib/core/src/lib/form/components/widgets/hyperlink/hyperlink.widget.spec.ts +++ b/lib/core/src/lib/form/components/widgets/hyperlink/hyperlink.widget.spec.ts @@ -21,22 +21,16 @@ import { FormFieldModel } from '../core/form-field.model'; import { FormModel } from '../core/form.model'; import { HyperlinkWidgetComponent } from './hyperlink.widget'; import { CoreTestingModule } from '../../../../testing'; -import { TranslateModule } from '@ngx-translate/core'; import { MatTooltipModule } from '@angular/material/tooltip'; describe('HyperlinkWidgetComponent', () => { - let widget: HyperlinkWidgetComponent; let fixture: ComponentFixture; let element: HTMLElement; beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - CoreTestingModule, - MatTooltipModule - ] + imports: [CoreTestingModule, MatTooltipModule] }); fixture = TestBed.createComponent(HyperlinkWidgetComponent); widget = fixture.componentInstance; @@ -134,8 +128,8 @@ describe('HyperlinkWidgetComponent', () => { const url = 'www.alfresco.com'; widget.field = new FormFieldModel(new FormModel(), { - value: url, - hyperlinkUrl: 'www.alfresco-test.com' + value: url, + hyperlinkUrl: 'www.alfresco-test.com' }); widget.ngOnInit(); @@ -146,7 +140,7 @@ describe('HyperlinkWidgetComponent', () => { const url = 'www.alfresco.com'; widget.field = new FormFieldModel(new FormModel(), { - displayText: url + displayText: url }); widget.ngOnInit(); diff --git a/lib/core/src/lib/form/components/widgets/multiline-text/multiline-text.widget.spec.ts b/lib/core/src/lib/form/components/widgets/multiline-text/multiline-text.widget.spec.ts index 533057a3d93..cff6dccb32c 100644 --- a/lib/core/src/lib/form/components/widgets/multiline-text/multiline-text.widget.spec.ts +++ b/lib/core/src/lib/form/components/widgets/multiline-text/multiline-text.widget.spec.ts @@ -16,7 +16,6 @@ */ import { ComponentFixture, TestBed } from '@angular/core/testing'; -import { TranslateModule } from '@ngx-translate/core'; import { MultilineTextWidgetComponentComponent } from './multiline-text.widget'; import { CoreTestingModule } from '../../../../testing/core.testing.module'; import { FormFieldModel } from '../core/form-field.model'; @@ -35,7 +34,7 @@ describe('MultilineTextWidgetComponentComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [TranslateModule.forRoot(), CoreTestingModule] + imports: [CoreTestingModule] }); fixture = TestBed.createComponent(MultilineTextWidgetComponentComponent); widget = fixture.componentInstance; diff --git a/lib/core/src/lib/form/components/widgets/number/number.widget.spec.ts b/lib/core/src/lib/form/components/widgets/number/number.widget.spec.ts index 96841b829ce..82bb0a005c4 100644 --- a/lib/core/src/lib/form/components/widgets/number/number.widget.spec.ts +++ b/lib/core/src/lib/form/components/widgets/number/number.widget.spec.ts @@ -19,7 +19,6 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; import { FormsModule } from '@angular/forms'; import { MatIconModule } from '@angular/material/icon'; import { MatInputModule } from '@angular/material/input'; -import { TranslateModule } from '@ngx-translate/core'; import { CoreTestingModule } from '../../../../testing'; import { FormFieldModel, FormFieldTypes, FormModel } from '../core'; import { NumberWidgetComponent } from './number.widget'; @@ -36,7 +35,7 @@ describe('NumberWidgetComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [TranslateModule.forRoot(), CoreTestingModule, MatInputModule, FormsModule, MatIconModule] + imports: [CoreTestingModule, MatInputModule, FormsModule, MatIconModule] }); fixture = TestBed.createComponent(NumberWidgetComponent); widget = fixture.componentInstance; diff --git a/lib/core/src/lib/form/components/widgets/text/text.widget.spec.ts b/lib/core/src/lib/form/components/widgets/text/text.widget.spec.ts index 1c4fa226cc5..cc1884352ba 100644 --- a/lib/core/src/lib/form/components/widgets/text/text.widget.spec.ts +++ b/lib/core/src/lib/form/components/widgets/text/text.widget.spec.ts @@ -24,7 +24,6 @@ import { FormsModule } from '@angular/forms'; import { MatIconModule } from '@angular/material/icon'; import { MatInputModule } from '@angular/material/input'; import { CoreTestingModule } from '../../../../testing'; -import { TranslateModule } from '@ngx-translate/core'; import { HarnessLoader } from '@angular/cdk/testing'; import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed'; import { MatInputHarness } from '@angular/material/input/testing'; @@ -42,7 +41,7 @@ describe('TextWidgetComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [TranslateModule.forRoot(), CoreTestingModule, MatInputModule, FormsModule, MatIconModule] + imports: [CoreTestingModule, MatInputModule, FormsModule, MatIconModule] }); fixture = TestBed.createComponent(TextWidgetComponent); widget = fixture.componentInstance; diff --git a/lib/core/src/lib/form/components/widgets/widget.component.spec.ts b/lib/core/src/lib/form/components/widgets/widget.component.spec.ts index 01470697490..51fe53c0805 100644 --- a/lib/core/src/lib/form/components/widgets/widget.component.spec.ts +++ b/lib/core/src/lib/form/components/widgets/widget.component.spec.ts @@ -20,22 +20,17 @@ import { FormFieldModel } from './core/form-field.model'; import { FormModel } from './core/form.model'; import { WidgetComponent } from './widget.component'; import { CoreTestingModule } from '../../../testing'; -import { TranslateModule } from '@ngx-translate/core'; import { filter } from 'rxjs/operators'; import { FormRulesEvent } from '../../events/form-rules.event'; describe('WidgetComponent', () => { - let widget: WidgetComponent; let fixture: ComponentFixture; let element: HTMLElement; beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - CoreTestingModule - ] + imports: [CoreTestingModule] }); fixture = TestBed.createComponent(WidgetComponent); @@ -46,7 +41,6 @@ describe('WidgetComponent', () => { }); describe('Events', () => { - it('should click event be redirect on the form event service', fakeAsync(() => { widget.formService.formEvents.subscribe((event) => { expect(event).toBeTruthy(); @@ -56,7 +50,7 @@ describe('WidgetComponent', () => { })); it('should click event be redirect on the form rules event service', fakeAsync(() => { - widget.formService.formRulesEvent.pipe(filter(event => event.type === 'click')).subscribe((event) => { + widget.formService.formRulesEvent.pipe(filter((event) => event.type === 'click')).subscribe((event) => { expect(event).toBeTruthy(); }); @@ -77,7 +71,7 @@ describe('WidgetComponent', () => { let lastValue: FormFieldModel; - widget.fieldChanged.subscribe((field) => lastValue = field); + widget.fieldChanged.subscribe((field) => (lastValue = field)); widget.ngAfterViewInit(); expect(lastValue).not.toBe(null); @@ -90,7 +84,7 @@ describe('WidgetComponent', () => { const fakeField = new FormFieldModel(fakeForm, { id: 'fakeField', value: 'fakeValue' }); let lastValue: FormFieldModel; - widget.fieldChanged.subscribe((field) => lastValue = field); + widget.fieldChanged.subscribe((field) => (lastValue = field)); widget.onFieldChanged(fakeField); expect(lastValue).not.toBe(null); @@ -103,7 +97,7 @@ describe('WidgetComponent', () => { const fakeField = new FormFieldModel(fakeForm, { id: 'fakeField', value: 'fakeValue' }); let lastValue: FormRulesEvent; - widget.formService.formRulesEvent.subscribe((event) => lastValue = event); + widget.formService.formRulesEvent.subscribe((event) => (lastValue = event)); widget.onFieldChanged(fakeField); expect(lastValue.type).toEqual('fieldValueChanged'); diff --git a/lib/core/src/lib/form/components/widgets/widget.component.ts b/lib/core/src/lib/form/components/widgets/widget.component.ts index d6799923a88..10f5c8fdd9b 100644 --- a/lib/core/src/lib/form/components/widgets/widget.component.ts +++ b/lib/core/src/lib/form/components/widgets/widget.component.ts @@ -55,7 +55,10 @@ export class WidgetComponent implements AfterViewInit { * Emitted when a field value changes. */ @Output() - fieldChanged: EventEmitter = new EventEmitter(); + fieldChanged = new EventEmitter(); + + @Output() + widgetError = new EventEmitter(); touched: boolean = false; diff --git a/lib/core/src/lib/form/models/form-rules.model.spec.ts b/lib/core/src/lib/form/models/form-rules.model.spec.ts index 50b2595c896..141681d9fda 100644 --- a/lib/core/src/lib/form/models/form-rules.model.spec.ts +++ b/lib/core/src/lib/form/models/form-rules.model.spec.ts @@ -17,7 +17,6 @@ import { FormBaseModule } from '../form-base.module'; import { CoreTestingModule } from '../../testing'; -import { TranslateModule } from '@ngx-translate/core'; import { ByPassFormRuleManager, FormRulesManager, formRulesManagerFactory, FORM_RULES_MANAGER } from './form-rules.model'; import { Injector } from '@angular/core'; import { TestBed } from '@angular/core/testing'; @@ -34,11 +33,9 @@ class CustomRuleManager extends FormRulesManager { protected handleRuleEvent(): void { return; } - } describe('Form Rules', () => { - let injector: Injector; const customRuleManager = new CustomRuleManager(null); let formService: FormService; @@ -46,11 +43,7 @@ describe('Form Rules', () => { describe('Injection token provided', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - CoreTestingModule, - FormBaseModule - ], + imports: [CoreTestingModule, FormBaseModule], providers: [ { provide: FORM_RULES_MANAGER, @@ -115,11 +108,7 @@ describe('Form Rules', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - CoreTestingModule, - FormBaseModule - ] + imports: [CoreTestingModule, FormBaseModule] }); injector = TestBed.inject(Injector); rulesManager = formRulesManagerFactory(injector); diff --git a/lib/core/src/lib/form/services/form.service.spec.ts b/lib/core/src/lib/form/services/form.service.spec.ts index 792e83ad632..a3948907ec3 100644 --- a/lib/core/src/lib/form/services/form.service.spec.ts +++ b/lib/core/src/lib/form/services/form.service.spec.ts @@ -19,28 +19,22 @@ import { TestBed } from '@angular/core/testing'; import { formModelTabs } from '../../mock'; import { FormService } from './form.service'; import { CoreTestingModule } from '../../testing/core.testing.module'; -import { TranslateModule } from '@ngx-translate/core'; describe('Form service', () => { let service: FormService; beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - CoreTestingModule - ] + imports: [CoreTestingModule] }); service = TestBed.inject(FormService); }); describe('parseForm', () => { - it('should parse a Form Definition with tabs', () => { expect(formModelTabs.formRepresentation.formDefinition).toBeDefined(); const formParsed = service.parseForm(formModelTabs); expect(formParsed).toBeDefined(); }); - }); }); diff --git a/lib/core/src/lib/form/services/widget-visibility-cloud.service.spec.ts b/lib/core/src/lib/form/services/widget-visibility-cloud.service.spec.ts index 1326519f879..635a2144b89 100644 --- a/lib/core/src/lib/form/services/widget-visibility-cloud.service.spec.ts +++ b/lib/core/src/lib/form/services/widget-visibility-cloud.service.spec.ts @@ -16,24 +16,19 @@ */ import { TestBed } from '@angular/core/testing'; -import { - ContainerModel, - FormFieldModel, - FormFieldTypes, - FormModel, - TabModel, - FormOutcomeModel -} from '../components/widgets/core'; +import { ContainerModel, FormFieldModel, FormFieldTypes, FormModel, TabModel, FormOutcomeModel } from '../components/widgets/core'; import { WidgetVisibilityModel, WidgetTypeEnum } from '../models/widget-visibility.model'; import { WidgetVisibilityService } from './widget-visibility.service'; import { fakeFormJson, - formTest, formValues, complexVisibilityJsonVisible, - nextConditionForm, complexVisibilityJsonNotVisible, + formTest, + formValues, + complexVisibilityJsonVisible, + nextConditionForm, + complexVisibilityJsonNotVisible, headerVisibilityCond } from '../../mock/form/widget-visibility-cloud.service.mock'; import { CoreTestingModule } from '../../testing/core.testing.module'; -import { TranslateModule } from '@ngx-translate/core'; declare let jasmine: any; @@ -45,10 +40,7 @@ describe('WidgetVisibilityCloudService', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - CoreTestingModule - ] + imports: [CoreTestingModule] }); service = TestBed.inject(WidgetVisibilityService); jasmine.Ajax.install(); @@ -59,7 +51,6 @@ describe('WidgetVisibilityCloudService', () => { }); describe('should be able to evaluate next condition operations', () => { - it('using == and return true', () => { booleanResult = service.evaluateCondition('test', 'test', '=='); expect(booleanResult).toBeTruthy(); @@ -167,7 +158,8 @@ describe('WidgetVisibilityCloudService', () => { name: 'FORM_VARIABLE_TEST', type: 'string', value: 'form_value_test' - }] + } + ] }); beforeEach(() => { @@ -484,7 +476,6 @@ describe('WidgetVisibilityCloudService', () => { }); it('should use the process variables when they are passed to check the visibility', () => { - visibilityObjTest.leftType = WidgetTypeEnum.field; visibilityObjTest.leftValue = 'FIELD_FORM_EMPTY'; visibilityObjTest.operator = '=='; @@ -560,13 +551,15 @@ describe('WidgetVisibilityCloudService', () => { visibilityObjTest.leftType = 'FIELD_TEST'; visibilityObjTest.operator = '=='; visibilityObjTest.rightType = 'LEFT_FORM_FIELD_ID'; - const contModel = new ContainerModel(new FormFieldModel(fakeFormWithField, { - id: 'fake-container-id', - type: FormFieldTypes.GROUP, - name: 'fake-container-name', - isVisible: true, - visibilityCondition: visibilityObjTest - })); + const contModel = new ContainerModel( + new FormFieldModel(fakeFormWithField, { + id: 'fake-container-id', + type: FormFieldTypes.GROUP, + name: 'fake-container-name', + isVisible: true, + visibilityCondition: visibilityObjTest + }) + ); fakeFormWithField.fieldsCache.push(contModel.field); service.refreshVisibility(fakeFormWithField); @@ -579,13 +572,15 @@ describe('WidgetVisibilityCloudService', () => { visibilityObjTest.operator = '!='; visibilityObjTest.rightType = WidgetTypeEnum.field; visibilityObjTest.rightValue = 'RIGHT_FORM_FIELD_ID'; - const contModel = new ContainerModel(new FormFieldModel(fakeFormWithField, { - id: 'fake-container-id', - type: FormFieldTypes.GROUP, - name: 'fake-container-name', - isVisible: true, - visibilityCondition: visibilityObjTest - })); + const contModel = new ContainerModel( + new FormFieldModel(fakeFormWithField, { + id: 'fake-container-id', + type: FormFieldTypes.GROUP, + name: 'fake-container-name', + isVisible: true, + visibilityCondition: visibilityObjTest + }) + ); service.refreshEntityVisibility(contModel.field); expect(contModel.isVisible).toBeFalsy(); }); @@ -633,7 +628,8 @@ describe('WidgetVisibilityCloudService', () => { name: 'No' } ] - }, { + }, + { id: 'textBoxTest', name: 'textbox test', type: 'people', @@ -661,7 +657,6 @@ describe('WidgetVisibilityCloudService', () => { }); describe('Visibility based on form variables', () => { - const fakeFormWithVariables = new FormModel(fakeFormJson); const complexVisibilityModel = new FormModel(complexVisibilityJsonVisible); const complexVisibilityJsonNotVisibleModel = new FormModel(complexVisibilityJsonNotVisible); @@ -682,15 +677,19 @@ describe('WidgetVisibilityCloudService', () => { }); it('should be able to analyze a complex visibility JSON truthy', () => { - const isVisible = service.isFieldVisible(complexVisibilityModel, - complexVisibilityJsonVisible.formDefinition.fields[2].fields[2][0].visibilityCondition); + const isVisible = service.isFieldVisible( + complexVisibilityModel, + complexVisibilityJsonVisible.formDefinition.fields[2].fields[2][0].visibilityCondition + ); expect(isVisible).toBe(true); }); it('should be able to analyze a complex visibility JSON false', () => { - const isVisible = service.isFieldVisible(complexVisibilityJsonNotVisibleModel, - complexVisibilityJsonNotVisible.formDefinition.fields[2].fields[2][0].visibilityCondition); + const isVisible = service.isFieldVisible( + complexVisibilityJsonNotVisibleModel, + complexVisibilityJsonNotVisible.formDefinition.fields[2].fields[2][0].visibilityCondition + ); expect(isVisible).toBe(false); }); diff --git a/lib/core/src/lib/form/services/widget-visibility.service.spec.ts b/lib/core/src/lib/form/services/widget-visibility.service.spec.ts index 603213bf207..6dfd0b04d73 100644 --- a/lib/core/src/lib/form/services/widget-visibility.service.spec.ts +++ b/lib/core/src/lib/form/services/widget-visibility.service.spec.ts @@ -16,25 +16,21 @@ */ import { TestBed } from '@angular/core/testing'; -import { - ContainerModel, - FormFieldModel, - FormFieldTypes, - FormModel, - TabModel -} from '../components/widgets/core'; +import { ContainerModel, FormFieldModel, FormFieldTypes, FormModel, TabModel } from '../components/widgets/core'; import { WidgetVisibilityModel } from '../models/widget-visibility.model'; import { WidgetVisibilityService } from './widget-visibility.service'; import { - fakeFormJson, formTest, - formValues, complexVisibilityJsonVisible, - complexVisibilityJsonNotVisible, tabVisibilityJsonMock, + fakeFormJson, + formTest, + formValues, + complexVisibilityJsonVisible, + complexVisibilityJsonNotVisible, + tabVisibilityJsonMock, tabInvalidFormVisibility, fakeFormChainedVisibilityJson, fakeFormCheckBoxVisibilityJson } from '../../mock/form/widget-visibility.service.mock'; import { CoreTestingModule } from '../../testing/core.testing.module'; -import { TranslateModule } from '@ngx-translate/core'; describe('WidgetVisibilityService', () => { let service: WidgetVisibilityService; @@ -42,7 +38,7 @@ describe('WidgetVisibilityService', () => { const stubFormWithFields = new FormModel(fakeFormJson); - const evaluateConditions = (conditionsArgs: [leftValue: any, rightValue: any][], operator: string ): (boolean | undefined)[] => { + const evaluateConditions = (conditionsArgs: [leftValue: any, rightValue: any][], operator: string): (boolean | undefined)[] => { const resultsArray: (boolean | undefined)[] = []; conditionsArgs.forEach(([leftValue, rightValue]) => { @@ -53,27 +49,26 @@ describe('WidgetVisibilityService', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - CoreTestingModule - ] + imports: [CoreTestingModule] }); service = TestBed.inject(WidgetVisibilityService); }); describe('should be able to evaluate next condition operations', () => { - it('using == and return true', () => { - const resultsArray = evaluateConditions([ - [true, true], - [false, false], - ['true', true], - [true, 'true'], - ['true', 'true'], - ['test', 'test'], - ['4', 4], - [0, 0] - ], '=='); + const resultsArray = evaluateConditions( + [ + [true, true], + [false, false], + ['true', true], + [true, 'true'], + ['true', 'true'], + ['test', 'test'], + ['4', 4], + [0, 0] + ], + '==' + ); resultsArray.forEach((result) => { expect(result).toBe(true); @@ -81,16 +76,19 @@ describe('WidgetVisibilityService', () => { }); it('using == and return false', () => { - const resultsArray = evaluateConditions([ - [true, false], - [false, true], - ['false', true], - [false, 'true'], - ['false', 'true'], - ['test', 'testt'], - ['2', 3], - [0, 1] - ], '=='); + const resultsArray = evaluateConditions( + [ + [true, false], + [false, true], + ['false', true], + [false, 'true'], + ['false', 'true'], + ['test', 'testt'], + ['2', 3], + [0, 1] + ], + '==' + ); resultsArray.forEach((result) => { expect(result).toBe(false); @@ -98,16 +96,19 @@ describe('WidgetVisibilityService', () => { }); it('using != and return true', () => { - const resultsArray = evaluateConditions([ - ['test', 'te'], - ['4', 123], - [0, 1], - [true, false], - [false, true], - ['false', true], - [false, 'true'], - ['false', 'true'] - ], '!='); + const resultsArray = evaluateConditions( + [ + ['test', 'te'], + ['4', 123], + [0, 1], + [true, false], + [false, true], + ['false', true], + [false, 'true'], + ['false', 'true'] + ], + '!=' + ); resultsArray.forEach((result) => { expect(result).toBe(true); @@ -115,16 +116,19 @@ describe('WidgetVisibilityService', () => { }); it('using != and return false', () => { - const resultsArray = evaluateConditions([ - ['testtest', 'testtest'], - ['7', 7], - [0, 0], - [true, true], - [false, false], - ['true', true], - [true, 'true'], - ['true', 'true'] - ], '!='); + const resultsArray = evaluateConditions( + [ + ['testtest', 'testtest'], + ['7', 7], + [0, 0], + [true, true], + [false, false], + ['true', true], + [true, 'true'], + ['true', 'true'] + ], + '!=' + ); resultsArray.forEach((result) => { expect(result).toBe(false); @@ -132,11 +136,14 @@ describe('WidgetVisibilityService', () => { }); it('using < and return false', () => { - const resultsArray = evaluateConditions([ - [2, 1], - [1, 0], - [0, -1] - ], '<'); + const resultsArray = evaluateConditions( + [ + [2, 1], + [1, 0], + [0, -1] + ], + '<' + ); resultsArray.forEach((result) => { expect(result).toBe(false); @@ -144,12 +151,15 @@ describe('WidgetVisibilityService', () => { }); it('using <= and return true', () => { - const resultsArray = evaluateConditions([ - [3, 4], - [0, 1], - [0, 0], - [1, 1] - ], '<='); + const resultsArray = evaluateConditions( + [ + [3, 4], + [0, 1], + [0, 0], + [1, 1] + ], + '<=' + ); resultsArray.forEach((result) => { expect(result).toBe(true); @@ -157,12 +167,15 @@ describe('WidgetVisibilityService', () => { }); it('using > and return false', () => { - const resultsArray = evaluateConditions([ - [0, 1], - [0, 141], - [-144, 0], - [32, 44] - ], '>'); + const resultsArray = evaluateConditions( + [ + [0, 1], + [0, 141], + [-144, 0], + [32, 44] + ], + '>' + ); resultsArray.forEach((result) => { expect(result).toBe(false); @@ -170,13 +183,16 @@ describe('WidgetVisibilityService', () => { }); it('using >= and return true', () => { - const resultsArray = evaluateConditions([ - [12, 2], - [2, 2], - [1, 0], - [0, 0], - [0, -10] - ], '>='); + const resultsArray = evaluateConditions( + [ + [12, 2], + [2, 2], + [1, 0], + [0, 0], + [0, -10] + ], + '>=' + ); resultsArray.forEach((result) => { expect(result).toBe(true); @@ -249,7 +265,8 @@ describe('WidgetVisibilityService', () => { name: 'FORM_VARIABLE_TEST', type: 'string', value: 'form_value_test' - }] + } + ] }); beforeEach(() => { @@ -415,7 +432,6 @@ describe('WidgetVisibilityService', () => { expect(isVisible).toBeTruthy(); }); - it('should return true when left field value is equal to true and rigth value is equal to "true"', () => { spyOn(service, 'getFieldValue').and.returnValue(true); spyOn(service, 'isFormFieldValid').and.returnValue(true); @@ -670,13 +686,15 @@ describe('WidgetVisibilityService', () => { visibilityObjTest.leftFormFieldId = 'FIELD_TEST'; visibilityObjTest.operator = '=='; visibilityObjTest.rightFormFieldId = 'LEFT_FORM_FIELD_ID'; - const contModel = new ContainerModel(new FormFieldModel(fakeFormWithField, { - id: 'fake-container-id', - type: FormFieldTypes.GROUP, - name: 'fake-container-name', - isVisible: true, - visibilityCondition: visibilityObjTest - })); + const contModel = new ContainerModel( + new FormFieldModel(fakeFormWithField, { + id: 'fake-container-id', + type: FormFieldTypes.GROUP, + name: 'fake-container-name', + isVisible: true, + visibilityCondition: visibilityObjTest + }) + ); fakeFormWithField.fieldsCache.push(contModel.field); service.refreshVisibility(fakeFormWithField); @@ -687,13 +705,15 @@ describe('WidgetVisibilityService', () => { visibilityObjTest.leftFormFieldId = 'FIELD_TEST'; visibilityObjTest.operator = '!='; visibilityObjTest.rightFormFieldId = 'RIGHT_FORM_FIELD_ID'; - const contModel = new ContainerModel(new FormFieldModel(fakeFormWithField, { - id: 'fake-container-id', - type: FormFieldTypes.GROUP, - name: 'fake-container-name', - isVisible: true, - visibilityCondition: visibilityObjTest - })); + const contModel = new ContainerModel( + new FormFieldModel(fakeFormWithField, { + id: 'fake-container-id', + type: FormFieldTypes.GROUP, + name: 'fake-container-name', + isVisible: true, + visibilityCondition: visibilityObjTest + }) + ); service.refreshEntityVisibility(contModel.field); expect(contModel.isVisible).toBeFalsy(); }); @@ -752,7 +772,8 @@ describe('WidgetVisibilityService', () => { name: 'No' } ] - }, { + }, + { id: 'textBoxTest', name: 'textbox test', type: 'people', @@ -780,7 +801,6 @@ describe('WidgetVisibilityService', () => { }); describe('Visibility based on form variables', () => { - let fakeFormWithVariables = new FormModel(fakeFormJson); const fakeTabVisibilityModel = new FormModel(tabVisibilityJsonMock); const complexVisibilityModel = new FormModel(complexVisibilityJsonVisible); @@ -804,14 +824,19 @@ describe('WidgetVisibilityService', () => { }); it('should be able to analyze a complex visibility JSON truthy', () => { - const isVisible = service.isFieldVisible(complexVisibilityModel, - complexVisibilityJsonVisible.formDefinition.fields[2].fields[2][0].visibilityCondition); + const isVisible = service.isFieldVisible( + complexVisibilityModel, + complexVisibilityJsonVisible.formDefinition.fields[2].fields[2][0].visibilityCondition + ); expect(isVisible).toBe(true); }); it('should be able to analyze a complex visibility JSON false', () => { - const formField = new FormFieldModel(complexVisibilityJsonNotVisibleModel, complexVisibilityJsonNotVisible.formDefinition.fields[2].fields[2][0]); + const formField = new FormFieldModel( + complexVisibilityJsonNotVisibleModel, + complexVisibilityJsonNotVisible.formDefinition.fields[2].fields[2][0] + ); const isVisible = service.isFieldVisible(complexVisibilityJsonNotVisibleModel, new WidgetVisibilityModel(formField.visibilityCondition)); expect(isVisible).toBe(false); }); @@ -899,7 +924,6 @@ describe('WidgetVisibilityService', () => { }); describe('Visibility calculation in complex forms', () => { - const fakeFormWithVariables = new FormModel(fakeFormChainedVisibilityJson); it('Should be able to validate correctly the visibility for the text field for complex expressions', () => { @@ -927,7 +951,6 @@ describe('WidgetVisibilityService', () => { }); describe('Visibility calculation in checkbox forms', () => { - const fakeFormWithValues = new FormModel(fakeFormCheckBoxVisibilityJson); it('Should be able to validate correctly the visibility for the checkbox expression', () => { diff --git a/lib/core/src/lib/identity-user-info/identity-user-info.component.spec.ts b/lib/core/src/lib/identity-user-info/identity-user-info.component.spec.ts index 703a8ea1daf..a6d7a82bd2f 100644 --- a/lib/core/src/lib/identity-user-info/identity-user-info.component.spec.ts +++ b/lib/core/src/lib/identity-user-info/identity-user-info.component.spec.ts @@ -17,7 +17,6 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; import { IdentityUserInfoComponent } from './identity-user-info.component'; -import { TranslateModule } from '@ngx-translate/core'; import { CoreTestingModule } from '../testing/core.testing.module'; import { MatMenuModule } from '@angular/material/menu'; import { By } from '@angular/platform-browser'; @@ -28,9 +27,21 @@ describe('IdentityUserInfoComponent', () => { let fixture: ComponentFixture; let element: HTMLElement; - const identityUserMock = { firstName: 'fake-identity-first-name', lastName: 'fake-identity-last-name', email: 'fakeIdentity@email.com' } as unknown as IdentityUserModel; - const identityUserWithOutFirstNameMock = { firstName: null, lastName: 'fake-identity-last-name', email: 'fakeIdentity@email.com' } as unknown as IdentityUserModel; - const identityUserWithOutLastNameMock = { firstName: 'fake-identity-first-name', lastName: null, email: 'fakeIdentity@email.com' } as unknown as IdentityUserModel; + const identityUserMock = { + firstName: 'fake-identity-first-name', + lastName: 'fake-identity-last-name', + email: 'fakeIdentity@email.com' + } as unknown as IdentityUserModel; + const identityUserWithOutFirstNameMock = { + firstName: null, + lastName: 'fake-identity-last-name', + email: 'fakeIdentity@email.com' + } as unknown as IdentityUserModel; + const identityUserWithOutLastNameMock = { + firstName: 'fake-identity-first-name', + lastName: null, + email: 'fakeIdentity@email.com' + } as unknown as IdentityUserModel; const whenFixtureReady = async () => { fixture.detectChanges(); @@ -40,11 +51,7 @@ describe('IdentityUserInfoComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - CoreTestingModule, - MatMenuModule - ] + imports: [CoreTestingModule, MatMenuModule] }); fixture = TestBed.createComponent(IdentityUserInfoComponent); component = fixture.componentInstance; @@ -70,7 +77,6 @@ describe('IdentityUserInfoComponent', () => { }); describe('when identity user is logged in', () => { - beforeEach(() => { component.identityUser = identityUserMock; component.isLoggedIn = true; diff --git a/lib/core/src/lib/info-drawer/info-drawer.component.spec.ts b/lib/core/src/lib/info-drawer/info-drawer.component.spec.ts index 16a9cb06bee..aa1a37c61ec 100644 --- a/lib/core/src/lib/info-drawer/info-drawer.component.spec.ts +++ b/lib/core/src/lib/info-drawer/info-drawer.component.spec.ts @@ -21,7 +21,7 @@ import { MatTabChangeEvent } from '@angular/material/tabs'; import { By } from '@angular/platform-browser'; import { InfoDrawerComponent } from './info-drawer.component'; import { of } from 'rxjs'; -import { TranslateService, TranslateModule } from '@ngx-translate/core'; +import { TranslateService } from '@ngx-translate/core'; import { CoreTestingModule } from '../testing/core.testing.module'; import { ESCAPE } from '@angular/cdk/keycodes'; import { HarnessLoader } from '@angular/cdk/testing'; @@ -36,10 +36,7 @@ describe('InfoDrawerComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - CoreTestingModule - ] + imports: [CoreTestingModule] }); translateService = TestBed.inject(TranslateService); spyOn(translateService, 'get').and.callFake((key) => of(key)); @@ -56,7 +53,7 @@ describe('InfoDrawerComponent', () => { it('should emit when tab is changed', () => { const tabEmitSpy = spyOn(component.currentTab, 'emit'); - const event = {index: 1, tab: {textLabel: 'DETAILS'}} as MatTabChangeEvent; + const event = { index: 1, tab: { textLabel: 'DETAILS' } } as MatTabChangeEvent; component.onTabChange(event); expect(tabEmitSpy).toHaveBeenCalledWith(1); }); @@ -91,12 +88,9 @@ describe('InfoDrawerComponent', () => { @Component({ template: ` - - - - - - + + + ` }) @@ -111,18 +105,12 @@ describe('Custom InfoDrawer', () => { let translateService: TranslateService; let loader: HarnessLoader; - const getNodeIcon = () => - fixture.debugElement.queryAll(By.css('[info-drawer-node-icon]')); + const getNodeIcon = () => fixture.debugElement.queryAll(By.css('[info-drawer-node-icon]')); beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - CoreTestingModule - ], - declarations: [ - CustomInfoDrawerComponent - ] + imports: [CoreTestingModule], + declarations: [CustomInfoDrawerComponent] }); translateService = TestBed.inject(TranslateService); spyOn(translateService, 'get').and.callFake((key) => of(key)); @@ -174,7 +162,7 @@ describe('Custom InfoDrawer', () => { it('should render a icon with title', () => { component.icon = '/assets/images/ft_ic_miscellaneous.svg'; fixture.detectChanges(); - const icon = getNodeIcon(); + const icon = getNodeIcon(); const srcAttribute = icon[0].nativeElement.getAttribute('src'); expect(icon.length).toBe(1); expect(srcAttribute).toContain('/assets/images/ft_ic_miscellaneous.svg'); @@ -182,10 +170,7 @@ describe('Custom InfoDrawer', () => { }); @Component({ - template: ` - - - ` + template: ` ` }) class VisibilityInfoDrawerComponent extends InfoDrawerComponent { showHeader: boolean; @@ -195,18 +180,12 @@ class VisibilityInfoDrawerComponent extends InfoDrawerComponent { describe('Header visibility InfoDrawer', () => { let fixture: ComponentFixture; let component: VisibilityInfoDrawerComponent; - const getNodeIcon = () => - fixture.debugElement.queryAll(By.css('[info-drawer-node-icon]')); + const getNodeIcon = () => fixture.debugElement.queryAll(By.css('[info-drawer-node-icon]')); beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - CoreTestingModule - ], - declarations: [ - VisibilityInfoDrawerComponent - ] + imports: [CoreTestingModule], + declarations: [VisibilityInfoDrawerComponent] }); fixture = TestBed.createComponent(VisibilityInfoDrawerComponent); fixture.detectChanges(); diff --git a/lib/core/src/lib/language-menu/language-menu.component.spec.ts b/lib/core/src/lib/language-menu/language-menu.component.spec.ts index a2bcb7d96e3..5634a518726 100644 --- a/lib/core/src/lib/language-menu/language-menu.component.spec.ts +++ b/lib/core/src/lib/language-menu/language-menu.component.spec.ts @@ -20,11 +20,9 @@ import { AppConfigService } from '../app-config/app-config.service'; import { LanguageMenuComponent } from './language-menu.component'; import { CoreTestingModule } from '../testing/core.testing.module'; import { UserPreferencesService } from '../common/services/user-preferences.service'; -import { TranslateModule } from '@ngx-translate/core'; import { LanguageService } from './service/language.service'; describe('LanguageMenuComponent', () => { - let fixture: ComponentFixture; let component: LanguageMenuComponent; let appConfig: AppConfigService; @@ -49,10 +47,7 @@ describe('LanguageMenuComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - CoreTestingModule - ] + imports: [CoreTestingModule] }); fixture = TestBed.createComponent(LanguageMenuComponent); @@ -71,7 +66,7 @@ describe('LanguageMenuComponent', () => { fixture.detectChanges(); fixture.whenStable().then(() => { - component.languages$.subscribe(langs => { + component.languages$.subscribe((langs) => { expect(langs).toEqual(languages); done(); }); diff --git a/lib/core/src/lib/layout/components/header/header.component.spec.ts b/lib/core/src/lib/layout/components/header/header.component.spec.ts index 579b9639408..dbbf30db91b 100644 --- a/lib/core/src/lib/layout/components/header/header.component.spec.ts +++ b/lib/core/src/lib/layout/components/header/header.component.spec.ts @@ -22,7 +22,6 @@ import { By } from '@angular/platform-browser'; import { SidenavLayoutModule } from '../../layout.module'; import { Component } from '@angular/core'; import { MaterialModule } from '../../../material.module'; -import { TranslateModule } from '@ngx-translate/core'; import { HarnessLoader } from '@angular/cdk/testing'; import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed'; import { MatToolbarHarness } from '@angular/material/toolbar/testing'; @@ -35,10 +34,7 @@ describe('HeaderLayoutComponent', () => { describe('Input parameters', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - CoreTestingModule - ] + imports: [CoreTestingModule] }); fixture = TestBed.createComponent(HeaderLayoutComponent); loader = TestbedHarnessEnvironment.loader(fixture); @@ -257,8 +253,7 @@ describe('HeaderLayoutComponent', () => { describe('Template transclusion', () => { @Component({ selector: 'adf-test-layout-header', - template: ` - + template: `

Test text

` @@ -267,7 +262,7 @@ describe('HeaderLayoutComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [TranslateModule.forRoot(), CoreTestingModule, SidenavLayoutModule, MaterialModule], + imports: [CoreTestingModule, SidenavLayoutModule, MaterialModule], declarations: [HeaderLayoutTesterComponent] }); }); diff --git a/lib/core/src/lib/layout/components/sidebar-action/sidebar-action-menu.component.spec.ts b/lib/core/src/lib/layout/components/sidebar-action/sidebar-action-menu.component.spec.ts index ac94814de9c..a6928608a18 100644 --- a/lib/core/src/lib/layout/components/sidebar-action/sidebar-action-menu.component.spec.ts +++ b/lib/core/src/lib/layout/components/sidebar-action/sidebar-action-menu.component.spec.ts @@ -21,7 +21,6 @@ import { MaterialModule } from '../../../material.module'; import { SidebarActionMenuComponent } from './sidebar-action-menu.component'; import { CoreTestingModule } from '../../../testing/core.testing.module'; import { NoopAnimationsModule } from '@angular/platform-browser/animations'; -import { TranslateModule } from '@ngx-translate/core'; describe('SidebarActionMenuComponent', () => { let element: HTMLElement; @@ -30,10 +29,7 @@ describe('SidebarActionMenuComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - CoreTestingModule - ] + imports: [CoreTestingModule] }); fixture = TestBed.createComponent(SidebarActionMenuComponent); element = fixture.nativeElement; @@ -86,14 +82,8 @@ describe('Custom SidebarActionMenuComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - declarations: [ - SidebarActionMenuComponent, - CustomSidebarActionMenuComponent - ], - imports: [ - MaterialModule, - NoopAnimationsModule - ] + declarations: [SidebarActionMenuComponent, CustomSidebarActionMenuComponent], + imports: [MaterialModule, NoopAnimationsModule] }); fixture = TestBed.createComponent(CustomSidebarActionMenuComponent); fixture.detectChanges(); diff --git a/lib/core/src/lib/login/components/login-dialog-panel/login-dialog-panel.component.spec.ts b/lib/core/src/lib/login/components/login-dialog-panel/login-dialog-panel.component.spec.ts index a352c39e2a7..f90a2150241 100644 --- a/lib/core/src/lib/login/components/login-dialog-panel/login-dialog-panel.component.spec.ts +++ b/lib/core/src/lib/login/components/login-dialog-panel/login-dialog-panel.component.spec.ts @@ -17,7 +17,6 @@ import { BasicAlfrescoAuthService, CoreTestingModule, LoginDialogPanelComponent } from '@alfresco/adf-core'; import { ComponentFixture, TestBed } from '@angular/core/testing'; -import { TranslateModule } from '@ngx-translate/core'; import { of } from 'rxjs'; import { OidcAuthenticationService } from '../../../auth/services/oidc-authentication.service'; @@ -31,13 +30,8 @@ describe('LoginDialogPanelComponent', () => { beforeEach(async () => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - CoreTestingModule - ], - providers: [ - { provide: OidcAuthenticationService, useValue: {} } - ] + imports: [CoreTestingModule], + providers: [{ provide: OidcAuthenticationService, useValue: {} }] }); fixture = TestBed.createComponent(LoginDialogPanelComponent); basicAlfrescoAuthService = TestBed.inject(BasicAlfrescoAuthService); diff --git a/lib/core/src/lib/login/components/login/login.component.spec.ts b/lib/core/src/lib/login/components/login/login.component.spec.ts index a4a0f34e34f..6bdefeac5d6 100644 --- a/lib/core/src/lib/login/components/login/login.component.spec.ts +++ b/lib/core/src/lib/login/components/login/login.component.spec.ts @@ -22,7 +22,6 @@ import { CoreTestingModule, LoginErrorEvent, LoginSuccessEvent, - LogService, UserPreferencesService } from '@alfresco/adf-core'; import { ComponentFixture, fakeAsync, TestBed } from '@angular/core/testing'; @@ -61,14 +60,12 @@ describe('LoginComponent', () => { beforeEach(fakeAsync(() => { TestBed.configureTestingModule({ - imports: [ - CoreTestingModule - ], + imports: [CoreTestingModule], providers: [ { - provide: OidcAuthenticationService, useValue: { - ssoLogin: () => { - }, + provide: OidcAuthenticationService, + useValue: { + ssoLogin: () => {}, isPublicUrl: () => false, hasValidIdToken: () => false, isLoggedIn: () => false @@ -89,9 +86,6 @@ describe('LoginComponent', () => { userPreferences = TestBed.inject(UserPreferencesService); appConfigService = TestBed.inject(AppConfigService); - const logService = TestBed.inject(LogService); - spyOn(logService, 'error'); - fixture.detectChanges(); fixture.whenStable().then(() => { @@ -117,17 +111,11 @@ describe('LoginComponent', () => { }; it('should be autocomplete off', () => { - expect( - element - .querySelector('#adf-login-form') - .getAttribute('autocomplete') - ).toBe('off'); + expect(element.querySelector('#adf-login-form').getAttribute('autocomplete')).toBe('off'); }); it('should redirect to route on successful login', () => { - spyOn(basicAlfrescoAuthService, 'login').and.returnValue( - of({ type: 'type', ticket: 'ticket' }) - ); + spyOn(basicAlfrescoAuthService, 'login').and.returnValue(of({ type: 'type', ticket: 'ticket' })); const redirect = '/home'; component.successRoute = redirect; spyOn(router, 'navigate'); @@ -200,7 +188,6 @@ describe('LoginComponent', () => { }); describe('Login button', () => { - const getLoginButton = () => element.querySelector('#login-button'); const getLoginButtonText = () => element.querySelector('#login-button span.adf-login-button-label').innerText; @@ -290,12 +277,11 @@ describe('LoginComponent', () => { }); describe('Remember me', () => { - it('should be checked by default', () => { expect(element.querySelector('#adf-login-remember input[type="checkbox"]').checked).toBe(true); }); - it('should set the component\'s rememberMe property properly', () => { + it('should set the component rememberMe property properly', () => { element.querySelector('#adf-login-remember').dispatchEvent(new Event('change')); fixture.detectChanges(); @@ -335,10 +321,11 @@ describe('LoginComponent', () => { }); describe('Copyright text', () => { - it('should render the default copyright text', () => { expect(element.querySelector('[data-automation-id="login-copyright"]')).toBeDefined(); - expect(element.querySelector('[data-automation-id="login-copyright"]').innerText).toEqual('\u00A9 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.'); + expect(element.querySelector('[data-automation-id="login-copyright"]').innerText).toEqual( + '\u00A9 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.' + ); }); it('should render the customised copyright text', () => { @@ -376,7 +363,6 @@ describe('LoginComponent', () => { }); describe('Error', () => { - it('should render validation min-length error when the username is just 1 character with a custom validation Validators.minLength(3)', () => { component.fieldsValidation = { username: ['', Validators.compose([Validators.required, Validators.minLength(3)])], @@ -529,12 +515,14 @@ describe('LoginComponent', () => { }); it('should return CORS error when server CORS error occurs', (done) => { - spyOn(basicAlfrescoAuthService, 'login').and.returnValue(throwError({ - error: { - crossDomain: true, - message: 'ERROR: the network is offline, Origin is not allowed by Access-Control-Allow-Origin' - } - })); + spyOn(basicAlfrescoAuthService, 'login').and.returnValue( + throwError({ + error: { + crossDomain: true, + message: 'ERROR: the network is offline, Origin is not allowed by Access-Control-Allow-Origin' + } + }) + ); component.error.subscribe(() => { fixture.detectChanges(); @@ -550,8 +538,7 @@ describe('LoginComponent', () => { }); it('should return CSRF error when server CSRF error occurs', fakeAsync(() => { - spyOn(basicAlfrescoAuthService, 'login') - .and.returnValue(throwError({ message: 'ERROR: Invalid CSRF-token', status: 403 })); + spyOn(basicAlfrescoAuthService, 'login').and.returnValue(throwError({ message: 'ERROR: Invalid CSRF-token', status: 403 })); component.error.subscribe(() => { fixture.detectChanges(); @@ -565,14 +552,12 @@ describe('LoginComponent', () => { })); it('should return ECM read-only error when error occurs', fakeAsync(() => { - spyOn(basicAlfrescoAuthService, 'login') - .and.returnValue( - throwError( - { - message: 'ERROR: 00170728 Access Denied. The system is currently in read-only mode', - status: 403 - } - )); + spyOn(basicAlfrescoAuthService, 'login').and.returnValue( + throwError({ + message: 'ERROR: 00170728 Access Denied. The system is currently in read-only mode', + status: 403 + }) + ); component.error.subscribe(() => { fixture.detectChanges(); @@ -635,9 +620,7 @@ describe('LoginComponent', () => { fixture.detectChanges(); expect(component.isError).toBe(false); - expect(event).toEqual( - new LoginSuccessEvent({ type: 'type', ticket: 'ticket' }, 'fake-username', null) - ); + expect(event).toEqual(new LoginSuccessEvent({ type: 'type', ticket: 'ticket' }, 'fake-username', null)); }); loginWithCredentials('fake-username', 'fake-password'); @@ -652,9 +635,7 @@ describe('LoginComponent', () => { expect(component.isError).toBe(true); expect(getLoginErrorElement()).toBeDefined(); expect(getLoginErrorMessage()).toEqual('LOGIN.MESSAGES.LOGIN-ERROR-CREDENTIALS'); - expect(error).toEqual( - new LoginErrorEvent('Fake server error') - ); + expect(error).toEqual(new LoginErrorEvent('Fake server error')); }); loginWithCredentials('fake-username', 'fake-wrong-password'); @@ -695,9 +676,7 @@ describe('LoginComponent', () => { })); describe('SSO ', () => { - describe('implicitFlow ', () => { - beforeEach(() => { appConfigService.config.oauth2 = { implicitFlow: true, silentLogin: false }; appConfigService.load(); @@ -727,7 +706,6 @@ describe('LoginComponent', () => { expect(component.ssoLogin).toBe(false); expect(component.redirectToSSOLogin).toHaveBeenCalled(); }); - })); it('should render the implicitFlow button in case silentLogin is disabled', fakeAsync(() => { @@ -739,7 +717,6 @@ describe('LoginComponent', () => { fixture.whenStable().then(() => { expect(component.ssoLogin).toBe(true); }); - })); it('should not show the login base auth button', fakeAsync(() => { diff --git a/lib/core/src/lib/login/directives/login-footer.directive.spec.ts b/lib/core/src/lib/login/directives/login-footer.directive.spec.ts index e5615884043..9e48f1c84cc 100644 --- a/lib/core/src/lib/login/directives/login-footer.directive.spec.ts +++ b/lib/core/src/lib/login/directives/login-footer.directive.spec.ts @@ -17,7 +17,6 @@ import { CoreTestingModule, LoginComponent, LoginFooterDirective } from '@alfresco/adf-core'; import { ComponentFixture, TestBed } from '@angular/core/testing'; -import { TranslateModule } from '@ngx-translate/core'; import { OidcAuthenticationService } from '../../auth/services/oidc-authentication.service'; describe('LoginFooterDirective', () => { @@ -27,13 +26,11 @@ describe('LoginFooterDirective', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - CoreTestingModule - ], + imports: [CoreTestingModule], providers: [ { - provide: OidcAuthenticationService, useValue: {} + provide: OidcAuthenticationService, + useValue: {} } ] }); diff --git a/lib/core/src/lib/login/directives/login-header.directive.spec.ts b/lib/core/src/lib/login/directives/login-header.directive.spec.ts index 01d75e2e1dd..6969ff74f00 100644 --- a/lib/core/src/lib/login/directives/login-header.directive.spec.ts +++ b/lib/core/src/lib/login/directives/login-header.directive.spec.ts @@ -17,7 +17,6 @@ import { CoreTestingModule, LoginComponent, LoginHeaderDirective } from '@alfresco/adf-core'; import { ComponentFixture, TestBed } from '@angular/core/testing'; -import { TranslateModule } from '@ngx-translate/core'; import { OidcAuthenticationService } from '../../auth/services/oidc-authentication.service'; describe('LoginHeaderDirective', () => { @@ -27,13 +26,8 @@ describe('LoginHeaderDirective', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - CoreTestingModule - ], - providers: [ - { provide: OidcAuthenticationService, useValue: {} } - ] + imports: [CoreTestingModule], + providers: [{ provide: OidcAuthenticationService, useValue: {} }] }); fixture = TestBed.createComponent(LoginComponent); component = fixture.componentInstance; diff --git a/lib/core/src/lib/notifications/components/notification-history.component.spec.ts b/lib/core/src/lib/notifications/components/notification-history.component.spec.ts index 4badb740156..79e725250e6 100644 --- a/lib/core/src/lib/notifications/components/notification-history.component.spec.ts +++ b/lib/core/src/lib/notifications/components/notification-history.component.spec.ts @@ -21,11 +21,9 @@ import { NotificationHistoryComponent } from './notification-history.component'; import { OverlayContainer } from '@angular/cdk/overlay'; import { NotificationService } from '../services/notification.service'; import { StorageService } from '../../common/services/storage.service'; -import { TranslateModule } from '@ngx-translate/core'; import { NotificationModel, NOTIFICATION_TYPE } from '../models/notification.model'; describe('Notification History Component', () => { - let fixture: ComponentFixture; let component: NotificationHistoryComponent; let element: HTMLElement; @@ -42,10 +40,7 @@ describe('Notification History Component', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - CoreTestingModule - ] + imports: [CoreTestingModule] }); fixture = TestBed.createComponent(NotificationHistoryComponent); component = fixture.componentInstance; @@ -66,7 +61,6 @@ describe('Notification History Component', () => { }); describe('ui ', () => { - it('should empty message be present when there are no notifications in the history', (done) => { openNotification(); fixture.detectChanges(); @@ -109,15 +103,12 @@ describe('Notification History Component', () => { it('should show message when pushed directly to Notification History', (done) => { const callBackSpy = jasmine.createSpy('callBack'); fixture.detectChanges(); - notificationService.pushToNotificationHistory( - { - clickCallBack: callBackSpy, - messages: ['My new message'], - datetime: new Date(), - type: NOTIFICATION_TYPE.RECURSIVE - - } as NotificationModel - ); + notificationService.pushToNotificationHistory({ + clickCallBack: callBackSpy, + messages: ['My new message'], + datetime: new Date(), + type: NOTIFICATION_TYPE.RECURSIVE + } as NotificationModel); openNotification(); fixture.detectChanges(); fixture.whenStable().then(() => { @@ -148,12 +139,16 @@ describe('Notification History Component', () => { }); it('should read notifications from local storage', (done) => { - storage.setItem(NotificationHistoryComponent.NOTIFICATION_STORAGE, JSON.stringify([{ - messages: ['My new message'], - datetime: new Date(), - type: NOTIFICATION_TYPE.RECURSIVE - - } as NotificationModel])); + storage.setItem( + NotificationHistoryComponent.NOTIFICATION_STORAGE, + JSON.stringify([ + { + messages: ['My new message'], + datetime: new Date(), + type: NOTIFICATION_TYPE.RECURSIVE + } as NotificationModel + ]) + ); fixture.detectChanges(); openNotification(); fixture.whenStable().then(() => { diff --git a/lib/core/src/lib/notifications/services/notification.service.spec.ts b/lib/core/src/lib/notifications/services/notification.service.spec.ts index 94ada59f582..086b7825691 100644 --- a/lib/core/src/lib/notifications/services/notification.service.spec.ts +++ b/lib/core/src/lib/notifications/services/notification.service.spec.ts @@ -21,7 +21,6 @@ import { MatSnackBarConfig, MatSnackBarModule } from '@angular/material/snack-ba import { NotificationService } from './notification.service'; import { TranslationService } from '../../translation/translation.service'; import { CoreTestingModule } from '../../testing/core.testing.module'; -import { TranslateModule } from '@ngx-translate/core'; import { HarnessLoader } from '@angular/cdk/testing'; import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed'; import { MatIconHarness } from '@angular/material/icon/testing'; @@ -92,7 +91,7 @@ describe('NotificationService', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [TranslateModule.forRoot(), CoreTestingModule, MatSnackBarModule], + imports: [CoreTestingModule, MatSnackBarModule], declarations: [ProvidesNotificationServiceComponent] }); translationService = TestBed.inject(TranslationService); diff --git a/lib/core/src/lib/pagination/infinite-pagination.component.spec.ts b/lib/core/src/lib/pagination/infinite-pagination.component.spec.ts index 5921212140e..9ad344292f2 100644 --- a/lib/core/src/lib/pagination/infinite-pagination.component.spec.ts +++ b/lib/core/src/lib/pagination/infinite-pagination.component.spec.ts @@ -24,13 +24,11 @@ import { BehaviorSubject } from 'rxjs'; import { CoreTestingModule } from '../testing/core.testing.module'; import { Component, ChangeDetectorRef } from '@angular/core'; import { RequestPaginationModel } from '../models/request-pagination.model'; -import { TranslateModule } from '@ngx-translate/core'; @Component({ template: `` }) class TestPaginatedComponent implements PaginatedComponent { - private _pagination: BehaviorSubject; get pagination(): BehaviorSubject { @@ -52,7 +50,6 @@ class TestPaginatedComponent implements PaginatedComponent { } describe('InfinitePaginationComponent', () => { - let fixture: ComponentFixture; let component: InfinitePaginationComponent; let pagination: PaginationModel; @@ -60,13 +57,8 @@ describe('InfinitePaginationComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - CoreTestingModule - ], - declarations: [ - TestPaginatedComponent - ] + imports: [CoreTestingModule], + declarations: [TestPaginatedComponent] }); fixture = TestBed.createComponent(InfinitePaginationComponent); component = fixture.componentInstance; @@ -84,7 +76,6 @@ describe('InfinitePaginationComponent', () => { }); describe('View', () => { - it('should show the loading spinner if loading', () => { pagination.hasMoreItems = true; component.isLoading = true; @@ -116,7 +107,7 @@ describe('InfinitePaginationComponent', () => { }); it('should NOT show the load more button if there are no more elements to load', (done) => { - pagination = {maxItems: 444, skipCount: 25, totalItems: 30, hasMoreItems: false}; + pagination = { maxItems: 444, skipCount: 25, totalItems: 30, hasMoreItems: false }; component.target.pagination.next(pagination); @@ -132,7 +123,7 @@ describe('InfinitePaginationComponent', () => { }); it('should show the load more button if there are more elements to load', (done) => { - pagination = {maxItems: 444, skipCount: 25, totalItems: 55, hasMoreItems: true}; + pagination = { maxItems: 444, skipCount: 25, totalItems: 55, hasMoreItems: true }; component.target.pagination.next(pagination); @@ -157,7 +148,7 @@ describe('InfinitePaginationComponent', () => { }); it('should trigger the loadMore event with skipcount 0 to reload all the elements', (done) => { - pagination = {maxItems: 444, skipCount: 25, totalItems: 55, hasMoreItems: true}; + pagination = { maxItems: 444, skipCount: 25, totalItems: 55, hasMoreItems: true }; component.target.pagination.next(pagination); @@ -175,7 +166,7 @@ describe('InfinitePaginationComponent', () => { }); it('should trigger the loadMore event with merge true to reload all the elements', (done) => { - pagination = {maxItems: 444, skipCount: 25, totalItems: 55, hasMoreItems: true}; + pagination = { maxItems: 444, skipCount: 25, totalItems: 55, hasMoreItems: true }; component.target.pagination.next(pagination); @@ -194,16 +185,15 @@ describe('InfinitePaginationComponent', () => { }); describe('Target', () => { - let spyTarget; beforeEach(() => { - pagination = {maxItems: 444, skipCount: 0, totalItems: 888, hasMoreItems: true}; + pagination = { maxItems: 444, skipCount: 0, totalItems: 888, hasMoreItems: true }; spyTarget = spyOn(component.target, 'updatePagination').and.callThrough(); }); - it('should subscribe to target\'s pagination observable to update pagination and pagesize correctly', () => { + it('should subscribe to target pagination observable to update pagination and pagesize correctly', () => { component.target.updatePagination(pagination); fixture.detectChanges(); @@ -211,7 +201,7 @@ describe('InfinitePaginationComponent', () => { expect(component.pageSize).toBe(25); }); - it('should call the target\'s updatePagination on invoking the onLoadMore', () => { + it('should call the target updatePagination on invoking the onLoadMore', () => { component.target.updatePagination(pagination); fixture.detectChanges(); @@ -226,7 +216,7 @@ describe('InfinitePaginationComponent', () => { }); }); - it('should call the target\'s updatePagination on invoking the onLoadMore with a specific pageSize', () => { + it('should call the target updatePagination on invoking the onLoadMore with a specific pageSize', () => { component.pageSize = 7; component.target.updatePagination(pagination); fixture.detectChanges(); @@ -241,12 +231,12 @@ describe('InfinitePaginationComponent', () => { }); }); - it('should unsubscribe from the target\'s pagination on onDestroy', () => { + it('should unsubscribe from the target pagination on onDestroy', () => { fixture.detectChanges(); fixture.destroy(); const emitNewPaginationEvent = () => { - const newPagination = {maxItems: 1, skipCount: 0, totalItems: 2, hasMoreItems: true}; + const newPagination = { maxItems: 1, skipCount: 0, totalItems: 2, hasMoreItems: true }; component.target.pagination.next(newPagination); }; diff --git a/lib/core/src/lib/pagination/pagination.component.spec.ts b/lib/core/src/lib/pagination/pagination.component.spec.ts index a8cab5df57e..113d9446939 100644 --- a/lib/core/src/lib/pagination/pagination.component.spec.ts +++ b/lib/core/src/lib/pagination/pagination.component.spec.ts @@ -21,7 +21,6 @@ import { PaginationComponent } from './pagination.component'; import { PaginatedComponent } from './paginated-component.interface'; import { BehaviorSubject } from 'rxjs'; import { CoreTestingModule } from '../testing/core.testing.module'; -import { TranslateModule } from '@ngx-translate/core'; import { PaginationModel } from '../models/pagination.model'; import { setupTestBed } from '@alfresco/adf-core'; @@ -33,22 +32,18 @@ class FakePaginationInput implements PaginationModel { maxItems = 25; constructor(pagesCount: number, currentPage: number, lastPageItems: number) { - this.totalItems = ((pagesCount - 1) * this.maxItems) + lastPageItems; + this.totalItems = (pagesCount - 1) * this.maxItems + lastPageItems; this.skipCount = (currentPage - 1) * this.maxItems; } } describe('PaginationComponent', () => { - let fixture: ComponentFixture; let component: PaginationComponent; setupTestBed({ - imports: [ - TranslateModule.forRoot(), - CoreTestingModule - ], - schemas: [ NO_ERRORS_SCHEMA ] + imports: [CoreTestingModule], + schemas: [NO_ERRORS_SCHEMA] }); beforeEach(() => { @@ -87,7 +82,7 @@ describe('PaginationComponent', () => { }); it('has range', () => { - expect(component.range).toEqual([ 1, 10 ]); + expect(component.range).toEqual([1, 10]); }); }); @@ -101,12 +96,11 @@ describe('PaginationComponent', () => { }); it('has range', () => { - expect(component.range).toEqual([ 1, 25 ]); + expect(component.range).toEqual([1, 25]); }); }); describe('Middle page', () => { - // This test describes 6 pages being on the third page // and last page has 5 items @@ -137,7 +131,7 @@ describe('PaginationComponent', () => { }); it('has range', () => { - expect(component.range).toEqual([ 51, 75 ]); + expect(component.range).toEqual([51, 75]); }); it('goes next', () => { @@ -186,7 +180,6 @@ describe('PaginationComponent', () => { }); describe('First page', () => { - // This test describes 10 pages being on the first page beforeEach(() => { @@ -207,12 +200,11 @@ describe('PaginationComponent', () => { }); it('has range', () => { - expect(component.range).toEqual([ 1, 25 ]); + expect(component.range).toEqual([1, 25]); }); }); describe('Last page', () => { - // This test describes 10 pages being on the last page beforeEach(() => { @@ -233,7 +225,7 @@ describe('PaginationComponent', () => { }); it('has range', () => { - expect(component.range).toEqual([ 226, 230 ]); + expect(component.range).toEqual([226, 230]); }); }); @@ -249,13 +241,12 @@ describe('PaginationComponent', () => { expect(component.isFirstPage).toBe(true, 'isFirstPage'); expect(component.isLastPage).toBe(true, 'isLastPage'); - expect(component.range).toEqual([ 0, 0 ], 'range'); - expect(component.pages).toEqual([ 1 ], 'pages'); + expect(component.range).toEqual([0, 0], 'range'); + expect(component.pages).toEqual([1], 'pages'); }); }); describe('with paginated component', () => { - it('should take pagination from the external component', () => { const pagination: PaginationModel = {}; @@ -347,7 +338,6 @@ describe('PaginationComponent', () => { expect(fixture.debugElement.nativeElement.querySelector('.adf-pagination__block')).toBeNull(); }); - }); describe('without total items', () => { @@ -366,7 +356,7 @@ describe('PaginationComponent', () => { }); it('has range', () => { - expect(component.range).toEqual([ 26, 50 ]); + expect(component.range).toEqual([26, 50]); }); it('cannot calculate number of pages', () => { expect(component.pages).toEqual([1]); @@ -384,8 +374,10 @@ describe('PaginationComponent', () => { it('should only some pages be available if over 100', () => { component.pagination = new FakePaginationInput(101, 30, 5); - const expectedPages = [1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, - 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 101]; + const expectedPages = [ + 1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, + 43, 44, 45, 46, 47, 48, 49, 50, 101 + ]; expect(component.limitedPages).toEqual(expectedPages); expect(component.limitedPages).not.toEqual(component.pages); diff --git a/lib/core/src/lib/pipes/date-time.pipe.spec.ts b/lib/core/src/lib/pipes/date-time.pipe.spec.ts index 51b65ae2361..6f85424ddd6 100644 --- a/lib/core/src/lib/pipes/date-time.pipe.spec.ts +++ b/lib/core/src/lib/pipes/date-time.pipe.spec.ts @@ -17,7 +17,6 @@ import { TestBed } from '@angular/core/testing'; import { CoreTestingModule } from '../testing/core.testing.module'; -import { TranslateModule } from '@ngx-translate/core'; import { DateTimePipe } from './date-time.pipe'; import { addMinutes, isValid } from 'date-fns'; @@ -26,7 +25,7 @@ describe('DateTimePipe', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [TranslateModule.forRoot(), CoreTestingModule], + imports: [CoreTestingModule], providers: [DateTimePipe] }); diff --git a/lib/core/src/lib/pipes/decimal-number.pipe.spec.ts b/lib/core/src/lib/pipes/decimal-number.pipe.spec.ts index 119f4063824..76efe1081e3 100644 --- a/lib/core/src/lib/pipes/decimal-number.pipe.spec.ts +++ b/lib/core/src/lib/pipes/decimal-number.pipe.spec.ts @@ -21,19 +21,14 @@ import { UserPreferencesService } from '../common/services/user-preferences.serv import { of } from 'rxjs'; import { CoreTestingModule } from '../testing/core.testing.module'; import { DecimalNumberPipe } from './decimal-number.pipe'; -import { TranslateModule } from '@ngx-translate/core'; describe('DecimalNumberPipe', () => { - let pipe: DecimalNumberPipe; let userPreferences: UserPreferencesService; beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - CoreTestingModule - ] + imports: [CoreTestingModule] }); userPreferences = TestBed.inject(UserPreferencesService); spyOn(userPreferences, 'select').and.returnValue(of('')); diff --git a/lib/core/src/lib/pipes/localized-date.pipe.spec.ts b/lib/core/src/lib/pipes/localized-date.pipe.spec.ts index 82697768077..617073e320b 100644 --- a/lib/core/src/lib/pipes/localized-date.pipe.spec.ts +++ b/lib/core/src/lib/pipes/localized-date.pipe.spec.ts @@ -23,20 +23,15 @@ import { of } from 'rxjs'; import { CoreTestingModule } from '../testing/core.testing.module'; import { registerLocaleData } from '@angular/common'; import localeFr from '@angular/common/locales/fr'; -import { TranslateModule } from '@ngx-translate/core'; registerLocaleData(localeFr); describe('LocalizedDatePipe', () => { - let pipe: LocalizedDatePipe; let userPreferences: UserPreferencesService; beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - CoreTestingModule - ] + imports: [CoreTestingModule] }); userPreferences = TestBed.inject(UserPreferencesService); spyOn(userPreferences, 'select').and.returnValue(of('')); diff --git a/lib/core/src/lib/pipes/time-ago.pipe.spec.ts b/lib/core/src/lib/pipes/time-ago.pipe.spec.ts index f3fc7b63abf..a6b5d8ac4f7 100644 --- a/lib/core/src/lib/pipes/time-ago.pipe.spec.ts +++ b/lib/core/src/lib/pipes/time-ago.pipe.spec.ts @@ -21,19 +21,14 @@ import { AppConfigService } from '../app-config/app-config.service'; import { UserPreferencesService } from '../common/services/user-preferences.service'; import { CoreTestingModule } from '../testing/core.testing.module'; import { of } from 'rxjs'; -import { TranslateModule } from '@ngx-translate/core'; describe('TimeAgoPipe', () => { - let pipe: TimeAgoPipe; let userPreferences: UserPreferencesService; beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - CoreTestingModule - ] + imports: [CoreTestingModule] }); userPreferences = TestBed.inject(UserPreferencesService); spyOn(userPreferences, 'select').and.returnValue(of('')); @@ -56,10 +51,9 @@ describe('TimeAgoPipe', () => { }); describe('When a locale is given', () => { - it('should return a localised message', () => { const date = new Date(); - const transformedDate = pipe.transform(date, 'de'); + const transformedDate = pipe.transform(date, 'de'); /* cspell:disable-next-line */ expect(transformedDate).toBe('vor weniger als 1 Minute'); }); diff --git a/lib/core/src/lib/search-text/search-text-input.component.spec.ts b/lib/core/src/lib/search-text/search-text-input.component.spec.ts index 52ebe158436..8859c4fc0eb 100644 --- a/lib/core/src/lib/search-text/search-text-input.component.spec.ts +++ b/lib/core/src/lib/search-text/search-text-input.component.spec.ts @@ -21,11 +21,9 @@ import { SearchTextInputComponent } from './search-text-input.component'; import { DebugElement } from '@angular/core'; import { By } from '@angular/platform-browser'; import { Subject } from 'rxjs'; -import { TranslateModule } from '@ngx-translate/core'; import { UserPreferencesService } from '../common/services/user-preferences.service'; describe('SearchTextInputComponent', () => { - let fixture: ComponentFixture; let component: SearchTextInputComponent; let debugElement: DebugElement; @@ -34,10 +32,7 @@ describe('SearchTextInputComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - CoreTestingModule - ] + imports: [CoreTestingModule] }); fixture = TestBed.createComponent(SearchTextInputComponent); component = fixture.componentInstance; @@ -52,7 +47,6 @@ describe('SearchTextInputComponent', () => { }); describe('component rendering', () => { - it('should display a search input field when specified', async () => { fixture.detectChanges(); await fixture.whenStable(); @@ -67,7 +61,6 @@ describe('SearchTextInputComponent', () => { }); describe('expandable option false', () => { - beforeEach(() => { component.expandable = false; }); @@ -86,7 +79,6 @@ describe('SearchTextInputComponent', () => { }); describe('search button', () => { - it('should NOT display a autocomplete list control when configured not to', fakeAsync(() => { fixture.detectChanges(); @@ -345,7 +337,6 @@ describe('SearchTextInputComponent', () => { expect(component.subscriptAnimationState.value).toEqual('inactive'); expect(component.searchTerm).toEqual(''); }); - }); describe('Collapse on blur', () => { @@ -355,7 +346,7 @@ describe('SearchTextInputComponent', () => { tick(200); })); - it('should collapse search on blur when the collapseOnBlur is set to true', fakeAsync (() => { + it('should collapse search on blur when the collapseOnBlur is set to true', fakeAsync(() => { const searchVisibilityChangeSpy = spyOn(component.searchVisibility, 'emit'); const resetEmitSpy = spyOn(component.reset, 'emit'); component.collapseOnBlur = true; diff --git a/lib/core/src/lib/snackbar-content/snackbar-content.component.spec.ts b/lib/core/src/lib/snackbar-content/snackbar-content.component.spec.ts index d9bff92a839..ddce4bb5e09 100644 --- a/lib/core/src/lib/snackbar-content/snackbar-content.component.spec.ts +++ b/lib/core/src/lib/snackbar-content/snackbar-content.component.spec.ts @@ -20,8 +20,8 @@ import { MatIcon, MatIconModule } from '@angular/material/icon'; import { MAT_SNACK_BAR_DATA, MatSnackBarModule, MatSnackBarRef } from '@angular/material/snack-bar'; import { MatButtonModule } from '@angular/material/button'; import { By } from '@angular/platform-browser'; -import { TranslateModule } from '@ngx-translate/core'; import { SnackbarContentComponent } from './snackbar-content.component'; +import { CoreTestingModule } from '@alfresco/adf-core'; describe('SnackbarContentComponent', () => { let component: SnackbarContentComponent; @@ -30,24 +30,20 @@ describe('SnackbarContentComponent', () => { beforeEach(async () => { await TestBed.configureTestingModule({ declarations: [SnackbarContentComponent], - imports: [ - MatIconModule, - MatSnackBarModule, - MatButtonModule, - TranslateModule.forRoot() - ], - providers: [{ - provide: MatSnackBarRef, - useValue: { - dismissWithAction() { + imports: [CoreTestingModule, MatIconModule, MatSnackBarModule, MatButtonModule], + providers: [ + { + provide: MatSnackBarRef, + useValue: { + dismissWithAction() {} } + }, + { + provide: MAT_SNACK_BAR_DATA, + useValue: {} } - }, { - provide: MAT_SNACK_BAR_DATA, - useValue: {} - }] - }) - .compileComponents(); + ] + }).compileComponents(); fixture = TestBed.createComponent(SnackbarContentComponent); component = fixture.componentInstance; diff --git a/lib/core/src/lib/templates/empty-content/empty-content.component.spec.ts b/lib/core/src/lib/templates/empty-content/empty-content.component.spec.ts index 6797c3eb912..251dd52ea7d 100644 --- a/lib/core/src/lib/templates/empty-content/empty-content.component.spec.ts +++ b/lib/core/src/lib/templates/empty-content/empty-content.component.spec.ts @@ -18,17 +18,14 @@ import { Component } from '@angular/core'; import { ComponentFixture, TestBed } from '@angular/core/testing'; import { By } from '@angular/platform-browser'; -import { TranslateService, TranslateModule } from '@ngx-translate/core'; +import { TranslateService } from '@ngx-translate/core'; import { of } from 'rxjs'; import { CoreTestingModule } from '../../testing/core.testing.module'; @Component({ selector: 'adf-test-component', template: ` - +
SUBTITLE-1
SUBTITLE-2
SUBTITLE-3
@@ -38,19 +35,13 @@ import { CoreTestingModule } from '../../testing/core.testing.module'; class TestComponent {} describe('EmptyContentComponent', () => { - let fixture: ComponentFixture; let translateService: TranslateService; beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - CoreTestingModule - ], - declarations: [ - TestComponent - ] + imports: [CoreTestingModule], + declarations: [TestComponent] }); fixture = TestBed.createComponent(TestComponent); translateService = TestBed.inject(TranslateService); diff --git a/lib/core/src/lib/templates/error-content/error-content.component.spec.ts b/lib/core/src/lib/templates/error-content/error-content.component.spec.ts index 8d5b7386732..c2171f404a5 100644 --- a/lib/core/src/lib/templates/error-content/error-content.component.spec.ts +++ b/lib/core/src/lib/templates/error-content/error-content.component.spec.ts @@ -21,10 +21,8 @@ import { ErrorContentComponent } from './error-content.component'; import { TranslationService } from '../../translation/translation.service'; import { ActivatedRoute } from '@angular/router'; import { of } from 'rxjs'; -import { TranslateModule } from '@ngx-translate/core'; describe('ErrorContentComponent', () => { - let fixture: ComponentFixture; let errorContentComponent: ErrorContentComponent; let element: HTMLElement; @@ -32,13 +30,8 @@ describe('ErrorContentComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - CoreTestingModule - ], - providers: [ - { provide: ActivatedRoute, useValue: { params: of() } } - ] + imports: [CoreTestingModule], + providers: [{ provide: ActivatedRoute, useValue: { params: of() } }] }); fixture = TestBed.createComponent(ErrorContentComponent); element = fixture.nativeElement; diff --git a/lib/core/src/lib/toolbar/toolbar.component.spec.ts b/lib/core/src/lib/toolbar/toolbar.component.spec.ts index 0ab5188972c..9c154674a65 100644 --- a/lib/core/src/lib/toolbar/toolbar.component.spec.ts +++ b/lib/core/src/lib/toolbar/toolbar.component.spec.ts @@ -16,7 +16,6 @@ */ import { ComponentFixture, TestBed } from '@angular/core/testing'; -import { TranslateModule } from '@ngx-translate/core'; import { CoreTestingModule } from '../testing/core.testing.module'; import { ToolbarComponent } from './toolbar.component'; import { ToolbarModule } from './toolbar.module'; @@ -26,11 +25,7 @@ describe('ToolbarComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - CoreTestingModule, - ToolbarModule - ] + imports: [CoreTestingModule, ToolbarModule] }); fixture = TestBed.createComponent(ToolbarComponent); diff --git a/lib/core/src/lib/viewer/components/download-prompt-dialog/download-prompt-dialog.component.spec.ts b/lib/core/src/lib/viewer/components/download-prompt-dialog/download-prompt-dialog.component.spec.ts index ab1e645ccc1..8edce2230ad 100644 --- a/lib/core/src/lib/viewer/components/download-prompt-dialog/download-prompt-dialog.component.spec.ts +++ b/lib/core/src/lib/viewer/components/download-prompt-dialog/download-prompt-dialog.component.spec.ts @@ -19,7 +19,6 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; import { By } from '@angular/platform-browser'; import { MatDialogRef } from '@angular/material/dialog'; -import { TranslateModule } from '@ngx-translate/core'; import { DownloadPromptDialogComponent } from './download-prompt-dialog.component'; import { CoreTestingModule } from '../../../testing/core.testing.module'; import { DownloadPromptActions } from '../../models/download-prompt.actions'; @@ -37,13 +36,8 @@ describe('DownloadPromptDialogComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ declarations: [DownloadPromptDialogComponent], - imports: [ - TranslateModule.forRoot(), - CoreTestingModule - ], - providers: [ - { provide: MatDialogRef, useValue: mockDialog } - ] + imports: [CoreTestingModule], + providers: [{ provide: MatDialogRef, useValue: mockDialog }] }); matDialogRef = TestBed.inject(MatDialogRef); diff --git a/lib/core/src/lib/viewer/components/img-viewer.component.spec.ts b/lib/core/src/lib/viewer/components/img-viewer.component.spec.ts index 1bd683ba058..fc7fbfb3d90 100644 --- a/lib/core/src/lib/viewer/components/img-viewer.component.spec.ts +++ b/lib/core/src/lib/viewer/components/img-viewer.component.spec.ts @@ -21,11 +21,9 @@ import { UrlService } from '../../common/services/url.service'; import { ImgViewerComponent } from './img-viewer.component'; import { CoreTestingModule } from '../../testing'; import { AppConfigService } from '../../app-config/app-config.service'; -import { TranslateModule } from '@ngx-translate/core'; import { By } from '@angular/platform-browser'; describe('Test Img viewer component ', () => { - let component: ImgViewerComponent; let urlService: UrlService; let fixture: ComponentFixture; @@ -38,15 +36,11 @@ describe('Test Img viewer component ', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - CoreTestingModule - ] + imports: [CoreTestingModule] }); }); describe('Zoom customization', () => { - beforeEach(() => { urlService = TestBed.inject(UrlService); fixture = TestBed.createComponent(ImgViewerComponent); @@ -58,16 +52,13 @@ describe('Test Img viewer component ', () => { }); describe('default value', () => { - it('should use default zoom if is not present a custom zoom in the app.config', () => { fixture.detectChanges(); expect(component.scale).toBe(1.0); }); - }); describe('custom value', () => { - beforeEach(() => { const appConfig: AppConfigService = TestBed.inject(AppConfigService); appConfig.config['adf-viewer-render.image-viewer-scaling'] = 70; @@ -78,7 +69,7 @@ describe('Test Img viewer component ', () => { fixture.detectChanges(); fixture.whenStable().then(() => { - expect(component.scale).toBe(0.70); + expect(component.scale).toBe(0.7); done(); }); }); @@ -86,14 +77,14 @@ describe('Test Img viewer component ', () => { }); describe('Url', () => { - beforeEach(() => { urlService = TestBed.inject(UrlService); fixture = TestBed.createComponent(ImgViewerComponent); element = fixture.nativeElement; component = fixture.componentInstance; - component.urlFile = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg=='; + component.urlFile = + 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg=='; fixture.detectChanges(); fixture.componentInstance.ngAfterViewInit(); component.ngAfterViewInit(); @@ -115,7 +106,6 @@ describe('Test Img viewer component ', () => { }); describe('Blob', () => { - beforeEach(() => { urlService = TestBed.inject(UrlService); fixture = TestBed.createComponent(ImgViewerComponent); @@ -169,7 +159,6 @@ describe('Test Img viewer component ', () => { }); describe('toolbar actions', () => { - beforeEach(() => { fixture = TestBed.createComponent(ImgViewerComponent); element = fixture.nativeElement; @@ -193,7 +182,7 @@ describe('Test Img viewer component ', () => { component.zoomIn(); expect(component.scale).toBe(1.4); expect(component.cropper.zoom).toHaveBeenCalledWith(0.2); - })); + })); it('should update scales on zoom out', fakeAsync(() => { spyOn(component, 'zoomOut').and.callThrough(); @@ -381,5 +370,4 @@ describe('Test Img viewer component ', () => { expect(component.reset).toHaveBeenCalled(); }); }); - }); diff --git a/lib/core/src/lib/viewer/components/pdf-viewer-password-dialog.spec.ts b/lib/core/src/lib/viewer/components/pdf-viewer-password-dialog.spec.ts index b4302e533fa..de95e2891ab 100644 --- a/lib/core/src/lib/viewer/components/pdf-viewer-password-dialog.spec.ts +++ b/lib/core/src/lib/viewer/components/pdf-viewer-password-dialog.spec.ts @@ -19,7 +19,6 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog'; import { PdfPasswordDialogComponent } from './pdf-viewer-password-dialog'; import { CoreTestingModule } from '../../testing/core.testing.module'; -import { TranslateModule } from '@ngx-translate/core'; declare const pdfjsLib: any; @@ -30,10 +29,7 @@ describe('PdfPasswordDialogComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - CoreTestingModule - ], + imports: [CoreTestingModule], providers: [ { provide: MAT_DIALOG_DATA, diff --git a/lib/core/src/lib/viewer/components/pdf-viewer-thumb.component.spec.ts b/lib/core/src/lib/viewer/components/pdf-viewer-thumb.component.spec.ts index e94a38adee7..ff8904da567 100644 --- a/lib/core/src/lib/viewer/components/pdf-viewer-thumb.component.spec.ts +++ b/lib/core/src/lib/viewer/components/pdf-viewer-thumb.component.spec.ts @@ -19,10 +19,8 @@ import { DomSanitizer } from '@angular/platform-browser'; import { ComponentFixture, TestBed } from '@angular/core/testing'; import { PdfThumbComponent } from './pdf-viewer-thumb.component'; import { CoreTestingModule } from '../../testing/core.testing.module'; -import { TranslateModule } from '@ngx-translate/core'; describe('PdfThumbComponent', () => { - let fixture: ComponentFixture; let component: PdfThumbComponent; const domSanitizer = { @@ -32,10 +30,12 @@ describe('PdfThumbComponent', () => { const height = 119; const page = { id: 'pageId', - getPage: jasmine.createSpy('getPage').and.returnValue(Promise.resolve({ - getViewport: () => ({ height: width, width: height }), - render: jasmine.createSpy('render').and.returnValue({ promise: Promise.resolve() }) - })), + getPage: jasmine.createSpy('getPage').and.returnValue( + Promise.resolve({ + getViewport: () => ({ height: width, width: height }), + render: jasmine.createSpy('render').and.returnValue({ promise: Promise.resolve() }) + }) + ), getWidth: jasmine.createSpy('getWidth').and.returnValue(width), getHeight: jasmine.createSpy('getHeight').and.returnValue(height) @@ -43,13 +43,8 @@ describe('PdfThumbComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - CoreTestingModule - ], - providers: [ - { provide: DomSanitizer, useValue: domSanitizer } - ] + imports: [CoreTestingModule], + providers: [{ provide: DomSanitizer, useValue: domSanitizer }] }); fixture = TestBed.createComponent(PdfThumbComponent); component = fixture.componentInstance; diff --git a/lib/core/src/lib/viewer/components/pdf-viewer-thumbnails.component.spec.ts b/lib/core/src/lib/viewer/components/pdf-viewer-thumbnails.component.spec.ts index 896b663698d..99c06699ba6 100644 --- a/lib/core/src/lib/viewer/components/pdf-viewer-thumbnails.component.spec.ts +++ b/lib/core/src/lib/viewer/components/pdf-viewer-thumbnails.component.spec.ts @@ -19,13 +19,11 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; import { By } from '@angular/platform-browser'; import { PdfThumbListComponent } from './pdf-viewer-thumbnails.component'; import { CoreTestingModule } from '../../testing/core.testing.module'; -import { TranslateModule } from '@ngx-translate/core'; import { DOWN_ARROW, UP_ARROW, ESCAPE } from '@angular/cdk/keycodes'; declare const pdfjsViewer: any; describe('PdfThumbListComponent', () => { - let fixture: ComponentFixture; let component: PdfThumbListComponent; @@ -45,26 +43,36 @@ describe('PdfThumbListComponent', () => { return this._currentPageNumber; }, pdfDocument: { - getPage: () => Promise.resolve({ - getViewport: () => ({ height: 421, width: 335 }), - render: jasmine.createSpy('render').and.returnValue({ promise: Promise.resolve() }) - }) + getPage: () => + Promise.resolve({ + getViewport: () => ({ height: 421, width: 335 }), + render: jasmine.createSpy('render').and.returnValue({ promise: Promise.resolve() }) + }) }, _pages: [ - page(1), page(2), page(3), page(4), - page(5), page(6), page(7), page(8), - page(9), page(10), page(11), page(12), - page(13), page(14), page(15), page(16) + page(1), + page(2), + page(3), + page(4), + page(5), + page(6), + page(7), + page(8), + page(9), + page(10), + page(11), + page(12), + page(13), + page(14), + page(15), + page(16) ], eventBus: new pdfjsViewer.EventBus() }; beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - CoreTestingModule - ] + imports: [CoreTestingModule] }); fixture = TestBed.createComponent(PdfThumbListComponent); component = fixture.componentInstance; @@ -173,7 +181,7 @@ describe('PdfThumbListComponent', () => { describe('Keyboard events', () => { it('should select next page in the list on DOWN_ARROW event', () => { - const event = new KeyboardEvent('keydown', {keyCode: DOWN_ARROW} as KeyboardEventInit); + const event = new KeyboardEvent('keydown', { keyCode: DOWN_ARROW } as KeyboardEventInit); fixture.detectChanges(); component.goTo(1); expect(document.activeElement.id).toBe('1'); @@ -183,7 +191,7 @@ describe('PdfThumbListComponent', () => { }); it('should select previous page in the list on UP_ARROW event', () => { - const event = new KeyboardEvent('keydown', {keyCode: UP_ARROW} as KeyboardEventInit); + const event = new KeyboardEvent('keydown', { keyCode: UP_ARROW } as KeyboardEventInit); fixture.detectChanges(); component.goTo(2); expect(document.activeElement.id).toBe('2'); @@ -193,7 +201,7 @@ describe('PdfThumbListComponent', () => { }); it('should not select previous page if it is the first page', () => { - const event = new KeyboardEvent('keydown', {keyCode: UP_ARROW} as KeyboardEventInit); + const event = new KeyboardEvent('keydown', { keyCode: UP_ARROW } as KeyboardEventInit); fixture.detectChanges(); component.goTo(1); expect(document.activeElement.id).toBe('1'); @@ -203,7 +211,7 @@ describe('PdfThumbListComponent', () => { }); it('should not select next item if it is the last page', () => { - const event = new KeyboardEvent('keydown', {keyCode: DOWN_ARROW} as KeyboardEventInit); + const event = new KeyboardEvent('keydown', { keyCode: DOWN_ARROW } as KeyboardEventInit); fixture.detectChanges(); component.scrollInto(16); fixture.detectChanges(); @@ -216,7 +224,7 @@ describe('PdfThumbListComponent', () => { }); it('should emit on ESCAPE event', () => { - const event = new KeyboardEvent('keydown', {keyCode: ESCAPE} as KeyboardEventInit); + const event = new KeyboardEvent('keydown', { keyCode: ESCAPE } as KeyboardEventInit); spyOn(component.close, 'emit'); fixture.detectChanges(); diff --git a/lib/core/src/lib/viewer/components/pdf-viewer.component.spec.ts b/lib/core/src/lib/viewer/components/pdf-viewer.component.spec.ts index e33a9e0f22f..0485e7e4712 100644 --- a/lib/core/src/lib/viewer/components/pdf-viewer.component.spec.ts +++ b/lib/core/src/lib/viewer/components/pdf-viewer.component.spec.ts @@ -26,7 +26,6 @@ import { of } from 'rxjs'; import { take } from 'rxjs/operators'; import { AppConfigService } from '../../app-config/app-config.service'; import { CoreTestingModule } from '../../testing/core.testing.module'; -import { TranslateModule } from '@ngx-translate/core'; import { PdfThumbListComponent } from '@alfresco/adf-core'; import { By } from '@angular/platform-browser'; @@ -36,19 +35,12 @@ declare const pdfjsLib: any; selector: 'adf-test-dialog-component', template: '' }) -class TestDialogComponent { -} +class TestDialogComponent {} @Component({ - template: ` - - - ` + template: ` ` }) class UrlTestComponent { - @ViewChild(PdfViewerComponent, { static: true }) pdfViewerComponent: PdfViewerComponent; @@ -60,15 +52,9 @@ class UrlTestComponent { } @Component({ - template: ` - - - ` + template: ` ` }) class UrlTestPasswordComponent { - @ViewChild(PdfViewerComponent, { static: true }) pdfViewerComponent: PdfViewerComponent; @@ -80,15 +66,9 @@ class UrlTestPasswordComponent { } @Component({ - template: ` - - - ` + template: ` ` }) class BlobTestComponent { - @ViewChild(PdfViewerComponent, { static: true }) pdfViewerComponent: PdfViewerComponent; @@ -101,25 +81,24 @@ class BlobTestComponent { createFakeBlob(): Blob { const pdfData = atob( 'JVBERi0xLjcKCjEgMCBvYmogICUgZW50cnkgcG9pbnQKPDwKICAvVHlwZSAvQ2F0YWxvZwog' + - 'IC9QYWdlcyAyIDAgUgo+PgplbmRvYmoKCjIgMCBvYmoKPDwKICAvVHlwZSAvUGFnZXMKICAv' + - 'TWVkaWFCb3ggWyAwIDAgMjAwIDIwMCBdCiAgL0NvdW50IDEKICAvS2lkcyBbIDMgMCBSIF0K' + - 'Pj4KZW5kb2JqCgozIDAgb2JqCjw8CiAgL1R5cGUgL1BhZ2UKICAvUGFyZW50IDIgMCBSCiAg' + - 'L1Jlc291cmNlcyA8PAogICAgL0ZvbnQgPDwKICAgICAgL0YxIDQgMCBSIAogICAgPj4KICA+' + - 'PgogIC9Db250ZW50cyA1IDAgUgo+PgplbmRvYmoKCjQgMCBvYmoKPDwKICAvVHlwZSAvRm9u' + - 'dAogIC9TdWJ0eXBlIC9UeXBlMQogIC9CYXNlRm9udCAvVGltZXMtUm9tYW4KPj4KZW5kb2Jq' + - 'Cgo1IDAgb2JqICAlIHBhZ2UgY29udGVudAo8PAogIC9MZW5ndGggNDQKPj4Kc3RyZWFtCkJU' + - 'CjcwIDUwIFRECi9GMSAxMiBUZgooSGVsbG8sIHdvcmxkISkgVGoKRVQKZW5kc3RyZWFtCmVu' + - 'ZG9iagoKeHJlZgowIDYKMDAwMDAwMDAwMCA2NTUzNSBmIAowMDAwMDAwMDEwIDAwMDAwIG4g' + - 'CjAwMDAwMDAwNzkgMDAwMDAgbiAKMDAwMDAwMDE3MyAwMDAwMCBuIAowMDAwMDAwMzAxIDAw' + - 'MDAwIG4gCjAwMDAwMDAzODAgMDAwMDAgbiAKdHJhaWxlcgo8PAogIC9TaXplIDYKICAvUm9v' + - 'dCAxIDAgUgo+PgpzdGFydHhyZWYKNDkyCiUlRU9G'); + 'IC9QYWdlcyAyIDAgUgo+PgplbmRvYmoKCjIgMCBvYmoKPDwKICAvVHlwZSAvUGFnZXMKICAv' + + 'TWVkaWFCb3ggWyAwIDAgMjAwIDIwMCBdCiAgL0NvdW50IDEKICAvS2lkcyBbIDMgMCBSIF0K' + + 'Pj4KZW5kb2JqCgozIDAgb2JqCjw8CiAgL1R5cGUgL1BhZ2UKICAvUGFyZW50IDIgMCBSCiAg' + + 'L1Jlc291cmNlcyA8PAogICAgL0ZvbnQgPDwKICAgICAgL0YxIDQgMCBSIAogICAgPj4KICA+' + + 'PgogIC9Db250ZW50cyA1IDAgUgo+PgplbmRvYmoKCjQgMCBvYmoKPDwKICAvVHlwZSAvRm9u' + + 'dAogIC9TdWJ0eXBlIC9UeXBlMQogIC9CYXNlRm9udCAvVGltZXMtUm9tYW4KPj4KZW5kb2Jq' + + 'Cgo1IDAgb2JqICAlIHBhZ2UgY29udGVudAo8PAogIC9MZW5ndGggNDQKPj4Kc3RyZWFtCkJU' + + 'CjcwIDUwIFRECi9GMSAxMiBUZgooSGVsbG8sIHdvcmxkISkgVGoKRVQKZW5kc3RyZWFtCmVu' + + 'ZG9iagoKeHJlZgowIDYKMDAwMDAwMDAwMCA2NTUzNSBmIAowMDAwMDAwMDEwIDAwMDAwIG4g' + + 'CjAwMDAwMDAwNzkgMDAwMDAgbiAKMDAwMDAwMDE3MyAwMDAwMCBuIAowMDAwMDAwMzAxIDAw' + + 'MDAwIG4gCjAwMDAwMDAzODAgMDAwMDAgbiAKdHJhaWxlcgo8PAogIC9TaXplIDYKICAvUm9v' + + 'dCAxIDAgUgo+PgpzdGFydHhyZWYKNDkyCiUlRU9G' + ); return new Blob([pdfData], { type: 'application/pdf' }); } - } describe('Test PdfViewer component', () => { - let component: PdfViewerComponent; let fixture: ComponentFixture; let element: HTMLElement; @@ -128,21 +107,13 @@ describe('Test PdfViewer component', () => { beforeEach((done) => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - CoreTestingModule - ], - declarations: [ - TestDialogComponent, - UrlTestComponent, - UrlTestPasswordComponent, - BlobTestComponent - ], + imports: [CoreTestingModule], + declarations: [TestDialogComponent, UrlTestComponent, UrlTestPasswordComponent, BlobTestComponent], providers: [ { - provide: MatDialog, useValue: { - open: () => { - } + provide: MatDialog, + useValue: { + open: () => {} } }, RenderingQueueServices @@ -164,7 +135,6 @@ describe('Test PdfViewer component', () => { }); describe('User interaction', () => { - let fixtureUrlTestComponent: ComponentFixture; let componentUrlTestComponent: UrlTestComponent; let elementUrlTestComponent: HTMLElement; @@ -176,11 +146,9 @@ describe('Test PdfViewer component', () => { fixtureUrlTestComponent.detectChanges(); - componentUrlTestComponent.pdfViewerComponent.rendered - .pipe(take(1)) - .subscribe(() => { - done(); - }); + componentUrlTestComponent.pdfViewerComponent.rendered.pipe(take(1)).subscribe(() => { + done(); + }); }); afterEach(() => { @@ -271,10 +239,8 @@ describe('Test PdfViewer component', () => { }, 55000); describe('Zoom', () => { - it('should zoom in increment the scale value', fakeAsync(() => { - spyOn(componentUrlTestComponent.pdfViewerComponent.pdfViewer, 'forceRendering').and.callFake(() => { - }); + spyOn(componentUrlTestComponent.pdfViewerComponent.pdfViewer, 'forceRendering').and.callFake(() => {}); const zoomInButton: any = elementUrlTestComponent.querySelector('#viewer-zoom-in-button'); @@ -288,8 +254,7 @@ describe('Test PdfViewer component', () => { }), 55000); it('should zoom out decrement the scale value', fakeAsync(() => { - spyOn(componentUrlTestComponent.pdfViewerComponent.pdfViewer, 'forceRendering').and.callFake(() => { - }); + spyOn(componentUrlTestComponent.pdfViewerComponent.pdfViewer, 'forceRendering').and.callFake(() => {}); const zoomOutButton: any = elementUrlTestComponent.querySelector('#viewer-zoom-out-button'); tick(250); @@ -302,8 +267,7 @@ describe('Test PdfViewer component', () => { }), 55000); it('should it-in button toggle page-fit and auto scale mode', fakeAsync(() => { - spyOn(componentUrlTestComponent.pdfViewerComponent.pdfViewer, 'forceRendering').and.callFake(() => { - }); + spyOn(componentUrlTestComponent.pdfViewerComponent.pdfViewer, 'forceRendering').and.callFake(() => {}); const itPage: any = elementUrlTestComponent.querySelector('#viewer-scale-page-button'); @@ -320,7 +284,6 @@ describe('Test PdfViewer component', () => { }); describe('Resize interaction', () => { - it('should resize event trigger setScaleUpdatePages', (done) => { spyOn(componentUrlTestComponent.pdfViewerComponent, 'onResize'); EventMock.resizeMobileView(); @@ -329,12 +292,10 @@ describe('Test PdfViewer component', () => { expect(componentUrlTestComponent.pdfViewerComponent.onResize).toHaveBeenCalled(); done(); }); - }, 55000); }); describe('Thumbnails', () => { - it('should have own context', (done) => { fixtureUrlTestComponent.detectChanges(); @@ -366,7 +327,6 @@ describe('Test PdfViewer component', () => { }); describe('Viewer events', () => { - it('should react on the emit of pageChange event', (done) => { fixtureUrlTestComponent.detectChanges(); fixtureUrlTestComponent.whenStable().then(() => { @@ -441,9 +401,7 @@ describe('Test PdfViewer component', () => { }); describe('Zoom customization', () => { - describe('custom value', () => { - let fixtureUrlTestComponent: ComponentFixture; let componentUrlTestComponent: UrlTestComponent; let elementUrlTestComponent: HTMLElement; @@ -458,11 +416,9 @@ describe('Test PdfViewer component', () => { fixtureUrlTestComponent.detectChanges(); - componentUrlTestComponent.pdfViewerComponent.rendered - .pipe(take(1)) - .subscribe(() => { - done(); - }); + componentUrlTestComponent.pdfViewerComponent.rendered.pipe(take(1)).subscribe(() => { + done(); + }); }); afterEach(() => { @@ -470,8 +426,7 @@ describe('Test PdfViewer component', () => { }); it('should use the custom zoom if it is present in the app.config', (done) => { - spyOn(componentUrlTestComponent.pdfViewerComponent.pdfViewer, 'forceRendering').and.callFake(() => { - }); + spyOn(componentUrlTestComponent.pdfViewerComponent.pdfViewer, 'forceRendering').and.callFake(() => {}); fixtureUrlTestComponent.detectChanges(); fixtureUrlTestComponent.whenStable().then(() => { @@ -482,7 +437,6 @@ describe('Test PdfViewer component', () => { }); describe('less than the minimum allowed value', () => { - let fixtureUrlTestComponent: ComponentFixture; let componentUrlTestComponent: UrlTestComponent; let elementUrlTestComponent: HTMLElement; @@ -497,11 +451,9 @@ describe('Test PdfViewer component', () => { fixtureUrlTestComponent.detectChanges(); - componentUrlTestComponent.pdfViewerComponent.rendered - .pipe(take(1)) - .subscribe(() => { - done(); - }); + componentUrlTestComponent.pdfViewerComponent.rendered.pipe(take(1)).subscribe(() => { + done(); + }); }); afterEach(() => { @@ -509,8 +461,7 @@ describe('Test PdfViewer component', () => { }); it('should use the minimum scale zoom if the value given in app.config is less than the minimum allowed scale', (done) => { - spyOn(componentUrlTestComponent.pdfViewerComponent.pdfViewer, 'forceRendering').and.callFake(() => { - }); + spyOn(componentUrlTestComponent.pdfViewerComponent.pdfViewer, 'forceRendering').and.callFake(() => {}); fixtureUrlTestComponent.detectChanges(); @@ -519,12 +470,10 @@ describe('Test PdfViewer component', () => { done(); }); }); - }); // TODO: https://alfresco.atlassian.net/browse/ACS-6061 // eslint-disable-next-line xdescribe('greater than the maximum allowed value', () => { - let fixtureUrlTestComponent: ComponentFixture; let componentUrlTestComponent: UrlTestComponent; let elementUrlTestComponent: HTMLElement; @@ -539,11 +488,9 @@ describe('Test PdfViewer component', () => { fixtureUrlTestComponent.detectChanges(); - componentUrlTestComponent.pdfViewerComponent.rendered - .pipe(take(1)) - .subscribe(() => { - done(); - }); + componentUrlTestComponent.pdfViewerComponent.rendered.pipe(take(1)).subscribe(() => { + done(); + }); }); afterEach(() => { @@ -551,8 +498,7 @@ describe('Test PdfViewer component', () => { }); it('should use the maximum scale zoom if the value given in app.config is greater than the maximum allowed scale', (done) => { - spyOn(componentUrlTestComponent.pdfViewerComponent.pdfViewer, 'forceRendering').and.callFake(() => { - }); + spyOn(componentUrlTestComponent.pdfViewerComponent.pdfViewer, 'forceRendering').and.callFake(() => {}); fixtureUrlTestComponent.detectChanges(); fixtureUrlTestComponent.whenStable().then(() => { @@ -582,7 +528,6 @@ describe('Test PdfViewer component', () => { }); describe('View with url file', () => { - let fixtureUrlTestComponent: ComponentFixture; let elementUrlTestComponent: HTMLElement; @@ -613,7 +558,6 @@ describe('Test PdfViewer component', () => { }, 55000); it('should Input Page elements be present', (done) => { - fixtureUrlTestComponent.detectChanges(); fixtureUrlTestComponent.whenStable().then(() => { /* cspell:disable-next-line */ @@ -639,7 +583,6 @@ describe('Test PdfViewer component', () => { }); describe('View with blob file', () => { - let fixtureBlobTestComponent: ComponentFixture; let elementBlobTestComponent: HTMLElement; @@ -706,12 +649,11 @@ describe('Test PdfViewer component', () => { }); describe('Password protection dialog', () => { - let fixtureUrlTestPasswordComponent: ComponentFixture; let componentUrlTestPasswordComponent: UrlTestPasswordComponent; describe('Open password dialog', () => { - beforeEach( async () => { + beforeEach(async () => { fixtureUrlTestPasswordComponent = TestBed.createComponent(UrlTestPasswordComponent); componentUrlTestPasswordComponent = fixtureUrlTestPasswordComponent.componentInstance; @@ -780,9 +722,12 @@ describe('Test PdfViewer component', () => { fixtureUrlTestPasswordComponent = TestBed.createComponent(UrlTestPasswordComponent); componentUrlTestPasswordComponent = fixtureUrlTestPasswordComponent.componentInstance; - spyOn(dialog, 'open').and.callFake(() => ({ - afterClosed: () => of('') - } as any)); + spyOn(dialog, 'open').and.callFake( + () => + ({ + afterClosed: () => of('') + } as any) + ); spyOn(componentUrlTestPasswordComponent.pdfViewerComponent.close, 'emit'); diff --git a/lib/core/src/lib/viewer/components/txt-viewer.component.spec.ts b/lib/core/src/lib/viewer/components/txt-viewer.component.spec.ts index ef361aae3a0..f872c9aadb7 100644 --- a/lib/core/src/lib/viewer/components/txt-viewer.component.spec.ts +++ b/lib/core/src/lib/viewer/components/txt-viewer.component.spec.ts @@ -19,20 +19,15 @@ import { SimpleChange } from '@angular/core'; import { ComponentFixture, TestBed } from '@angular/core/testing'; import { TxtViewerComponent } from './txt-viewer.component'; import { CoreTestingModule } from '../../testing/core.testing.module'; -import { TranslateModule } from '@ngx-translate/core'; describe('Text View component', () => { - let component: TxtViewerComponent; let fixture: ComponentFixture; let element: HTMLElement; beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - CoreTestingModule - ] + imports: [CoreTestingModule] }); fixture = TestBed.createComponent(TxtViewerComponent); @@ -41,7 +36,6 @@ describe('Text View component', () => { }); describe('View', () => { - it('Should text container be present with urlFile', (done) => { fixture.detectChanges(); const urlFile = './fake-test-file.txt'; @@ -57,7 +51,7 @@ describe('Text View component', () => { }); it('Should text container be present with Blob file', (done) => { - const blobFile = new Blob(['text example'], {type: 'text/txt'}); + const blobFile = new Blob(['text example'], { type: 'text/txt' }); const change = new SimpleChange(null, blobFile, true); @@ -69,5 +63,5 @@ describe('Text View component', () => { }); }); }); - }); + }); }); diff --git a/lib/core/src/lib/viewer/components/viewer-render.component.spec.ts b/lib/core/src/lib/viewer/components/viewer-render.component.spec.ts index fff55d9d557..41edb3e3fcb 100644 --- a/lib/core/src/lib/viewer/components/viewer-render.component.spec.ts +++ b/lib/core/src/lib/viewer/components/viewer-render.component.spec.ts @@ -22,9 +22,7 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; import { RenderingQueueServices } from '../services/rendering-queue.services'; import { ViewerRenderComponent } from './viewer-render.component'; import { CoreTestingModule } from '../../testing/core.testing.module'; -import { TranslateModule } from '@ngx-translate/core'; import { MatDialog } from '@angular/material/dialog'; -import { NoopAnimationsModule } from '@angular/platform-browser/animations'; import { AppExtensionService, ViewerExtensionRef } from '@alfresco/adf-extensions'; import { MatButtonModule } from '@angular/material/button'; import { MatIconModule } from '@angular/material/icon'; @@ -61,12 +59,9 @@ class DoubleViewerComponent { urlFileViewer1: string; urlFileViewer2: string; - } - describe('ViewerComponent', () => { - let component: ViewerRenderComponent; let fixture: ComponentFixture; let element: HTMLElement; @@ -75,21 +70,9 @@ describe('ViewerComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - NoopAnimationsModule, - TranslateModule.forRoot(), - CoreTestingModule, - MatButtonModule, - MatIconModule - ], - declarations: [ - DoubleViewerComponent - ], - providers: [ - RenderingQueueServices, - {provide: Location, useClass: SpyLocation}, - MatDialog - ] + imports: [CoreTestingModule, MatButtonModule, MatIconModule], + declarations: [DoubleViewerComponent], + providers: [RenderingQueueServices, { provide: Location, useClass: SpyLocation }, MatDialog] }); fixture = TestBed.createComponent(ViewerRenderComponent); element = fixture.nativeElement; @@ -103,7 +86,6 @@ describe('ViewerComponent', () => { }); describe('Double viewer Test', () => { - it('should not reload the content of all the viewer after type change', async () => { const fixtureDouble = TestBed.createComponent(DoubleViewerComponent); @@ -405,7 +387,6 @@ describe('ViewerComponent', () => { }); describe('Base component', () => { - beforeEach(() => { component.urlFile = 'fake-test-file.pdf'; component.mimeType = 'application/pdf'; @@ -426,17 +407,14 @@ describe('ViewerComponent', () => { }); describe('Attribute', () => { - it('should urlFile present not thrown any error ', () => { expect(() => { component.ngOnChanges(); }).not.toThrow(); }); - }); describe('error handling', () => { - it('should switch to the unknown template if the type specific viewers throw an error', (done) => { component.urlFile = 'fake-url-file.icns'; component.mimeType = 'image/png'; @@ -454,9 +432,7 @@ describe('ViewerComponent', () => { }); describe('Events', () => { - it('should if the extension change extension Change event be fired ', (done) => { - component.extensionChange.subscribe((fileExtension) => { expect(fileExtension).toEqual('png'); done(); @@ -469,7 +445,6 @@ describe('ViewerComponent', () => { }); describe('display name property override by urlFile', () => { - it('should fileName override the default name if is present and urlFile is set', () => { component.urlFile = 'fake-test-file.pdf'; component.fileName = 'test name'; @@ -490,16 +465,14 @@ describe('ViewerComponent', () => { }); describe('display name property override by blobFile', () => { - it('should fileName override the name if is present and blobFile is set', () => { component.fileName = 'blob file display name'; - component.blobFile = new Blob(['This is my blob content'], {type: 'text/plain'}); + component.blobFile = new Blob(['This is my blob content'], { type: 'text/plain' }); fixture.detectChanges(); component.ngOnChanges(); expect(component.internalFileName).toEqual('blob file display name'); }); - }); }); }); diff --git a/lib/core/src/lib/viewer/components/viewer.component.spec.ts b/lib/core/src/lib/viewer/components/viewer.component.spec.ts index 6d38519e58d..0a275696911 100644 --- a/lib/core/src/lib/viewer/components/viewer.component.spec.ts +++ b/lib/core/src/lib/viewer/components/viewer.component.spec.ts @@ -16,10 +16,7 @@ */ import { ComponentFixture, discardPeriodicTasks, fakeAsync, flush, TestBed, tick } from '@angular/core/testing'; - -import { TranslateModule } from '@ngx-translate/core'; import { MatDialog } from '@angular/material/dialog'; -import { NoopAnimationsModule } from '@angular/platform-browser/animations'; import { MatButtonModule } from '@angular/material/button'; import { MatIconModule } from '@angular/material/icon'; import { @@ -45,11 +42,9 @@ import { By } from '@angular/platform-browser'; selector: 'adf-dialog-dummy', template: `` }) -class DummyDialogComponent { -} +class DummyDialogComponent {} describe('ViewerComponent', () => { - let component: ViewerComponent; let fixture: ComponentFixture>; let element: HTMLElement; @@ -59,13 +54,7 @@ describe('ViewerComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - NoopAnimationsModule, - TranslateModule.forRoot(), - CoreTestingModule, - MatButtonModule, - MatIconModule - ], + imports: [CoreTestingModule, MatButtonModule, MatIconModule], declarations: [ ViewerWithCustomToolbarComponent, ViewerWithCustomSidebarComponent, @@ -73,10 +62,7 @@ describe('ViewerComponent', () => { ViewerWithCustomMoreActionsComponent, ViewerWithCustomToolbarActionsComponent ], - providers: [ - MatDialog, - { provide: DownloadPromptDialogComponent, useClass: DummyDialogComponent} - ] + providers: [MatDialog, { provide: DownloadPromptDialogComponent, useClass: DummyDialogComponent }] }); fixture = TestBed.createComponent(ViewerComponent); @@ -91,7 +77,7 @@ describe('ViewerComponent', () => { appConfigService.config = { ...appConfigService.config, viewer: { - enableDownloadPrompt: false, + enableDownloadPrompt: false, enableDownloadPromptReminder: false, downloadPromptDelay: 3, downloadPromptReminderDelay: 2 @@ -103,17 +89,14 @@ describe('ViewerComponent', () => { fixture.destroy(); }); - describe('Mime Type Test', () => { - it('should mimeType change when blobFile changes', () => { - const mockSimpleChanges: any = { blobFile: {currentValue: { type: 'image/png'}}}; + const mockSimpleChanges: any = { blobFile: { currentValue: { type: 'image/png' } } }; component.ngOnChanges(mockSimpleChanges); expect(component.mimeType).toBe('image/png'); }); - }); describe('originalMimeType', () => { @@ -149,11 +132,10 @@ describe('ViewerComponent', () => { }); describe('File Name Test', () => { - it('should fileName be set by urlFile input if the fileName is not provided as Input', () => { component.fileName = ''; spyOn(viewUtilService, 'getFilenameFromUrl').and.returnValue('fakeFileName.jpeg'); - const mockSimpleChanges: any = { urlFile: {currentValue: 'https://fakefile.url/fakeFileName.jpeg'}}; + const mockSimpleChanges: any = { urlFile: { currentValue: 'https://fakefile.url/fakeFileName.jpeg' } }; component.ngOnChanges(mockSimpleChanges); fixture.detectChanges(); @@ -164,18 +146,17 @@ describe('ViewerComponent', () => { it('should set fileName providing fileName input', () => { component.fileName = 'testFileName.jpg'; spyOn(viewUtilService, 'getFilenameFromUrl').and.returnValue('fakeFileName.jpeg'); - const mockSimpleChanges: any = { urlFile: {currentValue: 'https://fakefile.url/fakeFileName.jpeg'}}; + const mockSimpleChanges: any = { urlFile: { currentValue: 'https://fakefile.url/fakeFileName.jpeg' } }; component.ngOnChanges(mockSimpleChanges); - fixture.detectChanges();fixture.detectChanges(); + fixture.detectChanges(); + fixture.detectChanges(); expect(element.querySelector('#adf-viewer-display-name').textContent).toEqual('testFileName.jpg'); }); - }); describe('Viewer Example Component Rendering', () => { - it('should use custom toolbar', (done) => { const customFixture = TestBed.createComponent(ViewerWithCustomToolbarComponent); const customElement: HTMLElement = customFixture.nativeElement; @@ -232,12 +213,10 @@ describe('ViewerComponent', () => { expect(customElement.querySelector('.adf-viewer-container-more-actions')).toBeDefined(); done(); }); - }); }); describe('Toolbar', () => { - it('should show only next file button', async () => { component.allowNavigate = true; component.canNavigateBefore = false; @@ -360,11 +339,9 @@ describe('ViewerComponent', () => { done(); }); }); - }); describe('Base component', () => { - beforeEach(() => { component.mimeType = 'application/pdf'; @@ -372,7 +349,6 @@ describe('ViewerComponent', () => { }); describe('SideBar Test', () => { - it('should NOT display sidebar if is not allowed', (done) => { component.showRightSidebar = true; component.allowRightSidebar = false; @@ -407,7 +383,6 @@ describe('ViewerComponent', () => { expect(sidebar).toBeNull(); done(); }); - }); it('should display sidebar on the left side', (done) => { @@ -444,9 +419,7 @@ describe('ViewerComponent', () => { }); describe('View', () => { - describe('Overlay mode true', () => { - beforeEach(() => { component.overlayMode = true; component.fileName = 'fake-test-file.pdf'; @@ -458,7 +431,7 @@ describe('ViewerComponent', () => { }); it('should file name be present if is overlay mode ', async () => { - const mockSimpleChanges: any = { blobFile: {currentValue: { type: 'image/png'}}}; + const mockSimpleChanges: any = { blobFile: { currentValue: { type: 'image/png' } } }; component.ngOnChanges(mockSimpleChanges); fixture.detectChanges(); await fixture.whenStable(); @@ -513,7 +486,6 @@ describe('ViewerComponent', () => { }); describe('Overlay mode false', () => { - beforeEach(() => { component.overlayMode = false; fixture.detectChanges(); @@ -533,7 +505,6 @@ describe('ViewerComponent', () => { }); describe('Attribute', () => { - it('should showViewer default value be true', () => { expect(component.showViewer).toBe(true); }); @@ -547,7 +518,6 @@ describe('ViewerComponent', () => { }); describe('Close Button', () => { - const getRightCloseButton = () => element.querySelector('[data-automation-id="adf-toolbar-right-back"]'); const getLeftCloseButton = () => element.querySelector('[data-automation-id="adf-toolbar-left-back"]'); @@ -562,7 +532,7 @@ describe('ViewerComponent', () => { it('should show close button on right side when closeButtonPosition is right and allowGoBack is true', () => { component.allowGoBack = true; - component.closeButtonPosition = CloseButtonPosition.Right; + component.closeButtonPosition = CloseButtonPosition.Right; fixture.detectChanges(); expect(getRightCloseButton()).not.toBeNull(); @@ -579,7 +549,6 @@ describe('ViewerComponent', () => { }); describe('Viewer component - Full Screen Mode - Mocking fixture element', () => { - beforeEach(() => { fixture = TestBed.createComponent(ViewerComponent); element = fixture.nativeElement; @@ -634,31 +603,30 @@ describe('ViewerComponent', () => { }); }); - describe('Download Prompt Dialog',() => { - + describe('Download Prompt Dialog', () => { let dialogOpenSpy: jasmine.Spy; beforeEach(() => { appConfigService.config = { ...appConfigService.config, viewer: { - enableDownloadPrompt: true, + enableDownloadPrompt: true, enableDownloadPromptReminder: true, downloadPromptDelay: 3, downloadPromptReminderDelay: 2 } }; - dialogOpenSpy = spyOn(dialog, 'open').and.returnValue({afterClosed: () => of(null)} as any); + dialogOpenSpy = spyOn(dialog, 'open').and.returnValue({ afterClosed: () => of(null) } as any); component.urlFile = undefined; component.clearDownloadPromptTimeouts(); }); - it('should configure initial timeout to display non responsive dialog when initialising component', (() => { + it('should configure initial timeout to display non responsive dialog when initialising component', () => { fixture.detectChanges(); expect(component.downloadPromptTimer).toBeDefined(); - })); + }); - it('should configure reminder timeout to display non responsive dialog after initial dialog', fakeAsync( () => { + it('should configure reminder timeout to display non responsive dialog after initial dialog', fakeAsync(() => { dialogOpenSpy.and.returnValue({ afterClosed: () => of(DownloadPromptActions.WAIT) } as any); fixture.detectChanges(); tick(3000); @@ -668,14 +636,14 @@ describe('ViewerComponent', () => { discardPeriodicTasks(); })); - it('should show initial non responsive dialog after initial timeout', fakeAsync( () => { + it('should show initial non responsive dialog after initial timeout', fakeAsync(() => { fixture.detectChanges(); tick(3000); fixture.detectChanges(); expect(dialogOpenSpy).toHaveBeenCalled(); })); - it('should show reminder non responsive dialog after initial dialog', fakeAsync( () => { + it('should show reminder non responsive dialog after initial dialog', fakeAsync(() => { dialogOpenSpy.and.returnValue({ afterClosed: () => of(DownloadPromptActions.WAIT) } as any); fixture.detectChanges(); tick(3000); @@ -689,7 +657,7 @@ describe('ViewerComponent', () => { discardPeriodicTasks(); })); - it('should emit downloadFileEvent when DownloadPromptDialog return DownloadPromptActions.DOWNLOAD on close', fakeAsync( () => { + it('should emit downloadFileEvent when DownloadPromptDialog return DownloadPromptActions.DOWNLOAD on close', fakeAsync(() => { dialogOpenSpy.and.returnValue({ afterClosed: () => of(DownloadPromptActions.DOWNLOAD) } as any); spyOn(component.downloadFile, 'emit'); fixture.detectChanges(); diff --git a/lib/core/src/lib/viewer/directives/viewer-extension.directive.spec.ts b/lib/core/src/lib/viewer/directives/viewer-extension.directive.spec.ts index 2c034447949..0c6000e6295 100644 --- a/lib/core/src/lib/viewer/directives/viewer-extension.directive.spec.ts +++ b/lib/core/src/lib/viewer/directives/viewer-extension.directive.spec.ts @@ -22,7 +22,6 @@ import { TestBed } from '@angular/core/testing'; import { ViewerRenderComponent } from '../components/viewer-render.component'; import { ViewerExtensionDirective } from './viewer-extension.directive'; import { CoreTestingModule } from '../../testing/core.testing.module'; -import { TranslateModule } from '@ngx-translate/core'; describe('ExtensionViewerDirective', () => { let extensionViewerDirective: ViewerExtensionDirective; @@ -36,10 +35,7 @@ describe('ExtensionViewerDirective', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - CoreTestingModule - ], + imports: [CoreTestingModule], providers: [ { provide: Location, useClass: SpyLocation }, ViewerExtensionDirective, @@ -50,7 +46,7 @@ describe('ExtensionViewerDirective', () => { }); extensionViewerDirective = TestBed.inject(ViewerExtensionDirective); viewerRenderer = TestBed.inject(ViewerRenderComponent); - extensionViewerDirective.templateModel = {template: '', isVisible: false}; + extensionViewerDirective.templateModel = { template: '', isVisible: false }; }); it('is defined', () => { diff --git a/lib/insights/src/lib/analytics-process/components/analytics-generator.component.spec.ts b/lib/insights/src/lib/analytics-process/components/analytics-generator.component.spec.ts index f29ded45df5..b7e5eb71934 100644 --- a/lib/insights/src/lib/analytics-process/components/analytics-generator.component.spec.ts +++ b/lib/insights/src/lib/analytics-process/components/analytics-generator.component.spec.ts @@ -22,7 +22,6 @@ import { ReportQuery } from '../../diagram/models/report/report-query.model'; import * as analyticMock from '../../mock'; import { AnalyticsGeneratorComponent } from '../components/analytics-generator.component'; import { InsightsTestingModule } from '../../testing/insights.testing.module'; -import { TranslateModule } from '@ngx-translate/core'; declare let jasmine: any; @@ -32,7 +31,7 @@ describe('AnalyticsGeneratorComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [TranslateModule.forRoot(), InsightsTestingModule] + imports: [InsightsTestingModule] }); fixture = TestBed.createComponent(AnalyticsGeneratorComponent); component = fixture.componentInstance; diff --git a/lib/insights/src/lib/analytics-process/components/analytics-report-heat-map.component.spec.ts b/lib/insights/src/lib/analytics-process/components/analytics-report-heat-map.component.spec.ts index 0294220f18b..fc8a4928d51 100644 --- a/lib/insights/src/lib/analytics-process/components/analytics-report-heat-map.component.spec.ts +++ b/lib/insights/src/lib/analytics-process/components/analytics-report-heat-map.component.spec.ts @@ -18,12 +18,10 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; import { AnalyticsReportHeatMapComponent } from '../components/analytics-report-heat-map.component'; import { InsightsTestingModule } from '../../testing/insights.testing.module'; -import { TranslateModule } from '@ngx-translate/core'; declare let jasmine: any; describe('AnalyticsReportHeatMapComponent', () => { - let component: AnalyticsReportHeatMapComponent; let fixture: ComponentFixture; let element: HTMLElement; @@ -38,10 +36,7 @@ describe('AnalyticsReportHeatMapComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - InsightsTestingModule - ] + imports: [InsightsTestingModule] }); fixture = TestBed.createComponent(AnalyticsReportHeatMapComponent); component = fixture.componentInstance; @@ -58,7 +53,6 @@ describe('AnalyticsReportHeatMapComponent', () => { }); describe('Rendering tests: Heat Map', () => { - beforeEach(() => { jasmine.Ajax.install(); }); @@ -110,5 +104,5 @@ describe('AnalyticsReportHeatMapComponent', () => { expect(component.currentMetric).toEqual(avgTimeValues); expect(component.currentMetricColors).toEqual(avgTimePercentages); }); - }); + }); }); diff --git a/lib/insights/src/lib/analytics-process/components/analytics-report-list.component.spec.ts b/lib/insights/src/lib/analytics-process/components/analytics-report-list.component.spec.ts index 9b2199b6749..b43c8b23959 100644 --- a/lib/insights/src/lib/analytics-process/components/analytics-report-list.component.spec.ts +++ b/lib/insights/src/lib/analytics-process/components/analytics-report-list.component.spec.ts @@ -19,7 +19,6 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; import { AnalyticsReportListComponent, LAYOUT_GRID, LAYOUT_LIST } from '../components/analytics-report-list.component'; import { ReportParametersModel } from '../../diagram/models/report/report-parameters.model'; import { InsightsTestingModule } from '../../testing/insights.testing.module'; -import { TranslateModule } from '@ngx-translate/core'; declare let jasmine: any; @@ -40,7 +39,7 @@ describe('AnalyticsReportListComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [TranslateModule.forRoot(), InsightsTestingModule] + imports: [InsightsTestingModule] }); fixture = TestBed.createComponent(AnalyticsReportListComponent); component = fixture.componentInstance; diff --git a/lib/insights/src/lib/analytics-process/components/analytics-report-parameters.component.spec.ts b/lib/insights/src/lib/analytics-process/components/analytics-report-parameters.component.spec.ts index f2eef61b738..9e5342d61df 100644 --- a/lib/insights/src/lib/analytics-process/components/analytics-report-parameters.component.spec.ts +++ b/lib/insights/src/lib/analytics-process/components/analytics-report-parameters.component.spec.ts @@ -23,12 +23,10 @@ import { AnalyticsReportParametersComponent, ReportFormValues } from '../compone import { InsightsTestingModule } from '../../testing/insights.testing.module'; import { AnalyticsService } from '../services/analytics.service'; import { of } from 'rxjs'; -import { TranslateModule } from '@ngx-translate/core'; declare let jasmine: any; describe('AnalyticsReportParametersComponent', () => { - let component: AnalyticsReportParametersComponent; let fixture: ComponentFixture; let element: HTMLElement; @@ -37,10 +35,7 @@ describe('AnalyticsReportParametersComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - InsightsTestingModule - ] + imports: [InsightsTestingModule] }); fixture = TestBed.createComponent(AnalyticsReportParametersComponent); service = TestBed.inject(AnalyticsService); @@ -69,7 +64,7 @@ describe('AnalyticsReportParametersComponent', () => { component.successReportParams.emit(fakeReportParam); }); - it('Should render a dropdown with all the status when the definition parameter type is \'status\' ', async () => { + it(`Should render a dropdown with all the status when the definition parameter type is 'status'`, async () => { component.successReportParams.subscribe(() => { fixture.detectChanges(); const dropDown: any = element.querySelector('#select-status'); @@ -84,7 +79,7 @@ describe('AnalyticsReportParametersComponent', () => { const reportId = 1; const change = new SimpleChange(null, reportId, true); - component.ngOnChanges({reportId: change}); + component.ngOnChanges({ reportId: change }); jasmine.Ajax.requests.mostRecent().respondWith({ status: 200, @@ -93,7 +88,7 @@ describe('AnalyticsReportParametersComponent', () => { }); }); - it('Should render a number with the default value when the definition parameter type is \'integer\' ', async () => { + it(`Should render a number with the default value when the definition parameter type is 'integer'`, async () => { component.successReportParams.subscribe(() => { fixture.detectChanges(); const numberElement: any = element.querySelector('#slowProcessInstanceInteger'); @@ -102,7 +97,7 @@ describe('AnalyticsReportParametersComponent', () => { const reportId = 1; const change = new SimpleChange(null, reportId, true); - component.ngOnChanges({reportId: change}); + component.ngOnChanges({ reportId: change }); jasmine.Ajax.requests.mostRecent().respondWith({ status: 200, @@ -130,7 +125,7 @@ describe('AnalyticsReportParametersComponent', () => { const reportId = 1; const change = new SimpleChange(null, reportId, true); - component.ngOnChanges({reportId: change}); + component.ngOnChanges({ reportId: change }); jasmine.Ajax.requests.mostRecent().respondWith({ status: 200, @@ -154,7 +149,8 @@ describe('AnalyticsReportParametersComponent', () => { const values: ReportFormValues = { dateRange: { - startDate: '2016-09-01', endDate: '2016-10-05' + startDate: '2016-09-01', + endDate: '2016-10-05' }, statusGroup: { status: 'All' @@ -182,7 +178,7 @@ describe('AnalyticsReportParametersComponent', () => { component.submit(values); }); - it('Should render a checkbox with the value true when the definition parameter type is \'boolean\' ', async () => { + it(`Should render a checkbox with the value true when the definition parameter type is 'boolean'`, async () => { component.successReportParams.subscribe(() => { fixture.detectChanges(); const checkElement: any = element.querySelector('#typeFiltering-input'); @@ -191,7 +187,7 @@ describe('AnalyticsReportParametersComponent', () => { const reportId = 1; const change = new SimpleChange(null, reportId, true); - component.ngOnChanges({reportId: change}); + component.ngOnChanges({ reportId: change }); jasmine.Ajax.requests.mostRecent().respondWith({ status: 200, @@ -200,7 +196,7 @@ describe('AnalyticsReportParametersComponent', () => { }); }); - it('Should render a date range components when the definition parameter type is \'dateRange\' ', async () => { + it(`Should render a date range components when the definition parameter type is 'dateRange'`, async () => { component.successReportParams.subscribe(() => { const dateElement: any = element.querySelector('adf-date-range-widget'); expect(dateElement).toBeDefined(); @@ -209,7 +205,7 @@ describe('AnalyticsReportParametersComponent', () => { const reportId = 1; const change = new SimpleChange(null, reportId, true); component.toggleParameters(); - component.ngOnChanges({reportId: change}); + component.ngOnChanges({ reportId: change }); jasmine.Ajax.requests.mostRecent().respondWith({ status: 200, @@ -218,7 +214,7 @@ describe('AnalyticsReportParametersComponent', () => { }); }); - it('Should render a dropdown with all the RangeInterval when the definition parameter type is \'dateRangeInterval\' ', async () => { + it(`Should render a dropdown with all the RangeInterval when the definition parameter type is 'dateRangeInterval'`, async () => { component.successReportParams.subscribe(() => { fixture.detectChanges(); const dropDown: any = element.querySelector('#select-dateRangeInterval'); @@ -233,7 +229,7 @@ describe('AnalyticsReportParametersComponent', () => { const reportId = 1; const change = new SimpleChange(null, reportId, true); - component.ngOnChanges({reportId: change}); + component.ngOnChanges({ reportId: change }); jasmine.Ajax.requests.mostRecent().respondWith({ status: 200, @@ -242,70 +238,76 @@ describe('AnalyticsReportParametersComponent', () => { }); }); - it('Should render a dropdown with all the process definition when the definition parameter type is \'processDefinition\' and the' + - ' reportId change', async () => { - component.successParamOpt.subscribe(() => { - fixture.detectChanges(); - const dropDown: any = element.querySelector('#select-processDefinitionId'); - expect(dropDown).toBeDefined(); - expect(dropDown.length).toEqual(5); - expect(dropDown[0].innerHTML).toEqual('Choose One'); - expect(dropDown[1].innerHTML).toEqual('Fake Process Test 1 Name (v 1) '); - expect(dropDown[2].innerHTML).toEqual('Fake Process Test 1 Name (v 2) '); - expect(dropDown[3].innerHTML).toEqual('Fake Process Test 2 Name (v 1) '); - expect(dropDown[4].innerHTML).toEqual('Fake Process Test 3 Name (v 1) '); - }); - - jasmine.Ajax.stubRequest('http://localhost:9876/bpm/activiti-app/app/rest/reporting/report-params/1').andReturn({ - status: 200, - contentType: 'json', - responseText: analyticParamsMock.reportDefParamProcessDef - }); - - jasmine.Ajax.stubRequest('http://localhost:9876/bpm/activiti-app/app/rest/reporting/process-definitions').andReturn({ - status: 200, - contentType: 'json', - responseText: analyticParamsMock.reportDefParamProcessDefOptionsNoApp - }); - - const reportId = 1; - const change = new SimpleChange(null, reportId, true); - component.ngOnChanges({reportId: change}); + it( + `Should render a dropdown with all the process definition when the definition parameter type is 'processDefinition' and the` + + ' reportId change', + async () => { + component.successParamOpt.subscribe(() => { + fixture.detectChanges(); + const dropDown: any = element.querySelector('#select-processDefinitionId'); + expect(dropDown).toBeDefined(); + expect(dropDown.length).toEqual(5); + expect(dropDown[0].innerHTML).toEqual('Choose One'); + expect(dropDown[1].innerHTML).toEqual('Fake Process Test 1 Name (v 1) '); + expect(dropDown[2].innerHTML).toEqual('Fake Process Test 1 Name (v 2) '); + expect(dropDown[3].innerHTML).toEqual('Fake Process Test 2 Name (v 1) '); + expect(dropDown[4].innerHTML).toEqual('Fake Process Test 3 Name (v 1) '); + }); - }); + jasmine.Ajax.stubRequest('http://localhost:9876/bpm/activiti-app/app/rest/reporting/report-params/1').andReturn({ + status: 200, + contentType: 'json', + responseText: analyticParamsMock.reportDefParamProcessDef + }); - it('Should render a dropdown with all the process definition when the definition parameter type is \'processDefinition\' and the' + - ' appId change', async () => { - component.successParamOpt.subscribe(() => { - fixture.detectChanges(); - const dropDown: any = element.querySelector('#select-processDefinitionId'); - expect(dropDown).toBeDefined(); - expect(dropDown.length).toEqual(3); - expect(dropDown[0].innerHTML).toEqual('Choose One'); - expect(dropDown[1].innerHTML).toEqual('Fake Process Test 1 Name (v 1) '); - expect(dropDown[2].innerHTML).toEqual('Fake Process Test 1 Name (v 2) '); - }); + jasmine.Ajax.stubRequest('http://localhost:9876/bpm/activiti-app/app/rest/reporting/process-definitions').andReturn({ + status: 200, + contentType: 'json', + responseText: analyticParamsMock.reportDefParamProcessDefOptionsNoApp + }); - jasmine.Ajax.stubRequest('http://localhost:9876/bpm/activiti-app/app/rest/reporting/report-params/1').andReturn({ - status: 200, - contentType: 'json', - responseText: analyticParamsMock.reportDefParamProcessDef - }); + const reportId = 1; + const change = new SimpleChange(null, reportId, true); + component.ngOnChanges({ reportId: change }); + } + ); + + it( + `Should render a dropdown with all the process definition when the definition parameter type is 'processDefinition' and the` + + ' appId change', + async () => { + component.successParamOpt.subscribe(() => { + fixture.detectChanges(); + const dropDown: any = element.querySelector('#select-processDefinitionId'); + expect(dropDown).toBeDefined(); + expect(dropDown.length).toEqual(3); + expect(dropDown[0].innerHTML).toEqual('Choose One'); + expect(dropDown[1].innerHTML).toEqual('Fake Process Test 1 Name (v 1) '); + expect(dropDown[2].innerHTML).toEqual('Fake Process Test 1 Name (v 2) '); + }); - const appId = 1; + jasmine.Ajax.stubRequest('http://localhost:9876/bpm/activiti-app/app/rest/reporting/report-params/1').andReturn({ + status: 200, + contentType: 'json', + responseText: analyticParamsMock.reportDefParamProcessDef + }); - jasmine.Ajax.stubRequest('http://localhost:9876/bpm/activiti-app/api/enterprise/process-definitions?appDefinitionId=' + appId).andReturn({ - status: 200, - contentType: 'json', - responseText: analyticParamsMock.reportDefParamProcessDefOptionsApp - }); + const appId = 1; - component.appId = appId; - component.reportId = '1'; - const change = new SimpleChange(null, appId, true); - component.ngOnChanges({appId: change}); + jasmine.Ajax.stubRequest( + 'http://localhost:9876/bpm/activiti-app/api/enterprise/process-definitions?appDefinitionId=' + appId + ).andReturn({ + status: 200, + contentType: 'json', + responseText: analyticParamsMock.reportDefParamProcessDefOptionsApp + }); - }); + component.appId = appId; + component.reportId = '1'; + const change = new SimpleChange(null, appId, true); + component.ngOnChanges({ appId: change }); + } + ); it('Should create an empty valid form when there are no parameters definitions', () => { component.success.subscribe(() => { @@ -316,7 +318,7 @@ describe('AnalyticsReportParametersComponent', () => { const reportId = 1; const change = new SimpleChange(null, reportId, true); - component.ngOnChanges({reportId: change}); + component.ngOnChanges({ reportId: change }); jasmine.Ajax.requests.mostRecent().respondWith({ status: 200, @@ -365,8 +367,7 @@ describe('AnalyticsReportParametersComponent', () => { const reportId = 1; const change = new SimpleChange(null, reportId, true); - component.ngOnChanges({reportId: change}); - + component.ngOnChanges({ reportId: change }); }); it('Should emit an error with a 404 response when the report parameters response is not found', async () => { @@ -376,7 +377,7 @@ describe('AnalyticsReportParametersComponent', () => { const reportId = 1; const change = new SimpleChange(null, reportId, true); - component.ngOnChanges({reportId: change}); + component.ngOnChanges({ reportId: change }); jasmine.Ajax.requests.mostRecent().respondWith({ status: 404, @@ -391,11 +392,10 @@ describe('AnalyticsReportParametersComponent', () => { }); describe('When the form is rendered correctly', () => { - beforeEach(async () => { const reportId = 1; const change = new SimpleChange(null, reportId, true); - component.ngOnChanges({reportId: change}); + component.ngOnChanges({ reportId: change }); fixture.detectChanges(); jasmine.Ajax.requests.mostRecent().respondWith({ @@ -478,7 +478,6 @@ describe('AnalyticsReportParametersComponent', () => { expect(exportButton).toBeNull(); }); }); - })); it('Should hide save button if the form is not valid', fakeAsync(() => { diff --git a/lib/insights/src/lib/analytics-process/components/analytics-report-parameters.component.ts b/lib/insights/src/lib/analytics-process/components/analytics-report-parameters.component.ts index e7f1415da99..3f316f59bc7 100644 --- a/lib/insights/src/lib/analytics-process/components/analytics-report-parameters.component.ts +++ b/lib/insights/src/lib/analytics-process/components/analytics-report-parameters.component.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { AdfDateFnsAdapter, DownloadService, LogService } from '@alfresco/adf-core'; +import { AdfDateFnsAdapter, DownloadService } from '@alfresco/adf-core'; import { AfterContentChecked, Component, @@ -160,7 +160,6 @@ export class AnalyticsReportParametersComponent implements OnInit, OnChanges, On constructor( private analyticsService: AnalyticsService, private formBuilder: FormBuilder, - private logService: LogService, private downloadService: DownloadService, private dialog: MatDialog, private dateAdapter: AdfDateFnsAdapter @@ -351,12 +350,9 @@ export class AnalyticsReportParametersComponent implements OnInit, OnChanges, On } deleteReport(reportId: string) { - this.analyticsService.deleteReport(reportId).subscribe( - () => { - this.deleteReportSuccess.emit(reportId); - }, - (error) => this.logService.error(error) - ); + this.analyticsService.deleteReport(reportId).subscribe(() => { + this.deleteReportSuccess.emit(reportId); + }); } ngAfterContentChecked() { diff --git a/lib/insights/src/lib/analytics-process/components/widgets/date-range/date-range.widget.spec.ts b/lib/insights/src/lib/analytics-process/components/widgets/date-range/date-range.widget.spec.ts index 1b2a848a43f..555a46db97c 100644 --- a/lib/insights/src/lib/analytics-process/components/widgets/date-range/date-range.widget.spec.ts +++ b/lib/insights/src/lib/analytics-process/components/widgets/date-range/date-range.widget.spec.ts @@ -17,7 +17,6 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; import { DateRangeWidgetComponent } from './date-range.widget'; -import { TranslateModule } from '@ngx-translate/core'; import { InsightsTestingModule } from '../../../../testing/insights.testing.module'; import { ReportParameterDetailsModel } from '../../../../diagram/models/report/report-parameter-details.model'; import { format } from 'date-fns'; @@ -28,10 +27,7 @@ describe('DateRangeWidgetComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - InsightsTestingModule - ] + imports: [InsightsTestingModule] }); fixture = TestBed.createComponent(DateRangeWidgetComponent); @@ -71,7 +67,7 @@ describe('DateRangeWidgetComponent', () => { expect(widget.dateRange.valid).toBeTrue(); let emitted: { startDate: string; endDate: string }; - widget.dateRangeChanged.subscribe((value) => emitted = value); + widget.dateRangeChanged.subscribe((value) => (emitted = value)); widget.onGroupValueChanged(); diff --git a/lib/insights/src/lib/diagram/components/diagram.component.activities.spec.ts b/lib/insights/src/lib/diagram/components/diagram.component.activities.spec.ts index 7adb7313f9e..bb7703d26d7 100644 --- a/lib/insights/src/lib/diagram/components/diagram.component.activities.spec.ts +++ b/lib/insights/src/lib/diagram/components/diagram.component.activities.spec.ts @@ -20,22 +20,17 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; import * as diagramsActivitiesMock from '../../mock/diagram/diagram-activities.mock'; import { DiagramComponent } from './diagram.component'; import { InsightsTestingModule } from '../../testing/insights.testing.module'; -import { TranslateModule } from '@ngx-translate/core'; declare let jasmine: any; describe('Diagrams activities', () => { - let component: any; let fixture: ComponentFixture; let element: HTMLElement; beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - InsightsTestingModule - ] + imports: [InsightsTestingModule] }); fixture = TestBed.createComponent(DiagramComponent); component = fixture.componentInstance; @@ -57,7 +52,7 @@ describe('Diagrams activities', () => { jasmine.Ajax.uninstall(); }); - const ajaxReply = (resp: any) => { + const ajaxReply = (resp: any) => { jasmine.Ajax.requests.mostRecent().respondWith({ status: 200, contentType: 'json', @@ -66,7 +61,6 @@ describe('Diagrams activities', () => { }; describe('Diagrams component Activities: ', () => { - it('Should render the User Task', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); @@ -203,8 +197,9 @@ describe('Diagrams activities', () => { expect(taskText).not.toBeNull(); expect(taskText.attributes.getNamedItem('ng-reflect-text').value).toEqual('Fake Alfresco Publish task'); - const iconTask: any = element.querySelector('adf-diagram-publish-task > diagram-icon-alfresco-publish-task >' + - ' raphael-icon-alfresco-publish'); + const iconTask: any = element.querySelector( + 'adf-diagram-publish-task > diagram-icon-alfresco-publish-task >' + ' raphael-icon-alfresco-publish' + ); expect(iconTask).not.toBeNull(); const tooltip: any = element.querySelector('diagram-tooltip > div'); @@ -230,8 +225,9 @@ describe('Diagrams activities', () => { expect(taskText).not.toBeNull(); expect(taskText.attributes.getNamedItem('ng-reflect-text').value).toEqual('Fake Google Drive Publish task'); - const iconTask: any = element.querySelector('diagram-google-drive-publish-task >' + - ' diagram-icon-google-drive-publish-task > raphael-icon-google-drive-publish'); + const iconTask: any = element.querySelector( + 'diagram-google-drive-publish-task >' + ' diagram-icon-google-drive-publish-task > raphael-icon-google-drive-publish' + ); expect(iconTask).not.toBeNull(); const tooltip: any = element.querySelector('diagram-tooltip > div'); @@ -257,8 +253,7 @@ describe('Diagrams activities', () => { expect(taskText).not.toBeNull(); expect(taskText.attributes.getNamedItem('ng-reflect-text').value).toEqual('Fake Rest Call task'); - const iconTask: any = element.querySelector('diagram-rest-call-task > diagram-icon-rest-call-task >' + - ' raphael-icon-rest-call'); + const iconTask: any = element.querySelector('diagram-rest-call-task > diagram-icon-rest-call-task >' + ' raphael-icon-rest-call'); expect(iconTask).not.toBeNull(); const tooltip: any = element.querySelector('diagram-tooltip > div'); @@ -284,8 +279,9 @@ describe('Diagrams activities', () => { expect(taskText).not.toBeNull(); expect(taskText.attributes.getNamedItem('ng-reflect-text').value).toEqual('Fake Box Publish task'); - const iconTask: any = element.querySelector('diagram-box-publish-task >' + - ' diagram-icon-box-publish-task > raphael-icon-box-publish'); + const iconTask: any = element.querySelector( + 'diagram-box-publish-task >' + ' diagram-icon-box-publish-task > raphael-icon-box-publish' + ); expect(iconTask).not.toBeNull(); const tooltip: any = element.querySelector('diagram-tooltip > div'); @@ -363,7 +359,9 @@ describe('Diagrams activities', () => { expect(taskText).not.toBeNull(); expect(taskText.attributes.getNamedItem('ng-reflect-text').value).toEqual('Fake BusinessRule task'); - const iconTask: any = element.querySelector('diagram-business-rule-task > diagram-icon-business-rule-task > raphael-icon-business-rule'); + const iconTask: any = element.querySelector( + 'diagram-business-rule-task > diagram-icon-business-rule-task > raphael-icon-business-rule' + ); expect(iconTask).not.toBeNull(); const tooltip: any = element.querySelector('diagram-tooltip > div'); @@ -376,10 +374,9 @@ describe('Diagrams activities', () => { const resp = { elements: [diagramsActivitiesMock.businessRuleTask] }; ajaxReply(resp); }); - }); + }); describe('Diagrams component Activities with process instance id: ', () => { - it('Should render the User Task', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); @@ -772,8 +769,9 @@ describe('Diagrams activities', () => { expect(taskText).not.toBeNull(); expect(taskText.attributes.getNamedItem('ng-reflect-text').value).toEqual('Fake Alfresco Publish task'); - const iconTask: any = element.querySelector('adf-diagram-publish-task > diagram-icon-alfresco-publish-task >' + - ' raphael-icon-alfresco-publish'); + const iconTask: any = element.querySelector( + 'adf-diagram-publish-task > diagram-icon-alfresco-publish-task >' + ' raphael-icon-alfresco-publish' + ); expect(iconTask).not.toBeNull(); const tooltip: any = element.querySelector('diagram-tooltip > div'); @@ -799,8 +797,9 @@ describe('Diagrams activities', () => { expect(taskText).not.toBeNull(); expect(taskText.attributes.getNamedItem('ng-reflect-text').value).toEqual('Fake Alfresco Publish task'); - const iconTask: any = element.querySelector('adf-diagram-publish-task > diagram-icon-alfresco-publish-task >' + - ' raphael-icon-alfresco-publish'); + const iconTask: any = element.querySelector( + 'adf-diagram-publish-task > diagram-icon-alfresco-publish-task >' + ' raphael-icon-alfresco-publish' + ); expect(iconTask).not.toBeNull(); const tooltip: any = element.querySelector('diagram-tooltip > div'); @@ -826,8 +825,9 @@ describe('Diagrams activities', () => { expect(taskText).not.toBeNull(); expect(taskText.attributes.getNamedItem('ng-reflect-text').value).toEqual('Fake Alfresco Publish task'); - const iconTask: any = element.querySelector('adf-diagram-publish-task > diagram-icon-alfresco-publish-task >' + - ' raphael-icon-alfresco-publish'); + const iconTask: any = element.querySelector( + 'adf-diagram-publish-task > diagram-icon-alfresco-publish-task >' + ' raphael-icon-alfresco-publish' + ); expect(iconTask).not.toBeNull(); const tooltip: any = element.querySelector('diagram-tooltip > div'); @@ -853,8 +853,9 @@ describe('Diagrams activities', () => { expect(taskText).not.toBeNull(); expect(taskText.attributes.getNamedItem('ng-reflect-text').value).toEqual('Fake Google Drive Publish task'); - const iconTask: any = element.querySelector('diagram-google-drive-publish-task >' + - ' diagram-icon-google-drive-publish-task > raphael-icon-google-drive-publish'); + const iconTask: any = element.querySelector( + 'diagram-google-drive-publish-task >' + ' diagram-icon-google-drive-publish-task > raphael-icon-google-drive-publish' + ); expect(iconTask).not.toBeNull(); const tooltip: any = element.querySelector('diagram-tooltip > div'); @@ -873,15 +874,18 @@ describe('Diagrams activities', () => { fixture.detectChanges(); fixture.whenStable().then(() => { expect(res).not.toBeNull(); - const task: any = element.querySelector('diagram-google-drive-publish-task > diagram-task > raphael-rect[ng-reflect-stroke="#017501"]'); + const task: any = element.querySelector( + 'diagram-google-drive-publish-task > diagram-task > raphael-rect[ng-reflect-stroke="#017501"]' + ); expect(task).not.toBeNull(); const taskText: any = element.querySelector('diagram-google-drive-publish-task > diagram-task > raphael-multiline-text'); expect(taskText).not.toBeNull(); expect(taskText.attributes.getNamedItem('ng-reflect-text').value).toEqual('Fake Google Drive Publish task'); - const iconTask: any = element.querySelector('diagram-google-drive-publish-task >' + - ' diagram-icon-google-drive-publish-task > raphael-icon-google-drive-publish'); + const iconTask: any = element.querySelector( + 'diagram-google-drive-publish-task >' + ' diagram-icon-google-drive-publish-task > raphael-icon-google-drive-publish' + ); expect(iconTask).not.toBeNull(); const tooltip: any = element.querySelector('diagram-tooltip > div'); @@ -900,15 +904,18 @@ describe('Diagrams activities', () => { fixture.detectChanges(); fixture.whenStable().then(() => { expect(res).not.toBeNull(); - const task: any = element.querySelector('diagram-google-drive-publish-task > diagram-task > raphael-rect[ng-reflect-stroke="#2632aa"]'); + const task: any = element.querySelector( + 'diagram-google-drive-publish-task > diagram-task > raphael-rect[ng-reflect-stroke="#2632aa"]' + ); expect(task).not.toBeNull(); const taskText: any = element.querySelector('diagram-google-drive-publish-task > diagram-task > raphael-multiline-text'); expect(taskText).not.toBeNull(); expect(taskText.attributes.getNamedItem('ng-reflect-text').value).toEqual('Fake Google Drive Publish task'); - const iconTask: any = element.querySelector('diagram-google-drive-publish-task >' + - ' diagram-icon-google-drive-publish-task > raphael-icon-google-drive-publish'); + const iconTask: any = element.querySelector( + 'diagram-google-drive-publish-task >' + ' diagram-icon-google-drive-publish-task > raphael-icon-google-drive-publish' + ); expect(iconTask).not.toBeNull(); const tooltip: any = element.querySelector('diagram-tooltip > div'); @@ -934,8 +941,7 @@ describe('Diagrams activities', () => { expect(taskText).not.toBeNull(); expect(taskText.attributes.getNamedItem('ng-reflect-text').value).toEqual('Fake Rest Call task'); - const iconTask: any = element.querySelector('diagram-rest-call-task > diagram-icon-rest-call-task >' + - ' raphael-icon-rest-call'); + const iconTask: any = element.querySelector('diagram-rest-call-task > diagram-icon-rest-call-task >' + ' raphael-icon-rest-call'); expect(iconTask).not.toBeNull(); const tooltip: any = element.querySelector('diagram-tooltip > div'); @@ -961,8 +967,7 @@ describe('Diagrams activities', () => { expect(taskText).not.toBeNull(); expect(taskText.attributes.getNamedItem('ng-reflect-text').value).toEqual('Fake Rest Call task'); - const iconTask: any = element.querySelector('diagram-rest-call-task > diagram-icon-rest-call-task >' + - ' raphael-icon-rest-call'); + const iconTask: any = element.querySelector('diagram-rest-call-task > diagram-icon-rest-call-task >' + ' raphael-icon-rest-call'); expect(iconTask).not.toBeNull(); const tooltip: any = element.querySelector('diagram-tooltip > div'); @@ -988,8 +993,7 @@ describe('Diagrams activities', () => { expect(taskText).not.toBeNull(); expect(taskText.attributes.getNamedItem('ng-reflect-text').value).toEqual('Fake Rest Call task'); - const iconTask: any = element.querySelector('diagram-rest-call-task > diagram-icon-rest-call-task >' + - ' raphael-icon-rest-call'); + const iconTask: any = element.querySelector('diagram-rest-call-task > diagram-icon-rest-call-task >' + ' raphael-icon-rest-call'); expect(iconTask).not.toBeNull(); const tooltip: any = element.querySelector('diagram-tooltip > div'); @@ -1015,8 +1019,9 @@ describe('Diagrams activities', () => { expect(taskText).not.toBeNull(); expect(taskText.attributes.getNamedItem('ng-reflect-text').value).toEqual('Fake Box Publish task'); - const iconTask: any = element.querySelector('diagram-box-publish-task >' + - ' diagram-icon-box-publish-task > raphael-icon-box-publish'); + const iconTask: any = element.querySelector( + 'diagram-box-publish-task >' + ' diagram-icon-box-publish-task > raphael-icon-box-publish' + ); expect(iconTask).not.toBeNull(); const tooltip: any = element.querySelector('diagram-tooltip > div'); @@ -1042,8 +1047,9 @@ describe('Diagrams activities', () => { expect(taskText).not.toBeNull(); expect(taskText.attributes.getNamedItem('ng-reflect-text').value).toEqual('Fake Box Publish task'); - const iconTask: any = element.querySelector('diagram-box-publish-task >' + - ' diagram-icon-box-publish-task > raphael-icon-box-publish'); + const iconTask: any = element.querySelector( + 'diagram-box-publish-task >' + ' diagram-icon-box-publish-task > raphael-icon-box-publish' + ); expect(iconTask).not.toBeNull(); const tooltip: any = element.querySelector('diagram-tooltip > div'); @@ -1069,8 +1075,9 @@ describe('Diagrams activities', () => { expect(taskText).not.toBeNull(); expect(taskText.attributes.getNamedItem('ng-reflect-text').value).toEqual('Fake Box Publish task'); - const iconTask: any = element.querySelector('diagram-box-publish-task >' + - ' diagram-icon-box-publish-task > raphael-icon-box-publish'); + const iconTask: any = element.querySelector( + 'diagram-box-publish-task >' + ' diagram-icon-box-publish-task > raphael-icon-box-publish' + ); expect(iconTask).not.toBeNull(); const tooltip: any = element.querySelector('diagram-tooltip > div'); @@ -1252,7 +1259,9 @@ describe('Diagrams activities', () => { expect(taskText).not.toBeNull(); expect(taskText.attributes.getNamedItem('ng-reflect-text').value).toEqual('Fake BusinessRule task'); - const iconTask: any = element.querySelector('diagram-business-rule-task > diagram-icon-business-rule-task > raphael-icon-business-rule'); + const iconTask: any = element.querySelector( + 'diagram-business-rule-task > diagram-icon-business-rule-task > raphael-icon-business-rule' + ); expect(iconTask).not.toBeNull(); const tooltip: any = element.querySelector('diagram-tooltip > div'); @@ -1278,7 +1287,9 @@ describe('Diagrams activities', () => { expect(taskText).not.toBeNull(); expect(taskText.attributes.getNamedItem('ng-reflect-text').value).toEqual('Fake BusinessRule task'); - const iconTask: any = element.querySelector('diagram-business-rule-task > diagram-icon-business-rule-task > raphael-icon-business-rule'); + const iconTask: any = element.querySelector( + 'diagram-business-rule-task > diagram-icon-business-rule-task > raphael-icon-business-rule' + ); expect(iconTask).not.toBeNull(); const tooltip: any = element.querySelector('diagram-tooltip > div'); @@ -1304,7 +1315,9 @@ describe('Diagrams activities', () => { expect(taskText).not.toBeNull(); expect(taskText.attributes.getNamedItem('ng-reflect-text').value).toEqual('Fake BusinessRule task'); - const iconTask: any = element.querySelector('diagram-business-rule-task > diagram-icon-business-rule-task > raphael-icon-business-rule'); + const iconTask: any = element.querySelector( + 'diagram-business-rule-task > diagram-icon-business-rule-task > raphael-icon-business-rule' + ); expect(iconTask).not.toBeNull(); const tooltip: any = element.querySelector('diagram-tooltip > div'); @@ -1317,5 +1330,5 @@ describe('Diagrams activities', () => { const resp = { elements: [diagramsActivitiesMock.businessRuleTaskCompleted] }; ajaxReply(resp); }); - }); + }); }); diff --git a/lib/insights/src/lib/diagram/components/diagram.component.boundary.spec.ts b/lib/insights/src/lib/diagram/components/diagram.component.boundary.spec.ts index 0f34e6188a1..2f22fa4499b 100644 --- a/lib/insights/src/lib/diagram/components/diagram.component.boundary.spec.ts +++ b/lib/insights/src/lib/diagram/components/diagram.component.boundary.spec.ts @@ -20,22 +20,17 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; import * as boundaryEventMock from '../../mock/diagram/diagram-boundary.mock'; import { DiagramComponent } from './diagram.component'; import { InsightsTestingModule } from '../../testing/insights.testing.module'; -import { TranslateModule } from '@ngx-translate/core'; declare let jasmine: any; describe('Diagrams boundary', () => { - let component: any; let fixture: ComponentFixture; let element: HTMLElement; beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - InsightsTestingModule - ] + imports: [InsightsTestingModule] }); fixture = TestBed.createComponent(DiagramComponent); component = fixture.componentInstance; @@ -53,7 +48,7 @@ describe('Diagrams boundary', () => { jasmine.Ajax.uninstall(); }); - const ajaxReply = (resp: any) => { + const ajaxReply = (resp: any) => { jasmine.Ajax.requests.mostRecent().respondWith({ status: 200, contentType: 'json', @@ -62,7 +57,6 @@ describe('Diagrams boundary', () => { }; describe('Diagrams component Boundary events with process instance id: ', () => { - it('Should render the Boundary time event', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); @@ -78,8 +72,9 @@ describe('Diagrams boundary', () => { const innerCircle = shape.children[1]; expect(innerCircle.localName).toEqual('raphael-circle'); - const iconShape: any = element.querySelector('diagram-boundary-event > diagram-container-icon-event >' + - ' div > div > diagram-icon-timer'); + const iconShape: any = element.querySelector( + 'diagram-boundary-event > diagram-container-icon-event >' + ' div > div > diagram-icon-timer' + ); expect(iconShape).not.toBeNull(); const tooltip: any = element.querySelector('diagram-tooltip > div'); @@ -112,8 +107,9 @@ describe('Diagrams boundary', () => { const innerCircle = shape.children[1]; expect(innerCircle.localName).toEqual('raphael-circle'); - const iconShape: any = element.querySelector('diagram-boundary-event > diagram-container-icon-event >' + - ' div > div > diagram-icon-timer'); + const iconShape: any = element.querySelector( + 'diagram-boundary-event > diagram-container-icon-event >' + ' div > div > diagram-icon-timer' + ); expect(iconShape).not.toBeNull(); const tooltip: any = element.querySelector('diagram-tooltip > div'); @@ -146,8 +142,9 @@ describe('Diagrams boundary', () => { const innerCircle = shape.children[1]; expect(innerCircle.localName).toEqual('raphael-circle'); - const iconShape: any = element.querySelector('diagram-boundary-event > diagram-container-icon-event >' + - ' div > div > diagram-icon-timer'); + const iconShape: any = element.querySelector( + 'diagram-boundary-event > diagram-container-icon-event >' + ' div > div > diagram-icon-timer' + ); expect(iconShape).not.toBeNull(); const tooltip: any = element.querySelector('diagram-tooltip > div'); @@ -176,8 +173,9 @@ describe('Diagrams boundary', () => { const innerCircle = shape.children[1]; expect(innerCircle.localName).toEqual('raphael-circle'); - const iconShape: any = element.querySelector('diagram-boundary-event > diagram-container-icon-event >' + - ' div > div > diagram-icon-error'); + const iconShape: any = element.querySelector( + 'diagram-boundary-event > diagram-container-icon-event >' + ' div > div > diagram-icon-error' + ); expect(iconShape).not.toBeNull(); const tooltip: any = element.querySelector('diagram-tooltip > div'); @@ -210,8 +208,9 @@ describe('Diagrams boundary', () => { const innerCircle = shape.children[1]; expect(innerCircle.localName).toEqual('raphael-circle'); - const iconShape: any = element.querySelector('diagram-boundary-event > diagram-container-icon-event >' + - ' div > div > diagram-icon-error'); + const iconShape: any = element.querySelector( + 'diagram-boundary-event > diagram-container-icon-event >' + ' div > div > diagram-icon-error' + ); expect(iconShape).not.toBeNull(); const tooltip: any = element.querySelector('diagram-tooltip > div'); @@ -244,8 +243,9 @@ describe('Diagrams boundary', () => { const innerCircle = shape.children[1]; expect(innerCircle.localName).toEqual('raphael-circle'); - const iconShape: any = element.querySelector('diagram-boundary-event > diagram-container-icon-event >' + - ' div > div > diagram-icon-error'); + const iconShape: any = element.querySelector( + 'diagram-boundary-event > diagram-container-icon-event >' + ' div > div > diagram-icon-error' + ); expect(iconShape).not.toBeNull(); const tooltip: any = element.querySelector('diagram-tooltip > div'); @@ -274,8 +274,9 @@ describe('Diagrams boundary', () => { const innerCircle = shape.children[1]; expect(innerCircle.localName).toEqual('raphael-circle'); - const iconShape: any = element.querySelector('diagram-boundary-event > diagram-container-icon-event >' + - ' div > div > diagram-icon-signal'); + const iconShape: any = element.querySelector( + 'diagram-boundary-event > diagram-container-icon-event >' + ' div > div > diagram-icon-signal' + ); expect(iconShape).not.toBeNull(); const tooltip: any = element.querySelector('diagram-tooltip > div'); @@ -308,8 +309,9 @@ describe('Diagrams boundary', () => { const innerCircle = shape.children[1]; expect(innerCircle.localName).toEqual('raphael-circle'); - const iconShape: any = element.querySelector('diagram-boundary-event > diagram-container-icon-event >' + - ' div > div > diagram-icon-signal'); + const iconShape: any = element.querySelector( + 'diagram-boundary-event > diagram-container-icon-event >' + ' div > div > diagram-icon-signal' + ); expect(iconShape).not.toBeNull(); const tooltip: any = element.querySelector('diagram-tooltip > div'); @@ -342,8 +344,9 @@ describe('Diagrams boundary', () => { const innerCircle = shape.children[1]; expect(innerCircle.localName).toEqual('raphael-circle'); - const iconShape: any = element.querySelector('diagram-boundary-event > diagram-container-icon-event >' + - ' div > div > diagram-icon-signal'); + const iconShape: any = element.querySelector( + 'diagram-boundary-event > diagram-container-icon-event >' + ' div > div > diagram-icon-signal' + ); expect(iconShape).not.toBeNull(); const tooltip: any = element.querySelector('diagram-tooltip > div'); @@ -372,8 +375,9 @@ describe('Diagrams boundary', () => { const innerCircle = shape.children[1]; expect(innerCircle.localName).toEqual('raphael-circle'); - const iconShape: any = element.querySelector('diagram-boundary-event > diagram-container-icon-event >' + - ' div > div > diagram-icon-message'); + const iconShape: any = element.querySelector( + 'diagram-boundary-event > diagram-container-icon-event >' + ' div > div > diagram-icon-message' + ); expect(iconShape).not.toBeNull(); const tooltip: any = element.querySelector('diagram-tooltip > div'); @@ -406,8 +410,9 @@ describe('Diagrams boundary', () => { const innerCircle = shape.children[1]; expect(innerCircle.localName).toEqual('raphael-circle'); - const iconShape: any = element.querySelector('diagram-boundary-event > diagram-container-icon-event >' + - ' div > div > diagram-icon-message'); + const iconShape: any = element.querySelector( + 'diagram-boundary-event > diagram-container-icon-event >' + ' div > div > diagram-icon-message' + ); expect(iconShape).not.toBeNull(); const tooltip: any = element.querySelector('diagram-tooltip > div'); @@ -440,8 +445,9 @@ describe('Diagrams boundary', () => { const innerCircle = shape.children[1]; expect(innerCircle.localName).toEqual('raphael-circle'); - const iconShape: any = element.querySelector('diagram-boundary-event > diagram-container-icon-event >' + - ' div > div > diagram-icon-message'); + const iconShape: any = element.querySelector( + 'diagram-boundary-event > diagram-container-icon-event >' + ' div > div > diagram-icon-message' + ); expect(iconShape).not.toBeNull(); const tooltip: any = element.querySelector('diagram-tooltip > div'); @@ -470,8 +476,9 @@ describe('Diagrams boundary', () => { const innerCircle = shape.children[1]; expect(innerCircle.localName).toEqual('raphael-circle'); - const iconShape: any = element.querySelector('diagram-boundary-event > diagram-container-icon-event >' + - ' div > div > diagram-icon-message'); + const iconShape: any = element.querySelector( + 'diagram-boundary-event > diagram-container-icon-event >' + ' div > div > diagram-icon-message' + ); expect(iconShape).not.toBeNull(); const tooltip: any = element.querySelector('diagram-tooltip > div'); @@ -504,8 +511,9 @@ describe('Diagrams boundary', () => { const innerCircle = shape.children[1]; expect(innerCircle.localName).toEqual('raphael-circle'); - const iconShape: any = element.querySelector('diagram-boundary-event > diagram-container-icon-event >' + - ' div > div > diagram-icon-message'); + const iconShape: any = element.querySelector( + 'diagram-boundary-event > diagram-container-icon-event >' + ' div > div > diagram-icon-message' + ); expect(iconShape).not.toBeNull(); const tooltip: any = element.querySelector('diagram-tooltip > div'); @@ -538,8 +546,9 @@ describe('Diagrams boundary', () => { const innerCircle = shape.children[1]; expect(innerCircle.localName).toEqual('raphael-circle'); - const iconShape: any = element.querySelector('diagram-boundary-event > diagram-container-icon-event >' + - ' div > div > diagram-icon-message'); + const iconShape: any = element.querySelector( + 'diagram-boundary-event > diagram-container-icon-event >' + ' div > div > diagram-icon-message' + ); expect(iconShape).not.toBeNull(); const tooltip: any = element.querySelector('diagram-tooltip > div'); @@ -555,7 +564,6 @@ describe('Diagrams boundary', () => { }); describe('Diagrams component Boundary events: ', () => { - it('Should render the Boundary time event', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); @@ -571,8 +579,9 @@ describe('Diagrams boundary', () => { const innerCircle = shape.children[1]; expect(innerCircle.localName).toEqual('raphael-circle'); - const iconShape: any = element.querySelector('diagram-boundary-event > diagram-container-icon-event >' + - ' div > div > diagram-icon-timer'); + const iconShape: any = element.querySelector( + 'diagram-boundary-event > diagram-container-icon-event >' + ' div > div > diagram-icon-timer' + ); expect(iconShape).not.toBeNull(); const tooltip: any = element.querySelector('diagram-tooltip > div'); @@ -601,8 +610,9 @@ describe('Diagrams boundary', () => { const innerCircle = shape.children[1]; expect(innerCircle.localName).toEqual('raphael-circle'); - const iconShape: any = element.querySelector('diagram-boundary-event > diagram-container-icon-event >' + - ' div > div > diagram-icon-error'); + const iconShape: any = element.querySelector( + 'diagram-boundary-event > diagram-container-icon-event >' + ' div > div > diagram-icon-error' + ); expect(iconShape).not.toBeNull(); const tooltip: any = element.querySelector('diagram-tooltip > div'); @@ -631,8 +641,9 @@ describe('Diagrams boundary', () => { const innerCircle = shape.children[1]; expect(innerCircle.localName).toEqual('raphael-circle'); - const iconShape: any = element.querySelector('diagram-boundary-event > diagram-container-icon-event >' + - ' div > div > diagram-icon-signal'); + const iconShape: any = element.querySelector( + 'diagram-boundary-event > diagram-container-icon-event >' + ' div > div > diagram-icon-signal' + ); expect(iconShape).not.toBeNull(); const tooltip: any = element.querySelector('diagram-tooltip > div'); @@ -661,8 +672,9 @@ describe('Diagrams boundary', () => { const innerCircle = shape.children[1]; expect(innerCircle.localName).toEqual('raphael-circle'); - const iconShape: any = element.querySelector('diagram-boundary-event > diagram-container-icon-event >' + - ' div > div > diagram-icon-message'); + const iconShape: any = element.querySelector( + 'diagram-boundary-event > diagram-container-icon-event >' + ' div > div > diagram-icon-message' + ); expect(iconShape).not.toBeNull(); const tooltip: any = element.querySelector('diagram-tooltip > div'); @@ -691,8 +703,9 @@ describe('Diagrams boundary', () => { const innerCircle = shape.children[1]; expect(innerCircle.localName).toEqual('raphael-circle'); - const iconShape: any = element.querySelector('diagram-boundary-event > diagram-container-icon-event >' + - ' div > div > diagram-icon-message'); + const iconShape: any = element.querySelector( + 'diagram-boundary-event > diagram-container-icon-event >' + ' div > div > diagram-icon-message' + ); expect(iconShape).not.toBeNull(); const tooltip: any = element.querySelector('diagram-tooltip > div'); diff --git a/lib/insights/src/lib/diagram/components/diagram.component.catching.events.spec.ts b/lib/insights/src/lib/diagram/components/diagram.component.catching.events.spec.ts index a211c978b3b..22330f760ae 100644 --- a/lib/insights/src/lib/diagram/components/diagram.component.catching.events.spec.ts +++ b/lib/insights/src/lib/diagram/components/diagram.component.catching.events.spec.ts @@ -20,22 +20,17 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; import * as intermediateCatchingMock from '../../mock/diagram/diagram-intermediate.mock'; import { DiagramComponent } from './diagram.component'; import { InsightsTestingModule } from '../../testing/insights.testing.module'; -import { TranslateModule } from '@ngx-translate/core'; declare let jasmine: any; describe('Diagrams Catching', () => { - let component: any; let fixture: ComponentFixture; let element: HTMLElement; beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - InsightsTestingModule - ] + imports: [InsightsTestingModule] }); fixture = TestBed.createComponent(DiagramComponent); component = fixture.componentInstance; @@ -56,7 +51,7 @@ describe('Diagrams Catching', () => { jasmine.Ajax.uninstall(); }); - const ajaxReply = (resp: any) => { + const ajaxReply = (resp: any) => { jasmine.Ajax.requests.mostRecent().respondWith({ status: 200, contentType: 'json', @@ -65,7 +60,6 @@ describe('Diagrams Catching', () => { }; describe('Diagrams component Intermediate Catching events: ', () => { - it('Should render the Intermediate catching time event', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); @@ -81,8 +75,9 @@ describe('Diagrams Catching', () => { const innerCircle = shape.children[1]; expect(innerCircle.localName).toEqual('raphael-circle'); - const iconShape: any = element.querySelector('diagram-intermediate-catching-event > diagram-container-icon-event >' + - ' div > div > diagram-icon-timer'); + const iconShape: any = element.querySelector( + 'diagram-intermediate-catching-event > diagram-container-icon-event >' + ' div > div > diagram-icon-timer' + ); expect(iconShape).not.toBeNull(); const tooltip: any = element.querySelector('diagram-tooltip > div'); @@ -111,8 +106,9 @@ describe('Diagrams Catching', () => { const innerCircle = shape.children[1]; expect(innerCircle.localName).toEqual('raphael-circle'); - const iconShape: any = element.querySelector('diagram-intermediate-catching-event > diagram-container-icon-event >' + - ' div > div > diagram-icon-error'); + const iconShape: any = element.querySelector( + 'diagram-intermediate-catching-event > diagram-container-icon-event >' + ' div > div > diagram-icon-error' + ); expect(iconShape).not.toBeNull(); const tooltip: any = element.querySelector('diagram-tooltip > div'); @@ -141,8 +137,9 @@ describe('Diagrams Catching', () => { const innerCircle = shape.children[1]; expect(innerCircle.localName).toEqual('raphael-circle'); - const iconShape: any = element.querySelector('diagram-intermediate-catching-event > diagram-container-icon-event >' + - ' div > div > diagram-icon-signal'); + const iconShape: any = element.querySelector( + 'diagram-intermediate-catching-event > diagram-container-icon-event >' + ' div > div > diagram-icon-signal' + ); expect(iconShape).not.toBeNull(); const tooltip: any = element.querySelector('diagram-tooltip > div'); @@ -171,8 +168,9 @@ describe('Diagrams Catching', () => { const innerCircle = shape.children[1]; expect(innerCircle.localName).toEqual('raphael-circle'); - const iconShape: any = element.querySelector('diagram-intermediate-catching-event > diagram-container-icon-event >' + - ' div > div > diagram-icon-message'); + const iconShape: any = element.querySelector( + 'diagram-intermediate-catching-event > diagram-container-icon-event >' + ' div > div > diagram-icon-message' + ); expect(iconShape).not.toBeNull(); const tooltip: any = element.querySelector('diagram-tooltip > div'); @@ -188,7 +186,6 @@ describe('Diagrams Catching', () => { }); describe('Diagrams component Intermediate Catching events with process instance id: ', () => { - it('Should render the Intermediate catching time event', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); @@ -204,8 +201,9 @@ describe('Diagrams Catching', () => { const innerCircle = shape.children[1]; expect(innerCircle.localName).toEqual('raphael-circle'); - const iconShape: any = element.querySelector('diagram-intermediate-catching-event > diagram-container-icon-event >' + - ' div > div > diagram-icon-timer'); + const iconShape: any = element.querySelector( + 'diagram-intermediate-catching-event > diagram-container-icon-event >' + ' div > div > diagram-icon-timer' + ); expect(iconShape).not.toBeNull(); const tooltip: any = element.querySelector('diagram-tooltip > div'); @@ -225,7 +223,9 @@ describe('Diagrams Catching', () => { fixture.whenStable().then(() => { expect(res).not.toBeNull(); - const coloredShape: any = element.querySelector('diagram-intermediate-catching-event>raphael-circle[ng-reflect-stroke="#017501"]'); + const coloredShape: any = element.querySelector( + 'diagram-intermediate-catching-event>raphael-circle[ng-reflect-stroke="#017501"]' + ); expect(coloredShape).not.toBeNull(); const shape: any = element.querySelector('diagram-intermediate-catching-event'); @@ -238,8 +238,9 @@ describe('Diagrams Catching', () => { const innerCircle = shape.children[1]; expect(innerCircle.localName).toEqual('raphael-circle'); - const iconShape: any = element.querySelector('diagram-intermediate-catching-event > diagram-container-icon-event >' + - ' div > div > diagram-icon-timer'); + const iconShape: any = element.querySelector( + 'diagram-intermediate-catching-event > diagram-container-icon-event >' + ' div > div > diagram-icon-timer' + ); expect(iconShape).not.toBeNull(); const tooltip: any = element.querySelector('diagram-tooltip > div'); @@ -259,7 +260,9 @@ describe('Diagrams Catching', () => { fixture.whenStable().then(() => { expect(res).not.toBeNull(); - const coloredShape: any = element.querySelector('diagram-intermediate-catching-event>raphael-circle[ng-reflect-stroke="#2632aa"]'); + const coloredShape: any = element.querySelector( + 'diagram-intermediate-catching-event>raphael-circle[ng-reflect-stroke="#2632aa"]' + ); expect(coloredShape).not.toBeNull(); const shape: any = element.querySelector('diagram-intermediate-catching-event'); @@ -272,8 +275,9 @@ describe('Diagrams Catching', () => { const innerCircle = shape.children[1]; expect(innerCircle.localName).toEqual('raphael-circle'); - const iconShape: any = element.querySelector('diagram-intermediate-catching-event > diagram-container-icon-event >' + - ' div > div > diagram-icon-timer'); + const iconShape: any = element.querySelector( + 'diagram-intermediate-catching-event > diagram-container-icon-event >' + ' div > div > diagram-icon-timer' + ); expect(iconShape).not.toBeNull(); const tooltip: any = element.querySelector('diagram-tooltip > div'); @@ -302,8 +306,9 @@ describe('Diagrams Catching', () => { const innerCircle = shape.children[1]; expect(innerCircle.localName).toEqual('raphael-circle'); - const iconShape: any = element.querySelector('diagram-intermediate-catching-event > diagram-container-icon-event >' + - ' div > div > diagram-icon-error'); + const iconShape: any = element.querySelector( + 'diagram-intermediate-catching-event > diagram-container-icon-event >' + ' div > div > diagram-icon-error' + ); expect(iconShape).not.toBeNull(); const tooltip: any = element.querySelector('diagram-tooltip > div'); @@ -323,7 +328,9 @@ describe('Diagrams Catching', () => { fixture.whenStable().then(() => { expect(res).not.toBeNull(); - const coloredShape: any = element.querySelector('diagram-intermediate-catching-event>raphael-circle[ng-reflect-stroke="#017501"]'); + const coloredShape: any = element.querySelector( + 'diagram-intermediate-catching-event>raphael-circle[ng-reflect-stroke="#017501"]' + ); expect(coloredShape).not.toBeNull(); const shape: any = element.querySelector('diagram-intermediate-catching-event'); @@ -336,8 +343,9 @@ describe('Diagrams Catching', () => { const innerCircle = shape.children[1]; expect(innerCircle.localName).toEqual('raphael-circle'); - const iconShape: any = element.querySelector('diagram-intermediate-catching-event > diagram-container-icon-event >' + - ' div > div > diagram-icon-error'); + const iconShape: any = element.querySelector( + 'diagram-intermediate-catching-event > diagram-container-icon-event >' + ' div > div > diagram-icon-error' + ); expect(iconShape).not.toBeNull(); const tooltip: any = element.querySelector('diagram-tooltip > div'); @@ -357,7 +365,9 @@ describe('Diagrams Catching', () => { fixture.whenStable().then(() => { expect(res).not.toBeNull(); - const coloredShape: any = element.querySelector('diagram-intermediate-catching-event>raphael-circle[ng-reflect-stroke="#2632aa"]'); + const coloredShape: any = element.querySelector( + 'diagram-intermediate-catching-event>raphael-circle[ng-reflect-stroke="#2632aa"]' + ); expect(coloredShape).not.toBeNull(); const shape: any = element.querySelector('diagram-intermediate-catching-event'); @@ -370,8 +380,9 @@ describe('Diagrams Catching', () => { const innerCircle = shape.children[1]; expect(innerCircle.localName).toEqual('raphael-circle'); - const iconShape: any = element.querySelector('diagram-intermediate-catching-event > diagram-container-icon-event >' + - ' div > div > diagram-icon-error'); + const iconShape: any = element.querySelector( + 'diagram-intermediate-catching-event > diagram-container-icon-event >' + ' div > div > diagram-icon-error' + ); expect(iconShape).not.toBeNull(); const tooltip: any = element.querySelector('diagram-tooltip > div'); @@ -400,8 +411,9 @@ describe('Diagrams Catching', () => { const innerCircle = shape.children[1]; expect(innerCircle.localName).toEqual('raphael-circle'); - const iconShape: any = element.querySelector('diagram-intermediate-catching-event > diagram-container-icon-event >' + - ' div > div > diagram-icon-signal'); + const iconShape: any = element.querySelector( + 'diagram-intermediate-catching-event > diagram-container-icon-event >' + ' div > div > diagram-icon-signal' + ); expect(iconShape).not.toBeNull(); const tooltip: any = element.querySelector('diagram-tooltip > div'); @@ -421,7 +433,9 @@ describe('Diagrams Catching', () => { fixture.whenStable().then(() => { expect(res).not.toBeNull(); - const coloredShape: any = element.querySelector('diagram-intermediate-catching-event>raphael-circle[ng-reflect-stroke="#017501"]'); + const coloredShape: any = element.querySelector( + 'diagram-intermediate-catching-event>raphael-circle[ng-reflect-stroke="#017501"]' + ); expect(coloredShape).not.toBeNull(); const shape: any = element.querySelector('diagram-intermediate-catching-event'); @@ -434,8 +448,9 @@ describe('Diagrams Catching', () => { const innerCircle = shape.children[1]; expect(innerCircle.localName).toEqual('raphael-circle'); - const iconShape: any = element.querySelector('diagram-intermediate-catching-event > diagram-container-icon-event >' + - ' div > div > diagram-icon-signal'); + const iconShape: any = element.querySelector( + 'diagram-intermediate-catching-event > diagram-container-icon-event >' + ' div > div > diagram-icon-signal' + ); expect(iconShape).not.toBeNull(); const tooltip: any = element.querySelector('diagram-tooltip > div'); @@ -455,7 +470,9 @@ describe('Diagrams Catching', () => { fixture.whenStable().then(() => { expect(res).not.toBeNull(); - const coloredShape: any = element.querySelector('diagram-intermediate-catching-event>raphael-circle[ng-reflect-stroke="#2632aa"]'); + const coloredShape: any = element.querySelector( + 'diagram-intermediate-catching-event>raphael-circle[ng-reflect-stroke="#2632aa"]' + ); expect(coloredShape).not.toBeNull(); const shape: any = element.querySelector('diagram-intermediate-catching-event'); @@ -468,8 +485,9 @@ describe('Diagrams Catching', () => { const innerCircle = shape.children[1]; expect(innerCircle.localName).toEqual('raphael-circle'); - const iconShape: any = element.querySelector('diagram-intermediate-catching-event > diagram-container-icon-event >' + - ' div > div > diagram-icon-signal'); + const iconShape: any = element.querySelector( + 'diagram-intermediate-catching-event > diagram-container-icon-event >' + ' div > div > diagram-icon-signal' + ); expect(iconShape).not.toBeNull(); const tooltip: any = element.querySelector('diagram-tooltip > div'); @@ -498,8 +516,9 @@ describe('Diagrams Catching', () => { const innerCircle = shape.children[1]; expect(innerCircle.localName).toEqual('raphael-circle'); - const iconShape: any = element.querySelector('diagram-intermediate-catching-event > diagram-container-icon-event >' + - ' div > div > diagram-icon-message'); + const iconShape: any = element.querySelector( + 'diagram-intermediate-catching-event > diagram-container-icon-event >' + ' div > div > diagram-icon-message' + ); expect(iconShape).not.toBeNull(); const tooltip: any = element.querySelector('diagram-tooltip > div'); @@ -519,7 +538,9 @@ describe('Diagrams Catching', () => { fixture.whenStable().then(() => { expect(res).not.toBeNull(); - const coloredShape: any = element.querySelector('diagram-intermediate-catching-event>raphael-circle[ng-reflect-stroke="#017501"]'); + const coloredShape: any = element.querySelector( + 'diagram-intermediate-catching-event>raphael-circle[ng-reflect-stroke="#017501"]' + ); expect(coloredShape).not.toBeNull(); const shape: any = element.querySelector('diagram-intermediate-catching-event'); @@ -532,8 +553,9 @@ describe('Diagrams Catching', () => { const innerCircle = shape.children[1]; expect(innerCircle.localName).toEqual('raphael-circle'); - const iconShape: any = element.querySelector('diagram-intermediate-catching-event > diagram-container-icon-event >' + - ' div > div > diagram-icon-message'); + const iconShape: any = element.querySelector( + 'diagram-intermediate-catching-event > diagram-container-icon-event >' + ' div > div > diagram-icon-message' + ); expect(iconShape).not.toBeNull(); const tooltip: any = element.querySelector('diagram-tooltip > div'); @@ -553,7 +575,9 @@ describe('Diagrams Catching', () => { fixture.whenStable().then(() => { expect(res).not.toBeNull(); - const coloredShape: any = element.querySelector('diagram-intermediate-catching-event>raphael-circle[ng-reflect-stroke="#2632aa"]'); + const coloredShape: any = element.querySelector( + 'diagram-intermediate-catching-event>raphael-circle[ng-reflect-stroke="#2632aa"]' + ); expect(coloredShape).not.toBeNull(); const shape: any = element.querySelector('diagram-intermediate-catching-event'); @@ -566,8 +590,9 @@ describe('Diagrams Catching', () => { const innerCircle = shape.children[1]; expect(innerCircle.localName).toEqual('raphael-circle'); - const iconShape: any = element.querySelector('diagram-intermediate-catching-event > diagram-container-icon-event >' + - ' div > div > diagram-icon-message'); + const iconShape: any = element.querySelector( + 'diagram-intermediate-catching-event > diagram-container-icon-event >' + ' div > div > diagram-icon-message' + ); expect(iconShape).not.toBeNull(); const tooltip: any = element.querySelector('diagram-tooltip > div'); diff --git a/lib/insights/src/lib/diagram/components/diagram.component.events.spec.ts b/lib/insights/src/lib/diagram/components/diagram.component.events.spec.ts index 1d5d5dc1ce5..6220d9400c1 100644 --- a/lib/insights/src/lib/diagram/components/diagram.component.events.spec.ts +++ b/lib/insights/src/lib/diagram/components/diagram.component.events.spec.ts @@ -20,22 +20,17 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; import * as diagramsEventsMock from '../../mock/diagram/diagram-events.mock'; import { DiagramComponent } from './diagram.component'; import { InsightsTestingModule } from '../../testing/insights.testing.module'; -import { TranslateModule } from '@ngx-translate/core'; declare let jasmine: any; describe('Diagrams events', () => { - let component: any; let fixture: ComponentFixture; let element: HTMLElement; beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - InsightsTestingModule - ] + imports: [InsightsTestingModule] }); fixture = TestBed.createComponent(DiagramComponent); component = fixture.componentInstance; @@ -54,7 +49,7 @@ describe('Diagrams events', () => { jasmine.Ajax.uninstall(); }); - const ajaxReply = (resp: any) => { + const ajaxReply = (resp: any) => { jasmine.Ajax.requests.mostRecent().respondWith({ status: 200, contentType: 'json', @@ -63,7 +58,6 @@ describe('Diagrams events', () => { }; describe('Diagrams component Events: ', () => { - it('Should render the Start Event', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); @@ -90,8 +84,10 @@ describe('Diagrams events', () => { const event: any = element.querySelector('diagram-start-event > diagram-event > raphael-circle'); expect(event).not.toBeNull(); - const iconEvent: any = element.querySelector('diagram-start-event > diagram-event >' + - ' diagram-container-icon-event > div > div > diagram-icon-timer > raphael-icon-timer'); + const iconEvent: any = element.querySelector( + 'diagram-start-event > diagram-event >' + + ' diagram-container-icon-event > div > div > diagram-icon-timer > raphael-icon-timer' + ); expect(iconEvent).not.toBeNull(); const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); @@ -113,8 +109,10 @@ describe('Diagrams events', () => { const event: any = element.querySelector('diagram-start-event'); expect(event).not.toBeNull(); - const iconEvent: any = element.querySelector('diagram-start-event > diagram-event >' + - ' diagram-container-icon-event > div > div > diagram-icon-signal > raphael-icon-signal'); + const iconEvent: any = element.querySelector( + 'diagram-start-event > diagram-event >' + + ' diagram-container-icon-event > div > div > diagram-icon-signal > raphael-icon-signal' + ); expect(iconEvent).not.toBeNull(); const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); @@ -135,8 +133,10 @@ describe('Diagrams events', () => { const event: any = element.querySelector('diagram-start-event > diagram-event > raphael-circle'); expect(event).not.toBeNull(); - const iconEvent: any = element.querySelector('diagram-start-event > diagram-event >' + - ' diagram-container-icon-event > div > div > diagram-icon-message > raphael-icon-message'); + const iconEvent: any = element.querySelector( + 'diagram-start-event > diagram-event >' + + ' diagram-container-icon-event > div > div > diagram-icon-message > raphael-icon-message' + ); expect(iconEvent).not.toBeNull(); const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); @@ -157,8 +157,10 @@ describe('Diagrams events', () => { const event: any = element.querySelector('diagram-start-event > diagram-event > raphael-circle'); expect(event).not.toBeNull(); - const iconEvent: any = element.querySelector('diagram-start-event > diagram-event >' + - ' diagram-container-icon-event > div > div > diagram-icon-error > raphael-icon-error'); + const iconEvent: any = element.querySelector( + 'diagram-start-event > diagram-event >' + + ' diagram-container-icon-event > div > div > diagram-icon-error > raphael-icon-error' + ); expect(iconEvent).not.toBeNull(); const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); @@ -197,8 +199,9 @@ describe('Diagrams events', () => { const event: any = element.querySelector('diagram-end-event > diagram-event > raphael-circle'); expect(event).not.toBeNull(); - const iconEvent: any = element.querySelector('diagram-end-event > diagram-event >' + - ' diagram-container-icon-event > div > div > diagram-icon-error > raphael-icon-error'); + const iconEvent: any = element.querySelector( + 'diagram-end-event > diagram-event >' + ' diagram-container-icon-event > div > div > diagram-icon-error > raphael-icon-error' + ); expect(iconEvent).not.toBeNull(); const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); @@ -213,7 +216,6 @@ describe('Diagrams events', () => { }); describe('Diagrams component Events with process instance id: ', () => { - it('Should render the Start Event', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); @@ -276,8 +278,10 @@ describe('Diagrams events', () => { const event: any = element.querySelector('diagram-start-event > diagram-event > raphael-circle'); expect(event).not.toBeNull(); - const iconEvent: any = element.querySelector('diagram-start-event > diagram-event >' + - ' diagram-container-icon-event > div > div > diagram-icon-timer > raphael-icon-timer'); + const iconEvent: any = element.querySelector( + 'diagram-start-event > diagram-event >' + + ' diagram-container-icon-event > div > div > diagram-icon-timer > raphael-icon-timer' + ); expect(iconEvent).not.toBeNull(); const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); @@ -299,8 +303,10 @@ describe('Diagrams events', () => { const event: any = element.querySelector('diagram-start-event > diagram-event > raphael-circle[ng-reflect-stroke="#017501"]'); expect(event).not.toBeNull(); - const iconEvent: any = element.querySelector('diagram-start-event > diagram-event >' + - ' diagram-container-icon-event > div > div > diagram-icon-timer > raphael-icon-timer'); + const iconEvent: any = element.querySelector( + 'diagram-start-event > diagram-event >' + + ' diagram-container-icon-event > div > div > diagram-icon-timer > raphael-icon-timer' + ); expect(iconEvent).not.toBeNull(); const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); @@ -322,8 +328,10 @@ describe('Diagrams events', () => { const event: any = element.querySelector('diagram-start-event > diagram-event > raphael-circle[ng-reflect-stroke="#2632aa"]'); expect(event).not.toBeNull(); - const iconEvent: any = element.querySelector('diagram-start-event > diagram-event >' + - ' diagram-container-icon-event > div > div > diagram-icon-timer > raphael-icon-timer'); + const iconEvent: any = element.querySelector( + 'diagram-start-event > diagram-event >' + + ' diagram-container-icon-event > div > div > diagram-icon-timer > raphael-icon-timer' + ); expect(iconEvent).not.toBeNull(); const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); @@ -345,8 +353,10 @@ describe('Diagrams events', () => { const event: any = element.querySelector('diagram-start-event > diagram-event > raphael-circle'); expect(event).not.toBeNull(); - const iconEvent: any = element.querySelector('diagram-start-event > diagram-event >' + - ' diagram-container-icon-event > div > div > diagram-icon-signal > raphael-icon-signal'); + const iconEvent: any = element.querySelector( + 'diagram-start-event > diagram-event >' + + ' diagram-container-icon-event > div > div > diagram-icon-signal > raphael-icon-signal' + ); expect(iconEvent).not.toBeNull(); const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); @@ -367,8 +377,10 @@ describe('Diagrams events', () => { const event: any = element.querySelector('diagram-start-event > diagram-event > raphael-circle[ng-reflect-stroke="#017501"]'); expect(event).not.toBeNull(); - const iconEvent: any = element.querySelector('diagram-start-event > diagram-event >' + - ' diagram-container-icon-event > div > div > diagram-icon-signal > raphael-icon-signal'); + const iconEvent: any = element.querySelector( + 'diagram-start-event > diagram-event >' + + ' diagram-container-icon-event > div > div > diagram-icon-signal > raphael-icon-signal' + ); expect(iconEvent).not.toBeNull(); const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); @@ -389,8 +401,10 @@ describe('Diagrams events', () => { const event: any = element.querySelector('diagram-start-event > diagram-event > raphael-circle[ng-reflect-stroke="#2632aa"]'); expect(event).not.toBeNull(); - const iconEvent: any = element.querySelector('diagram-start-event > diagram-event >' + - ' diagram-container-icon-event > div > div > diagram-icon-signal > raphael-icon-signal'); + const iconEvent: any = element.querySelector( + 'diagram-start-event > diagram-event >' + + ' diagram-container-icon-event > div > div > diagram-icon-signal > raphael-icon-signal' + ); expect(iconEvent).not.toBeNull(); const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); @@ -411,8 +425,10 @@ describe('Diagrams events', () => { const event: any = element.querySelector('diagram-start-event > diagram-event > raphael-circle'); expect(event).not.toBeNull(); - const iconEvent: any = element.querySelector('diagram-start-event > diagram-event >' + - ' diagram-container-icon-event > div > div > diagram-icon-message > raphael-icon-message'); + const iconEvent: any = element.querySelector( + 'diagram-start-event > diagram-event >' + + ' diagram-container-icon-event > div > div > diagram-icon-message > raphael-icon-message' + ); expect(iconEvent).not.toBeNull(); const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); @@ -433,8 +449,10 @@ describe('Diagrams events', () => { const event: any = element.querySelector('diagram-start-event > diagram-event > raphael-circle[ng-reflect-stroke="#017501"]'); expect(event).not.toBeNull(); - const iconEvent: any = element.querySelector('diagram-start-event > diagram-event >' + - ' diagram-container-icon-event > div > div > diagram-icon-message > raphael-icon-message'); + const iconEvent: any = element.querySelector( + 'diagram-start-event > diagram-event >' + + ' diagram-container-icon-event > div > div > diagram-icon-message > raphael-icon-message' + ); expect(iconEvent).not.toBeNull(); const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); @@ -455,8 +473,10 @@ describe('Diagrams events', () => { const event: any = element.querySelector('diagram-start-event > diagram-event > raphael-circle[ng-reflect-stroke="#2632aa"]'); expect(event).not.toBeNull(); - const iconEvent: any = element.querySelector('diagram-start-event > diagram-event >' + - ' diagram-container-icon-event > div > div > diagram-icon-message > raphael-icon-message'); + const iconEvent: any = element.querySelector( + 'diagram-start-event > diagram-event >' + + ' diagram-container-icon-event > div > div > diagram-icon-message > raphael-icon-message' + ); expect(iconEvent).not.toBeNull(); const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); @@ -477,8 +497,10 @@ describe('Diagrams events', () => { const event: any = element.querySelector('diagram-start-event > diagram-event > raphael-circle'); expect(event).not.toBeNull(); - const iconEvent: any = element.querySelector('diagram-start-event > diagram-event >' + - ' diagram-container-icon-event > div > div > diagram-icon-error > raphael-icon-error'); + const iconEvent: any = element.querySelector( + 'diagram-start-event > diagram-event >' + + ' diagram-container-icon-event > div > div > diagram-icon-error > raphael-icon-error' + ); expect(iconEvent).not.toBeNull(); const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); @@ -499,8 +521,10 @@ describe('Diagrams events', () => { const event: any = element.querySelector('diagram-start-event > diagram-event > raphael-circle[ng-reflect-stroke="#017501"]'); expect(event).not.toBeNull(); - const iconEvent: any = element.querySelector('diagram-start-event > diagram-event >' + - ' diagram-container-icon-event > div > div > diagram-icon-error > raphael-icon-error'); + const iconEvent: any = element.querySelector( + 'diagram-start-event > diagram-event >' + + ' diagram-container-icon-event > div > div > diagram-icon-error > raphael-icon-error' + ); expect(iconEvent).not.toBeNull(); const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); @@ -521,8 +545,10 @@ describe('Diagrams events', () => { const event: any = element.querySelector('diagram-start-event > diagram-event > raphael-circle[ng-reflect-stroke="#2632aa"]'); expect(event).not.toBeNull(); - const iconEvent: any = element.querySelector('diagram-start-event > diagram-event >' + - ' diagram-container-icon-event > div > div > diagram-icon-error > raphael-icon-error'); + const iconEvent: any = element.querySelector( + 'diagram-start-event > diagram-event >' + + ' diagram-container-icon-event > div > div > diagram-icon-error > raphael-icon-error' + ); expect(iconEvent).not.toBeNull(); const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); @@ -597,8 +623,9 @@ describe('Diagrams events', () => { const event: any = element.querySelector('diagram-end-event > diagram-event > raphael-circle'); expect(event).not.toBeNull(); - const iconEvent: any = element.querySelector('diagram-end-event > diagram-event >' + - ' diagram-container-icon-event > div > div > diagram-icon-error > raphael-icon-error'); + const iconEvent: any = element.querySelector( + 'diagram-end-event > diagram-event >' + ' diagram-container-icon-event > div > div > diagram-icon-error > raphael-icon-error' + ); expect(iconEvent).not.toBeNull(); const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); @@ -619,8 +646,9 @@ describe('Diagrams events', () => { const event: any = element.querySelector('diagram-end-event > diagram-event > raphael-circle[ng-reflect-stroke="#017501"]'); expect(event).not.toBeNull(); - const iconEvent: any = element.querySelector('diagram-end-event > diagram-event >' + - ' diagram-container-icon-event > div > div > diagram-icon-error > raphael-icon-error'); + const iconEvent: any = element.querySelector( + 'diagram-end-event > diagram-event >' + ' diagram-container-icon-event > div > div > diagram-icon-error > raphael-icon-error' + ); expect(iconEvent).not.toBeNull(); const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); @@ -641,8 +669,9 @@ describe('Diagrams events', () => { const event: any = element.querySelector('diagram-end-event > diagram-event > raphael-circle[ng-reflect-stroke="#2632aa"]'); expect(event).not.toBeNull(); - const iconEvent: any = element.querySelector('diagram-end-event > diagram-event >' + - ' diagram-container-icon-event > div > div > diagram-icon-error > raphael-icon-error'); + const iconEvent: any = element.querySelector( + 'diagram-end-event > diagram-event >' + ' diagram-container-icon-event > div > div > diagram-icon-error > raphael-icon-error' + ); expect(iconEvent).not.toBeNull(); const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); diff --git a/lib/insights/src/lib/diagram/components/diagram.component.flows.spec.ts b/lib/insights/src/lib/diagram/components/diagram.component.flows.spec.ts index d58f74fadda..892c5536a10 100644 --- a/lib/insights/src/lib/diagram/components/diagram.component.flows.spec.ts +++ b/lib/insights/src/lib/diagram/components/diagram.component.flows.spec.ts @@ -20,22 +20,17 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; import * as flowsMock from '../../mock/diagram/diagram-flows.mock'; import { DiagramComponent } from './diagram.component'; import { InsightsTestingModule } from '../../testing/insights.testing.module'; -import { TranslateModule } from '@ngx-translate/core'; declare let jasmine: any; describe('Diagrams flows', () => { - let component: any; let fixture: ComponentFixture; let element: HTMLElement; beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - InsightsTestingModule - ] + imports: [InsightsTestingModule] }); fixture = TestBed.createComponent(DiagramComponent); component = fixture.componentInstance; @@ -54,7 +49,7 @@ describe('Diagrams flows', () => { jasmine.Ajax.uninstall(); }); - const ajaxReply = (resp: any) => { + const ajaxReply = (resp: any) => { jasmine.Ajax.requests.mostRecent().respondWith({ status: 200, contentType: 'json', @@ -63,7 +58,6 @@ describe('Diagrams flows', () => { }; describe('Diagrams component Flows with process instance id: ', () => { - it('Should render the flow', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); @@ -85,7 +79,6 @@ describe('Diagrams flows', () => { }); describe('Diagrams component Flows: ', () => { - it('Should render the flow', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); diff --git a/lib/insights/src/lib/diagram/components/diagram.component.gateways.spec.ts b/lib/insights/src/lib/diagram/components/diagram.component.gateways.spec.ts index 4e1e6332858..90dbe36b432 100644 --- a/lib/insights/src/lib/diagram/components/diagram.component.gateways.spec.ts +++ b/lib/insights/src/lib/diagram/components/diagram.component.gateways.spec.ts @@ -20,22 +20,17 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; import * as diagramsGatewaysMock from '../../mock/diagram/diagram-gateways.mock'; import { DiagramComponent } from './diagram.component'; import { InsightsTestingModule } from '../../testing/insights.testing.module'; -import { TranslateModule } from '@ngx-translate/core'; declare let jasmine: any; describe('Diagrams gateways', () => { - let component: any; let fixture: ComponentFixture; let element: HTMLElement; beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - InsightsTestingModule - ] + imports: [InsightsTestingModule] }); fixture = TestBed.createComponent(DiagramComponent); component = fixture.componentInstance; @@ -54,7 +49,7 @@ describe('Diagrams gateways', () => { jasmine.Ajax.uninstall(); }); - const ajaxReply = (resp: any) => { + const ajaxReply = (resp: any) => { jasmine.Ajax.requests.mostRecent().respondWith({ status: 200, contentType: 'json', @@ -63,7 +58,6 @@ describe('Diagrams gateways', () => { }; describe('Diagrams component Gateways: ', () => { - it('Should render the Exclusive Gateway', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); @@ -164,7 +158,6 @@ describe('Diagrams gateways', () => { }); describe('Diagrams component Gateways with process instance id: ', () => { - it('Should render the Exclusive Gateway', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); @@ -192,7 +185,9 @@ describe('Diagrams gateways', () => { fixture.detectChanges(); fixture.whenStable().then(() => { expect(res).not.toBeNull(); - const shape: any = element.querySelector('diagram-exclusive-gateway > diagram-gateway > raphael-rhombus[ng-reflect-stroke="#017501"]'); + const shape: any = element.querySelector( + 'diagram-exclusive-gateway > diagram-gateway > raphael-rhombus[ng-reflect-stroke="#017501"]' + ); expect(shape).not.toBeNull(); const shape1: any = element.querySelector('diagram-exclusive-gateway > raphael-cross'); @@ -214,7 +209,9 @@ describe('Diagrams gateways', () => { fixture.detectChanges(); fixture.whenStable().then(() => { expect(res).not.toBeNull(); - const shape: any = element.querySelector('diagram-exclusive-gateway > diagram-gateway > raphael-rhombus[ng-reflect-stroke="#2632aa"]'); + const shape: any = element.querySelector( + 'diagram-exclusive-gateway > diagram-gateway > raphael-rhombus[ng-reflect-stroke="#2632aa"]' + ); expect(shape).not.toBeNull(); const shape1: any = element.querySelector('diagram-exclusive-gateway > raphael-cross'); @@ -258,7 +255,9 @@ describe('Diagrams gateways', () => { fixture.detectChanges(); fixture.whenStable().then(() => { expect(res).not.toBeNull(); - const shape: any = element.querySelector('diagram-inclusive-gateway > diagram-gateway > raphael-rhombus[ng-reflect-stroke="#017501"]'); + const shape: any = element.querySelector( + 'diagram-inclusive-gateway > diagram-gateway > raphael-rhombus[ng-reflect-stroke="#017501"]' + ); expect(shape).not.toBeNull(); const shape1: any = element.querySelector('diagram-inclusive-gateway > raphael-circle'); @@ -280,7 +279,9 @@ describe('Diagrams gateways', () => { fixture.detectChanges(); fixture.whenStable().then(() => { expect(res).not.toBeNull(); - const shape: any = element.querySelector('diagram-inclusive-gateway > diagram-gateway > raphael-rhombus[ng-reflect-stroke="#2632aa"]'); + const shape: any = element.querySelector( + 'diagram-inclusive-gateway > diagram-gateway > raphael-rhombus[ng-reflect-stroke="#2632aa"]' + ); expect(shape).not.toBeNull(); const shape1: any = element.querySelector('diagram-inclusive-gateway > raphael-circle'); @@ -324,7 +325,9 @@ describe('Diagrams gateways', () => { fixture.detectChanges(); fixture.whenStable().then(() => { expect(res).not.toBeNull(); - const shape: any = element.querySelector('diagram-parallel-gateway > diagram-gateway > raphael-rhombus[ng-reflect-stroke="#017501"]'); + const shape: any = element.querySelector( + 'diagram-parallel-gateway > diagram-gateway > raphael-rhombus[ng-reflect-stroke="#017501"]' + ); expect(shape).not.toBeNull(); const shape1: any = element.querySelector('diagram-parallel-gateway > raphael-plus'); @@ -346,7 +349,9 @@ describe('Diagrams gateways', () => { fixture.detectChanges(); fixture.whenStable().then(() => { expect(res).not.toBeNull(); - const shape: any = element.querySelector('diagram-parallel-gateway > diagram-gateway > raphael-rhombus[ng-reflect-stroke="#2632aa"]'); + const shape: any = element.querySelector( + 'diagram-parallel-gateway > diagram-gateway > raphael-rhombus[ng-reflect-stroke="#2632aa"]' + ); expect(shape).not.toBeNull(); const shape1: any = element.querySelector('diagram-parallel-gateway > raphael-plus'); @@ -400,7 +405,9 @@ describe('Diagrams gateways', () => { fixture.detectChanges(); fixture.whenStable().then(() => { expect(res).not.toBeNull(); - const shape: any = element.querySelector('diagram-event-gateway > diagram-gateway > raphael-rhombus[ng-reflect-stroke="#017501"]'); + const shape: any = element.querySelector( + 'diagram-event-gateway > diagram-gateway > raphael-rhombus[ng-reflect-stroke="#017501"]' + ); expect(shape).not.toBeNull(); const shape1: any = element.querySelector('diagram-event-gateway'); @@ -432,7 +439,9 @@ describe('Diagrams gateways', () => { fixture.detectChanges(); fixture.whenStable().then(() => { expect(res).not.toBeNull(); - const shape: any = element.querySelector('diagram-event-gateway > diagram-gateway > raphael-rhombus[ng-reflect-stroke="#2632aa"]'); + const shape: any = element.querySelector( + 'diagram-event-gateway > diagram-gateway > raphael-rhombus[ng-reflect-stroke="#2632aa"]' + ); expect(shape).not.toBeNull(); const shape1: any = element.querySelector('diagram-event-gateway'); diff --git a/lib/insights/src/lib/diagram/components/diagram.component.structural.spec.ts b/lib/insights/src/lib/diagram/components/diagram.component.structural.spec.ts index 0bd5b5d7abe..f2ce6d8a72a 100644 --- a/lib/insights/src/lib/diagram/components/diagram.component.structural.spec.ts +++ b/lib/insights/src/lib/diagram/components/diagram.component.structural.spec.ts @@ -19,22 +19,17 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; import * as structuralMock from '../../mock/diagram/diagram-structural.mock'; import { DiagramComponent } from './diagram.component'; import { InsightsTestingModule } from '../../testing/insights.testing.module'; -import { TranslateModule } from '@ngx-translate/core'; declare let jasmine: any; describe('Diagrams structural', () => { - let component: any; let fixture: ComponentFixture; let element: HTMLElement; beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - InsightsTestingModule - ] + imports: [InsightsTestingModule] }); fixture = TestBed.createComponent(DiagramComponent); component = fixture.componentInstance; @@ -53,7 +48,7 @@ describe('Diagrams structural', () => { jasmine.Ajax.uninstall(); }); - const ajaxReply = (resp: any) => { + const ajaxReply = (resp: any) => { jasmine.Ajax.requests.mostRecent().respondWith({ status: 200, contentType: 'json', @@ -62,7 +57,6 @@ describe('Diagrams structural', () => { }; describe('Diagrams component Structural: ', () => { - it('Should render the Subprocess', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); @@ -103,7 +97,6 @@ describe('Diagrams structural', () => { }); describe('Diagrams component Structural with process instance id: ', () => { - it('Should render the Subprocess', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); diff --git a/lib/insights/src/lib/diagram/components/diagram.component.swim.spec.ts b/lib/insights/src/lib/diagram/components/diagram.component.swim.spec.ts index 8c090a15ad0..b5dbab8237a 100644 --- a/lib/insights/src/lib/diagram/components/diagram.component.swim.spec.ts +++ b/lib/insights/src/lib/diagram/components/diagram.component.swim.spec.ts @@ -19,22 +19,17 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; import * as swimLanesMock from '../../mock/diagram/diagram-swimlanes.mock'; import { DiagramComponent } from './diagram.component'; import { InsightsTestingModule } from '../../testing/insights.testing.module'; -import { TranslateModule } from '@ngx-translate/core'; declare let jasmine: any; describe('Diagrams swim', () => { - let component: any; let fixture: ComponentFixture; let element: HTMLElement; beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - InsightsTestingModule - ] + imports: [InsightsTestingModule] }); fixture = TestBed.createComponent(DiagramComponent); component = fixture.componentInstance; @@ -53,7 +48,7 @@ describe('Diagrams swim', () => { jasmine.Ajax.uninstall(); }); - const ajaxReply = (resp: any) => { + const ajaxReply = (resp: any) => { jasmine.Ajax.requests.mostRecent().respondWith({ status: 200, contentType: 'json', @@ -62,7 +57,6 @@ describe('Diagrams swim', () => { }; describe('Diagrams component Swim lane: ', () => { - it('Should render the Pool', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); @@ -106,7 +100,6 @@ describe('Diagrams swim', () => { }); describe('Diagrams component Swim lane with process instance id: ', () => { - it('Should render the Pool', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); diff --git a/lib/insights/src/lib/diagram/components/diagram.component.throw.spec.ts b/lib/insights/src/lib/diagram/components/diagram.component.throw.spec.ts index 8791f182d5d..4e39a7ce591 100644 --- a/lib/insights/src/lib/diagram/components/diagram.component.throw.spec.ts +++ b/lib/insights/src/lib/diagram/components/diagram.component.throw.spec.ts @@ -19,22 +19,17 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; import * as throwEventMock from '../../mock/diagram/diagram-throw.mock'; import { DiagramComponent } from './diagram.component'; import { InsightsTestingModule } from '../../testing/insights.testing.module'; -import { TranslateModule } from '@ngx-translate/core'; declare let jasmine: any; describe('Diagrams throw', () => { - let component: any; let fixture: ComponentFixture; let element: HTMLElement; beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - InsightsTestingModule - ] + imports: [InsightsTestingModule] }); jasmine.Ajax.install(); @@ -62,7 +57,6 @@ describe('Diagrams throw', () => { }; describe('Diagrams component Throw events with process instance id: ', () => { - it('Should render the Throw time event', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); @@ -78,8 +72,9 @@ describe('Diagrams throw', () => { const innerCircle = shape.children[1]; expect(innerCircle.localName).toEqual('raphael-circle'); - const iconShape: any = element.querySelector('diagram-throw-event > diagram-container-icon-event >' + - ' div > div > diagram-icon-timer'); + const iconShape: any = element.querySelector( + 'diagram-throw-event > diagram-container-icon-event >' + ' div > div > diagram-icon-timer' + ); expect(iconShape).not.toBeNull(); done(); }); @@ -108,8 +103,9 @@ describe('Diagrams throw', () => { const innerCircle = shape.children[1]; expect(innerCircle.localName).toEqual('raphael-circle'); - const iconShape: any = element.querySelector('diagram-throw-event > diagram-container-icon-event >' + - ' div > div > diagram-icon-timer'); + const iconShape: any = element.querySelector( + 'diagram-throw-event > diagram-container-icon-event >' + ' div > div > diagram-icon-timer' + ); expect(iconShape).not.toBeNull(); done(); }); @@ -138,8 +134,9 @@ describe('Diagrams throw', () => { const innerCircle = shape.children[1]; expect(innerCircle.localName).toEqual('raphael-circle'); - const iconShape: any = element.querySelector('diagram-throw-event > diagram-container-icon-event >' + - ' div > div > diagram-icon-timer'); + const iconShape: any = element.querySelector( + 'diagram-throw-event > diagram-container-icon-event >' + ' div > div > diagram-icon-timer' + ); expect(iconShape).not.toBeNull(); done(); }); @@ -164,8 +161,9 @@ describe('Diagrams throw', () => { const innerCircle = shape.children[1]; expect(innerCircle.localName).toEqual('raphael-circle'); - const iconShape: any = element.querySelector('diagram-throw-event > diagram-container-icon-event >' + - ' div > div > diagram-icon-error'); + const iconShape: any = element.querySelector( + 'diagram-throw-event > diagram-container-icon-event >' + ' div > div > diagram-icon-error' + ); expect(iconShape).not.toBeNull(); const tooltip: any = element.querySelector('diagram-tooltip > div'); @@ -198,8 +196,9 @@ describe('Diagrams throw', () => { const innerCircle = shape.children[1]; expect(innerCircle.localName).toEqual('raphael-circle'); - const iconShape: any = element.querySelector('diagram-throw-event > diagram-container-icon-event >' + - ' div > div > diagram-icon-error'); + const iconShape: any = element.querySelector( + 'diagram-throw-event > diagram-container-icon-event >' + ' div > div > diagram-icon-error' + ); expect(iconShape).not.toBeNull(); const tooltip: any = element.querySelector('diagram-tooltip > div'); @@ -232,8 +231,9 @@ describe('Diagrams throw', () => { const innerCircle = shape.children[1]; expect(innerCircle.localName).toEqual('raphael-circle'); - const iconShape: any = element.querySelector('diagram-throw-event > diagram-container-icon-event >' + - ' div > div > diagram-icon-error'); + const iconShape: any = element.querySelector( + 'diagram-throw-event > diagram-container-icon-event >' + ' div > div > diagram-icon-error' + ); expect(iconShape).not.toBeNull(); const tooltip: any = element.querySelector('diagram-tooltip > div'); @@ -262,8 +262,9 @@ describe('Diagrams throw', () => { const innerCircle = shape.children[1]; expect(innerCircle.localName).toEqual('raphael-circle'); - const iconShape: any = element.querySelector('diagram-throw-event > diagram-container-icon-event >' + - ' div > div > diagram-icon-signal'); + const iconShape: any = element.querySelector( + 'diagram-throw-event > diagram-container-icon-event >' + ' div > div > diagram-icon-signal' + ); expect(iconShape).not.toBeNull(); const tooltip: any = element.querySelector('diagram-tooltip > div'); @@ -296,8 +297,9 @@ describe('Diagrams throw', () => { const innerCircle = shape.children[1]; expect(innerCircle.localName).toEqual('raphael-circle'); - const iconShape: any = element.querySelector('diagram-throw-event > diagram-container-icon-event >' + - ' div > div > diagram-icon-signal'); + const iconShape: any = element.querySelector( + 'diagram-throw-event > diagram-container-icon-event >' + ' div > div > diagram-icon-signal' + ); expect(iconShape).not.toBeNull(); const tooltip: any = element.querySelector('diagram-tooltip > div'); @@ -330,8 +332,9 @@ describe('Diagrams throw', () => { const innerCircle = shape.children[1]; expect(innerCircle.localName).toEqual('raphael-circle'); - const iconShape: any = element.querySelector('diagram-throw-event > diagram-container-icon-event >' + - ' div > div > diagram-icon-signal'); + const iconShape: any = element.querySelector( + 'diagram-throw-event > diagram-container-icon-event >' + ' div > div > diagram-icon-signal' + ); expect(iconShape).not.toBeNull(); const tooltip: any = element.querySelector('diagram-tooltip > div'); @@ -360,8 +363,9 @@ describe('Diagrams throw', () => { const innerCircle = shape.children[1]; expect(innerCircle.localName).toEqual('raphael-circle'); - const iconShape: any = element.querySelector('diagram-throw-event > diagram-container-icon-event >' + - ' div > div > diagram-icon-message'); + const iconShape: any = element.querySelector( + 'diagram-throw-event > diagram-container-icon-event >' + ' div > div > diagram-icon-message' + ); expect(iconShape).not.toBeNull(); const tooltip: any = element.querySelector('diagram-tooltip > div'); @@ -394,8 +398,9 @@ describe('Diagrams throw', () => { const innerCircle = shape.children[1]; expect(innerCircle.localName).toEqual('raphael-circle'); - const iconShape: any = element.querySelector('diagram-throw-event > diagram-container-icon-event >' + - ' div > div > diagram-icon-message'); + const iconShape: any = element.querySelector( + 'diagram-throw-event > diagram-container-icon-event >' + ' div > div > diagram-icon-message' + ); expect(iconShape).not.toBeNull(); const tooltip: any = element.querySelector('diagram-tooltip > div'); @@ -428,8 +433,9 @@ describe('Diagrams throw', () => { const innerCircle = shape.children[1]; expect(innerCircle.localName).toEqual('raphael-circle'); - const iconShape: any = element.querySelector('diagram-throw-event > diagram-container-icon-event >' + - ' div > div > diagram-icon-message'); + const iconShape: any = element.querySelector( + 'diagram-throw-event > diagram-container-icon-event >' + ' div > div > diagram-icon-message' + ); expect(iconShape).not.toBeNull(); const tooltip: any = element.querySelector('diagram-tooltip > div'); @@ -458,8 +464,9 @@ describe('Diagrams throw', () => { const innerCircle = shape.children[1]; expect(innerCircle.localName).toEqual('raphael-circle'); - const iconShape: any = element.querySelector('diagram-throw-event > diagram-container-icon-event >' + - ' div > div > diagram-icon-message'); + const iconShape: any = element.querySelector( + 'diagram-throw-event > diagram-container-icon-event >' + ' div > div > diagram-icon-message' + ); expect(iconShape).not.toBeNull(); const tooltip: any = element.querySelector('diagram-tooltip > div'); @@ -492,8 +499,9 @@ describe('Diagrams throw', () => { const innerCircle = shape.children[1]; expect(innerCircle.localName).toEqual('raphael-circle'); - const iconShape: any = element.querySelector('diagram-throw-event > diagram-container-icon-event >' + - ' div > div > diagram-icon-message'); + const iconShape: any = element.querySelector( + 'diagram-throw-event > diagram-container-icon-event >' + ' div > div > diagram-icon-message' + ); expect(iconShape).not.toBeNull(); const tooltip: any = element.querySelector('diagram-tooltip > div'); @@ -526,8 +534,9 @@ describe('Diagrams throw', () => { const innerCircle = shape.children[1]; expect(innerCircle.localName).toEqual('raphael-circle'); - const iconShape: any = element.querySelector('diagram-throw-event > diagram-container-icon-event >' + - ' div > div > diagram-icon-message'); + const iconShape: any = element.querySelector( + 'diagram-throw-event > diagram-container-icon-event >' + ' div > div > diagram-icon-message' + ); expect(iconShape).not.toBeNull(); const tooltip: any = element.querySelector('diagram-tooltip > div'); @@ -543,7 +552,6 @@ describe('Diagrams throw', () => { }); describe('Diagrams component Throw events: ', () => { - it('Should render the Throw time event', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); @@ -559,8 +567,9 @@ describe('Diagrams throw', () => { const innerCircle = shape.children[1]; expect(innerCircle.localName).toEqual('raphael-circle'); - const iconShape: any = element.querySelector('diagram-throw-event > diagram-container-icon-event >' + - ' div > div > diagram-icon-timer'); + const iconShape: any = element.querySelector( + 'diagram-throw-event > diagram-container-icon-event >' + ' div > div > diagram-icon-timer' + ); expect(iconShape).not.toBeNull(); done(); }); @@ -585,8 +594,9 @@ describe('Diagrams throw', () => { const innerCircle = shape.children[1]; expect(innerCircle.localName).toEqual('raphael-circle'); - const iconShape: any = element.querySelector('diagram-throw-event > diagram-container-icon-event >' + - ' div > div > diagram-icon-error'); + const iconShape: any = element.querySelector( + 'diagram-throw-event > diagram-container-icon-event >' + ' div > div > diagram-icon-error' + ); expect(iconShape).not.toBeNull(); const tooltip: any = element.querySelector('diagram-tooltip > div'); @@ -615,8 +625,9 @@ describe('Diagrams throw', () => { const innerCircle = shape.children[1]; expect(innerCircle.localName).toEqual('raphael-circle'); - const iconShape: any = element.querySelector('diagram-throw-event > diagram-container-icon-event >' + - ' div > div > diagram-icon-signal'); + const iconShape: any = element.querySelector( + 'diagram-throw-event > diagram-container-icon-event >' + ' div > div > diagram-icon-signal' + ); expect(iconShape).not.toBeNull(); const tooltip: any = element.querySelector('diagram-tooltip > div'); @@ -645,8 +656,9 @@ describe('Diagrams throw', () => { const innerCircle = shape.children[1]; expect(innerCircle.localName).toEqual('raphael-circle'); - const iconShape: any = element.querySelector('diagram-throw-event > diagram-container-icon-event >' + - ' div > div > diagram-icon-message'); + const iconShape: any = element.querySelector( + 'diagram-throw-event > diagram-container-icon-event >' + ' div > div > diagram-icon-message' + ); expect(iconShape).not.toBeNull(); const tooltip: any = element.querySelector('diagram-tooltip > div'); @@ -675,8 +687,9 @@ describe('Diagrams throw', () => { const innerCircle = shape.children[1]; expect(innerCircle.localName).toEqual('raphael-circle'); - const iconShape: any = element.querySelector('diagram-throw-event > diagram-container-icon-event >' + - ' div > div > diagram-icon-message'); + const iconShape: any = element.querySelector( + 'diagram-throw-event > diagram-container-icon-event >' + ' div > div > diagram-icon-message' + ); expect(iconShape).not.toBeNull(); const tooltip: any = element.querySelector('diagram-tooltip > div'); diff --git a/lib/insights/src/lib/testing/insights.testing.module.ts b/lib/insights/src/lib/testing/insights.testing.module.ts index 37cd940f62d..39165ba0d43 100644 --- a/lib/insights/src/lib/testing/insights.testing.module.ts +++ b/lib/insights/src/lib/testing/insights.testing.module.ts @@ -26,27 +26,17 @@ import { AppConfigServiceMock, TranslationService, TranslationMock, - CoreModule, AuthModule + CoreModule, + AuthModule } from '@alfresco/adf-core'; @NgModule({ - imports: [ - AuthModule.forRoot({ useHash: true }), - NoopAnimationsModule, - TranslateModule, - CoreModule.forRoot(), - InsightsModule - ], + imports: [AuthModule.forRoot({ useHash: true }), NoopAnimationsModule, TranslateModule.forRoot(), CoreModule.forRoot(), InsightsModule], providers: [ { provide: AlfrescoApiService, useClass: AlfrescoApiServiceMock }, { provide: AppConfigService, useClass: AppConfigServiceMock }, { provide: TranslationService, useClass: TranslationMock } ], - exports: [ - NoopAnimationsModule, - TranslateModule, - CoreModule, - InsightsModule - ] + exports: [NoopAnimationsModule, TranslateModule, CoreModule, InsightsModule] }) export class InsightsTestingModule {} diff --git a/lib/process-services-cloud/src/lib/app/components/app-details-cloud.component.spec.ts b/lib/process-services-cloud/src/lib/app/components/app-details-cloud.component.spec.ts index 2f6564bdc40..1dc7c3448e7 100644 --- a/lib/process-services-cloud/src/lib/app/components/app-details-cloud.component.spec.ts +++ b/lib/process-services-cloud/src/lib/app/components/app-details-cloud.component.spec.ts @@ -21,7 +21,6 @@ import { AppDetailsCloudComponent } from './app-details-cloud.component'; import { ProcessServiceCloudTestingModule } from '../../testing/process-service-cloud.testing.module'; import { AppListCloudModule } from '../app-list-cloud.module'; import { DEFAULT_APP_INSTANCE_THEME } from '../models/application-instance.model'; -import { TranslateModule } from '@ngx-translate/core'; describe('AppDetailsCloudComponent', () => { let component: AppDetailsCloudComponent; @@ -30,7 +29,7 @@ describe('AppDetailsCloudComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [TranslateModule.forRoot(), ProcessServiceCloudTestingModule, AppListCloudModule] + imports: [ProcessServiceCloudTestingModule, AppListCloudModule] }); fixture = TestBed.createComponent(AppDetailsCloudComponent); component = fixture.componentInstance; diff --git a/lib/process-services-cloud/src/lib/app/components/app-list-cloud.component.spec.ts b/lib/process-services-cloud/src/lib/app/components/app-list-cloud.component.spec.ts index b0cccc551e5..d8e520c11fd 100644 --- a/lib/process-services-cloud/src/lib/app/components/app-list-cloud.component.spec.ts +++ b/lib/process-services-cloud/src/lib/app/components/app-list-cloud.component.spec.ts @@ -19,12 +19,10 @@ import { Component } from '@angular/core'; import { ComponentFixture, TestBed } from '@angular/core/testing'; import { AlfrescoApiService } from '@alfresco/adf-core'; import { of, throwError } from 'rxjs'; - import { fakeApplicationInstance } from '../mock/app-model.mock'; import { AppListCloudComponent, LAYOUT_GRID, LAYOUT_LIST } from './app-list-cloud.component'; import { AppsProcessCloudService } from '../services/apps-process-cloud.service'; import { ProcessServiceCloudTestingModule } from '../../testing/process-service-cloud.testing.module'; -import { TranslateModule } from '@ngx-translate/core'; describe('AppListCloudComponent', () => { let component: AppListCloudComponent; @@ -55,7 +53,7 @@ describe('AppListCloudComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [TranslateModule.forRoot(), ProcessServiceCloudTestingModule], + imports: [ProcessServiceCloudTestingModule], declarations: [CustomEmptyAppListCloudTemplateComponent] }); fixture = TestBed.createComponent(AppListCloudComponent); diff --git a/lib/process-services-cloud/src/lib/app/services/apps-process-cloud.service.spec.ts b/lib/process-services-cloud/src/lib/app/services/apps-process-cloud.service.spec.ts index a3319609d91..29c7534a4c3 100644 --- a/lib/process-services-cloud/src/lib/app/services/apps-process-cloud.service.spec.ts +++ b/lib/process-services-cloud/src/lib/app/services/apps-process-cloud.service.spec.ts @@ -22,29 +22,22 @@ import { HttpErrorResponse } from '@angular/common/http'; import { AppsProcessCloudService } from './apps-process-cloud.service'; 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'; import { AdfHttpClient } from '@alfresco/adf-core/api'; describe('AppsProcessCloudService', () => { - let service: AppsProcessCloudService; let appConfigService: AppConfigService; let adfHttpClient: AdfHttpClient; - const apiMockResponse: any = Promise.resolve({list : { entries: [ {entry: fakeApplicationInstance[0]}, {entry: fakeApplicationInstance[1]}] }}); + const apiMockResponse: any = Promise.resolve({ + list: { entries: [{ entry: fakeApplicationInstance[0] }, { entry: fakeApplicationInstance[1] }] } + }); beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - CoreTestingModule, - ProcessServiceCloudTestingModule - ], - providers: [ - AlfrescoApiService, - AppConfigService - ] + imports: [CoreTestingModule, ProcessServiceCloudTestingModule], + providers: [AlfrescoApiService, AppConfigService] }); adfHttpClient = TestBed.inject(AdfHttpClient); spyOn(adfHttpClient, 'request').and.returnValue(apiMockResponse); @@ -56,50 +49,45 @@ describe('AppsProcessCloudService', () => { it('should get the deployed applications no apps are specified in app.config', (done) => { spyOn(appConfigService, 'get').and.returnValue([]); service.loadApps(); - service.getDeployedApplicationsByStatus('fake').subscribe( - (res) => { - expect(res).toBeDefined(); - expect(res.length).toEqual(2); - expect(res[0].name).toEqual('application-new-1'); - expect(res[1].name).toEqual('application-new-2'); - done(); - } - ); + service.getDeployedApplicationsByStatus('fake').subscribe((res) => { + expect(res).toBeDefined(); + expect(res.length).toEqual(2); + expect(res[0].name).toEqual('application-new-1'); + expect(res[1].name).toEqual('application-new-2'); + done(); + }); }); it('should get apps from app.config when apps are specified in app.config', (done) => { spyOn(appConfigService, 'get').and.returnValue([fakeApplicationInstance[0]]); service.loadApps(); - service.getDeployedApplicationsByStatus('fake').subscribe( - (res) => { - expect(res).toBeDefined(); - expect(res.length).toEqual(1); - expect(res[0]).toEqual(fakeApplicationInstance[0]); - expect(res[0].name).toEqual('application-new-1'); - done(); - } - ); + service.getDeployedApplicationsByStatus('fake').subscribe((res) => { + expect(res).toBeDefined(); + expect(res.length).toEqual(1); + expect(res[0]).toEqual(fakeApplicationInstance[0]); + expect(res[0].name).toEqual('application-new-1'); + done(); + }); }); it('Should not fetch deployed applications if error occurred', () => { const errorResponse = new HttpErrorResponse({ error: 'Mock Error', - status: 404, statusText: 'Not Found' + status: 404, + statusText: 'Not Found' }); spyOn(service, 'getDeployedApplicationsByStatus').and.returnValue(throwError(errorResponse)); - service.getDeployedApplicationsByStatus('fake') - .subscribe( - () => fail('expected an error, not applications'), - (error) => { - expect(error.status).toEqual(404); - expect(error.statusText).toEqual('Not Found'); - expect(error.error).toEqual('Mock Error'); - } - ); + service.getDeployedApplicationsByStatus('fake').subscribe( + () => fail('expected an error, not applications'), + (error) => { + expect(error.status).toEqual(404); + expect(error.statusText).toEqual('Not Found'); + expect(error.error).toEqual('Mock Error'); + } + ); }); - it('should return label with application name', () => { const applicationLabel = service.getApplicationLabel(fakeApplicationInstance[0]); expect(applicationLabel).toBe('application-new-1'); diff --git a/lib/process-services-cloud/src/lib/common/date-range-filter/date-range-filter.component.spec.ts b/lib/process-services-cloud/src/lib/common/date-range-filter/date-range-filter.component.spec.ts index 897a11933a7..a0b5fec913c 100644 --- a/lib/process-services-cloud/src/lib/common/date-range-filter/date-range-filter.component.spec.ts +++ b/lib/process-services-cloud/src/lib/common/date-range-filter/date-range-filter.component.spec.ts @@ -17,7 +17,6 @@ import { DateRangeFilterComponent } from './date-range-filter.component'; import { ComponentFixture, TestBed } from '@angular/core/testing'; -import { TranslateModule } from '@ngx-translate/core'; import { ProcessServiceCloudTestingModule } from '../../testing/process-service-cloud.testing.module'; import { MatSelectChange } from '@angular/material/select'; import { DateCloudFilterType } from '../../models/date-cloud-filter.model'; @@ -38,10 +37,7 @@ describe('DateRangeFilterComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - ProcessServiceCloudTestingModule - ] + imports: [ProcessServiceCloudTestingModule] }); fixture = TestBed.createComponent(DateRangeFilterComponent); component = fixture.componentInstance; @@ -66,9 +62,11 @@ describe('DateRangeFilterComponent', () => { spyOn(service, 'getDateRange'); spyOn(component.dateTypeChange, 'emit'); - const stateElement = await loader.getHarness(MatSelectHarness.with({ selector: '[data-automation-id="adf-cloud-edit-process-property-createdDate"]' })); + const stateElement = await loader.getHarness( + MatSelectHarness.with({ selector: '[data-automation-id="adf-cloud-edit-process-property-createdDate"]' }) + ); - await stateElement.clickOptions({ selector: '[data-automation-id="adf-cloud-edit-process-property-options-WEEK"]'}); + await stateElement.clickOptions({ selector: '[data-automation-id="adf-cloud-edit-process-property-options-WEEK"]' }); expect(service.getDateRange).not.toHaveBeenCalled(); expect(component.dateTypeChange.emit).toHaveBeenCalled(); @@ -76,9 +74,11 @@ describe('DateRangeFilterComponent', () => { it('should not emit event on `RANGE` option change', async () => { spyOn(component.dateTypeChange, 'emit'); - const stateElement = await loader.getHarness(MatSelectHarness.with({ selector: '[data-automation-id="adf-cloud-edit-process-property-createdDate"]' })); + const stateElement = await loader.getHarness( + MatSelectHarness.with({ selector: '[data-automation-id="adf-cloud-edit-process-property-createdDate"]' }) + ); - await stateElement.clickOptions({ selector: '[data-automation-id="adf-cloud-edit-process-property-options-RANGE"]'}); + await stateElement.clickOptions({ selector: '[data-automation-id="adf-cloud-edit-process-property-options-RANGE"]' }); expect(component.dateTypeChange.emit).not.toHaveBeenCalled(); }); @@ -133,7 +133,9 @@ describe('DateRangeFilterComponent', () => { }); it('should have floating labels when values are present', async () => { - const stateElement = await loader.getHarness(MatSelectHarness.with({ selector: '[data-automation-id="adf-cloud-edit-process-property-createdDate"]' })); + const stateElement = await loader.getHarness( + MatSelectHarness.with({ selector: '[data-automation-id="adf-cloud-edit-process-property-createdDate"]' }) + ); await stateElement.open(); const selectField = await loader.getHarness(MatFormFieldHarness.with({ selector: '[data-automation-id="createdDate"]' })); diff --git a/lib/process-services-cloud/src/lib/form/components/form-cloud-custom-outcomes.component.spec.ts b/lib/process-services-cloud/src/lib/form/components/form-cloud-custom-outcomes.component.spec.ts index 359daa79f02..f1a208dc26f 100644 --- a/lib/process-services-cloud/src/lib/form/components/form-cloud-custom-outcomes.component.spec.ts +++ b/lib/process-services-cloud/src/lib/form/components/form-cloud-custom-outcomes.component.spec.ts @@ -19,60 +19,43 @@ import { FormModel } from '@alfresco/adf-core'; import { Component, DebugElement, ViewChild } from '@angular/core'; import { ComponentFixture, TestBed } from '@angular/core/testing'; import { By } from '@angular/platform-browser'; -import { TranslateModule } from '@ngx-translate/core'; import { ProcessServiceCloudTestingModule } from '../../testing/process-service-cloud.testing.module'; import { FormCloudComponent } from './form-cloud.component'; @Component({ selector: 'adf-cloud-form-with-custom-outcomes', - template: ` - - - - - - ` + template: ` + + + + + ` }) class FormCloudWithCustomOutComesComponent { - @ViewChild('adfCloudForm', { static: true }) adfCloudForm: FormCloudComponent; - onCustomButtonOneClick() { - } + onCustomButtonOneClick() {} - onCustomButtonTwoClick() { - } + onCustomButtonTwoClick() {} } describe('FormCloudWithCustomOutComesComponent', () => { - let fixture: ComponentFixture; let customComponent: FormCloudWithCustomOutComesComponent; let debugElement: DebugElement; beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - ProcessServiceCloudTestingModule - ], + imports: [ProcessServiceCloudTestingModule], declarations: [FormCloudWithCustomOutComesComponent] }); fixture = TestBed.createComponent(FormCloudWithCustomOutComesComponent); customComponent = fixture.componentInstance; debugElement = fixture.debugElement; const formRepresentation = { - fields: [ - { id: 'container1' } - ], - outcomes: [ - { id: 'outcome-1', name: 'outcome 1' } - ] + fields: [{ id: 'container1' }], + outcomes: [{ id: 'outcome-1', name: 'outcome 1' }] }; const form = new FormModel(formRepresentation); diff --git a/lib/process-services-cloud/src/lib/form/components/form-definition-selector-cloud.component.spec.ts b/lib/process-services-cloud/src/lib/form/components/form-definition-selector-cloud.component.spec.ts index d10748ee5e7..2ec0e23b698 100644 --- a/lib/process-services-cloud/src/lib/form/components/form-definition-selector-cloud.component.spec.ts +++ b/lib/process-services-cloud/src/lib/form/components/form-definition-selector-cloud.component.spec.ts @@ -21,13 +21,11 @@ import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core'; import { FormDefinitionSelectorCloudComponent } from './form-definition-selector-cloud.component'; import { of } from 'rxjs'; import { FormDefinitionSelectorCloudService } from '../services/form-definition-selector-cloud.service'; -import { TranslateModule } from '@ngx-translate/core'; import { HarnessLoader } from '@angular/cdk/testing'; import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed'; import { MatSelectHarness } from '@angular/material/select/testing'; describe('FormDefinitionCloudComponent', () => { - let fixture: ComponentFixture; let service: FormDefinitionSelectorCloudService; let getFormsSpy: jasmine.Spy; @@ -35,10 +33,7 @@ describe('FormDefinitionCloudComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - ProcessServiceCloudTestingModule - ], + imports: [ProcessServiceCloudTestingModule], schemas: [CUSTOM_ELEMENTS_SCHEMA] }); fixture = TestBed.createComponent(FormDefinitionSelectorCloudComponent); @@ -65,7 +60,7 @@ describe('FormDefinitionCloudComponent', () => { const options = await selectElement.getOptions(); - expect((options).length).toBe(1); + expect(options.length).toBe(1); }); it('should not preselect any form by default', async () => { diff --git a/lib/process-services-cloud/src/lib/form/components/widgets/attach-file/attach-file-cloud-widget.component.spec.ts b/lib/process-services-cloud/src/lib/form/components/widgets/attach-file/attach-file-cloud-widget.component.spec.ts index f3738e4730e..a63bb7ce8ed 100644 --- a/lib/process-services-cloud/src/lib/form/components/widgets/attach-file/attach-file-cloud-widget.component.spec.ts +++ b/lib/process-services-cloud/src/lib/form/components/widgets/attach-file/attach-file-cloud-widget.component.spec.ts @@ -71,7 +71,6 @@ import { import { By } from '@angular/platform-browser'; import { of, throwError } from 'rxjs'; import { FormCloudModule } from '../../../form-cloud.module'; -import { TranslateModule } from '@ngx-translate/core'; import { HarnessLoader } from '@angular/cdk/testing'; import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed'; import { MatTooltipHarness } from '@angular/material/tooltip/testing'; @@ -155,7 +154,7 @@ describe('AttachFileCloudWidgetComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [TranslateModule.forRoot(), ProcessServiceCloudTestingModule, FormCloudModule, ContentModule.forRoot()], + imports: [ProcessServiceCloudTestingModule, FormCloudModule, ContentModule.forRoot()], schemas: [CUSTOM_ELEMENTS_SCHEMA] }); notificationService = TestBed.inject(NotificationService); @@ -599,7 +598,7 @@ describe('AttachFileCloudWidgetComponent', () => { it('should preview file when show is clicked', () => { spyOn(processCloudContentService, 'getRawContentNode').and.returnValue(of(new Blob())); let lastValue: ContentLinkModel; - formService.formContentClicked.subscribe((fileClicked) => lastValue = fileClicked); + formService.formContentClicked.subscribe((fileClicked) => (lastValue = fileClicked)); fixture.detectChanges(); const menuButton = fixture.debugElement.query(By.css('#file-fake-properties-option-menu')).nativeElement as HTMLButtonElement; diff --git a/lib/process-services-cloud/src/lib/form/components/widgets/attach-file/attach-file-cloud-widget.component.ts b/lib/process-services-cloud/src/lib/form/components/widgets/attach-file/attach-file-cloud-widget.component.ts index 63e2541b672..39b93df7945 100644 --- a/lib/process-services-cloud/src/lib/form/components/widgets/attach-file/attach-file-cloud-widget.component.ts +++ b/lib/process-services-cloud/src/lib/form/components/widgets/attach-file/attach-file-cloud-widget.component.ts @@ -17,10 +17,9 @@ /* eslint-disable @angular-eslint/component-selector */ -import { Component, OnDestroy, OnInit, ViewEncapsulation } from '@angular/core'; +import { Component, EventEmitter, OnDestroy, OnInit, Output, ViewEncapsulation } from '@angular/core'; import { FormService, - LogService, ThumbnailService, NotificationService, FormValues, @@ -35,13 +34,19 @@ import { ContentCloudNodeSelectorService } from '../../../services/content-cloud import { ProcessCloudContentService } from '../../../services/process-cloud-content.service'; import { UploadCloudWidgetComponent } from './upload-cloud.widget'; import { DestinationFolderPathModel, DestinationFolderPathType } from '../../../models/form-cloud-representation.model'; -import { ContentNodeSelectorPanelService, NewVersionUploaderDataAction, NewVersionUploaderDialogData, NewVersionUploaderService, VersionManagerUploadData } from '@alfresco/adf-content-services'; +import { + ContentNodeSelectorPanelService, + NewVersionUploaderDataAction, + NewVersionUploaderDialogData, + NewVersionUploaderService, + VersionManagerUploadData +} from '@alfresco/adf-content-services'; export const RETRIEVE_METADATA_OPTION = 'retrieveMetadata'; export const ALIAS_ROOT_FOLDER = '-root-'; export const ALIAS_USER_FOLDER = '-my-'; export const APP_NAME = '-appname-'; -export const VALID_ALIAS = [ ALIAS_ROOT_FOLDER, ALIAS_USER_FOLDER, '-shared-' ]; +export const VALID_ALIAS = [ALIAS_ROOT_FOLDER, ALIAS_USER_FOLDER, '-shared-']; @Component({ selector: 'adf-cloud-attach-file-cloud-widget', @@ -65,6 +70,9 @@ export class AttachFileCloudWidgetComponent extends UploadCloudWidgetComponent i rootNodeId = ALIAS_USER_FOLDER; selectedNode: Node; + @Output() + error = new EventEmitter(); + private previewState = false; private _nodesApi: NodesApi; get nodesApi(): NodesApi { @@ -75,7 +83,6 @@ export class AttachFileCloudWidgetComponent extends UploadCloudWidgetComponent i constructor( formService: FormService, - logger: LogService, thumbnails: ThumbnailService, processCloudContentService: ProcessCloudContentService, notificationService: NotificationService, @@ -85,7 +92,7 @@ export class AttachFileCloudWidgetComponent extends UploadCloudWidgetComponent i private contentNodeSelectorPanelService: ContentNodeSelectorPanelService, private newVersionUploaderService: NewVersionUploaderService ) { - super(formService, thumbnails, processCloudContentService, notificationService, logger); + super(formService, thumbnails, processCloudContentService, notificationService); } ngOnInit() { @@ -95,7 +102,7 @@ export class AttachFileCloudWidgetComponent extends UploadCloudWidgetComponent i this.contentModelFormFileHandler(files[0]); } this.field.params.displayableCMProperties = this.field.params.displayableCMProperties ?? []; - this.displayedColumns.splice(2, 0, ...(this.field.params.displayableCMProperties?.map(property => property?.name) || [])); + this.displayedColumns.splice(2, 0, ...(this.field.params.displayableCMProperties?.map((property) => property?.name) || [])); this.setPreviewState(); } @@ -139,7 +146,7 @@ export class AttachFileCloudWidgetComponent extends UploadCloudWidgetComponent i this.contentNodeSelectorService .openUploadFileDialog(this.rootNodeId, selectedMode, this.isAlfrescoAndLocal(), true) .subscribe((selections: Node[]) => { - selections.forEach(node => (node['isExternal'] = true)); + selections.forEach((node) => (node['isExternal'] = true)); const selectionWithoutDuplication = this.removeExistingSelection(selections); const hadFilesAttached = this.field.value?.length > 0; this.fixIncompatibilityFromPreviousAndNewForm(selectionWithoutDuplication); @@ -171,14 +178,14 @@ export class AttachFileCloudWidgetComponent extends UploadCloudWidgetComponent i return rootNodeId; } - async getNodeIdFromPath(destinationFolderPath: DestinationFolderPath): Promise { + async getNodeIdFromPath(destinationFolderPath: DestinationFolderPath): Promise { let nodeId: string; - const destinationPath = this.getAliasAndRelativePathFromDestinationFolderPath(destinationFolderPath.value); + const destinationPath = this.getAliasAndRelativePathFromDestinationFolderPath(destinationFolderPath.value); destinationPath.path = this.replaceAppNameAliasWithValue(destinationPath.path); try { nodeId = await this.contentNodeSelectorService.getNodeIdFromPath(destinationPath); } catch (error) { - this.logService.error(error); + this.error.emit(error); } return nodeId; @@ -189,14 +196,15 @@ export class AttachFileCloudWidgetComponent extends UploadCloudWidgetComponent i try { nodeId = await this.contentNodeSelectorService.getNodeIdFromFolderVariableValue(destinationFolderPath.value, ALIAS_USER_FOLDER); } catch (error) { - this.logService.error(error); + this.error.emit(error); } return nodeId; } getAliasAndRelativePathFromDestinationFolderPath(destinationFolderPath: string): DestinationFolderPathModel { - let alias: string; let path: string; + let alias: string; + let path: string; if (destinationFolderPath) { const startOfRelativePathIndex = destinationFolderPath.indexOf('/'); if (startOfRelativePathIndex >= 0) { @@ -211,8 +219,8 @@ export class AttachFileCloudWidgetComponent extends UploadCloudWidgetComponent i } removeExistingSelection(selections: Node[]) { - const existingNode: Node[] = [...this.field.value || []]; - return selections.filter(opt => !existingNode.some((node) => node.id === opt.id)); + const existingNode: Node[] = [...(this.field.value || [])]; + return selections.filter((opt) => !existingNode.some((node) => node.id === opt.id)); } downloadContent(file: Node): void { @@ -220,12 +228,13 @@ export class AttachFileCloudWidgetComponent extends UploadCloudWidgetComponent i } onUploadNewFileVersion(node: NewVersionUploaderDialogData): void { - this.newVersionUploaderService.openUploadNewVersionDialog(node).subscribe((newVersionUploaderData) => { - if (newVersionUploaderData.action === NewVersionUploaderDataAction.upload) { - this.replaceOldFileVersionWithNew(newVersionUploaderData as VersionManagerUploadData); - } - }, - error => this.notificationService.showError(error.value) + this.newVersionUploaderService.openUploadNewVersionDialog(node).subscribe( + (newVersionUploaderData) => { + if (newVersionUploaderData.action === NewVersionUploaderDataAction.upload) { + this.replaceOldFileVersionWithNew(newVersionUploaderData as VersionManagerUploadData); + } + }, + (error) => this.notificationService.showError(error.value) ); } @@ -250,11 +259,11 @@ export class AttachFileCloudWidgetComponent extends UploadCloudWidgetComponent i contentModelFormFileHandler(file?: any) { if (file?.id && this.isRetrieveMetadataOptionEnabled()) { const values: FormValues = {}; - this.nodesApi.getNode(file.id).then(acsNode => { + this.nodesApi.getNode(file.id).then((acsNode) => { const metadata = acsNode?.entry?.properties; if (metadata) { const keys = Object.keys(metadata); - keys.forEach(key => { + keys.forEach((key) => { const sanitizedKey = key.replace(':', '_'); values[sanitizedKey] = metadata[key]; }); diff --git a/lib/process-services-cloud/src/lib/form/components/widgets/attach-file/file-properties-table-cloud.component.spec.ts b/lib/process-services-cloud/src/lib/form/components/widgets/attach-file/file-properties-table-cloud.component.spec.ts index c620078cc65..7ebbd53b466 100644 --- a/lib/process-services-cloud/src/lib/form/components/widgets/attach-file/file-properties-table-cloud.component.spec.ts +++ b/lib/process-services-cloud/src/lib/form/components/widgets/attach-file/file-properties-table-cloud.component.spec.ts @@ -18,7 +18,6 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; import { ProcessServiceCloudTestingModule } from '../../../../testing/process-service-cloud.testing.module'; -import { TranslateModule } from '@ngx-translate/core'; import { FilePropertiesTableCloudComponent } from './file-properties-table-cloud.component'; import { By } from '@angular/platform-browser'; import { MatTableModule } from '@angular/material/table'; @@ -30,12 +29,7 @@ describe('FilePropertiesTableCloudComponent', () => { beforeEach(async () => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - ProcessServiceCloudTestingModule, - MatTableModule, - MatIconModule - ], + imports: [ProcessServiceCloudTestingModule, MatTableModule, MatIconModule], declarations: [FilePropertiesTableCloudComponent] }).compileComponents(); }); @@ -44,34 +38,34 @@ describe('FilePropertiesTableCloudComponent', () => { fixture = TestBed.createComponent(FilePropertiesTableCloudComponent); widget = fixture.componentInstance; - widget.uploadedFiles = [{ - id: 'id', - name: 'download.png', - mimeType: 'image/png', - isExternal: true, - isFile: true, - isFolder: false, - content: { - mimeType: 'image/png' + widget.uploadedFiles = [ + { + id: 'id', + name: 'download.png', + mimeType: 'image/png', + isExternal: true, + isFile: true, + isFolder: false, + content: { + mimeType: 'image/png' + } + }, + { + id: 'id2', + name: 'download2.png', + mimeType: 'image/png', + isExternal: true, + isFile: true, + isFolder: false, + content: { + mimeType: 'image/png' + } } - }, { - id: 'id2', - name: 'download2.png', - mimeType: 'image/png', - isExternal: true, - isFile: true, - isFolder: false, - content: { - mimeType: 'image/png' - } - }]; + ]; widget.hasFile = true; - widget.displayedColumns = [ - 'icon', - 'fileName' - ]; + widget.displayedColumns = ['icon', 'fileName']; fixture.detectChanges(); }); diff --git a/lib/process-services-cloud/src/lib/form/components/widgets/attach-file/upload-cloud.widget.ts b/lib/process-services-cloud/src/lib/form/components/widgets/attach-file/upload-cloud.widget.ts index 27acd8a0ab1..7a72ef0939e 100644 --- a/lib/process-services-cloud/src/lib/form/components/widgets/attach-file/upload-cloud.widget.ts +++ b/lib/process-services-cloud/src/lib/form/components/widgets/attach-file/upload-cloud.widget.ts @@ -17,11 +17,11 @@ /* eslint-disable @angular-eslint/component-selector */ -import { Component, ElementRef, OnInit, ViewChild, ViewEncapsulation } from '@angular/core'; +import { Component, ElementRef, EventEmitter, OnInit, Output, ViewChild, ViewEncapsulation } from '@angular/core'; import { Node } from '@alfresco/js-api'; import { Observable, from } from 'rxjs'; import { mergeMap } from 'rxjs/operators'; -import { WidgetComponent, LogService, FormService, ThumbnailService, NotificationService } from '@alfresco/adf-core'; +import { WidgetComponent, FormService, ThumbnailService, NotificationService } from '@alfresco/adf-core'; import { ProcessCloudContentService } from '../../../services/process-cloud-content.service'; import { FileSourceTypes, DestinationFolderPathType } from '../../../models/form-cloud-representation.model'; import { VersionManagerUploadData } from '@alfresco/adf-content-services'; @@ -49,6 +49,9 @@ export class UploadCloudWidgetComponent extends WidgetComponent implements OnIni multipleOption: string = ''; mimeTypeIcon: string; + @Output() + error = new EventEmitter(); + @ViewChild('uploadFiles') fileInput: ElementRef; @@ -56,8 +59,7 @@ export class UploadCloudWidgetComponent extends WidgetComponent implements OnIni formService: FormService, private thumbnailService: ThumbnailService, protected processCloudContentService: ProcessCloudContentService, - protected notificationService: NotificationService, - protected logService: LogService + protected notificationService: NotificationService ) { super(formService); } @@ -103,7 +105,7 @@ export class UploadCloudWidgetComponent extends WidgetComponent implements OnIni (res) => { filesSaved.push(res); }, - (error) => this.logService.error(`Error uploading file. See console output for more details. ${error}`), + (error) => this.widgetError.emit(`Error uploading file. See console output for more details. ${error}`), () => { this.fixIncompatibilityFromPreviousAndNewForm(filesSaved); this.hasFile = true; diff --git a/lib/process-services-cloud/src/lib/form/components/widgets/data-table/data-table.widget.spec.ts b/lib/process-services-cloud/src/lib/form/components/widgets/data-table/data-table.widget.spec.ts index 6dd718bc6c7..79ba05d47bf 100644 --- a/lib/process-services-cloud/src/lib/form/components/widgets/data-table/data-table.widget.spec.ts +++ b/lib/process-services-cloud/src/lib/form/components/widgets/data-table/data-table.widget.spec.ts @@ -16,7 +16,7 @@ */ import { ComponentFixture, TestBed } from '@angular/core/testing'; -import { DataColumn, FormFieldModel, FormFieldTypes, FormModel, LogService, VariableConfig } from '@alfresco/adf-core'; +import { DataColumn, FormFieldModel, FormFieldTypes, FormModel, VariableConfig } from '@alfresco/adf-core'; import { By } from '@angular/platform-browser'; import { DataTableWidgetComponent } from './data-table.widget'; import { ProcessServiceCloudTestingModule } from '../../../../testing/process-service-cloud.testing.module'; @@ -41,8 +41,6 @@ describe('DataTableWidgetComponent', () => { let widget: DataTableWidgetComponent; let fixture: ComponentFixture; let formCloudService: FormCloudService; - let logService: LogService; - let logServiceSpy: jasmine.Spy; const errorIcon: string = 'error_outline'; @@ -86,14 +84,11 @@ describe('DataTableWidgetComponent', () => { widget = fixture.componentInstance; formCloudService = TestBed.inject(FormCloudService); - logService = TestBed.inject(LogService); widget.field = new FormFieldModel(new FormModel({ taskId: 'fake-task-id' }), { type: FormFieldTypes.DATA_TABLE, name: 'Data Table' }); - - logServiceSpy = spyOn(logService, 'error'); }); it('should display label', () => { @@ -219,34 +214,31 @@ describe('DataTableWidgetComponent', () => { expect(dataTable).toBeNull(); }); - it('should display and log error if data source is not linked to every column', () => { + it('should display error if data source is not linked to every column', () => { widget.field = getDataVariable(mockVariableConfig, mockSchemaDefinition, [], mockJsonFormVariableWithIncorrectData); fixture.detectChanges(); checkDataTableErrorMessage(); - expect(logServiceSpy).toHaveBeenCalledWith('Data source has corrupted model or structure'); expect(widget.dataSource.getRows()).toEqual([]); }); - it('should display and log error if data source has invalid column structure', () => { + it('should display error if data source has invalid column structure', () => { widget.field = getDataVariable(mockVariableConfig, mockInvalidSchemaDefinition, [], mockJsonFormVariableWithIncorrectData); fixture.detectChanges(); checkDataTableErrorMessage(); - expect(logServiceSpy).toHaveBeenCalledWith('Data source has corrupted model or structure'); expect(widget.dataSource.getRows()).toEqual([]); }); - it('should display and log error if data source is not found', () => { + it('should display error if data source is not found', () => { widget.field = getDataVariable({ variableName: 'not-found-data-source' }, mockSchemaDefinition, [], mockJsonFormVariableWithIncorrectData); fixture.detectChanges(); checkDataTableErrorMessage(); - expect(logServiceSpy).toHaveBeenCalledWith('Data source not found or it is not an array'); expect(widget.dataSource).toBeUndefined(); }); - it('should display and log error if path is incorrect', () => { + it('should display error if path is incorrect', () => { widget.field = getDataVariable( { ...mockVariableConfig, optionsPath: 'wrong.path' }, mockSchemaDefinition, @@ -256,11 +248,10 @@ describe('DataTableWidgetComponent', () => { fixture.detectChanges(); checkDataTableErrorMessage(); - expect(logServiceSpy).toHaveBeenCalledWith('Data source not found or it is not an array'); expect(widget.dataSource).toBeUndefined(); }); - it('should display and log error if provided data by path is not an array', () => { + it('should display error if provided data by path is not an array', () => { widget.field = getDataVariable( { ...mockVariableConfig, optionsPath: 'response.no-array' }, mockSchemaDefinition, @@ -270,7 +261,6 @@ describe('DataTableWidgetComponent', () => { fixture.detectChanges(); checkDataTableErrorMessage(); - expect(logServiceSpy).toHaveBeenCalledWith('Data source not found or it is not an array'); expect(widget.dataSource).toBeUndefined(); }); }); diff --git a/lib/process-services-cloud/src/lib/form/components/widgets/data-table/data-table.widget.ts b/lib/process-services-cloud/src/lib/form/components/widgets/data-table/data-table.widget.ts index dadb811249b..70806d0d6af 100644 --- a/lib/process-services-cloud/src/lib/form/components/widgets/data-table/data-table.widget.ts +++ b/lib/process-services-cloud/src/lib/form/components/widgets/data-table/data-table.widget.ts @@ -18,7 +18,7 @@ /* eslint-disable @angular-eslint/component-selector */ import { Component, OnInit, ViewEncapsulation } from '@angular/core'; -import { WidgetComponent, FormService, DataTableModule, LogService, FormBaseModule, DataRow, DataColumn } from '@alfresco/adf-core'; +import { WidgetComponent, FormService, DataTableModule, FormBaseModule, DataRow, DataColumn } from '@alfresco/adf-core'; import { CommonModule } from '@angular/common'; import { TranslateModule } from '@ngx-translate/core'; import { FormCloudService } from '../../../services/form-cloud.service'; @@ -46,6 +46,7 @@ import { DataTablePathParserHelper } from './helpers/data-table-path-parser.help encapsulation: ViewEncapsulation.None }) export class DataTableWidgetComponent extends WidgetComponent implements OnInit { + dataSource: WidgetDataTableAdapter; dataTableLoadFailed = false; previewState = false; @@ -56,7 +57,7 @@ export class DataTableWidgetComponent extends WidgetComponent implements OnInit private defaultResponseProperty = 'data'; private pathParserHelper = new DataTablePathParserHelper(); - constructor(public formService: FormService, private formCloudService: FormCloudService, private logService: LogService) { + constructor(public formService: FormService, private formCloudService: FormCloudService) { super(formService); } @@ -120,7 +121,7 @@ export class DataTableWidgetComponent extends WidgetComponent implements OnInit private handleError(error: any) { if (!this.previewState) { this.dataTableLoadFailed = true; - this.logService.error(error); + this.widgetError.emit(error); } } } diff --git a/lib/process-services-cloud/src/lib/form/components/widgets/date/date-cloud.widget.spec.ts b/lib/process-services-cloud/src/lib/form/components/widgets/date/date-cloud.widget.spec.ts index 843678ed28b..c6b987ddb11 100644 --- a/lib/process-services-cloud/src/lib/form/components/widgets/date/date-cloud.widget.spec.ts +++ b/lib/process-services-cloud/src/lib/form/components/widgets/date/date-cloud.widget.spec.ts @@ -19,7 +19,6 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; import { DateCloudWidgetComponent } from './date-cloud.widget'; import { FormFieldModel, FormModel, FormFieldTypes, DateFieldValidator, MinDateFieldValidator, MaxDateFieldValidator } from '@alfresco/adf-core'; import { ProcessServiceCloudTestingModule } from '../../../../testing/process-service-cloud.testing.module'; -import { TranslateModule } from '@ngx-translate/core'; import { DateAdapter } from '@angular/material/core'; import { isEqual, subDays, addDays } from 'date-fns'; import { HarnessLoader } from '@angular/cdk/testing'; @@ -37,7 +36,7 @@ describe('DateWidgetComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [TranslateModule.forRoot(), ProcessServiceCloudTestingModule] + imports: [ProcessServiceCloudTestingModule] }); form = new FormModel(); diff --git a/lib/process-services-cloud/src/lib/form/components/widgets/display-external-property/display-external-property.widget.spec.ts b/lib/process-services-cloud/src/lib/form/components/widgets/display-external-property/display-external-property.widget.spec.ts index cd0d532a0e2..038cb98058b 100644 --- a/lib/process-services-cloud/src/lib/form/components/widgets/display-external-property/display-external-property.widget.spec.ts +++ b/lib/process-services-cloud/src/lib/form/components/widgets/display-external-property/display-external-property.widget.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { FormService, FormFieldModel, FormModel, FormFieldTypes, LogService } from '@alfresco/adf-core'; +import { FormService, FormFieldModel, FormModel, FormFieldTypes } from '@alfresco/adf-core'; import { HarnessLoader } from '@angular/cdk/testing'; import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed'; import { ComponentFixture, TestBed } from '@angular/core/testing'; @@ -23,27 +23,19 @@ import { ReactiveFormsModule } from '@angular/forms'; import { MatInputHarness } from '@angular/material/input/testing'; import { DisplayExternalPropertyWidgetComponent } from './display-external-property.widget'; import { FormCloudService } from '../../../services/form-cloud.service'; -import { TranslateModule } from '@ngx-translate/core'; -import { NoopAnimationsModule } from '@angular/platform-browser/animations'; import { By } from '@angular/platform-browser'; +import { ProcessServiceCloudTestingModule } from '../../../../testing/process-service-cloud.testing.module'; describe('DisplayExternalPropertyWidgetComponent', () => { let loader: HarnessLoader; let widget: DisplayExternalPropertyWidgetComponent; let fixture: ComponentFixture; let element: HTMLElement; - let logService: LogService; - let logServiceSpy: jasmine.Spy; let formCloudService: FormCloudService; beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - NoopAnimationsModule, - ReactiveFormsModule, - DisplayExternalPropertyWidgetComponent - ], + imports: [ProcessServiceCloudTestingModule, ReactiveFormsModule, DisplayExternalPropertyWidgetComponent], providers: [FormService] }).compileComponents(); @@ -51,10 +43,7 @@ describe('DisplayExternalPropertyWidgetComponent', () => { widget = fixture.componentInstance; element = fixture.nativeElement; loader = TestbedHarnessEnvironment.loader(fixture); - logService = TestBed.inject(LogService); formCloudService = TestBed.inject(FormCloudService); - - logServiceSpy = spyOn(logService, 'error'); }); it('should display initial value', async () => { @@ -101,10 +90,6 @@ describe('DisplayExternalPropertyWidgetComponent', () => { const errorElement = element.querySelector('error-widget'); expect(errorElement.textContent.trim()).toContain('FORM.FIELD.EXTERNAL_PROPERTY_LOAD_FAILED'); }); - - it('should log the error', () => { - expect(logServiceSpy).toHaveBeenCalledWith('External property not found'); - }); }); describe('when property is in preview state', () => { @@ -124,10 +109,6 @@ describe('DisplayExternalPropertyWidgetComponent', () => { expect(errorElement).toBeFalsy(); }); - it('should NOT log the error', () => { - expect(logServiceSpy).not.toHaveBeenCalled(); - }); - it('should display external property name', () => { const externalPropertyPreview = fixture.debugElement.query(By.css('[data-automation-id="adf-display-external-property-widget-preview"]')); expect(externalPropertyPreview.nativeElement.textContent.trim()).toBe('fruitName'); diff --git a/lib/process-services-cloud/src/lib/form/components/widgets/display-external-property/display-external-property.widget.ts b/lib/process-services-cloud/src/lib/form/components/widgets/display-external-property/display-external-property.widget.ts index d9377632718..57242b578e7 100644 --- a/lib/process-services-cloud/src/lib/form/components/widgets/display-external-property/display-external-property.widget.ts +++ b/lib/process-services-cloud/src/lib/form/components/widgets/display-external-property/display-external-property.widget.ts @@ -16,12 +16,7 @@ */ import { ChangeDetectionStrategy, Component, OnInit, ViewEncapsulation } from '@angular/core'; -import { - WidgetComponent, - FormService, - LogService, - FormBaseModule -} from '@alfresco/adf-core'; +import { WidgetComponent, FormService, FormBaseModule } from '@alfresco/adf-core'; import { CommonModule } from '@angular/common'; import { TranslateModule } from '@ngx-translate/core'; import { FormCloudService } from '../../../services/form-cloud.service'; @@ -31,14 +26,7 @@ import { MatInputModule } from '@angular/material/input'; @Component({ standalone: true, - imports: [ - CommonModule, - TranslateModule, - ReactiveFormsModule, - MatFormFieldModule, - MatInputModule, - FormBaseModule - ], + imports: [CommonModule, TranslateModule, ReactiveFormsModule, MatFormFieldModule, MatInputModule, FormBaseModule], selector: 'adf-cloud-display-external-property', templateUrl: './display-external-property.widget.html', styleUrls: ['./display-external-property.widget.scss'], @@ -57,16 +45,11 @@ import { MatInputModule } from '@angular/material/input'; changeDetection: ChangeDetectionStrategy.OnPush }) export class DisplayExternalPropertyWidgetComponent extends WidgetComponent implements OnInit { - propertyLoadFailed = false; previewState = false; propertyControl: FormControl; - constructor( - public readonly formService: FormService, - private readonly formCloudService: FormCloudService, - private readonly logService: LogService - ) { + constructor(public readonly formService: FormService, private readonly formCloudService: FormCloudService) { super(formService); } @@ -103,7 +86,7 @@ export class DisplayExternalPropertyWidgetComponent extends WidgetComponent impl private handleError(error: any): void { if (!this.previewState) { this.propertyLoadFailed = true; - this.logService.error(error); + this.widgetError.emit(error); } } } diff --git a/lib/process-services-cloud/src/lib/form/components/widgets/dropdown/dropdown-cloud.widget.spec.ts b/lib/process-services-cloud/src/lib/form/components/widgets/dropdown/dropdown-cloud.widget.spec.ts index 47185bf3415..079752593b1 100644 --- a/lib/process-services-cloud/src/lib/form/components/widgets/dropdown/dropdown-cloud.widget.spec.ts +++ b/lib/process-services-cloud/src/lib/form/components/widgets/dropdown/dropdown-cloud.widget.spec.ts @@ -19,23 +19,14 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; import { By } from '@angular/platform-browser'; import { of, throwError } from 'rxjs'; import { DropdownCloudWidgetComponent } from './dropdown-cloud.widget'; -import { - FormFieldModel, - FormModel, - FormService, - FormFieldEvent, - FormFieldTypes, - LogService -} from '@alfresco/adf-core'; +import { FormFieldModel, FormModel, FormService, FormFieldEvent, FormFieldTypes } from '@alfresco/adf-core'; import { FormCloudService } from '../../../services/form-cloud.service'; import { ProcessServiceCloudTestingModule } from '../../../../testing/process-service-cloud.testing.module'; -import { TranslateModule } from '@ngx-translate/core'; import { fakeOptionList, filterOptionList, mockConditionalEntries, mockFormVariableWithJson, - mockPlayersResponse, mockRestDropdownOptions, mockSecondRestDropdownOptions, mockVariablesWithDefaultJson, @@ -49,21 +40,16 @@ import { MatFormFieldHarness } from '@angular/material/form-field/testing'; import { MatTooltipHarness } from '@angular/material/tooltip/testing'; describe('DropdownCloudWidgetComponent', () => { - let formService: FormService; let widget: DropdownCloudWidgetComponent; let formCloudService: FormCloudService; - let logService: LogService; let fixture: ComponentFixture; let element: HTMLElement; let loader: HarnessLoader; beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - ProcessServiceCloudTestingModule - ] + imports: [ProcessServiceCloudTestingModule] }); fixture = TestBed.createComponent(DropdownCloudWidgetComponent); widget = fixture.componentInstance; @@ -71,14 +57,12 @@ describe('DropdownCloudWidgetComponent', () => { formService = TestBed.inject(FormService); formCloudService = TestBed.inject(FormCloudService); - logService = TestBed.inject(LogService); loader = TestbedHarnessEnvironment.loader(fixture); }); afterEach(() => fixture.destroy()); describe('Simple Dropdown', () => { - beforeEach(() => { widget.field = new FormFieldModel(new FormModel({ taskId: 'fake-task-id' }), { id: 'dropdown-id', @@ -163,23 +147,25 @@ describe('DropdownCloudWidgetComponent', () => { name: 'default1_value' }; - spyOn(formCloudService, 'getRestWidgetData').and.returnValue(of([ - { - id: 'opt1', - name: 'default1_value' - }, - { - id: 2, - name: 'default2_value' - } - ] as any)); + spyOn(formCloudService, 'getRestWidgetData').and.returnValue( + of([ + { + id: 'opt1', + name: 'default1_value' + }, + { + id: 2, + name: 'default2_value' + } + ] as any) + ); widget.ngOnInit(); const dropdown = await loader.getHarness(MatSelectHarness.with({ selector: '.adf-select' })); await dropdown.open(); - expect((await (await dropdown.getOptions())[0].getText())).toEqual('default1_value'); + expect(await (await dropdown.getOptions())[0].getText()).toEqual('default1_value'); }); it('should preselect dropdown widget value when String (defined value) passed ', async () => { @@ -187,30 +173,29 @@ describe('DropdownCloudWidgetComponent', () => { widget.field.optionType = 'rest'; widget.field.value = 'opt1'; - spyOn(formCloudService, 'getRestWidgetData').and.returnValue(of([ - { - id: 'opt1', - name: 'default1_value' - }, - { - id: 2, - name: 'default2_value' - } - ] as any)); + spyOn(formCloudService, 'getRestWidgetData').and.returnValue( + of([ + { + id: 'opt1', + name: 'default1_value' + }, + { + id: 2, + name: 'default2_value' + } + ] as any) + ); widget.ngOnInit(); const dropdown = await loader.getHarness(MatSelectHarness.with({ selector: '.adf-select' })); await dropdown.open(); - expect((await (await dropdown.getOptions())[0].getText())).toEqual('default1_value'); + expect(await (await dropdown.getOptions())[0].getText()).toEqual('default1_value'); expect(widget.field.form.values['dropdown-id']).toEqual({ id: 'opt1', name: 'default1_value' }); }); it('should not display required error for a non required dropdown when selecting the none option', async () => { - widget.field.options = [ - { id: 'empty', name: 'Choose empty' }, - ...fakeOptionList - ]; + widget.field.options = [{ id: 'empty', name: 'Choose empty' }, ...fakeOptionList]; widget.ngOnInit(); const dropdown = await loader.getHarness(MatSelectHarness.with({ selector: '.adf-select' })); @@ -226,10 +211,7 @@ describe('DropdownCloudWidgetComponent', () => { it('should not display required error when selecting a valid option for a required dropdown', async () => { widget.field.required = true; - widget.field.options = [ - { id: 'empty', name: 'Choose empty' }, - ...fakeOptionList - ]; + widget.field.options = [{ id: 'empty', name: 'Choose empty' }, ...fakeOptionList]; widget.ngOnInit(); const dropdown = await loader.getHarness(MatSelectHarness.with({ selector: '.adf-select' })); @@ -243,10 +225,7 @@ describe('DropdownCloudWidgetComponent', () => { }); it('should not have a value when switching from an available option to the None option', async () => { - widget.field.options = [ - { id: 'empty', name: 'This is a mock none option' }, - ...fakeOptionList - ]; + widget.field.options = [{ id: 'empty', name: 'This is a mock none option' }, ...fakeOptionList]; widget.ngOnInit(); const dropdown = await loader.getHarness(MatSelectHarness.with({ selector: '.adf-select' })); @@ -270,7 +249,6 @@ describe('DropdownCloudWidgetComponent', () => { }); describe('when tooltip is set', () => { - beforeEach(() => { widget.field = new FormFieldModel(new FormModel({ taskId: '' }), { type: FormFieldTypes.DROPDOWN, @@ -288,7 +266,7 @@ describe('DropdownCloudWidgetComponent', () => { expect(tooltipElement).toBeTruthy(); expect(await tooltipElement.getTooltipText()).toBe('my custom tooltip'); expect(await tooltipElement.isOpen()).toBeTruthy(); - }); + }); it('should hide tooltip', async () => { const dropdown = await loader.getHarness(MatSelectHarness.with({ selector: '.adf-select' })); @@ -303,9 +281,8 @@ describe('DropdownCloudWidgetComponent', () => { }); describe('when is required', () => { - beforeEach(() => { - widget.field = new FormFieldModel( new FormModel({ taskId: '' }), { + widget.field = new FormFieldModel(new FormModel({ taskId: '' }), { type: FormFieldTypes.DROPDOWN, required: true }); @@ -341,7 +318,6 @@ describe('DropdownCloudWidgetComponent', () => { }); describe('filter', () => { - beforeEach(() => { widget.field = new FormFieldModel(new FormModel({ taskId: 'fake-task-id' }), { id: 'dropdown-id', @@ -393,7 +369,6 @@ describe('DropdownCloudWidgetComponent', () => { }); describe('multiple selection', () => { - it('should show preselected option', async () => { widget.field = new FormFieldModel(new FormModel({ taskId: 'fake-task-id' }), { id: 'dropdown-id', @@ -439,31 +414,33 @@ describe('DropdownCloudWidgetComponent', () => { type: 'dropdown', readOnly: 'false', restUrl: 'https://fake-rest-url', - optionType : 'rest', + optionType: 'rest', selectionType: 'multiple', value: [ { id: 'opt_3', name: 'option_3' }, { id: 'opt_4', name: 'option_4' } ] }); - spyOn(formCloudService, 'getRestWidgetData').and.returnValue(of([ - { - id: 'opt_1', - name: 'option_1' - }, - { - id: 'opt_2', - name: 'option_2' - }, - { - id: 'opt_3', - name: 'option_3' - }, - { - id: 'opt_4', - name: 'option_4' - } - ] as any)); + spyOn(formCloudService, 'getRestWidgetData').and.returnValue( + of([ + { + id: 'opt_1', + name: 'option_1' + }, + { + id: 'opt_2', + name: 'option_2' + }, + { + id: 'opt_3', + name: 'option_3' + }, + { + id: 'opt_4', + name: 'option_4' + } + ] as any) + ); const dropdown = await loader.getHarness(MatSelectHarness.with({ selector: '.adf-select' })); @@ -477,28 +454,30 @@ describe('DropdownCloudWidgetComponent', () => { type: 'dropdown', readOnly: 'false', restUrl: 'https://fake-rest-url', - optionType : 'rest', + optionType: 'rest', selectionType: 'multiple' }); - spyOn(formCloudService, 'getRestWidgetData').and.returnValue(of([ - { - id: 'opt_1', - name: 'option_1' - }, - { - id: 'opt_2', - name: 'option_2' - }, - { - id: 'opt_3', - name: 'option_3' - }, - { - id: 'opt_4', - name: 'option_4' - } - ] as any)); + spyOn(formCloudService, 'getRestWidgetData').and.returnValue( + of([ + { + id: 'opt_1', + name: 'option_1' + }, + { + id: 'opt_2', + name: 'option_2' + }, + { + id: 'opt_3', + name: 'option_3' + }, + { + id: 'opt_4', + name: 'option_4' + } + ] as any) + ); const dropdown = await loader.getHarness(MatSelectHarness.with({ selector: '.adf-select' })); await dropdown.clickOptions({ selector: '[id="opt_2"]' }); @@ -512,9 +491,7 @@ describe('DropdownCloudWidgetComponent', () => { }); describe('Linked Dropdown', () => { - describe('Rest URL options', () => { - const parentDropdown = new FormFieldModel(new FormModel(), { id: 'parentDropdown', type: 'dropdown', @@ -716,7 +693,6 @@ describe('DropdownCloudWidgetComponent', () => { }); describe('Load selection for linked dropdown (i.e. saved, completed forms)', () => { - it('should load the selection of a manual type linked dropdown', () => { widget.field = new FormFieldModel(new FormModel({ taskId: 'fake-task-id' }), { id: 'child-dropdown-id', @@ -737,7 +713,7 @@ describe('DropdownCloudWidgetComponent', () => { expect(updateFormSpy).toHaveBeenCalled(); expect(widget.field.options).toEqual(mockConditionalEntries[1].options); - expect(widget.field.form.values).toEqual({ 'child-dropdown-id': { id: 'MI', name: 'MILAN' }}); + expect(widget.field.form.values).toEqual({ 'child-dropdown-id': { id: 'MI', name: 'MILAN' } }); }); it('should load the selection of a rest type linked dropdown', () => { @@ -767,7 +743,6 @@ describe('DropdownCloudWidgetComponent', () => { }); describe('when form model has left labels', () => { - it('should have left labels classes on leftLabels true', async () => { widget.field = new FormFieldModel(new FormModel({ taskId: 'fake-task-id', leftLabels: true }), { id: 'dropdown-id', @@ -828,18 +803,17 @@ describe('DropdownCloudWidgetComponent', () => { }); describe('variable options', () => { - let logServiceSpy: jasmine.Spy; const errorIcon: string = 'error_outline'; const getVariableDropdownWidget = ( - variableName: string, - optionsPath: string, - optionsId: string, - optionsLabel: string, - processVariables?: TaskVariableCloud[], - variables?: TaskVariableCloud[] - ) => new FormFieldModel( - new FormModel({ taskId: 'fake-task-id', processVariables, variables }), { + variableName: string, + optionsPath: string, + optionsId: string, + optionsLabel: string, + processVariables?: TaskVariableCloud[], + variables?: TaskVariableCloud[] + ) => + new FormFieldModel(new FormModel({ taskId: 'fake-task-id', processVariables, variables }), { id: 'variable-dropdown-id', name: 'variable-options-dropdown', type: 'dropdown', @@ -860,12 +834,14 @@ describe('DropdownCloudWidgetComponent', () => { expect(widget.field.options.length).toEqual(0); }; - beforeEach(() => { - logServiceSpy = spyOn(logService, 'error'); - }); - it('should display options persisted from process variable', async () => { - widget.field = getVariableDropdownWidget('variables.json-variable', 'response.people.players', 'playerId', 'playerFullName', mockProcessVariablesWithJson); + widget.field = getVariableDropdownWidget( + 'variables.json-variable', + 'response.people.players', + 'playerId', + 'playerFullName', + mockProcessVariablesWithJson + ); fixture.detectChanges(); const dropdown = await loader.getHarness(MatSelectHarness.with({ selector: '.adf-select' })); await dropdown.open(); @@ -913,35 +889,55 @@ describe('DropdownCloudWidgetComponent', () => { }); it('should return empty array and display error when path is incorrect', () => { - widget.field = getVariableDropdownWidget('variables.json-variable', 'response.wrongPath.players', 'playerId', 'playerFullName', mockProcessVariablesWithJson); + widget.field = getVariableDropdownWidget( + 'variables.json-variable', + 'response.wrongPath.players', + 'playerId', + 'playerFullName', + mockProcessVariablesWithJson + ); fixture.detectChanges(); checkDropdownVariableOptionsFailed(); - expect(logServiceSpy).toHaveBeenCalledWith(`wrongPath not found in ${JSON.stringify(mockPlayersResponse.response)}`); }); it('should return empty array and display error when id is incorrect', () => { - widget.field = getVariableDropdownWidget('variables.json-variable', 'response.people.players', 'wrongId', 'playerFullName', mockProcessVariablesWithJson); + widget.field = getVariableDropdownWidget( + 'variables.json-variable', + 'response.people.players', + 'wrongId', + 'playerFullName', + mockProcessVariablesWithJson + ); fixture.detectChanges(); checkDropdownVariableOptionsFailed(); - expect(logServiceSpy).toHaveBeenCalledWith(`'id' or 'label' is not properly defined`); }); it('should return empty array and display error when label is incorrect', () => { - widget.field = getVariableDropdownWidget('variables.json-variable', 'response.people.players', 'playerId', 'wrongFullName', mockProcessVariablesWithJson); + widget.field = getVariableDropdownWidget( + 'variables.json-variable', + 'response.people.players', + 'playerId', + 'wrongFullName', + mockProcessVariablesWithJson + ); fixture.detectChanges(); checkDropdownVariableOptionsFailed(); - expect(logServiceSpy).toHaveBeenCalledWith(`'id' or 'label' is not properly defined`); }); it('should return empty array and display error when variable is NOT found', () => { - widget.field = getVariableDropdownWidget('variables.wrong-variable-id', 'response.people.players', 'playerId', 'playerFullName', mockProcessVariablesWithJson); + widget.field = getVariableDropdownWidget( + 'variables.wrong-variable-id', + 'response.people.players', + 'playerId', + 'playerFullName', + mockProcessVariablesWithJson + ); fixture.detectChanges(); checkDropdownVariableOptionsFailed(); - expect(logServiceSpy).toHaveBeenCalledWith(`variables.wrong-variable-id not found`); }); it('should return empty array and display error if there are NO process and form variables', () => { @@ -949,11 +945,16 @@ describe('DropdownCloudWidgetComponent', () => { fixture.detectChanges(); checkDropdownVariableOptionsFailed(); - expect(logServiceSpy).toHaveBeenCalledWith('variables.json-variable not found'); }); it('should NOT display errors if form is in the preview state', () => { - widget.field = getVariableDropdownWidget('variables.json-variable', 'response.wrongPath.players', 'playerId', 'playerFullName', mockProcessVariablesWithJson); + widget.field = getVariableDropdownWidget( + 'variables.json-variable', + 'response.wrongPath.players', + 'playerId', + 'playerFullName', + mockProcessVariablesWithJson + ); spyOn(formCloudService, 'getPreviewState').and.returnValue(true); fixture.detectChanges(); diff --git a/lib/process-services-cloud/src/lib/form/components/widgets/dropdown/dropdown-cloud.widget.ts b/lib/process-services-cloud/src/lib/form/components/widgets/dropdown/dropdown-cloud.widget.ts index a53b52bb43b..ec7975a262f 100644 --- a/lib/process-services-cloud/src/lib/form/components/widgets/dropdown/dropdown-cloud.widget.ts +++ b/lib/process-services-cloud/src/lib/form/components/widgets/dropdown/dropdown-cloud.widget.ts @@ -23,7 +23,6 @@ import { FormFieldOption, FormFieldTypes, FormService, - LogService, RuleEntry, WidgetComponent } from '@alfresco/adf-core'; @@ -73,10 +72,7 @@ export class DropdownCloudWidgetComponent extends WidgetComponent implements OnI protected onDestroy$ = new Subject(); - constructor(public formService: FormService, - private formCloudService: FormCloudService, - private logService: LogService, - private appConfig: AppConfigService) { + constructor(public formService: FormService, private formCloudService: FormCloudService, private appConfig: AppConfigService) { super(formService); } @@ -148,8 +144,8 @@ export class DropdownCloudWidgetComponent extends WidgetComponent implements OnI } private getOptionsFromArray(nestedData: any[], id: string, label: string): FormFieldOption[] { - const options = nestedData.map(item => this.createOption(item, id, label)); - const hasInvalidOption = options.some(option => !option); + const options = nestedData.map((item) => this.createOption(item, id, label)); + const hasInvalidOption = options.some((option) => !option); if (hasInvalidOption) { this.variableOptionsFailed = true; @@ -174,7 +170,11 @@ export class DropdownCloudWidgetComponent extends WidgetComponent implements OnI return option; } - private getOptionsFromVariable(processVariables: TaskVariableCloud[], formVariables: TaskVariableCloud[], variableName: string): TaskVariableCloud { + private getOptionsFromVariable( + processVariables: TaskVariableCloud[], + formVariables: TaskVariableCloud[], + variableName: string + ): TaskVariableCloud { const processVariableDropdownOptions: TaskVariableCloud = this.getVariableValueByName(processVariables, variableName); const formVariableDropdownOptions: TaskVariableCloud = this.getVariableValueByName(formVariables, variableName); @@ -182,7 +182,8 @@ export class DropdownCloudWidgetComponent extends WidgetComponent implements OnI } private getVariableValueByName(variables: TaskVariableCloud[], variableName: string): any { - return variables?.find((variable: TaskVariableCloud) => variable?.name === `variables.${variableName}` || variable?.name === variableName)?.value; + return variables?.find((variable: TaskVariableCloud) => variable?.name === `variables.${variableName}` || variable?.name === variableName) + ?.value; } private isVariableOptionType(): boolean { @@ -193,18 +194,22 @@ export class DropdownCloudWidgetComponent extends WidgetComponent implements OnI if (this.isValidRestType()) { this.resetRestApiErrorMessage(); const bodyParam = this.buildBodyParam(); - this.formCloudService.getRestWidgetData(this.field.form.id, this.field.id, bodyParam) + this.formCloudService + .getRestWidgetData(this.field.form.id, this.field.id, bodyParam) .pipe(takeUntil(this.onDestroy$)) - .subscribe((result: FormFieldOption[]) => { - this.resetRestApiErrorMessage(); - this.field.options = result; - this.updateOptions(); - this.field.updateForm(); - this.resetInvalidValue(); - }, (err) => { - this.resetRestApiOptions(); - this.handleError(err); - }); + .subscribe( + (result: FormFieldOption[]) => { + this.resetRestApiErrorMessage(); + this.field.options = result; + this.updateOptions(); + this.field.updateForm(); + this.resetInvalidValue(); + }, + (err) => { + this.resetRestApiOptions(); + this.handleError(err); + } + ); } } @@ -225,7 +230,8 @@ export class DropdownCloudWidgetComponent extends WidgetComponent implements OnI this.formService.formFieldValueChanged .pipe( filter((event: FormFieldEvent) => this.isFormFieldEventOfTypeDropdown(event) && this.isParentFormFieldEvent(event)), - takeUntil(this.onDestroy$)) + takeUntil(this.onDestroy$) + ) .subscribe((event: FormFieldEvent) => { const valueOfParentWidget = event.field.value; this.parentValueChanged(valueOfParentWidget); @@ -291,11 +297,11 @@ export class DropdownCloudWidgetComponent extends WidgetComponent implements OnI private isSelectedValueInOptions(): boolean { if (Array.isArray(this.fieldValue)) { - const optionIdList = [...this.field.options].map(option => option.id); - const fieldValueIds = this.fieldValue.map(valueOption => valueOption.id); - return fieldValueIds.every(valueOptionId => optionIdList.includes(valueOptionId)); + const optionIdList = [...this.field.options].map((option) => option.id); + const fieldValueIds = this.fieldValue.map((valueOption) => valueOption.id); + return fieldValueIds.every((valueOptionId) => optionIdList.includes(valueOptionId)); } else { - return [...this.field.options].map(option => option.id).includes(this.fieldValue); + return [...this.field.options].map((option) => option.id).includes(this.fieldValue); } } @@ -380,7 +386,7 @@ export class DropdownCloudWidgetComponent extends WidgetComponent implements OnI private handleError(error: any) { if (!this.previewState) { - this.logService.error(error); + this.widgetError.emit(error); } } @@ -395,16 +401,15 @@ export class DropdownCloudWidgetComponent extends WidgetComponent implements OnI updateOptions(): void { this.showInputFilter = this.field.options.length > this.appConfig.get('form.dropDownFilterLimit', HIDE_FILTER_LIMIT); - this.list$ = combineLatest([of(this.field.options), this.filter$]) - .pipe( - map(([items, search]) => { - if (!search) { - return items; - } - return items.filter(({ name }) => name.toLowerCase().includes(search.toLowerCase())); - }), - takeUntil(this.onDestroy$) - ); + this.list$ = combineLatest([of(this.field.options), this.filter$]).pipe( + map(([items, search]) => { + if (!search) { + return items; + } + return items.filter(({ name }) => name.toLowerCase().includes(search.toLowerCase())); + }), + takeUntil(this.onDestroy$) + ); } resetRestApiErrorMessage() { @@ -428,10 +433,12 @@ export class DropdownCloudWidgetComponent extends WidgetComponent implements OnI } showRequiredMessage(): boolean { - return (this.isInvalidFieldRequired() || (this.isNoneValueSelected(this.field.value) && this.isRequired())) && + return ( + (this.isInvalidFieldRequired() || (this.isNoneValueSelected(this.field.value) && this.isRequired())) && this.isTouched() && !this.isRestApiFailed && - !this.variableOptionsFailed; + !this.variableOptionsFailed + ); } getDefaultOption(options: FormFieldOption[]): FormFieldOption { diff --git a/lib/process-services-cloud/src/lib/form/components/widgets/group/group-cloud.widget.spec.ts b/lib/process-services-cloud/src/lib/form/components/widgets/group/group-cloud.widget.spec.ts index 1bc3eb5f393..3288b0e096f 100644 --- a/lib/process-services-cloud/src/lib/form/components/widgets/group/group-cloud.widget.spec.ts +++ b/lib/process-services-cloud/src/lib/form/components/widgets/group/group-cloud.widget.spec.ts @@ -19,7 +19,6 @@ import { FormFieldModel, FormFieldTypes, FormModel, IdentityGroupModel } from '@ import { ComponentFixture, TestBed } from '@angular/core/testing'; import { GroupCloudWidgetComponent } from './group-cloud.widget'; import { ProcessServiceCloudTestingModule } from '../../../../testing/process-service-cloud.testing.module'; -import { TranslateModule } from '@ngx-translate/core'; import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core'; import { HarnessLoader } from '@angular/cdk/testing'; import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed'; @@ -35,16 +34,9 @@ describe('GroupCloudWidgetComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - ProcessServiceCloudTestingModule - ], - declarations: [ - GroupCloudWidgetComponent - ], - schemas: [ - CUSTOM_ELEMENTS_SCHEMA - ] + imports: [ProcessServiceCloudTestingModule], + declarations: [GroupCloudWidgetComponent], + schemas: [CUSTOM_ELEMENTS_SCHEMA] }); fixture = TestBed.createComponent(GroupCloudWidgetComponent); widget = fixture.componentInstance; @@ -58,7 +50,7 @@ describe('GroupCloudWidgetComponent', () => { it('should have enabled validation if field is NOT readOnly', () => { const readOnly = false; - widget.field = new FormFieldModel( new FormModel({ taskId: '' }, null, readOnly), { + widget.field = new FormFieldModel(new FormModel({ taskId: '' }, null, readOnly), { type: FormFieldTypes.GROUP, value: [] }); @@ -68,7 +60,6 @@ describe('GroupCloudWidgetComponent', () => { }); describe('when tooltip is set', () => { - beforeEach(() => { widget.field = new FormFieldModel(new FormModel({ taskId: '' }), { type: FormFieldTypes.GROUP, @@ -86,7 +77,7 @@ describe('GroupCloudWidgetComponent', () => { const tooltipElement = await loader.getHarness(MatTooltipHarness); expect(await tooltipElement.isOpen()).toBeTruthy(); expect(await tooltipElement.getTooltipText()).toEqual('my custom tooltip'); - }); + }); it('should hide tooltip', async () => { const cloudGroupInput = element.querySelector('[data-automation-id="adf-cloud-group-search-input"]'); @@ -104,9 +95,8 @@ describe('GroupCloudWidgetComponent', () => { }); describe('when is required', () => { - beforeEach(() => { - widget.field = new FormFieldModel( new FormModel({ taskId: '' }), { + widget.field = new FormFieldModel(new FormModel({ taskId: '' }), { type: FormFieldTypes.GROUP, required: true }); @@ -138,7 +128,7 @@ describe('GroupCloudWidgetComponent', () => { }); it('should be invalid after deselecting all groups', async () => { - widget.onChangedGroup([{id: 'test-id', name: 'test-name'}]); + widget.onChangedGroup([{ id: 'test-id', name: 'test-name' }]); fixture.detectChanges(); await fixture.whenStable(); @@ -156,16 +146,17 @@ describe('GroupCloudWidgetComponent', () => { }); describe('when is readOnly', () => { - const readOnly = true; it('should single chip be disabled', async () => { - const mockSpaghetti: IdentityGroupModel[] = [{ - id: 'bolognese', - name: 'Bolognese' - }]; + const mockSpaghetti: IdentityGroupModel[] = [ + { + id: 'bolognese', + name: 'Bolognese' + } + ]; - widget.field = new FormFieldModel( new FormModel({ taskId: ''}, null, readOnly), { + widget.field = new FormFieldModel(new FormModel({ taskId: '' }, null, readOnly), { type: FormFieldTypes.GROUP, value: mockSpaghetti }); @@ -186,7 +177,7 @@ describe('GroupCloudWidgetComponent', () => { { id: 'carbonara', name: 'Carbonara' } ]; - widget.field = new FormFieldModel( new FormModel({ taskId: ''}, null, readOnly), { + widget.field = new FormFieldModel(new FormModel({ taskId: '' }, null, readOnly), { type: FormFieldTypes.GROUP, value: mockSpaghetti }); @@ -203,7 +194,7 @@ describe('GroupCloudWidgetComponent', () => { }); it('should have disabled validation', () => { - widget.field = new FormFieldModel( new FormModel({ taskId: ''}, null, readOnly), { + widget.field = new FormFieldModel(new FormModel({ taskId: '' }, null, readOnly), { type: FormFieldTypes.GROUP, value: [] }); @@ -214,7 +205,6 @@ describe('GroupCloudWidgetComponent', () => { }); describe('when form model has left labels', () => { - it('should have left labels classes on leftLabels true', async () => { widget.field = new FormFieldModel(new FormModel({ taskId: 'fake-task-id', leftLabels: true }), { id: 'group-id', diff --git a/lib/process-services-cloud/src/lib/form/components/widgets/people/people-cloud.widget.spec.ts b/lib/process-services-cloud/src/lib/form/components/widgets/people/people-cloud.widget.spec.ts index f436c0e1e80..8ad6bbc0c6f 100644 --- a/lib/process-services-cloud/src/lib/form/components/widgets/people/people-cloud.widget.spec.ts +++ b/lib/process-services-cloud/src/lib/form/components/widgets/people/people-cloud.widget.spec.ts @@ -16,7 +16,6 @@ */ import { FormFieldModel, FormFieldTypes, FormModel, IdentityUserModel } from '@alfresco/adf-core'; -import { TranslateModule } from '@ngx-translate/core'; import { ComponentFixture, TestBed } from '@angular/core/testing'; import { PeopleCloudWidgetComponent } from './people-cloud.widget'; import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core'; @@ -38,16 +37,9 @@ describe('PeopleCloudWidgetComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - ProcessServiceCloudTestingModule - ], - declarations: [ - PeopleCloudWidgetComponent - ], - schemas: [ - CUSTOM_ELEMENTS_SCHEMA - ] + imports: [ProcessServiceCloudTestingModule], + declarations: [PeopleCloudWidgetComponent], + schemas: [CUSTOM_ELEMENTS_SCHEMA] }); identityUserService = TestBed.inject(IdentityUserService); fixture = TestBed.createComponent(PeopleCloudWidgetComponent); @@ -85,7 +77,7 @@ describe('PeopleCloudWidgetComponent', () => { it('should have enabled validation if field is NOT readOnly', () => { const readOnly = false; - widget.field = new FormFieldModel( new FormModel({ taskId: ''}, null, readOnly), { + widget.field = new FormFieldModel(new FormModel({ taskId: '' }, null, readOnly), { type: FormFieldTypes.PEOPLE, value: [] }); @@ -95,7 +87,6 @@ describe('PeopleCloudWidgetComponent', () => { }); describe('when tooltip is set', () => { - beforeEach(() => { widget.field = new FormFieldModel(new FormModel({ taskId: '' }), { type: FormFieldTypes.PEOPLE, @@ -114,7 +105,7 @@ describe('PeopleCloudWidgetComponent', () => { const tooltipElement = await loader.getHarness(MatTooltipHarness); expect(await tooltipElement.isOpen()).toBeTruthy(); expect(await tooltipElement.getTooltipText()).toEqual('my custom tooltip'); - }); + }); it('should hide tooltip', async () => { const cloudPeopleInput = element.querySelector('adf-cloud-people'); @@ -132,9 +123,8 @@ describe('PeopleCloudWidgetComponent', () => { }); describe('when is required', () => { - beforeEach(() => { - widget.field = new FormFieldModel( new FormModel({ taskId: '' }), { + widget.field = new FormFieldModel(new FormModel({ taskId: '' }), { type: FormFieldTypes.PEOPLE, required: true }); @@ -166,7 +156,7 @@ describe('PeopleCloudWidgetComponent', () => { }); it('should be invalid after deselecting all people', async () => { - widget.onChangedUser([{id: 'test-id', username: 'test-name'}]); + widget.onChangedUser([{ id: 'test-id', username: 'test-name' }]); fixture.detectChanges(); await fixture.whenStable(); @@ -184,17 +174,18 @@ describe('PeopleCloudWidgetComponent', () => { }); describe('when is readOnly', () => { - const readOnly = true; it('should single chip be disabled', async () => { - const mockSpaghetti: IdentityUserModel[] = [{ - id: 'bolognese', - username: 'Bolognese', - email: 'bolognese@example.com' - }]; + const mockSpaghetti: IdentityUserModel[] = [ + { + id: 'bolognese', + username: 'Bolognese', + email: 'bolognese@example.com' + } + ]; - widget.field = new FormFieldModel( new FormModel({ taskId: ''}, null, readOnly), { + widget.field = new FormFieldModel(new FormModel({ taskId: '' }, null, readOnly), { type: FormFieldTypes.PEOPLE, value: mockSpaghetti }); @@ -214,7 +205,7 @@ describe('PeopleCloudWidgetComponent', () => { { id: 'carbonara', username: 'Carbonara', email: 'carbonara@example.com' } ]; - widget.field = new FormFieldModel( new FormModel({ taskId: ''}, null, readOnly), { + widget.field = new FormFieldModel(new FormModel({ taskId: '' }, null, readOnly), { type: FormFieldTypes.PEOPLE, value: mockSpaghetti }); @@ -229,7 +220,7 @@ describe('PeopleCloudWidgetComponent', () => { }); it('should have disabled validation', () => { - widget.field = new FormFieldModel( new FormModel({ taskId: ''}, null, readOnly), { + widget.field = new FormFieldModel(new FormModel({ taskId: '' }, null, readOnly), { type: FormFieldTypes.PEOPLE, value: [] }); @@ -240,7 +231,6 @@ describe('PeopleCloudWidgetComponent', () => { }); describe('when form model has left labels', () => { - it('should have left labels classes on leftLabels true', async () => { widget.field = new FormFieldModel(new FormModel({ taskId: 'fake-task-id', leftLabels: true }), { id: 'people-id', diff --git a/lib/process-services-cloud/src/lib/form/components/widgets/properties-viewer/properties-viewer-wrapper/properties-viewer.widget.spec.ts b/lib/process-services-cloud/src/lib/form/components/widgets/properties-viewer/properties-viewer-wrapper/properties-viewer.widget.spec.ts index 21461be3ac4..78be6b03ad2 100644 --- a/lib/process-services-cloud/src/lib/form/components/widgets/properties-viewer/properties-viewer-wrapper/properties-viewer.widget.spec.ts +++ b/lib/process-services-cloud/src/lib/form/components/widgets/properties-viewer/properties-viewer-wrapper/properties-viewer.widget.spec.ts @@ -16,7 +16,6 @@ */ import { ComponentFixture, TestBed } from '@angular/core/testing'; -import { TranslateModule } from '@ngx-translate/core'; import { PropertiesViewerWrapperComponent } from './properties-viewer-wrapper.component'; import { ProcessServiceCloudTestingModule } from '../../../../../testing/process-service-cloud.testing.module'; import { of } from 'rxjs'; @@ -30,14 +29,8 @@ describe('PropertiesViewerWidgetComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - ProcessServiceCloudTestingModule - ], - providers: [ - NodesApiService, - { provide: BasicPropertiesService, useValue: { getProperties: () => [] } } - ] + imports: [ProcessServiceCloudTestingModule], + providers: [NodesApiService, { provide: BasicPropertiesService, useValue: { getProperties: () => [] } }] }); fixture = TestBed.createComponent(PropertiesViewerWrapperComponent); component = fixture.componentInstance; diff --git a/lib/process-services-cloud/src/lib/form/components/widgets/properties-viewer/properties-viewer.widget.spec.ts b/lib/process-services-cloud/src/lib/form/components/widgets/properties-viewer/properties-viewer.widget.spec.ts index 7f36ddea9e6..0f685628da6 100644 --- a/lib/process-services-cloud/src/lib/form/components/widgets/properties-viewer/properties-viewer.widget.spec.ts +++ b/lib/process-services-cloud/src/lib/form/components/widgets/properties-viewer/properties-viewer.widget.spec.ts @@ -17,7 +17,6 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; import { FormFieldModel, FormModel } from '@alfresco/adf-core'; -import { TranslateModule } from '@ngx-translate/core'; import { PropertiesViewerWidgetComponent } from './properties-viewer.widget'; import { ProcessServiceCloudTestingModule } from '../../../../testing/process-service-cloud.testing.module'; import { fakeNodeWithProperties } from '../../../mocks/attach-file-cloud-widget.mock'; @@ -48,15 +47,9 @@ describe('PropertiesViewerWidgetComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - ProcessServiceCloudTestingModule - ], + imports: [ProcessServiceCloudTestingModule], declarations: [PropertiesViewerWrapperComponent], - providers: [ - NodesApiService, - { provide: BasicPropertiesService, useValue: { getProperties: () => [] } } - ] + providers: [NodesApiService, { provide: BasicPropertiesService, useValue: { getProperties: () => [] } }] }); fixture = TestBed.createComponent(PropertiesViewerWidgetComponent); nodesApiService = TestBed.inject(NodesApiService); diff --git a/lib/process-services-cloud/src/lib/form/components/widgets/radio-buttons/radio-buttons-cloud.widget.spec.ts b/lib/process-services-cloud/src/lib/form/components/widgets/radio-buttons/radio-buttons-cloud.widget.spec.ts index a783446a0c5..18822cb365b 100644 --- a/lib/process-services-cloud/src/lib/form/components/widgets/radio-buttons/radio-buttons-cloud.widget.spec.ts +++ b/lib/process-services-cloud/src/lib/form/components/widgets/radio-buttons/radio-buttons-cloud.widget.spec.ts @@ -16,7 +16,6 @@ */ import { ComponentFixture, TestBed } from '@angular/core/testing'; -import { TranslateModule } from '@ngx-translate/core'; import { FormFieldModel, FormFieldOption, FormFieldTypes, FormModel } from '@alfresco/adf-core'; import { FormCloudService } from '../../../services/form-cloud.service'; import { RadioButtonsCloudWidgetComponent } from './radio-buttons-cloud.widget'; @@ -46,10 +45,7 @@ describe('RadioButtonsCloudWidgetComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - ProcessServiceCloudTestingModule - ] + imports: [ProcessServiceCloudTestingModule] }); formCloudService = TestBed.inject(FormCloudService); fixture = TestBed.createComponent(RadioButtonsCloudWidgetComponent); @@ -132,7 +128,7 @@ describe('RadioButtonsCloudWidgetComponent', () => { const option = await loader.getHarness(MatRadioButtonHarness.with({ label: 'opt-name-1' })); await option.check(); - await loader.getHarness(MatRadioButtonHarness.with({ checked: true, label: 'opt-name-1'})); + await loader.getHarness(MatRadioButtonHarness.with({ checked: true, label: 'opt-name-1' })); expect(widget.field.isValid).toBe(true); }); @@ -210,7 +206,6 @@ describe('RadioButtonsCloudWidgetComponent', () => { }); describe('when tooltip is set', () => { - beforeEach(() => { widget.field = new FormFieldModel(new FormModel({ taskId: '' }), { type: FormFieldTypes.RADIO_BUTTONS, @@ -226,7 +221,7 @@ describe('RadioButtonsCloudWidgetComponent', () => { await (await radioButton.host()).hover(); const tooltip = await loader.getHarness(MatTooltipHarness); expect(await tooltip.getTooltipText()).toBe('my custom tooltip'); - }); + }); it('should hide tooltip', async () => { const radioButton = await loader.getHarness(MatRadioButtonHarness); diff --git a/lib/process-services-cloud/src/lib/form/components/widgets/radio-buttons/radio-buttons-cloud.widget.ts b/lib/process-services-cloud/src/lib/form/components/widgets/radio-buttons/radio-buttons-cloud.widget.ts index a99d4525ca5..3e351a91484 100644 --- a/lib/process-services-cloud/src/lib/form/components/widgets/radio-buttons/radio-buttons-cloud.widget.ts +++ b/lib/process-services-cloud/src/lib/form/components/widgets/radio-buttons/radio-buttons-cloud.widget.ts @@ -18,7 +18,7 @@ /* eslint-disable @angular-eslint/component-selector */ import { Component, OnInit, ViewEncapsulation } from '@angular/core'; -import { WidgetComponent, FormService, LogService, FormFieldOption, ErrorMessageModel } from '@alfresco/adf-core'; +import { WidgetComponent, FormService, FormFieldOption, ErrorMessageModel } from '@alfresco/adf-core'; import { FormCloudService } from '../../../services/form-cloud.service'; import { Subject } from 'rxjs'; import { takeUntil } from 'rxjs/operators'; @@ -47,12 +47,7 @@ export class RadioButtonsCloudWidgetComponent extends WidgetComponent implements protected onDestroy$ = new Subject(); - constructor( - public formService: FormService, - private formCloudService: FormCloudService, - private logService: LogService, - private translateService: TranslateService - ) { + constructor(public formService: FormService, private formCloudService: FormCloudService, private translateService: TranslateService) { super(formService); } @@ -87,7 +82,7 @@ export class RadioButtonsCloudWidgetComponent extends WidgetComponent implements this.restApiError = new ErrorMessageModel({ message: this.translateService.instant('FORM.FIELD.REST_API_FAILED', { hostname: this.getRestUrlHostName() }) }); - this.logService.error(error); + this.widgetError.emit(error); } isChecked(option: FormFieldOption): boolean { diff --git a/lib/process-services-cloud/src/lib/form/services/content-cloud-node-selector.service.spec.ts b/lib/process-services-cloud/src/lib/form/services/content-cloud-node-selector.service.spec.ts index 85e3bc32f52..3ea32b24eb9 100644 --- a/lib/process-services-cloud/src/lib/form/services/content-cloud-node-selector.service.spec.ts +++ b/lib/process-services-cloud/src/lib/form/services/content-cloud-node-selector.service.spec.ts @@ -18,7 +18,6 @@ import { TestBed } from '@angular/core/testing'; import { AlfrescoApiService, AlfrescoApiServiceMock, NotificationService } from '@alfresco/adf-core'; import { ProcessServiceCloudTestingModule } from '../../testing/process-service-cloud.testing.module'; -import { TranslateModule } from '@ngx-translate/core'; import { MatDialog, MatDialogModule } from '@angular/material/dialog'; import { of, Subject } from 'rxjs'; import { ContentCloudNodeSelectorService } from './content-cloud-node-selector.service'; @@ -51,7 +50,7 @@ describe('ContentCloudNodeSelectorService', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [TranslateModule.forRoot(), ProcessServiceCloudTestingModule, MatDialogModule], + imports: [ProcessServiceCloudTestingModule, MatDialogModule], providers: [{ provide: AlfrescoApiService, useClass: AlfrescoApiServiceMock }] }); service = TestBed.inject(ContentCloudNodeSelectorService); diff --git a/lib/process-services-cloud/src/lib/form/services/content-cloud-node-selector.service.ts b/lib/process-services-cloud/src/lib/form/services/content-cloud-node-selector.service.ts index e84bdbc20d0..fb123132d88 100644 --- a/lib/process-services-cloud/src/lib/form/services/content-cloud-node-selector.service.ts +++ b/lib/process-services-cloud/src/lib/form/services/content-cloud-node-selector.service.ts @@ -16,13 +16,9 @@ */ import { Injectable } from '@angular/core'; -import { AlfrescoApiService, LogService, NotificationService } from '@alfresco/adf-core'; +import { AlfrescoApiService, NotificationService } from '@alfresco/adf-core'; import { MatDialog } from '@angular/material/dialog'; -import { - ContentNodeSelectorComponent, - ContentNodeSelectorComponentData, - NodeAction -} from '@alfresco/adf-content-services'; +import { ContentNodeSelectorComponent, ContentNodeSelectorComponentData, NodeAction } from '@alfresco/adf-content-services'; import { Node, NodeEntry, NodesApi } from '@alfresco/js-api'; import { from, Observable, Subject, throwError } from 'rxjs'; import { catchError, map, mapTo } from 'rxjs/operators'; @@ -32,7 +28,6 @@ import { DestinationFolderPathModel } from '../models/form-cloud-representation. providedIn: 'root' }) export class ContentCloudNodeSelectorService { - private _nodesApi: NodesApi; get nodesApi(): NodesApi { this._nodesApi = this._nodesApi ?? new NodesApi(this.apiService.getInstance()); @@ -41,14 +36,14 @@ export class ContentCloudNodeSelectorService { sourceNodeNotFound = false; - constructor( - private apiService: AlfrescoApiService, - private notificationService: NotificationService, - private logService: LogService, - private dialog: MatDialog) { - } + constructor(private apiService: AlfrescoApiService, private notificationService: NotificationService, private dialog: MatDialog) {} - openUploadFileDialog(currentFolderId?: string, selectionMode?: string, isAllFileSources?: boolean, restrictRootToCurrentFolderId?: boolean): Observable { + openUploadFileDialog( + currentFolderId?: string, + selectionMode?: string, + isAllFileSources?: boolean, + restrictRootToCurrentFolderId?: boolean + ): Observable { const select = new Subject(); select.subscribe({ complete: this.close.bind(this) }); const data = { @@ -71,9 +66,7 @@ export class ContentCloudNodeSelectorService { if (destinationFolderPath.alias && destinationFolderPath.path) { try { return await this.getNodeId(destinationFolderPath.alias, destinationFolderPath.path).toPromise(); - } catch (error) { - this.logService.error(error); - } + } catch {} } return this.getNodeId(destinationFolderPath.alias).toPromise(); @@ -89,9 +82,7 @@ export class ContentCloudNodeSelectorService { if (nodeId) { try { isExistingNode = await this.getNodeId(nodeId).pipe(mapTo(true)).toPromise(); - } catch (error) { - this.logService.error(error); - } + } catch {} } return isExistingNode; } diff --git a/lib/process-services-cloud/src/lib/form/services/form-cloud.service.spec.ts b/lib/process-services-cloud/src/lib/form/services/form-cloud.service.spec.ts index 15d7a3a72cc..afa3eede1cf 100644 --- a/lib/process-services-cloud/src/lib/form/services/form-cloud.service.spec.ts +++ b/lib/process-services-cloud/src/lib/form/services/form-cloud.service.spec.ts @@ -19,18 +19,15 @@ import { TestBed } from '@angular/core/testing'; import { FormCloudService } from './form-cloud.service'; import { of } from 'rxjs'; import { ProcessServiceCloudTestingModule } from '../../testing/process-service-cloud.testing.module'; -import { TranslateModule } from '@ngx-translate/core'; import { AdfHttpClient } from '@alfresco/adf-core/api'; const mockTaskResponseBody = { - entry: - { id: 'id', name: 'name', formKey: 'form-key' } + entry: { id: 'id', name: 'name', formKey: 'form-key' } }; const mockFormResponseBody = { formRepresentation: { id: 'form-id', name: 'task-form', taskId: 'task-id' } }; describe('Form Cloud service', () => { - let service: FormCloudService; let adfHttpClient: AdfHttpClient; let requestSpy: jasmine.Spy; @@ -40,10 +37,7 @@ describe('Form Cloud service', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - ProcessServiceCloudTestingModule - ] + imports: [ProcessServiceCloudTestingModule] }); service = TestBed.inject(FormCloudService); adfHttpClient = TestBed.inject(AdfHttpClient); @@ -88,44 +82,45 @@ describe('Form Cloud service', () => { expect(requestSpy.calls.mostRecent().args[1].httpMethod).toBe('GET'); done(); }); - }); it('should fetch task variables', (done) => { - requestSpy.and.returnValue(Promise.resolve({ - list: { - entries: [ - { - entry: { - serviceName: 'fake-rb', - serviceFullName: 'fake-rb', - serviceVersion: '', - appName: 'fake', - appVersion: '', - serviceType: null, - id: 25, - type: 'string', - name: 'fakeProperty', - createTime: 1556112661342, - lastUpdatedTime: 1556112661342, - executionId: null, - value: 'fakeValue', - markedAsDeleted: false, - processInstanceId: '18e16bc7-6694-11e9-9c1b-0a586460028a', - taskId: '18e192da-6694-11e9-9c1b-0a586460028a', - taskVariable: true + requestSpy.and.returnValue( + Promise.resolve({ + list: { + entries: [ + { + entry: { + serviceName: 'fake-rb', + serviceFullName: 'fake-rb', + serviceVersion: '', + appName: 'fake', + appVersion: '', + serviceType: null, + id: 25, + type: 'string', + name: 'fakeProperty', + createTime: 1556112661342, + lastUpdatedTime: 1556112661342, + executionId: null, + value: 'fakeValue', + markedAsDeleted: false, + processInstanceId: '18e16bc7-6694-11e9-9c1b-0a586460028a', + taskId: '18e192da-6694-11e9-9c1b-0a586460028a', + taskVariable: true + } } + ], + pagination: { + skipCount: 0, + maxItems: 100, + count: 1, + hasMoreItems: false, + totalItems: 1 } - ], - pagination: { - skipCount: 0, - maxItems: 100, - count: 1, - hasMoreItems: false, - totalItems: 1 } - } - })); + }) + ); service.getTaskVariables(appName, taskId).subscribe((result) => { expect(result).toBeDefined(); @@ -139,40 +134,42 @@ describe('Form Cloud service', () => { }); it('should fetch result if the variable value is 0', (done) => { - requestSpy.and.returnValue(Promise.resolve({ - list: { - entries: [ - { - entry: { - serviceName: 'fake-rb', - serviceFullName: 'fake-rb', - serviceVersion: '', - appName: 'fake', - appVersion: '', - serviceType: null, - id: 25, - type: 'string', - name: 'fakeProperty', - createTime: 1556112661342, - lastUpdatedTime: 1556112661342, - executionId: null, - value: 0, - markedAsDeleted: false, - processInstanceId: '18e16bc7-6694-11e9-9c1b-0a586460028a', - taskId: '18e192da-6694-11e9-9c1b-0a586460028a', - taskVariable: true + requestSpy.and.returnValue( + Promise.resolve({ + list: { + entries: [ + { + entry: { + serviceName: 'fake-rb', + serviceFullName: 'fake-rb', + serviceVersion: '', + appName: 'fake', + appVersion: '', + serviceType: null, + id: 25, + type: 'string', + name: 'fakeProperty', + createTime: 1556112661342, + lastUpdatedTime: 1556112661342, + executionId: null, + value: 0, + markedAsDeleted: false, + processInstanceId: '18e16bc7-6694-11e9-9c1b-0a586460028a', + taskId: '18e192da-6694-11e9-9c1b-0a586460028a', + taskVariable: true + } } + ], + pagination: { + skipCount: 0, + maxItems: 100, + count: 1, + hasMoreItems: false, + totalItems: 1 } - ], - pagination: { - skipCount: 0, - maxItems: 100, - count: 1, - hasMoreItems: false, - totalItems: 1 } - } - })); + }) + ); service.getTaskVariables(appName, taskId).subscribe((result) => { expect(result).toBeDefined(); @@ -185,12 +182,14 @@ describe('Form Cloud service', () => { it('should fetch task form flattened', (done) => { spyOn(service, 'getTask').and.returnValue(of(mockTaskResponseBody.entry)); - spyOn(service, 'getForm').and.returnValue(of({ - formRepresentation: { - name: 'task-form', - formDefinition: {} - } - } as any)); + spyOn(service, 'getForm').and.returnValue( + of({ + formRepresentation: { + name: 'task-form', + formDefinition: {} + } + } as any) + ); service.getTaskForm(appName, taskId).subscribe((result) => { expect(result).toBeDefined(); @@ -199,7 +198,6 @@ describe('Form Cloud service', () => { expect(result.taskName).toBe('name'); done(); }); - }); it('should save task form', (done) => { @@ -214,7 +212,6 @@ describe('Form Cloud service', () => { expect(requestSpy.calls.mostRecent().args[1].httpMethod).toBe('POST'); done(); }); - }); it('should complete task form', (done) => { diff --git a/lib/process-services-cloud/src/lib/form/services/form-definition-selector-cloud.service.spec.ts b/lib/process-services-cloud/src/lib/form/services/form-definition-selector-cloud.service.spec.ts index 7d5b4d8ffaf..35703215eec 100644 --- a/lib/process-services-cloud/src/lib/form/services/form-definition-selector-cloud.service.spec.ts +++ b/lib/process-services-cloud/src/lib/form/services/form-definition-selector-cloud.service.spec.ts @@ -18,22 +18,17 @@ import { TestBed } from '@angular/core/testing'; import { FormDefinitionSelectorCloudService } from './form-definition-selector-cloud.service'; import { ProcessServiceCloudTestingModule } from '../../testing/process-service-cloud.testing.module'; -import { TranslateModule } from '@ngx-translate/core'; import { mockFormRepresentations } from '../mocks/form-representation.mock'; import { AdfHttpClient } from '@alfresco/adf-core/api'; describe('Form Definition Selector Cloud Service', () => { - let service: FormDefinitionSelectorCloudService; let adfHttpClient: AdfHttpClient; const appName = 'app-name'; beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - ProcessServiceCloudTestingModule - ] + imports: [ProcessServiceCloudTestingModule] }); service = TestBed.inject(FormDefinitionSelectorCloudService); adfHttpClient = TestBed.inject(AdfHttpClient); diff --git a/lib/process-services-cloud/src/lib/group/components/group-cloud.component.spec.ts b/lib/process-services-cloud/src/lib/group/components/group-cloud.component.spec.ts index 43a9068f696..c82cfa3c64f 100644 --- a/lib/process-services-cloud/src/lib/group/components/group-cloud.component.spec.ts +++ b/lib/process-services-cloud/src/lib/group/components/group-cloud.component.spec.ts @@ -23,7 +23,6 @@ import { GroupCloudModule } from '../group-cloud.module'; import { GroupCloudComponent } from './group-cloud.component'; import { CoreTestingModule } from '@alfresco/adf-core'; import { DebugElement, SimpleChange } from '@angular/core'; -import { TranslateModule } from '@ngx-translate/core'; import { IdentityGroupService } from '../services/identity-group.service'; import { mockFoodGroups, mockMeatChicken, mockVegetableAubergine } from '../mock/group-cloud.mock'; import { HarnessLoader } from '@angular/cdk/testing'; @@ -74,7 +73,7 @@ describe('GroupCloudComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [TranslateModule.forRoot(), CoreTestingModule, ProcessServiceCloudTestingModule, GroupCloudModule] + imports: [CoreTestingModule, ProcessServiceCloudTestingModule, GroupCloudModule] }); fixture = TestBed.createComponent(GroupCloudComponent); component = fixture.componentInstance; diff --git a/lib/process-services-cloud/src/lib/group/components/group-cloud.component.ts b/lib/process-services-cloud/src/lib/group/components/group-cloud.component.ts index 411eb1e7727..302e8ac3cb3 100644 --- a/lib/process-services-cloud/src/lib/group/components/group-cloud.component.ts +++ b/lib/process-services-cloud/src/lib/group/components/group-cloud.component.ts @@ -33,7 +33,6 @@ import { UntypedFormControl } from '@angular/forms'; import { trigger, state, style, transition, animate } from '@angular/animations'; import { BehaviorSubject, Observable, Subject } from 'rxjs'; import { distinctUntilChanged, switchMap, mergeMap, filter, tap, takeUntil, debounceTime } from 'rxjs/operators'; -import { LogService } from '@alfresco/adf-core'; import { ComponentSelectionMode } from '../../types'; import { IdentityGroupModel } from '../models/identity-group.model'; import { IdentityGroupServiceInterface } from '../services/identity-group.service.interface'; @@ -140,8 +139,7 @@ export class GroupCloudComponent implements OnInit, OnChanges, OnDestroy { constructor( @Inject(IDENTITY_GROUP_SERVICE_TOKEN) - private identityGroupService: IdentityGroupServiceInterface, - private logService: LogService + private identityGroupService: IdentityGroupServiceInterface ) {} ngOnInit(): void { @@ -247,7 +245,6 @@ export class GroupCloudComponent implements OnInit, OnChanges, OnDestroy { } } catch (error) { this.invalidGroups.push(group); - this.logService.error(error); } } diff --git a/lib/process-services-cloud/src/lib/group/services/identity-group.service.spec.ts b/lib/process-services-cloud/src/lib/group/services/identity-group.service.spec.ts index 0da48e3672e..c77405ad21a 100644 --- a/lib/process-services-cloud/src/lib/group/services/identity-group.service.spec.ts +++ b/lib/process-services-cloud/src/lib/group/services/identity-group.service.spec.ts @@ -16,7 +16,6 @@ */ import { TestBed } from '@angular/core/testing'; -import { TranslateModule } from '@ngx-translate/core'; import { ProcessServiceCloudTestingModule } from '../../testing/process-service-cloud.testing.module'; import { IdentityGroupService } from './identity-group.service'; import { @@ -29,17 +28,13 @@ import { mockFoodGroups } from '../mock/group-cloud.mock'; import { AdfHttpClient } from '@alfresco/adf-core/api'; describe('IdentityGroupService', () => { - let service: IdentityGroupService; let adfHttpClient: AdfHttpClient; let requestSpy: jasmine.Spy; beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - ProcessServiceCloudTestingModule - ] + imports: [ProcessServiceCloudTestingModule] }); service = TestBed.inject(IdentityGroupService); adfHttpClient = TestBed.inject(AdfHttpClient); @@ -47,21 +42,18 @@ describe('IdentityGroupService', () => { }); describe('Search', () => { - it('should fetch groups', (done) => { requestSpy.and.returnValue(Promise.resolve(mockFoodGroups)); const searchSpy = spyOn(service, 'search').and.callThrough(); - service.search('fake').subscribe( - res => { - expect(res).toBeDefined(); - expect(searchSpy).toHaveBeenCalled(); - expect(service.queryParams).toEqual({ - search: 'fake' - }); - done(); - } - ); + service.search('fake').subscribe((res) => { + expect(res).toBeDefined(); + expect(searchSpy).toHaveBeenCalled(); + expect(service.queryParams).toEqual({ + search: 'fake' + }); + done(); + }); }); it('should not fetch groups if error occurred', (done) => { @@ -69,113 +61,104 @@ describe('IdentityGroupService', () => { const searchSpy = spyOn(service, 'search').and.callThrough(); - service.search('fake') - .subscribe( - () => { - fail('expected an error, not groups'); - }, - (error) => { - expect(searchSpy).toHaveBeenCalled(); - expect(error.status).toEqual(404); - expect(error.statusText).toEqual('Not Found'); - expect(error.error).toEqual('Mock Error'); - done(); - } - ); + service.search('fake').subscribe( + () => { + fail('expected an error, not groups'); + }, + (error) => { + expect(searchSpy).toHaveBeenCalled(); + expect(error.status).toEqual(404); + expect(error.statusText).toEqual('Not Found'); + expect(error.error).toEqual('Mock Error'); + done(); + } + ); }); it('should fetch groups by roles', (done) => { requestSpy.and.returnValue(Promise.resolve(mockFoodGroups)); const searchSpy = spyOn(service, 'search').and.callThrough(); + service.search('fake', mockSearchGroupByRoles).subscribe((res) => { + expect(res).toBeDefined(); + expect(searchSpy).toHaveBeenCalled(); + expect(service.queryParams).toEqual({ + search: 'fake', + role: 'fake-role-1,fake-role-2' + }); + done(); + }); + }); + + it('should not fetch groups by roles if error occurred', (done) => { + requestSpy.and.returnValue(Promise.reject(mockHttpErrorResponse)); + const searchSpy = spyOn(service, 'search').and.callThrough(); + service.search('fake', mockSearchGroupByRoles).subscribe( - res => { - expect(res).toBeDefined(); + () => { + fail('expected an error, not groups'); + }, + (error) => { expect(searchSpy).toHaveBeenCalled(); expect(service.queryParams).toEqual({ search: 'fake', role: 'fake-role-1,fake-role-2' }); + expect(error.status).toEqual(404); + expect(error.statusText).toEqual('Not Found'); + expect(error.error).toEqual('Mock Error'); done(); } ); }); - it('should not fetch groups by roles if error occurred', (done) => { - requestSpy.and.returnValue(Promise.reject(mockHttpErrorResponse)); - const searchSpy = spyOn(service, 'search').and.callThrough(); - - service.search('fake', mockSearchGroupByRoles) - .subscribe( - () => { - fail('expected an error, not groups'); - }, - (error) => { - expect(searchSpy).toHaveBeenCalled(); - expect(service.queryParams).toEqual({ - search: 'fake', - role: 'fake-role-1,fake-role-2' - }); - expect(error.status).toEqual(404); - expect(error.statusText).toEqual('Not Found'); - expect(error.error).toEqual('Mock Error'); - done(); - } - ); - }); - it('should fetch groups within app', (done) => { requestSpy.and.returnValue(Promise.resolve(mockFoodGroups)); - service.search('fake', mockSearchGroupByApp).subscribe( - res => { - expect(res).toBeDefined(); - expect(service.queryParams).toEqual({ - search: 'fake', - application: 'fake-app-name' - }); - done(); - } - ); + service.search('fake', mockSearchGroupByApp).subscribe((res) => { + expect(res).toBeDefined(); + expect(service.queryParams).toEqual({ + search: 'fake', + application: 'fake-app-name' + }); + done(); + }); }); it('should fetch groups within app with roles', (done) => { requestSpy.and.returnValue(Promise.resolve(mockFoodGroups)); - service.search('fake', mockSearchGroupByRolesAndApp).subscribe( - res => { - expect(res).toBeDefined(); - expect(service.queryParams).toEqual({ - search: 'fake', - application: 'fake-app-name', - role: 'fake-role-1,fake-role-2' - }); - done(); - } - ); + service.search('fake', mockSearchGroupByRolesAndApp).subscribe((res) => { + expect(res).toBeDefined(); + expect(service.queryParams).toEqual({ + search: 'fake', + application: 'fake-app-name', + role: 'fake-role-1,fake-role-2' + }); + done(); + }); }); it('should not fetch groups within app if error occurred', (done) => { requestSpy.and.returnValue(Promise.reject(mockHttpErrorResponse)); const searchSpy = spyOn(service, 'search').and.callThrough(); - service.search('fake', mockSearchGroupByApp) - .subscribe( - () => { - fail('expected an error, not groups'); - }, - (error) => { - expect(searchSpy).toHaveBeenCalled(); - expect(service.queryParams).toEqual({ - search: 'fake', - application: 'fake-app-name' - }); - expect(error.status).toEqual(404); - expect(error.statusText).toEqual('Not Found'); - expect(error.error).toEqual('Mock Error'); - done(); - } - ); + service.search('fake', mockSearchGroupByApp).subscribe( + () => { + fail('expected an error, not groups'); + }, + (error) => { + expect(searchSpy).toHaveBeenCalled(); + expect(service.queryParams).toEqual({ + search: 'fake', + application: 'fake-app-name' + }); + expect(error.status).toEqual(404); + expect(error.statusText).toEqual('Not Found'); + expect(error.error).toEqual('Mock Error'); + done(); + } + ); }); }); }); diff --git a/lib/process-services-cloud/src/lib/people/components/people-cloud.component.spec.ts b/lib/process-services-cloud/src/lib/people/components/people-cloud.component.spec.ts index a2dadeaf245..d6cf48e84fb 100644 --- a/lib/process-services-cloud/src/lib/people/components/people-cloud.component.spec.ts +++ b/lib/process-services-cloud/src/lib/people/components/people-cloud.component.spec.ts @@ -22,7 +22,6 @@ import { ProcessServiceCloudTestingModule } from '../../testing/process-service- import { PeopleCloudModule } from '../people-cloud.module'; import { DebugElement, SimpleChange } from '@angular/core'; import { By } from '@angular/platform-browser'; -import { TranslateModule } from '@ngx-translate/core'; import { of } from 'rxjs'; import { IdentityUserServiceInterface } from '../services/identity-user.service.interface'; import { IDENTITY_USER_SERVICE_TOKEN } from '../services/identity-user-service.token'; @@ -83,7 +82,7 @@ describe('PeopleCloudComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [TranslateModule.forRoot(), CoreTestingModule, ProcessServiceCloudTestingModule, PeopleCloudModule] + imports: [CoreTestingModule, ProcessServiceCloudTestingModule, PeopleCloudModule] }); fixture = TestBed.createComponent(PeopleCloudComponent); component = fixture.componentInstance; diff --git a/lib/process-services-cloud/src/lib/people/components/people-cloud.component.ts b/lib/process-services-cloud/src/lib/people/components/people-cloud.component.ts index 890779966e7..6189faaa757 100644 --- a/lib/process-services-cloud/src/lib/people/components/people-cloud.component.ts +++ b/lib/process-services-cloud/src/lib/people/components/people-cloud.component.ts @@ -32,7 +32,7 @@ import { } from '@angular/core'; import { BehaviorSubject, Observable, Subject } from 'rxjs'; import { switchMap, debounceTime, distinctUntilChanged, mergeMap, tap, filter, takeUntil } from 'rxjs/operators'; -import { FullNamePipe, LogService } from '@alfresco/adf-core'; +import { FullNamePipe } from '@alfresco/adf-core'; import { trigger, state, style, transition, animate } from '@angular/animations'; import { ComponentSelectionMode } from '../../types'; import { IdentityUserModel } from '../models/identity-user.model'; @@ -162,8 +162,7 @@ export class PeopleCloudComponent implements OnInit, OnChanges, OnDestroy { constructor( @Inject(IDENTITY_USER_SERVICE_TOKEN) - private identityUserService: IdentityUserServiceInterface, - private logService: LogService + private identityUserService: IdentityUserServiceInterface ) {} ngOnInit(): void { @@ -300,7 +299,6 @@ export class PeopleCloudComponent implements OnInit, OnChanges, OnDestroy { } } catch (error) { this.invalidUsers.push(user); - this.logService.error(error); } } diff --git a/lib/process-services-cloud/src/lib/people/services/identity-user.service.spec.ts b/lib/process-services-cloud/src/lib/people/services/identity-user.service.spec.ts index fa9cdecad2b..67e4328cd61 100644 --- a/lib/process-services-cloud/src/lib/people/services/identity-user.service.spec.ts +++ b/lib/process-services-cloud/src/lib/people/services/identity-user.service.spec.ts @@ -16,7 +16,6 @@ */ import { TestBed } from '@angular/core/testing'; -import { TranslateModule } from '@ngx-translate/core'; import { IdentityUserService } from './identity-user.service'; import { ProcessServiceCloudTestingModule } from '../../testing/process-service-cloud.testing.module'; import { @@ -33,17 +32,13 @@ import { AdfHttpClient } from '@alfresco/adf-core/api'; import { mockHttpErrorResponse } from '../../group/mock/identity-group.service.mock'; describe('IdentityUserService', () => { - let service: IdentityUserService; let adfHttpClient: AdfHttpClient; let requestSpy: jasmine.Spy; beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - ProcessServiceCloudTestingModule - ] + imports: [ProcessServiceCloudTestingModule] }); service = TestBed.inject(IdentityUserService); adfHttpClient = TestBed.inject(AdfHttpClient); @@ -51,21 +46,18 @@ describe('IdentityUserService', () => { }); describe('Search', () => { - it('should fetch users', (done) => { requestSpy.and.returnValue(Promise.resolve(mockFoodUsers)); const searchSpy = spyOn(service, 'search').and.callThrough(); - service.search('fake').subscribe( - res => { - expect(res).toBeDefined(); - expect(searchSpy).toHaveBeenCalled(); - expect(service.queryParams).toEqual({ - search: 'fake' - }); - done(); - } - ); + service.search('fake').subscribe((res) => { + expect(res).toBeDefined(); + expect(searchSpy).toHaveBeenCalled(); + expect(service.queryParams).toEqual({ + search: 'fake' + }); + done(); + }); }); it('should not fetch users if error occurred', (done) => { @@ -73,190 +65,172 @@ describe('IdentityUserService', () => { const searchSpy = spyOn(service, 'search').and.callThrough(); - service.search('fake') - .subscribe( - () => { - fail('expected an error, not users'); - }, - (error) => { - expect(searchSpy).toHaveBeenCalled(); - expect(error.status).toEqual(404); - expect(error.statusText).toEqual('Not Found'); - expect(error.error).toEqual('Mock Error'); - done(); - } - ); + service.search('fake').subscribe( + () => { + fail('expected an error, not users'); + }, + (error) => { + expect(searchSpy).toHaveBeenCalled(); + expect(error.status).toEqual(404); + expect(error.statusText).toEqual('Not Found'); + expect(error.error).toEqual('Mock Error'); + done(); + } + ); }); it('should fetch users by roles', (done) => { requestSpy.and.returnValue(Promise.resolve(mockFoodUsers)); const searchSpy = spyOn(service, 'search').and.callThrough(); - service.search('fake', mockSearchUserByRoles).subscribe( - res => { - expect(res).toBeDefined(); - expect(searchSpy).toHaveBeenCalled(); - expect(service.queryParams).toEqual({ - search: 'fake', - role: 'fake-role-1,fake-role-2' - }); - done(); - } - ); + service.search('fake', mockSearchUserByRoles).subscribe((res) => { + expect(res).toBeDefined(); + expect(searchSpy).toHaveBeenCalled(); + expect(service.queryParams).toEqual({ + search: 'fake', + role: 'fake-role-1,fake-role-2' + }); + done(); + }); }); it('should not fetch users by roles if error occurred', (done) => { requestSpy.and.returnValue(Promise.reject(mockHttpErrorResponse)); - service.search('fake', mockSearchUserByRoles) - .subscribe( - () => { - fail('expected an error, not users'); - }, - (error) => { - expect(error.status).toEqual(404); - expect(error.statusText).toEqual('Not Found'); - expect(error.error).toEqual('Mock Error'); - done(); - } - ); + service.search('fake', mockSearchUserByRoles).subscribe( + () => { + fail('expected an error, not users'); + }, + (error) => { + expect(error.status).toEqual(404); + expect(error.statusText).toEqual('Not Found'); + expect(error.error).toEqual('Mock Error'); + done(); + } + ); }); it('should fetch users by groups', (done) => { requestSpy.and.returnValue(Promise.resolve(mockFoodUsers)); const searchSpy = spyOn(service, 'search').and.callThrough(); - service.search('fake', mockSearchUserByGroups).subscribe( - res => { - expect(res).toBeDefined(); - expect(searchSpy).toHaveBeenCalled(); - expect(service.queryParams).toEqual({ - search: 'fake', - group: 'fake-group-1,fake-group-2' - }); - done(); - } - ); + service.search('fake', mockSearchUserByGroups).subscribe((res) => { + expect(res).toBeDefined(); + expect(searchSpy).toHaveBeenCalled(); + expect(service.queryParams).toEqual({ + search: 'fake', + group: 'fake-group-1,fake-group-2' + }); + done(); + }); }); it('should fetch users by roles with groups', (done) => { requestSpy.and.returnValue(Promise.resolve(mockFoodUsers)); const searchSpy = spyOn(service, 'search').and.callThrough(); - service.search('fake', mockSearchUserByGroupsAndRoles).subscribe( - res => { - expect(res).toBeDefined(); - expect(searchSpy).toHaveBeenCalled(); - expect(service.queryParams).toEqual({ - search: 'fake', - role: 'fake-role-1,fake-role-2', - group: 'fake-group-1,fake-group-2' - }); - done(); - } - ); + service.search('fake', mockSearchUserByGroupsAndRoles).subscribe((res) => { + expect(res).toBeDefined(); + expect(searchSpy).toHaveBeenCalled(); + expect(service.queryParams).toEqual({ + search: 'fake', + role: 'fake-role-1,fake-role-2', + group: 'fake-group-1,fake-group-2' + }); + done(); + }); }); it('should fetch users by roles with groups and appName', (done) => { requestSpy.and.returnValue(Promise.resolve(mockFoodUsers)); const searchSpy = spyOn(service, 'search').and.callThrough(); - service.search('fake', mockSearchUserByGroupsAndRolesAndApp).subscribe( - res => { - expect(res).toBeDefined(); - expect(searchSpy).toHaveBeenCalled(); - expect(service.queryParams).toEqual({ - search: 'fake', - role: 'fake-role-1,fake-role-2', - application: 'fake-app-name', - group: 'fake-group-1,fake-group-2' - }); - done(); - } - ); + service.search('fake', mockSearchUserByGroupsAndRolesAndApp).subscribe((res) => { + expect(res).toBeDefined(); + expect(searchSpy).toHaveBeenCalled(); + expect(service.queryParams).toEqual({ + search: 'fake', + role: 'fake-role-1,fake-role-2', + application: 'fake-app-name', + group: 'fake-group-1,fake-group-2' + }); + done(); + }); }); it('should not fetch users by groups if error occurred', (done) => { requestSpy.and.returnValue(Promise.reject(mockHttpErrorResponse)); - service.search('fake', mockSearchUserByGroups) - .subscribe( - () => { - fail('expected an error, not users'); - }, - (error) => { - expect(error.status).toEqual(404); - expect(error.statusText).toEqual('Not Found'); - expect(error.error).toEqual('Mock Error'); - done(); - } - ); + service.search('fake', mockSearchUserByGroups).subscribe( + () => { + fail('expected an error, not users'); + }, + (error) => { + expect(error.status).toEqual(404); + expect(error.statusText).toEqual('Not Found'); + expect(error.error).toEqual('Mock Error'); + done(); + } + ); }); it('should fetch users within app', (done) => { requestSpy.and.returnValue(Promise.resolve(mockFoodUsers)); - service.search('fake', mockSearchUserByApp).subscribe( - res => { - expect(res).toBeDefined(); - expect(service.queryParams).toEqual({ - search: 'fake', - application: 'fake-app-name' - }); - done(); - } - ); + service.search('fake', mockSearchUserByApp).subscribe((res) => { + expect(res).toBeDefined(); + expect(service.queryParams).toEqual({ + search: 'fake', + application: 'fake-app-name' + }); + done(); + }); }); it('should fetch users within app with roles', (done) => { requestSpy.and.returnValue(Promise.resolve(mockFoodUsers)); - service.search('fake', mockSearchUserByRolesAndApp).subscribe( - res => { - expect(res).toBeDefined(); - expect(service.queryParams).toEqual({ - search: 'fake', - application: 'fake-app-name', - role: 'fake-role-1,fake-role-2' - }); - done(); - } - ); + service.search('fake', mockSearchUserByRolesAndApp).subscribe((res) => { + expect(res).toBeDefined(); + expect(service.queryParams).toEqual({ + search: 'fake', + application: 'fake-app-name', + role: 'fake-role-1,fake-role-2' + }); + done(); + }); }); it('should fetch users within app with groups', (done) => { requestSpy.and.returnValue(Promise.resolve(mockFoodUsers)); const searchSpy = spyOn(service, 'search').and.callThrough(); - service.search('fake', mockSearchUserByAppAndGroups).subscribe( - res => { - expect(res).toBeDefined(); - expect(searchSpy).toHaveBeenCalled(); - expect(service.queryParams).toEqual({ - search: 'fake', - application: 'fake-app-name', - group: 'fake-group-1,fake-group-2' - }); - done(); - } - ); + service.search('fake', mockSearchUserByAppAndGroups).subscribe((res) => { + expect(res).toBeDefined(); + expect(searchSpy).toHaveBeenCalled(); + expect(service.queryParams).toEqual({ + search: 'fake', + application: 'fake-app-name', + group: 'fake-group-1,fake-group-2' + }); + done(); + }); }); it('should not fetch users within app if error occurred', (done) => { requestSpy.and.returnValue(Promise.reject(mockHttpErrorResponse)); - service.search('fake', mockSearchUserByApp) - .subscribe( - () => { - fail('expected an error, not users'); - }, - (error) => { - expect(error.status).toEqual(404); - expect(error.statusText).toEqual('Not Found'); - expect(error.error).toEqual('Mock Error'); - done(); - } - ); + service.search('fake', mockSearchUserByApp).subscribe( + () => { + fail('expected an error, not users'); + }, + (error) => { + expect(error.status).toEqual(404); + expect(error.statusText).toEqual('Not Found'); + expect(error.error).toEqual('Mock Error'); + done(); + } + ); }); }); }); diff --git a/lib/process-services-cloud/src/lib/pipes/process-name-cloud.pipe.spec.ts b/lib/process-services-cloud/src/lib/pipes/process-name-cloud.pipe.spec.ts index e58a15da5eb..c5da80734b3 100644 --- a/lib/process-services-cloud/src/lib/pipes/process-name-cloud.pipe.spec.ts +++ b/lib/process-services-cloud/src/lib/pipes/process-name-cloud.pipe.spec.ts @@ -16,13 +16,11 @@ */ import { TestBed } from '@angular/core/testing'; -import { TranslateModule } from '@ngx-translate/core'; import { ProcessNameCloudPipe } from './process-name-cloud.pipe'; import { LocalizedDatePipe, CoreTestingModule } from '@alfresco/adf-core'; import { ProcessInstanceCloud } from '../process/start-process/models/process-instance-cloud.model'; describe('ProcessNameCloudPipe', () => { - let processNamePipe: ProcessNameCloudPipe; const defaultName = 'default-name'; const datetimeIdentifier = '%{datetime}'; @@ -36,10 +34,7 @@ describe('ProcessNameCloudPipe', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - CoreTestingModule - ] + imports: [CoreTestingModule] }); const localizedDatePipe = TestBed.inject(LocalizedDatePipe); processNamePipe = new ProcessNameCloudPipe(localizedDatePipe); @@ -71,5 +66,4 @@ describe('ProcessNameCloudPipe', () => { const transformResult = processNamePipe.transform(nameWithProcessDefinitionIdentifier); expect(transformResult).toEqual(`${defaultName} - `); }); - }); diff --git a/lib/process-services-cloud/src/lib/process/directives/cancel-process.directive.spec.ts b/lib/process-services-cloud/src/lib/process/directives/cancel-process.directive.spec.ts index 0c53b5f4cf1..e2b785ca067 100644 --- a/lib/process-services-cloud/src/lib/process/directives/cancel-process.directive.spec.ts +++ b/lib/process-services-cloud/src/lib/process/directives/cancel-process.directive.spec.ts @@ -19,7 +19,6 @@ import { Component, ViewChild } from '@angular/core'; import { ComponentFixture, TestBed } from '@angular/core/testing'; import { CancelProcessDirective } from './cancel-process.directive'; import { ProcessServiceCloudTestingModule } from '../../testing/process-service-cloud.testing.module'; -import { TranslateModule } from '@ngx-translate/core'; import { ProcessInstanceCloud } from '../start-process/models/process-instance-cloud.model'; import { IdentityUserService } from '../../people/services/identity-user.service'; @@ -27,13 +26,11 @@ const processDetailsMockRunning: ProcessInstanceCloud = { initiator: 'usermock', const processDetailsMockCompleted: ProcessInstanceCloud = { initiator: 'usermock', status: 'COMPLETED' }; describe('CancelProcessDirective', () => { - @Component({ selector: 'adf-cloud-cancel-process-test-component', template: '' }) class TestComponent { - @ViewChild(CancelProcessDirective) cancelProcessDirective: CancelProcessDirective; } @@ -44,18 +41,13 @@ describe('CancelProcessDirective', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - ProcessServiceCloudTestingModule - ], - declarations: [ - TestComponent - ] + imports: [ProcessServiceCloudTestingModule], + declarations: [TestComponent] }); fixture = TestBed.createComponent(TestComponent); component = fixture.componentInstance; identityUserService = TestBed.inject(IdentityUserService); - spyOn(identityUserService, 'getCurrentUserInfo').and.returnValue({username: 'usermock'}); + spyOn(identityUserService, 'getCurrentUserInfo').and.returnValue({ username: 'usermock' }); fixture.detectChanges(); }); diff --git a/lib/process-services-cloud/src/lib/process/mock/process-cloud.service.mock.ts b/lib/process-services-cloud/src/lib/process/mock/process-cloud.service.mock.ts index bfa8c0b5f63..ac70278498f 100644 --- a/lib/process-services-cloud/src/lib/process/mock/process-cloud.service.mock.ts +++ b/lib/process-services-cloud/src/lib/process/mock/process-cloud.service.mock.ts @@ -15,7 +15,6 @@ * limitations under the License. */ -import { LogService } from '@alfresco/adf-core'; import { Injectable } from '@angular/core'; import { Observable, of, Subject, throwError } from 'rxjs'; import { ProcessInstanceCloud } from '../start-process/models/process-instance-cloud.model'; @@ -30,11 +29,8 @@ import { ProcessCloudInterface } from '../services/process-cloud.interface'; providedIn: 'root' }) export class ProcessCloudServiceMock implements ProcessCloudInterface { - dataChangesDetected = new Subject(); - constructor(private logService: LogService) { } - getProcessInstanceById(appName: string, processInstanceId: string): Observable { if (appName === 'app-placeholders' && processInstanceId) { return of(processInstancePlaceholdersCloudMock); @@ -42,9 +38,7 @@ export class ProcessCloudServiceMock implements ProcessCloudInterface { if (appName && processInstanceId) { return of(processInstanceDetailsCloudMock); - } else { - this.logService.error('AppName and ProcessInstanceId are mandatory for querying a process'); return throwError('AppName/ProcessInstanceId not configured'); } } @@ -52,9 +46,7 @@ export class ProcessCloudServiceMock implements ProcessCloudInterface { getProcessDefinitions(appName: string): Observable { if (appName || appName === '') { return of(fakeProcessDefinitions); - } else { - this.logService.error('AppName is mandatory for querying task'); return throwError('AppName not configured'); } } @@ -63,7 +55,6 @@ export class ProcessCloudServiceMock implements ProcessCloudInterface { if (appName) { return of(mockAppVersions); } else { - this.logService.error('AppName is mandatory for querying the versions of an application'); return throwError('AppName not configured'); } } @@ -72,7 +63,6 @@ export class ProcessCloudServiceMock implements ProcessCloudInterface { if (appName && processInstanceId) { return of(); } else { - this.logService.error('App name and Process id are mandatory for deleting a process'); return throwError('App name and process id not configured'); } } diff --git a/lib/process-services-cloud/src/lib/process/process-filters/components/edit-process-filter-cloud.component.spec.ts b/lib/process-services-cloud/src/lib/process/process-filters/components/edit-process-filter-cloud.component.spec.ts index d8f6201b809..2c93c66630c 100644 --- a/lib/process-services-cloud/src/lib/process/process-filters/components/edit-process-filter-cloud.component.spec.ts +++ b/lib/process-services-cloud/src/lib/process/process-filters/components/edit-process-filter-cloud.component.spec.ts @@ -34,7 +34,6 @@ import { AppsProcessCloudService } from '../../../app/services/apps-process-clou import { fakeApplicationInstance, fakeApplicationInstanceWithEnvironment } from './../../../app/mock/app-model.mock'; import { PROCESS_FILTERS_SERVICE_TOKEN } from '../../../services/cloud-token.service'; import { LocalPreferenceCloudService } from '../../../services/local-preference-cloud.service'; -import { TranslateModule } from '@ngx-translate/core'; import { ProcessCloudService } from '../../services/process-cloud.service'; import { DateCloudFilterType } from '../../../models/date-cloud-filter.model'; import { MatIconTestingModule } from '@angular/material/icon/testing'; @@ -84,7 +83,7 @@ describe('EditProcessFilterCloudComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [TranslateModule.forRoot(), ProcessFiltersCloudModule, ProcessServiceCloudTestingModule, MatIconTestingModule], + imports: [ProcessFiltersCloudModule, ProcessServiceCloudTestingModule, MatIconTestingModule], providers: [MatDialog, { provide: PROCESS_FILTERS_SERVICE_TOKEN, useClass: LocalPreferenceCloudService }] }); fixture = TestBed.createComponent(EditProcessFilterCloudComponent); diff --git a/lib/process-services-cloud/src/lib/process/process-filters/components/process-filter-dialog-cloud.component.spec.ts b/lib/process-services-cloud/src/lib/process/process-filters/components/process-filter-dialog-cloud.component.spec.ts index 5d32a2d0546..5a865a6e3ac 100644 --- a/lib/process-services-cloud/src/lib/process/process-filters/components/process-filter-dialog-cloud.component.spec.ts +++ b/lib/process-services-cloud/src/lib/process/process-filters/components/process-filter-dialog-cloud.component.spec.ts @@ -20,7 +20,6 @@ import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog'; import { ProcessFilterDialogCloudComponent } from './process-filter-dialog-cloud.component'; import { ProcessServiceCloudTestingModule } from '../../../testing/process-service-cloud.testing.module'; import { ProcessFiltersCloudModule } from '../process-filters-cloud.module'; -import { TranslateModule } from '@ngx-translate/core'; describe('ProcessFilterDialogCloudComponent', () => { let component: ProcessFilterDialogCloudComponent; @@ -32,16 +31,12 @@ describe('ProcessFilterDialogCloudComponent', () => { }; const mockDialogData = { - data: {name: 'Mock-Title'} + data: { name: 'Mock-Title' } }; beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - ProcessServiceCloudTestingModule, - ProcessFiltersCloudModule - ], + imports: [ProcessServiceCloudTestingModule, ProcessFiltersCloudModule], providers: [ { provide: MatDialogRef, useValue: mockDialogRef }, { provide: MAT_DIALOG_DATA, useValue: mockDialogData } @@ -62,20 +57,14 @@ describe('ProcessFilterDialogCloudComponent', () => { it('should display title', () => { fixture.detectChanges(); - const titleElement = fixture.debugElement.nativeElement.querySelector( - '#adf-process-filter-dialog-title' - ); + const titleElement = fixture.debugElement.nativeElement.querySelector('#adf-process-filter-dialog-title'); expect(titleElement.textContent).toEqual(' ADF_CLOUD_EDIT_PROCESS_FILTER.DIALOG.TITLE '); }); it('should enable save button if form is valid', async () => { fixture.detectChanges(); - const saveButton = fixture.debugElement.nativeElement.querySelector( - '#adf-save-button-id' - ); - const inputElement = fixture.debugElement.nativeElement.querySelector( - '#adf-filter-name-id' - ); + const saveButton = fixture.debugElement.nativeElement.querySelector('#adf-save-button-id'); + const inputElement = fixture.debugElement.nativeElement.querySelector('#adf-filter-name-id'); inputElement.value = 'My custom Name'; inputElement.dispatchEvent(new Event('input')); @@ -88,36 +77,28 @@ describe('ProcessFilterDialogCloudComponent', () => { it('should disable save button if form is not valid', async () => { fixture.detectChanges(); - const inputElement = fixture.debugElement.nativeElement.querySelector( - '#adf-filter-name-id' - ); + const inputElement = fixture.debugElement.nativeElement.querySelector('#adf-filter-name-id'); inputElement.value = ''; inputElement.dispatchEvent(new Event('input')); fixture.detectChanges(); await fixture.whenStable(); - const saveButton = fixture.debugElement.nativeElement.querySelector( - '#adf-save-button-id' - ); + const saveButton = fixture.debugElement.nativeElement.querySelector('#adf-save-button-id'); expect(saveButton).toBeDefined(); expect(saveButton.disabled).toBe(true); }); it('should able to close dialog on click of save button if form is valid', async () => { fixture.detectChanges(); - const inputElement = fixture.debugElement.nativeElement.querySelector( - '#adf-filter-name-id' - ); + const inputElement = fixture.debugElement.nativeElement.querySelector('#adf-filter-name-id'); inputElement.value = 'My custom Name'; inputElement.dispatchEvent(new Event('input')); fixture.detectChanges(); await fixture.whenStable(); - const saveButton = fixture.debugElement.nativeElement.querySelector( - '#adf-save-button-id' - ); + const saveButton = fixture.debugElement.nativeElement.querySelector('#adf-save-button-id'); expect(saveButton).toBeDefined(); expect(saveButton.disabled).toBeFalsy(); @@ -127,9 +108,7 @@ describe('ProcessFilterDialogCloudComponent', () => { it('should able close dialog on click of cancel button', () => { component.data = { data: { name: '' } }; - const cancelButton = fixture.debugElement.nativeElement.querySelector( - '#adf-cancel-button-id' - ); + const cancelButton = fixture.debugElement.nativeElement.querySelector('#adf-cancel-button-id'); fixture.detectChanges(); cancelButton.click(); expect(cancelButton).toBeDefined(); diff --git a/lib/process-services-cloud/src/lib/process/process-filters/components/process-filters-cloud.component.spec.ts b/lib/process-services-cloud/src/lib/process/process-filters/components/process-filters-cloud.component.spec.ts index cab67bf1f8c..18e4336d57d 100644 --- a/lib/process-services-cloud/src/lib/process/process-filters/components/process-filters-cloud.component.spec.ts +++ b/lib/process-services-cloud/src/lib/process/process-filters/components/process-filters-cloud.component.spec.ts @@ -25,7 +25,6 @@ import { ProcessServiceCloudTestingModule } from '../../../testing/process-servi import { ProcessFiltersCloudModule } from '../process-filters-cloud.module'; import { PROCESS_FILTERS_SERVICE_TOKEN } from '../../../services/cloud-token.service'; import { LocalPreferenceCloudService } from '../../../services/local-preference-cloud.service'; -import { TranslateModule } from '@ngx-translate/core'; import { mockProcessFilters } from '../mock/process-filters-cloud.mock'; describe('ProcessFiltersCloudComponent', () => { @@ -36,14 +35,8 @@ describe('ProcessFiltersCloudComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - ProcessServiceCloudTestingModule, - ProcessFiltersCloudModule - ], - providers: [ - { provide: PROCESS_FILTERS_SERVICE_TOKEN, useClass: LocalPreferenceCloudService } - ] + imports: [ProcessServiceCloudTestingModule, ProcessFiltersCloudModule], + providers: [{ provide: PROCESS_FILTERS_SERVICE_TOKEN, useClass: LocalPreferenceCloudService }] }); fixture = TestBed.createComponent(ProcessFiltersCloudComponent); component = fixture.componentInstance; @@ -58,7 +51,7 @@ describe('ProcessFiltersCloudComponent', () => { it('should attach specific icon for each filter if hasIcon is true', async () => { const change = new SimpleChange(undefined, 'my-app-1', true); - component.ngOnChanges({appName: change}); + component.ngOnChanges({ appName: change }); fixture.detectChanges(); await fixture.whenStable(); @@ -90,7 +83,7 @@ describe('ProcessFiltersCloudComponent', () => { it('should display the filters', async () => { const change = new SimpleChange(undefined, 'my-app-1', true); - component.ngOnChanges({appName: change}); + component.ngOnChanges({ appName: change }); fixture.detectChanges(); await fixture.whenStable(); @@ -115,9 +108,9 @@ describe('ProcessFiltersCloudComponent', () => { const change = new SimpleChange(null, appName, true); let lastValue: any; - component.error.subscribe((err) => lastValue = err); + component.error.subscribe((err) => (lastValue = err)); - component.ngOnChanges({appName: change}); + component.ngOnChanges({ appName: change }); fixture.detectChanges(); expect(lastValue).toBeDefined(); }); @@ -168,7 +161,7 @@ describe('ProcessFiltersCloudComponent', () => { expect(component.currentFilter).toEqual(mockProcessFilters[1]); expect(filterSelectedSpy).toHaveBeenCalledWith(mockProcessFilters[1]); - }); + }); it('should select the filter based on the input by key param', async () => { const filterSelectedSpy = spyOn(component.filterSelected, 'emit'); @@ -180,7 +173,7 @@ describe('ProcessFiltersCloudComponent', () => { expect(component.currentFilter).toEqual(mockProcessFilters[2]); expect(filterSelectedSpy).toHaveBeenCalledWith(mockProcessFilters[2]); - }); + }); it('should select the filter based on the input by index param', async () => { const filterSelectedSpy = spyOn(component.filterSelected, 'emit'); @@ -192,7 +185,7 @@ describe('ProcessFiltersCloudComponent', () => { expect(component.currentFilter).toEqual(mockProcessFilters[2]); expect(filterSelectedSpy).toHaveBeenCalledWith(mockProcessFilters[2]); - }); + }); it('should select the filter based on the input by id param', async () => { const filterSelectedSpy = spyOn(component.filterSelected, 'emit'); @@ -285,7 +278,6 @@ describe('ProcessFiltersCloudComponent', () => { }); describe('Highlight Selected Filter', () => { - const allProcessesFilterKey = mockProcessFilters[0].key; const runningProcessesFilterKey = mockProcessFilters[1].key; const completedProcessesFilterKey = mockProcessFilters[2].key; diff --git a/lib/process-services-cloud/src/lib/process/process-filters/services/process-filter-cloud.service.spec.ts b/lib/process-services-cloud/src/lib/process/process-filters/services/process-filter-cloud.service.spec.ts index a4f07c519ae..4e5fb0fb72a 100644 --- a/lib/process-services-cloud/src/lib/process/process-filters/services/process-filter-cloud.service.spec.ts +++ b/lib/process-services-cloud/src/lib/process/process-filters/services/process-filter-cloud.service.spec.ts @@ -21,8 +21,13 @@ import { ProcessFilterCloudService } from './process-filter-cloud.service'; import { PROCESS_FILTERS_SERVICE_TOKEN } from '../../../services/cloud-token.service'; import { LocalPreferenceCloudService } from '../../../services/local-preference-cloud.service'; import { ProcessServiceCloudTestingModule } from '../../../testing/process-service-cloud.testing.module'; -import { TranslateModule } from '@ngx-translate/core'; -import { fakeEmptyProcessCloudFilterEntries, fakeProcessCloudFilterEntries, fakeProcessCloudFilters, fakeProcessCloudFilterWithDifferentEntries, fakeProcessFilter } from '../mock/process-filters-cloud.mock'; +import { + fakeEmptyProcessCloudFilterEntries, + fakeProcessCloudFilterEntries, + fakeProcessCloudFilters, + fakeProcessCloudFilterWithDifferentEntries, + fakeProcessFilter +} from '../mock/process-filters-cloud.mock'; import { ProcessFilterCloudModel } from '../models/process-filter-cloud.model'; import { IdentityUserService } from '../../../people/services/identity-user.service'; @@ -43,13 +48,8 @@ describe('ProcessFilterCloudService', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - ProcessServiceCloudTestingModule - ], - providers: [ - { provide: PROCESS_FILTERS_SERVICE_TOKEN, useClass: LocalPreferenceCloudService } - ] + imports: [ProcessServiceCloudTestingModule], + providers: [{ provide: PROCESS_FILTERS_SERVICE_TOKEN, useClass: LocalPreferenceCloudService }] }); service = TestBed.inject(ProcessFilterCloudService); diff --git a/lib/process-services-cloud/src/lib/process/process-header/components/process-header-cloud.component.spec.ts b/lib/process-services-cloud/src/lib/process/process-header/components/process-header-cloud.component.spec.ts index f8c08702d39..c3163b58952 100644 --- a/lib/process-services-cloud/src/lib/process/process-header/components/process-header-cloud.component.spec.ts +++ b/lib/process-services-cloud/src/lib/process/process-header/components/process-header-cloud.component.spec.ts @@ -23,7 +23,6 @@ import { ProcessServiceCloudTestingModule } from '../../../testing/process-servi import { ProcessHeaderCloudComponent } from './process-header-cloud.component'; import { ProcessHeaderCloudModule } from '../process-header-cloud.module'; import { ProcessCloudService } from '../../services/process-cloud.service'; -import { TranslateModule } from '@ngx-translate/core'; import { processInstanceDetailsCloudMock } from '../../mock/process-instance-details-cloud.mock'; describe('ProcessHeaderCloudComponent', () => { @@ -34,11 +33,7 @@ describe('ProcessHeaderCloudComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - ProcessServiceCloudTestingModule, - ProcessHeaderCloudModule - ] + imports: [ProcessServiceCloudTestingModule, ProcessHeaderCloudModule] }); fixture = TestBed.createComponent(ProcessHeaderCloudComponent); component = fixture.componentInstance; @@ -174,7 +169,6 @@ describe('ProcessHeaderCloudComponent', () => { }); describe('Config Filtering', () => { - it('should show only the properties from the configuration file', async () => { spyOn(appConfigService, 'get').and.returnValue(['name', 'status']); component.ngOnChanges(); @@ -207,7 +201,6 @@ describe('ProcessHeaderCloudComponent', () => { }); describe('Date values format', () => { - beforeEach(() => { appConfigService.config = { 'adf-cloud-process-header': { diff --git a/lib/process-services-cloud/src/lib/process/process-list/components/process-list-cloud.component.spec.ts b/lib/process-services-cloud/src/lib/process/process-list/components/process-list-cloud.component.spec.ts index 2c5dd2c20d4..f788a8b0867 100644 --- a/lib/process-services-cloud/src/lib/process/process-list/components/process-list-cloud.component.spec.ts +++ b/lib/process-services-cloud/src/lib/process/process-list/components/process-list-cloud.component.spec.ts @@ -35,13 +35,10 @@ import { fakeCustomSchema, fakeProcessCloudList, processListSchemaMock } from '. import { of } from 'rxjs'; import { shareReplay, skip } from 'rxjs/operators'; import { ProcessServiceCloudTestingModule } from '../../../testing/process-service-cloud.testing.module'; -import { TranslateModule } from '@ngx-translate/core'; import { ProcessListCloudSortingModel } from '../models/process-list-sorting.model'; import { PROCESS_LISTS_PREFERENCES_SERVICE_TOKEN } from '../../../services/cloud-token.service'; import { ProcessListCloudPreferences } from '../models/process-cloud-preferences'; import { PROCESS_LIST_CUSTOM_VARIABLE_COLUMN } from '../../../models/data-column-custom-data'; -import { HttpClientModule } from '@angular/common/http'; -import { NoopAnimationsModule } from '@angular/platform-browser/animations'; import { MatProgressSpinnerModule } from '@angular/material/progress-spinner'; import { PreferenceCloudServiceInterface } from '@alfresco/adf-process-services-cloud'; import { HarnessLoader } from '@angular/cdk/testing'; @@ -82,7 +79,7 @@ describe('ProcessListCloudComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [TranslateModule.forRoot(), ProcessServiceCloudTestingModule] + imports: [ProcessServiceCloudTestingModule] }); appConfig = TestBed.inject(AppConfigService); processListCloudService = TestBed.inject(ProcessListCloudService); @@ -594,7 +591,7 @@ describe('ProcessListCloudComponent: Injecting custom columns for task list - Cu beforeEach(() => { TestBed.configureTestingModule({ - imports: [TranslateModule.forRoot(), ProcessServiceCloudTestingModule], + imports: [ProcessServiceCloudTestingModule], declarations: [CustomTaskListComponent] }); fixtureCustom = TestBed.createComponent(CustomTaskListComponent); @@ -639,7 +636,7 @@ describe('ProcessListCloudComponent: Creating an empty custom template - EmptyTe beforeEach(() => { TestBed.configureTestingModule({ - imports: [TranslateModule.forRoot(), HttpClientModule, NoopAnimationsModule, DataTableModule, MatProgressSpinnerModule], + imports: [ProcessServiceCloudTestingModule, DataTableModule, MatProgressSpinnerModule], providers: [{ provide: PROCESS_LISTS_PREFERENCES_SERVICE_TOKEN, useValue: preferencesService }], declarations: [EmptyTemplateComponent, ProcessListCloudComponent, CustomEmptyContentTemplateDirective] }); diff --git a/lib/process-services-cloud/src/lib/process/process-list/services/process-list-cloud.service.ts b/lib/process-services-cloud/src/lib/process/process-list/services/process-list-cloud.service.ts index 51a0d10726b..e5289623247 100644 --- a/lib/process-services-cloud/src/lib/process/process-list/services/process-list-cloud.service.ts +++ b/lib/process-services-cloud/src/lib/process/process-list/services/process-list-cloud.service.ts @@ -49,7 +49,6 @@ export class ProcessListCloudService extends BaseCloudService { }) ); } else { - this.logService.error('Appname is mandatory for querying task'); return throwError('Appname not configured'); } } @@ -107,7 +106,11 @@ export class ProcessListCloudService extends BaseCloudService { const queryParam = {}; for (const property in requestNode) { - if (Object.prototype.hasOwnProperty.call(requestNode, property) && !this.isExcludedField(property) && this.isPropertyValueValid(requestNode, property)) { + if ( + Object.prototype.hasOwnProperty.call(requestNode, property) && + !this.isExcludedField(property) && + this.isPropertyValueValid(requestNode, property) + ) { queryParam[property] = this.getQueryParamValueFromRequestNode(requestNode, property as keyof ProcessQueryCloudRequestModel); } } diff --git a/lib/process-services-cloud/src/lib/process/process-list/services/process-task-list-cloud.service.ts b/lib/process-services-cloud/src/lib/process/process-list/services/process-task-list-cloud.service.ts index a3dd5bf6252..4bf0098f7c1 100644 --- a/lib/process-services-cloud/src/lib/process/process-list/services/process-task-list-cloud.service.ts +++ b/lib/process-services-cloud/src/lib/process/process-list/services/process-task-list-cloud.service.ts @@ -52,7 +52,6 @@ export class ProcessTaskListCloudService extends BaseCloudService implements Tas }) ); } else { - this.logService.error('Appname is mandatory for querying task'); return throwError('Appname not configured'); } } @@ -60,7 +59,11 @@ export class ProcessTaskListCloudService extends BaseCloudService implements Tas protected buildQueryParams(requestNode: TaskQueryCloudRequestModel): any { const queryParam: any = {}; for (const property in requestNode) { - if (Object.prototype.hasOwnProperty.call(requestNode, property) && !this.isExcludedField(property) && this.isPropertyValueValid(requestNode, property)) { + if ( + Object.prototype.hasOwnProperty.call(requestNode, property) && + !this.isExcludedField(property) && + this.isPropertyValueValid(requestNode, property) + ) { queryParam[property] = requestNode[property]; } } diff --git a/lib/process-services-cloud/src/lib/process/services/process-cloud.service.ts b/lib/process-services-cloud/src/lib/process/services/process-cloud.service.ts index 93b4a9d61b1..347e28dacbd 100644 --- a/lib/process-services-cloud/src/lib/process/services/process-cloud.service.ts +++ b/lib/process-services-cloud/src/lib/process/services/process-cloud.service.ts @@ -17,7 +17,7 @@ import { Injectable } from '@angular/core'; import { Observable, Subject, throwError } from 'rxjs'; -import { catchError, map } from 'rxjs/operators'; +import { map } from 'rxjs/operators'; import { ProcessInstanceCloud } from '../start-process/models/process-instance-cloud.model'; import { BaseCloudService } from '../../services/base-cloud.service'; import { ProcessDefinitionCloud } from '../../models/process-definition-cloud.model'; @@ -48,7 +48,6 @@ export class ProcessCloudService extends BaseCloudService implements ProcessClou }) ); } else { - this.logService.error('AppName and ProcessInstanceId are mandatory for querying a process'); return throwError('AppName/ProcessInstanceId not configured'); } } @@ -63,11 +62,8 @@ export class ProcessCloudService extends BaseCloudService implements ProcessClou if (appName || appName === '') { const url = `${this.getBasePath(appName)}/rb/v1/process-definitions`; - return this.get(url).pipe( - map((res: any) => res.list.entries.map((processDefs) => new ProcessDefinitionCloud(processDefs.entry))) - ); + return this.get(url).pipe(map((res: any) => res.list.entries.map((processDefs) => new ProcessDefinitionCloud(processDefs.entry)))); } else { - this.logService.error('AppName is mandatory for querying task'); return throwError('AppName not configured'); } } @@ -82,12 +78,8 @@ export class ProcessCloudService extends BaseCloudService implements ProcessClou if (appName) { const url = `${this.getBasePath(appName)}/query/v1/applications`; - return this.get(url).pipe( - map((appEntities: ApplicationVersionResponseModel) => appEntities.list.entries), - catchError((err) => this.handleError(err)) - ); + return this.get(url).pipe(map((appEntities: ApplicationVersionResponseModel) => appEntities.list.entries)); } else { - this.logService.error('AppName is mandatory for querying the versions of an application'); return throwError('AppName not configured'); } } @@ -104,18 +96,12 @@ export class ProcessCloudService extends BaseCloudService implements ProcessClou const queryUrl = `${this.getBasePath(appName)}/rb/v1/process-instances/${processInstanceId}`; return this.delete(queryUrl).pipe( map((res: any) => { - this.dataChangesDetected.next(res.entry); - return res.entry; + this.dataChangesDetected.next(res.entry); + return res.entry; }) ); } else { - this.logService.error('App name and Process id are mandatory for deleting a process'); return throwError('App name and process id not configured'); } } - - private handleError(error?: any) { - this.logService.error(error); - return throwError(error || 'Server error'); - } } diff --git a/lib/process-services-cloud/src/lib/process/start-process/components/start-process-cloud.component.spec.ts b/lib/process-services-cloud/src/lib/process/start-process/components/start-process-cloud.component.spec.ts index 94a2902c94a..1ef9ac5a39c 100755 --- a/lib/process-services-cloud/src/lib/process/start-process/components/start-process-cloud.component.spec.ts +++ b/lib/process-services-cloud/src/lib/process/start-process/components/start-process-cloud.component.spec.ts @@ -43,7 +43,6 @@ import { import { By } from '@angular/platform-browser'; import { ProcessPayloadCloud } from '../models/process-payload-cloud.model'; import { ProcessServiceCloudTestingModule } from '../../../testing/process-service-cloud.testing.module'; -import { TranslateModule } from '@ngx-translate/core'; import { ProcessNameCloudPipe } from '../../../pipes/process-name-cloud.pipe'; import { ProcessInstanceCloud } from '../models/process-instance-cloud.model'; import { ESCAPE } from '@angular/cdk/keycodes'; @@ -84,7 +83,6 @@ describe('StartProcessCloudComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ imports: [ - TranslateModule.forRoot(), ProcessServiceCloudTestingModule, FormsModule, MatCommonModule, diff --git a/lib/process-services-cloud/src/lib/process/start-process/services/start-process-cloud.service.ts b/lib/process-services-cloud/src/lib/process/start-process/services/start-process-cloud.service.ts index 1c19c262b0a..023c6d2974c 100755 --- a/lib/process-services-cloud/src/lib/process/start-process/services/start-process-cloud.service.ts +++ b/lib/process-services-cloud/src/lib/process/start-process/services/start-process-cloud.service.ts @@ -47,7 +47,6 @@ export class StartProcessCloudService extends BaseCloudService { map((res: any) => res.list.entries.map((processDefs) => new ProcessDefinitionCloud(processDefs.entry))) ); } else { - this.logService.error('AppName is mandatory for querying task'); return throwError('AppName not configured'); } } @@ -63,9 +62,7 @@ export class StartProcessCloudService extends BaseCloudService { const url = `${this.getBasePath(appName)}/rb/v1/process-instances`; payload.payloadType = 'StartProcessPayload'; - return this.post(url, payload).pipe( - map((result: any) => result.entry) - ); + return this.post(url, payload).pipe(map((result: any) => result.entry)); } /** @@ -80,9 +77,7 @@ export class StartProcessCloudService extends BaseCloudService { const url = `${this.getBasePath(appName)}/rb/v1/process-instances/${processInstanceId}`; payload.payloadType = 'UpdateProcessPayload'; - return this.put(url, payload).pipe( - map((processInstance: any) => processInstance.entry) - ); + return this.put(url, payload).pipe(map((processInstance: any) => processInstance.entry)); } /** @@ -111,7 +106,7 @@ export class StartProcessCloudService extends BaseCloudService { map((res: { [key: string]: any }) => { const result = []; if (res) { - Object.keys(res).forEach(mapping => result.push(new TaskVariableCloud({ name: mapping, value: res[mapping] }))); + Object.keys(res).forEach((mapping) => result.push(new TaskVariableCloud({ name: mapping, value: res[mapping] }))); } return result; }) diff --git a/lib/process-services-cloud/src/lib/services/base-cloud.service.ts b/lib/process-services-cloud/src/lib/services/base-cloud.service.ts index 2f2a60b928f..aca9fcf801d 100644 --- a/lib/process-services-cloud/src/lib/services/base-cloud.service.ts +++ b/lib/process-services-cloud/src/lib/services/base-cloud.service.ts @@ -15,19 +15,16 @@ * limitations under the License. */ -import { AlfrescoApiService, AppConfigService, LogService } from '@alfresco/adf-core'; +import { AlfrescoApiService, AppConfigService } from '@alfresco/adf-core'; import { Injectable, inject } from '@angular/core'; import { from, Observable } from 'rxjs'; import { AdfHttpClient } from '@alfresco/adf-core/api'; import { RequestOptions } from '@alfresco/js-api'; - @Injectable() - export class BaseCloudService { protected apiService = inject(AlfrescoApiService); protected appConfigService = inject(AppConfigService); - protected logService = inject(LogService); protected defaultParams: RequestOptions = { path: '', @@ -36,76 +33,58 @@ export class BaseCloudService { accepts: ['application/json'] }; - constructor( - protected adfHttpClient: AdfHttpClient) {} + constructor(protected adfHttpClient: AdfHttpClient) {} getBasePath(appName: string): string { - return appName - ? `${this.contextRoot}/${appName}` - : this.contextRoot; + return appName ? `${this.contextRoot}/${appName}` : this.contextRoot; } protected post(url: string, data?: T, queryParams?: any): Observable { return from( - this.callApi( - url, - { - ...this.defaultParams, - path: url, - httpMethod: 'POST', - bodyParam: data, - queryParams - } - ) + this.callApi(url, { + ...this.defaultParams, + path: url, + httpMethod: 'POST', + bodyParam: data, + queryParams + }) ); } protected put(url: string, data?: T): Observable { return from( - this.callApi( - url, - { - ...this.defaultParams, - path: url, - httpMethod: 'PUT', - bodyParam: data - } - ) + this.callApi(url, { + ...this.defaultParams, + path: url, + httpMethod: 'PUT', + bodyParam: data + }) ); } protected delete(url: string): Observable { return from( - this.callApi( - url, - { - ...this.defaultParams, - path: url, - httpMethod: 'DELETE' - } - ) + this.callApi(url, { + ...this.defaultParams, + path: url, + httpMethod: 'DELETE' + }) ); } protected get(url: string, queryParams?: any): Observable { return from( - this.callApi( - url, - { - ...this.defaultParams, - path: url, - httpMethod: 'GET', - queryParams - } - ) + this.callApi(url, { + ...this.defaultParams, + path: url, + httpMethod: 'GET', + queryParams + }) ); } protected callApi(url: string, params: RequestOptions): Promise { - return this.adfHttpClient.request( - url, - params - ); + return this.adfHttpClient.request(url, params); } protected get contextRoot() { diff --git a/lib/process-services-cloud/src/lib/services/notification-cloud.service.spec.ts b/lib/process-services-cloud/src/lib/services/notification-cloud.service.spec.ts index 1544175e38e..627b2db0a6f 100644 --- a/lib/process-services-cloud/src/lib/services/notification-cloud.service.spec.ts +++ b/lib/process-services-cloud/src/lib/services/notification-cloud.service.spec.ts @@ -17,7 +17,6 @@ import { TestBed } from '@angular/core/testing'; import { ProcessServiceCloudTestingModule } from '../testing/process-service-cloud.testing.module'; -import { TranslateModule } from '@ngx-translate/core'; import { NotificationCloudService } from './notification-cloud.service'; import { Apollo } from 'apollo-angular'; @@ -44,10 +43,7 @@ describe('NotificationCloudService', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - ProcessServiceCloudTestingModule - ] + imports: [ProcessServiceCloudTestingModule] }); service = TestBed.inject(NotificationCloudService); apollo = TestBed.inject(Apollo); diff --git a/lib/process-services-cloud/src/lib/services/user-preference-cloud.service.spec.ts b/lib/process-services-cloud/src/lib/services/user-preference-cloud.service.spec.ts index 0fa3b3fbaa7..88428caec18 100644 --- a/lib/process-services-cloud/src/lib/services/user-preference-cloud.service.spec.ts +++ b/lib/process-services-cloud/src/lib/services/user-preference-cloud.service.spec.ts @@ -19,164 +19,156 @@ import { TestBed } from '@angular/core/testing'; import { UserPreferenceCloudService } from './user-preference-cloud.service'; import { mockPreferences, getMockPreference, createMockPreference, updateMockPreference } from '../mock/user-preference.mock'; import { ProcessServiceCloudTestingModule } from '../testing/process-service-cloud.testing.module'; -import { TranslateModule } from '@ngx-translate/core'; import { AdfHttpClient } from '@alfresco/adf-core/api'; describe('PreferenceService', () => { - let service: UserPreferenceCloudService; - let adfHttpClient: AdfHttpClient; - let requestSpy: jasmine.Spy; - - const errorResponse = { - error: 'Mock Error', - state: 404, stateText: 'Not Found' - }; - - beforeEach(() => { - TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - ProcessServiceCloudTestingModule - ] - }); - service = TestBed.inject(UserPreferenceCloudService); - adfHttpClient = TestBed.inject(AdfHttpClient); - requestSpy = spyOn(adfHttpClient, 'request').and.returnValue(Promise.resolve(mockPreferences)); - }); - - it('should return the preferences', (done) => { - service.getPreferences('mock-app-name').subscribe((res: any) => { - expect(res).toBeDefined(); - expect(res).not.toBeNull(); - expect(res.list.entries.length).toBe(3); - expect(res.list.entries[0].entry.key).toBe('mock-preference-key-1'); - expect(res.list.entries[0].entry.value.length).toBe(2); - expect(res.list.entries[0].entry.value[0].username).toBe('mock-username-1'); - expect(res.list.entries[0].entry.value[0].firstName).toBe('mock-firstname-1'); - - expect(res.list.entries[1].entry.key).toBe('mock-preference-key-2'); - expect(res.list.entries[1].entry.value).toBe('my mock preference value'); - - expect(res.list.entries[2].entry.key).toBe('mock-preference-key-3'); - expect(res.list.entries[2].entry.value.appName).toBe('mock-appName'); - expect(res.list.entries[2].entry.value.state).toBe('MOCK-COMPLETED'); - done(); + let service: UserPreferenceCloudService; + let adfHttpClient: AdfHttpClient; + let requestSpy: jasmine.Spy; + + const errorResponse = { + error: 'Mock Error', + state: 404, + stateText: 'Not Found' + }; + + beforeEach(() => { + TestBed.configureTestingModule({ + imports: [ProcessServiceCloudTestingModule] + }); + service = TestBed.inject(UserPreferenceCloudService); + adfHttpClient = TestBed.inject(AdfHttpClient); + requestSpy = spyOn(adfHttpClient, 'request').and.returnValue(Promise.resolve(mockPreferences)); }); - }); - - it('Should not fetch preferences if error occurred', (done) => { - requestSpy.and.returnValue(Promise.reject(errorResponse)); - service.getPreferences('mock-app-name') - .subscribe( - () => fail('expected an error, not preferences'), - (error) => { - expect(error.state).toEqual(404); - expect(error.stateText).toEqual('Not Found'); - expect(error.error).toEqual('Mock Error'); - done(); - } - ); - }); - - it('should return the preference by key', (done) => { - requestSpy.and.returnValue(Promise.resolve(getMockPreference)); - service.getPreferenceByKey('mock-app-name', 'mock-preference-key').subscribe((res: any) => { - expect(res).toBeDefined(); - expect(res).not.toBeNull(); - expect(res.length).toBe(2); - expect(res[0].appName).toBe('mock-appName'); - expect(res[0].firstName).toBe('mock-firstname-1'); - expect(res[1].appName).toBe('mock-appName'); - expect(res[1].username).toBe('mock-username-2'); - done(); + + it('should return the preferences', (done) => { + service.getPreferences('mock-app-name').subscribe((res: any) => { + expect(res).toBeDefined(); + expect(res).not.toBeNull(); + expect(res.list.entries.length).toBe(3); + expect(res.list.entries[0].entry.key).toBe('mock-preference-key-1'); + expect(res.list.entries[0].entry.value.length).toBe(2); + expect(res.list.entries[0].entry.value[0].username).toBe('mock-username-1'); + expect(res.list.entries[0].entry.value[0].firstName).toBe('mock-firstname-1'); + + expect(res.list.entries[1].entry.key).toBe('mock-preference-key-2'); + expect(res.list.entries[1].entry.value).toBe('my mock preference value'); + + expect(res.list.entries[2].entry.key).toBe('mock-preference-key-3'); + expect(res.list.entries[2].entry.value.appName).toBe('mock-appName'); + expect(res.list.entries[2].entry.value.state).toBe('MOCK-COMPLETED'); + done(); + }); + }); + + it('Should not fetch preferences if error occurred', (done) => { + requestSpy.and.returnValue(Promise.reject(errorResponse)); + service.getPreferences('mock-app-name').subscribe( + () => fail('expected an error, not preferences'), + (error) => { + expect(error.state).toEqual(404); + expect(error.stateText).toEqual('Not Found'); + expect(error.error).toEqual('Mock Error'); + done(); + } + ); + }); + + it('should return the preference by key', (done) => { + requestSpy.and.returnValue(Promise.resolve(getMockPreference)); + service.getPreferenceByKey('mock-app-name', 'mock-preference-key').subscribe((res: any) => { + expect(res).toBeDefined(); + expect(res).not.toBeNull(); + expect(res.length).toBe(2); + expect(res[0].appName).toBe('mock-appName'); + expect(res[0].firstName).toBe('mock-firstname-1'); + expect(res[1].appName).toBe('mock-appName'); + expect(res[1].username).toBe('mock-username-2'); + done(); + }); + }); + + it('Should not fetch preference by key if error occurred', (done) => { + requestSpy.and.returnValue(Promise.reject(errorResponse)); + service.getPreferenceByKey('mock-app-name', 'mock-preference-key').subscribe( + () => fail('expected an error, not preference'), + (error) => { + expect(error.state).toEqual(404); + expect(error.stateText).toEqual('Not Found'); + expect(error.error).toEqual('Mock Error'); + done(); + } + ); + }); + + it('should create preference', (done) => { + requestSpy.and.returnValue(Promise.resolve(createMockPreference)); + service.createPreference('mock-app-name', 'mock-preference-key', createMockPreference).subscribe((res: any) => { + expect(res).toBeDefined(); + expect(res).not.toBeNull(); + expect(res).toBe(createMockPreference); + expect(res.appName).toBe('mock-appName'); + expect(res.name).toBe('create-preference'); + done(); + }); + }); + + it('Should not create preference if error occurred', (done) => { + requestSpy.and.returnValue(Promise.reject(errorResponse)); + service.createPreference('mock-app-name', 'mock-preference-key', createMockPreference).subscribe( + () => fail('expected an error, not to create preference'), + (error) => { + expect(error.state).toEqual(404); + expect(error.stateText).toEqual('Not Found'); + expect(error.error).toEqual('Mock Error'); + done(); + } + ); + }); + + it('should update preference', (done) => { + requestSpy.and.returnValue(Promise.resolve(updateMockPreference)); + service.updatePreference('mock-app-name', 'mock-preference-key', updateMockPreference).subscribe((res: any) => { + expect(res).toBeDefined(); + expect(res).not.toBeNull(); + expect(res).toBe(updateMockPreference); + expect(res.appName).toBe('mock-appName'); + expect(res.name).toBe('update-preference'); + done(); + }); }); - }); - - it('Should not fetch preference by key if error occurred', (done) => { - requestSpy.and.returnValue(Promise.reject(errorResponse)); - service.getPreferenceByKey('mock-app-name', 'mock-preference-key') - .subscribe( - () => fail('expected an error, not preference'), - (error) => { - expect(error.state).toEqual(404); - expect(error.stateText).toEqual('Not Found'); - expect(error.error).toEqual('Mock Error'); - done(); - } - ); - }); - - it('should create preference', (done) => { - requestSpy.and.returnValue(Promise.resolve(createMockPreference)); - service.createPreference('mock-app-name', 'mock-preference-key', createMockPreference).subscribe((res: any) => { - expect(res).toBeDefined(); - expect(res).not.toBeNull(); - expect(res).toBe(createMockPreference); - expect(res.appName).toBe('mock-appName'); - expect(res.name).toBe('create-preference'); - done(); + + it('Should not update preference if error occurred', (done) => { + requestSpy.and.returnValue(Promise.reject(errorResponse)); + service.createPreference('mock-app-name', 'mock-preference-key', updateMockPreference).subscribe( + () => fail('expected an error, not to update preference'), + (error) => { + expect(error.state).toEqual(404); + expect(error.stateText).toEqual('Not Found'); + expect(error.error).toEqual('Mock Error'); + done(); + } + ); }); - }); - - it('Should not create preference if error occurred', (done) => { - requestSpy.and.returnValue(Promise.reject(errorResponse)); - service.createPreference('mock-app-name', 'mock-preference-key', createMockPreference) - .subscribe( - () => fail('expected an error, not to create preference'), - (error) => { - expect(error.state).toEqual(404); - expect(error.stateText).toEqual('Not Found'); - expect(error.error).toEqual('Mock Error'); - done(); - } - ); - }); - - it('should update preference', (done) => { - requestSpy.and.returnValue(Promise.resolve(updateMockPreference)); - service.updatePreference('mock-app-name', 'mock-preference-key', updateMockPreference).subscribe((res: any) => { - expect(res).toBeDefined(); - expect(res).not.toBeNull(); - expect(res).toBe(updateMockPreference); - expect(res.appName).toBe('mock-appName'); - expect(res.name).toBe('update-preference'); - done(); + + it('should delete preference', (done) => { + requestSpy.and.returnValue(Promise.resolve('')); + service.deletePreference('mock-app-name', 'mock-preference-key').subscribe((res: any) => { + expect(res).toBeDefined(); + done(); + }); }); - }); - - it('Should not update preference if error occurred', (done) => { - requestSpy.and.returnValue(Promise.reject(errorResponse)); - service.createPreference('mock-app-name', 'mock-preference-key', updateMockPreference) - .subscribe( - () => fail('expected an error, not to update preference'), - (error) => { - expect(error.state).toEqual(404); - expect(error.stateText).toEqual('Not Found'); - expect(error.error).toEqual('Mock Error'); - done(); - } - ); - }); - - it('should delete preference', (done) => { - requestSpy.and.returnValue(Promise.resolve('')); - service.deletePreference('mock-app-name', 'mock-preference-key').subscribe((res: any) => { - expect(res).toBeDefined(); - done(); + + it('Should not delete preference if error occurred', (done) => { + requestSpy.and.returnValue(Promise.reject(errorResponse)); + service.deletePreference('mock-app-name', 'mock-preference-key').subscribe( + () => fail('expected an error, not to delete preference'), + (error) => { + expect(error.state).toEqual(404); + expect(error.stateText).toEqual('Not Found'); + expect(error.error).toEqual('Mock Error'); + done(); + } + ); }); - }); - - it('Should not delete preference if error occurred', (done) => { - requestSpy.and.returnValue(Promise.reject(errorResponse)); - service.deletePreference('mock-app-name', 'mock-preference-key') - .subscribe( - () => fail('expected an error, not to delete preference'), - (error) => { - expect(error.state).toEqual(404); - expect(error.stateText).toEqual('Not Found'); - expect(error.error).toEqual('Mock Error'); - done(); - } - ); - }); }); diff --git a/lib/process-services-cloud/src/lib/services/user-preference-cloud.service.ts b/lib/process-services-cloud/src/lib/services/user-preference-cloud.service.ts index 72f0532c325..2872f1826a9 100644 --- a/lib/process-services-cloud/src/lib/services/user-preference-cloud.service.ts +++ b/lib/process-services-cloud/src/lib/services/user-preference-cloud.service.ts @@ -22,85 +22,81 @@ import { BaseCloudService } from './base-cloud.service'; @Injectable({ providedIn: 'root' }) export class UserPreferenceCloudService extends BaseCloudService implements PreferenceCloudServiceInterface { - /** - * Gets user preferences - * - * @param appName Name of the target app - * @returns List of user preferences - */ - getPreferences(appName: string): Observable { - if (appName) { - const url = `${this.getBasePath(appName)}/preference/v1/preferences`; - return this.get(url); - } else { - this.logService.error('Appname is mandatory for querying preferences'); - return throwError('Appname not configured'); + /** + * Gets user preferences + * + * @param appName Name of the target app + * @returns List of user preferences + */ + getPreferences(appName: string): Observable { + if (appName) { + const url = `${this.getBasePath(appName)}/preference/v1/preferences`; + return this.get(url); + } else { + return throwError('Appname not configured'); + } } - } - /** - * Gets user preference. - * - * @param appName Name of the target app - * @param key Key of the target preference - * @returns Observable of user preference - */ - getPreferenceByKey(appName: string, key: string): Observable { - if (appName) { - const url = `${this.getBasePath(appName)}/preference/v1/preferences/${key}`; - return this.get(url); - } else { - this.logService.error('Appname and key are mandatory for querying preference'); - return throwError('Appname not configured'); + /** + * Gets user preference. + * + * @param appName Name of the target app + * @param key Key of the target preference + * @returns Observable of user preference + */ + getPreferenceByKey(appName: string, key: string): Observable { + if (appName) { + const url = `${this.getBasePath(appName)}/preference/v1/preferences/${key}`; + return this.get(url); + } else { + return throwError('Appname not configured'); + } } - } - /** - * Creates user preference. - * - * @param appName Name of the target app - * @param key Key of the target preference - * @param newPreference Details of new user preference - * @returns Observable of created user preferences - */ - createPreference(appName: string, key: string, newPreference: any): Observable { - if (appName) { - const url = `${this.getBasePath(appName)}/preference/v1/preferences/${key}`; - const payload = JSON.stringify(newPreference); + /** + * Creates user preference. + * + * @param appName Name of the target app + * @param key Key of the target preference + * @param newPreference Details of new user preference + * @returns Observable of created user preferences + */ + createPreference(appName: string, key: string, newPreference: any): Observable { + if (appName) { + const url = `${this.getBasePath(appName)}/preference/v1/preferences/${key}`; + const payload = JSON.stringify(newPreference); - return this.put(url, payload); - } else { - this.logService.error('Appname and key are mandatory for creating preference'); - return throwError('Appname not configured'); + return this.put(url, payload); + } else { + return throwError('Appname not configured'); + } } - } - /** - * Updates user preference. - * - * @param appName Name of the target app - * @param key Key of the target preference - * @param updatedPreference Details of updated preference - * @returns Observable of updated user preferences - */ - updatePreference(appName: string, key: string, updatedPreference: any): Observable { - return this.createPreference(appName, key, updatedPreference); - } + /** + * Updates user preference. + * + * @param appName Name of the target app + * @param key Key of the target preference + * @param updatedPreference Details of updated preference + * @returns Observable of updated user preferences + */ + updatePreference(appName: string, key: string, updatedPreference: any): Observable { + return this.createPreference(appName, key, updatedPreference); + } - /** - * Deletes user preference by given preference key. - * - * @param appName Name of the target app - * @param key Key of the target preference - * @returns Observable of delete operation status - */ - deletePreference(appName: string, key: string): Observable { - if (appName) { - const url = `${this.getBasePath(appName)}/preference/v1/preferences/${key}`; - return this.delete(url); - } else { - this.logService.error('Appname and key are mandatory to delete preference'); - return throwError('Appname not configured'); + /** + * Deletes user preference by given preference key. + * + * @param appName Name of the target app + * @param key Key of the target preference + * @returns Observable of delete operation status + */ + deletePreference(appName: string, key: string): Observable { + if (appName) { + const url = `${this.getBasePath(appName)}/preference/v1/preferences/${key}`; + return this.delete(url); + } else { + return throwError('Appname not configured'); + } } - } } diff --git a/lib/process-services-cloud/src/lib/task/directives/claim-task-cloud.directive.spec.ts b/lib/process-services-cloud/src/lib/task/directives/claim-task-cloud.directive.spec.ts index 11e2869ac35..578ff654d78 100644 --- a/lib/process-services-cloud/src/lib/task/directives/claim-task-cloud.directive.spec.ts +++ b/lib/process-services-cloud/src/lib/task/directives/claim-task-cloud.directive.spec.ts @@ -22,17 +22,14 @@ import { of, throwError } from 'rxjs'; import { ClaimTaskCloudDirective } from './claim-task-cloud.directive'; import { taskClaimCloudMock } from '../task-header/mocks/fake-claim-task.mock'; import { ProcessServiceCloudTestingModule } from '../../testing/process-service-cloud.testing.module'; -import { TranslateModule } from '@ngx-translate/core'; import { By } from '@angular/platform-browser'; describe('ClaimTaskCloudDirective', () => { - @Component({ - selector: 'adf-cloud-claim-test-component', + selector: 'adf-cloud-claim-test-component', template: '' }) class TestComponent { - taskMock = 'test1234'; appNameMock = 'simple-app'; @@ -49,13 +46,8 @@ describe('ClaimTaskCloudDirective', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - ProcessServiceCloudTestingModule - ], - declarations: [ - TestComponent - ] + imports: [ProcessServiceCloudTestingModule], + declarations: [TestComponent] }); taskCloudService = TestBed.inject(TaskCloudService); fixture = TestBed.createComponent(TestComponent); @@ -101,13 +93,11 @@ describe('ClaimTaskCloudDirective', () => { }); describe('Claim Task Directive validation errors', () => { - @Component({ - selector: 'adf-cloud-claim-no-fields-validation-component', + selector: 'adf-cloud-claim-no-fields-validation-component', template: '' }) class ClaimTestMissingInputDirectiveComponent { - appName = 'simple-app'; appNameUndefined = undefined; appNameNull = null; @@ -117,11 +107,10 @@ describe('Claim Task Directive validation errors', () => { } @Component({ - selector: 'adf-cloud-claim-no-taskid-validation-component', + selector: 'adf-cloud-claim-no-taskid-validation-component', template: '' }) class ClaimTestMissingTaskIdDirectiveComponent { - appName = 'simple-app'; @ContentChildren(ClaimTaskCloudDirective) @@ -129,11 +118,10 @@ describe('Claim Task Directive validation errors', () => { } @Component({ - selector: 'adf-cloud-claim-undefined-appname-component', + selector: 'adf-cloud-claim-undefined-appname-component', template: '' }) class ClaimTestInvalidAppNameUndefinedDirectiveComponent { - appNameUndefined = undefined; taskMock = 'test1234'; @@ -142,11 +130,10 @@ describe('Claim Task Directive validation errors', () => { } @Component({ - selector: 'adf-cloud-claim-null-appname-component', + selector: 'adf-cloud-claim-null-appname-component', template: '' }) class ClaimTestInvalidAppNameNullDirectiveComponent { - appNameNull = null; taskMock = 'test1234'; @@ -158,10 +145,7 @@ describe('Claim Task Directive validation errors', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - ProcessServiceCloudTestingModule - ], + imports: [ProcessServiceCloudTestingModule], declarations: [ ClaimTestMissingTaskIdDirectiveComponent, ClaimTestInvalidAppNameUndefinedDirectiveComponent, @@ -179,16 +163,16 @@ describe('Claim Task Directive validation errors', () => { it('should throw error when taskId is not set', () => { fixture = TestBed.createComponent(ClaimTestMissingTaskIdDirectiveComponent); - expect( () => fixture.detectChanges()).toThrowError('Attribute taskId is required'); + expect(() => fixture.detectChanges()).toThrowError('Attribute taskId is required'); }); it('should throw error when appName is undefined', () => { fixture = TestBed.createComponent(ClaimTestInvalidAppNameUndefinedDirectiveComponent); - expect( () => fixture.detectChanges()).toThrowError('Attribute appName is required'); + expect(() => fixture.detectChanges()).toThrowError('Attribute appName is required'); }); it('should throw error when appName is null', () => { fixture = TestBed.createComponent(ClaimTestInvalidAppNameUndefinedDirectiveComponent); - expect( () => fixture.detectChanges()).toThrowError('Attribute appName is required'); + expect(() => fixture.detectChanges()).toThrowError('Attribute appName is required'); }); }); diff --git a/lib/process-services-cloud/src/lib/task/directives/complete-task.directive.spec.ts b/lib/process-services-cloud/src/lib/task/directives/complete-task.directive.spec.ts index e75793bc9f2..5c0122ad70d 100644 --- a/lib/process-services-cloud/src/lib/task/directives/complete-task.directive.spec.ts +++ b/lib/process-services-cloud/src/lib/task/directives/complete-task.directive.spec.ts @@ -22,17 +22,20 @@ import { of, throwError } from 'rxjs'; import { taskCompleteCloudMock } from '../task-header/mocks/fake-complete-task.mock'; import { TaskCloudService } from '../services/task-cloud.service'; import { ProcessServiceCloudTestingModule } from '../../testing/process-service-cloud.testing.module'; -import { TranslateModule } from '@ngx-translate/core'; import { By } from '@angular/platform-browser'; describe('CompleteTaskDirective', () => { - @Component({ - selector: 'adf-cloud-test-component', - template: `` + selector: 'adf-cloud-test-component', + template: `` }) class TestComponent { - taskMock = 'test1234'; appNameMock = 'simple-app'; @@ -53,13 +56,8 @@ describe('CompleteTaskDirective', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - ProcessServiceCloudTestingModule - ], - declarations: [ - TestComponent - ] + imports: [ProcessServiceCloudTestingModule], + declarations: [TestComponent] }); taskCloudService = TestBed.inject(TaskCloudService); fixture = TestBed.createComponent(TestComponent); @@ -73,7 +71,7 @@ describe('CompleteTaskDirective', () => { expect(taskCloudService.completeTask).toHaveBeenCalled(); }); - it('should emit error on api fail', async () => { + it('should emit error on api fail', async () => { const error = { message: 'process key not found' }; spyOn(taskCloudService, 'completeTask').and.returnValue(throwError(error)); spyOn(fixture.componentInstance, 'onError').and.callThrough(); @@ -105,13 +103,11 @@ describe('CompleteTaskDirective', () => { }); describe('Complete Task Directive validation errors', () => { - @Component({ - selector: 'adf-cloud-no-fields-validation-component', + selector: 'adf-cloud-no-fields-validation-component', template: '' }) class TestMissingInputDirectiveComponent { - appName = 'simple-app'; appNameUndefined = undefined; appNameNull = null; @@ -125,11 +121,10 @@ describe('Complete Task Directive validation errors', () => { } @Component({ - selector: 'adf-cloud-no-taskid-validation-component', + selector: 'adf-cloud-no-taskid-validation-component', template: '' }) class TestMissingTaskIdDirectiveComponent { - appName = 'simple-app'; @ContentChildren(CompleteTaskDirective) @@ -141,11 +136,10 @@ describe('Complete Task Directive validation errors', () => { } @Component({ - selector: 'adf-cloud-undefined-appname-component', + selector: 'adf-cloud-undefined-appname-component', template: '' }) class TestInvalidAppNameUndefinedDirectiveComponent { - appName = 'simple-app'; taskMock = 'test1234'; @@ -158,11 +152,10 @@ describe('Complete Task Directive validation errors', () => { } @Component({ - selector: 'adf-cloud-null-appname-component', + selector: 'adf-cloud-null-appname-component', template: '' }) class TestInvalidAppNameNullDirectiveComponent { - appName = 'simple-app'; taskMock = 'test1234'; @@ -178,10 +171,7 @@ describe('Complete Task Directive validation errors', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - ProcessServiceCloudTestingModule - ], + imports: [ProcessServiceCloudTestingModule], declarations: [ TestMissingTaskIdDirectiveComponent, TestInvalidAppNameUndefinedDirectiveComponent, @@ -198,16 +188,16 @@ describe('Complete Task Directive validation errors', () => { it('should throw error when taskId is not set', () => { fixture = TestBed.createComponent(TestMissingTaskIdDirectiveComponent); - expect( () => fixture.detectChanges()).toThrowError('Attribute taskId is required'); + expect(() => fixture.detectChanges()).toThrowError('Attribute taskId is required'); }); it('should throw error when appName is undefined', () => { fixture = TestBed.createComponent(TestInvalidAppNameUndefinedDirectiveComponent); - expect( () => fixture.detectChanges()).toThrowError('Attribute appName is required'); + expect(() => fixture.detectChanges()).toThrowError('Attribute appName is required'); }); it('should throw error when appName is null', () => { fixture = TestBed.createComponent(TestInvalidAppNameUndefinedDirectiveComponent); - expect( () => fixture.detectChanges()).toThrowError('Attribute appName is required'); + expect(() => fixture.detectChanges()).toThrowError('Attribute appName is required'); }); }); diff --git a/lib/process-services-cloud/src/lib/task/directives/unclaim-task-cloud.directive.spec.ts b/lib/process-services-cloud/src/lib/task/directives/unclaim-task-cloud.directive.spec.ts index 7bd1f69262c..cb476ec3c6c 100644 --- a/lib/process-services-cloud/src/lib/task/directives/unclaim-task-cloud.directive.spec.ts +++ b/lib/process-services-cloud/src/lib/task/directives/unclaim-task-cloud.directive.spec.ts @@ -22,17 +22,14 @@ import { of, throwError } from 'rxjs'; import { UnClaimTaskCloudDirective } from './unclaim-task-cloud.directive'; import { taskClaimCloudMock } from '../task-header/mocks/fake-claim-task.mock'; import { ProcessServiceCloudTestingModule } from '../../testing/process-service-cloud.testing.module'; -import { TranslateModule } from '@ngx-translate/core'; import { By } from '@angular/platform-browser'; describe('UnClaimTaskCloudDirective', () => { - @Component({ - selector: 'adf-cloud-test-component', + selector: 'adf-cloud-test-component', template: '' }) class TestComponent { - appName = 'simple-app'; taskIdMock = '1234'; @@ -49,13 +46,8 @@ describe('UnClaimTaskCloudDirective', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - ProcessServiceCloudTestingModule - ], - declarations: [ - TestComponent - ] + imports: [ProcessServiceCloudTestingModule], + declarations: [TestComponent] }); taskCloudService = TestBed.inject(TaskCloudService); fixture = TestBed.createComponent(TestComponent); @@ -101,13 +93,11 @@ describe('UnClaimTaskCloudDirective', () => { }); describe('UnClaim Task Directive validation errors', () => { - @Component({ - selector: 'adf-cloud-claim-no-fields-validation-component', + selector: 'adf-cloud-claim-no-fields-validation-component', template: '' }) class ClaimTestMissingInputDirectiveComponent { - appName = 'simple-app'; appNameUndefined = undefined; appNameNull = null; @@ -117,11 +107,10 @@ describe('UnClaim Task Directive validation errors', () => { } @Component({ - selector: 'adf-cloud-claim-no-taskid-validation-component', + selector: 'adf-cloud-claim-no-taskid-validation-component', template: '' }) class ClaimTestMissingTaskIdDirectiveComponent { - appName = 'simple-app'; @ContentChildren(UnClaimTaskCloudDirective) @@ -129,11 +118,10 @@ describe('UnClaim Task Directive validation errors', () => { } @Component({ - selector: 'adf-cloud-claim-undefined-appname-component', + selector: 'adf-cloud-claim-undefined-appname-component', template: '' }) class ClaimTestInvalidAppNameUndefinedDirectiveComponent { - appNameUndefined = undefined; taskMock = 'test1234'; @@ -142,11 +130,10 @@ describe('UnClaim Task Directive validation errors', () => { } @Component({ - selector: 'adf-cloud-claim-null-appname-component', + selector: 'adf-cloud-claim-null-appname-component', template: '' }) class ClaimTestInvalidAppNameNullDirectiveComponent { - appNameNull = null; taskMock = 'test1234'; @@ -158,10 +145,7 @@ describe('UnClaim Task Directive validation errors', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - ProcessServiceCloudTestingModule - ], + imports: [ProcessServiceCloudTestingModule], declarations: [ ClaimTestMissingTaskIdDirectiveComponent, ClaimTestInvalidAppNameUndefinedDirectiveComponent, @@ -179,16 +163,16 @@ describe('UnClaim Task Directive validation errors', () => { it('should throw error when taskId is not set', () => { fixture = TestBed.createComponent(ClaimTestMissingTaskIdDirectiveComponent); - expect( () => fixture.detectChanges()).toThrowError('Attribute taskId is required'); + expect(() => fixture.detectChanges()).toThrowError('Attribute taskId is required'); }); it('should throw error when appName is undefined', () => { fixture = TestBed.createComponent(ClaimTestInvalidAppNameUndefinedDirectiveComponent); - expect( () => fixture.detectChanges()).toThrowError('Attribute appName is required'); + expect(() => fixture.detectChanges()).toThrowError('Attribute appName is required'); }); it('should throw error when appName is null', () => { fixture = TestBed.createComponent(ClaimTestInvalidAppNameUndefinedDirectiveComponent); - expect( () => fixture.detectChanges()).toThrowError('Attribute appName is required'); + expect(() => fixture.detectChanges()).toThrowError('Attribute appName is required'); }); }); diff --git a/lib/process-services-cloud/src/lib/task/mock/task-cloud.service.mock.ts b/lib/process-services-cloud/src/lib/task/mock/task-cloud.service.mock.ts index f4b4eb0d5e3..685f04e3f59 100644 --- a/lib/process-services-cloud/src/lib/task/mock/task-cloud.service.mock.ts +++ b/lib/process-services-cloud/src/lib/task/mock/task-cloud.service.mock.ts @@ -16,7 +16,7 @@ */ import { Injectable } from '@angular/core'; -import { AppConfigService, CardViewArrayItem, LogService } from '@alfresco/adf-core'; +import { AppConfigService, CardViewArrayItem } from '@alfresco/adf-core'; import { from, Observable, of, Subject, throwError } from 'rxjs'; import { DEFAULT_TASK_PRIORITIES, TaskPriorityOption } from '../models/task.model'; import { TaskDetailsCloudModel, TASK_ASSIGNED_STATE, TASK_CREATED_STATE } from '../start-task/models/task-details-cloud.model'; @@ -29,11 +29,10 @@ import { TaskCloudServiceInterface } from '../services/task-cloud.service.interf providedIn: 'root' }) export class TaskCloudServiceMock implements TaskCloudServiceInterface { - currentUserMock = 'AssignedTaskUser'; dataChangesDetected$ = new Subject(); - constructor(private appConfigService: AppConfigService, private logService: LogService) { } + constructor(private appConfigService: AppConfigService) {} getTaskById(_appName: string, taskId: string): Observable { return of(taskDetailsContainer[taskId]); @@ -68,7 +67,11 @@ export class TaskCloudServiceMock implements TaskCloudServiceInterface { return taskDetails.status === TASK_ASSIGNED_STATE && this.isAssignedToMe(taskDetails.assignee); } - isAssigneePropertyClickable(taskDetails: TaskDetailsCloudModel, candidateUsers: CardViewArrayItem[], candidateGroups: CardViewArrayItem[]): boolean { + isAssigneePropertyClickable( + taskDetails: TaskDetailsCloudModel, + candidateUsers: CardViewArrayItem[], + candidateGroups: CardViewArrayItem[] + ): boolean { let isClickable = false; const states = [TASK_ASSIGNED_STATE]; if (candidateUsers?.length || candidateGroups?.length) { @@ -103,7 +106,6 @@ export class TaskCloudServiceMock implements TaskCloudServiceInterface { return from([]); } else { - this.logService.error('AppName and TaskId are mandatory for complete a task'); return throwError('AppName/TaskId not configured'); } } @@ -119,7 +121,6 @@ export class TaskCloudServiceMock implements TaskCloudServiceInterface { return from([]); } else { - this.logService.error('AppName and TaskId are mandatory for querying a task'); return throwError('AppName/TaskId not configured'); } } @@ -130,7 +131,6 @@ export class TaskCloudServiceMock implements TaskCloudServiceInterface { return from([]); } else { - this.logService.error('AppName and TaskId are mandatory for querying a task'); return throwError('AppName/TaskId not configured'); } } @@ -147,7 +147,6 @@ export class TaskCloudServiceMock implements TaskCloudServiceInterface { return from([]); } else { - this.logService.error('AppName is mandatory for querying task'); return throwError('AppName not configured'); } } @@ -158,7 +157,6 @@ export class TaskCloudServiceMock implements TaskCloudServiceInterface { return from([]); } else { - this.logService.error('AppName and TaskId are mandatory to change/update the task assignee'); return throwError('AppName/TaskId not configured'); } } diff --git a/lib/process-services-cloud/src/lib/task/services/task-cloud.service.spec.ts b/lib/process-services-cloud/src/lib/task/services/task-cloud.service.spec.ts index 40297abf942..246f015a76a 100644 --- a/lib/process-services-cloud/src/lib/task/services/task-cloud.service.spec.ts +++ b/lib/process-services-cloud/src/lib/task/services/task-cloud.service.spec.ts @@ -19,16 +19,18 @@ import { TestBed } from '@angular/core/testing'; import { TranslationService } from '@alfresco/adf-core'; import { TaskCloudService } from './task-cloud.service'; import { taskCompleteCloudMock } from '../task-header/mocks/fake-complete-task.mock'; -import { assignedTaskDetailsCloudMock, createdTaskDetailsCloudMock, emptyOwnerTaskDetailsCloudMock } from '../task-header/mocks/task-details-cloud.mock'; +import { + assignedTaskDetailsCloudMock, + createdTaskDetailsCloudMock, + emptyOwnerTaskDetailsCloudMock +} from '../task-header/mocks/task-details-cloud.mock'; import { fakeTaskDetailsCloud } from '../task-header/mocks/fake-task-details-response.mock'; import { cloudMockUser } from '../start-task/mock/user-cloud.mock'; import { ProcessServiceCloudTestingModule } from '../../testing/process-service-cloud.testing.module'; -import { TranslateModule } from '@ngx-translate/core'; import { IdentityUserService } from '../../people/services/identity-user.service'; import { AdfHttpClient } from '@alfresco/adf-core/api'; describe('Task Cloud Service', () => { - let service: TaskCloudService; let adfHttpClient: AdfHttpClient; let identityUserService: IdentityUserService; @@ -47,16 +49,13 @@ describe('Task Cloud Service', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - ProcessServiceCloudTestingModule - ] + imports: [ProcessServiceCloudTestingModule] }); adfHttpClient = TestBed.inject(AdfHttpClient); identityUserService = TestBed.inject(IdentityUserService); translateService = TestBed.inject(TranslationService); service = TestBed.inject(TaskCloudService); - spyOn(translateService, 'instant').and.callFake((key) => key ? `${key}_translated` : null); + spyOn(translateService, 'instant').and.callFake((key) => (key ? `${key}_translated` : null)); spyOn(identityUserService, 'getCurrentUserInfo').and.returnValue(cloudMockUser); requestSpy = spyOn(adfHttpClient, 'request'); }); @@ -104,7 +103,11 @@ describe('Task Cloud Service', () => { }); it('should verify if the task assignee property is clickable', () => { - const isAssigneePropertyClickable = service.isAssigneePropertyClickable(assignedTaskDetailsCloudMock, [ { icon: '', value: 'user' } ], [ { icon: '', value: 'group' } ]); + const isAssigneePropertyClickable = service.isAssigneePropertyClickable( + assignedTaskDetailsCloudMock, + [{ icon: '', value: 'user' }], + [{ icon: '', value: 'group' }] + ); expect(isAssigneePropertyClickable).toEqual(true); }); @@ -144,11 +147,12 @@ describe('Task Cloud Service', () => { const assignee = 'user12'; requestSpy.and.callFake(returnFakeTaskDetailsResults); service.claimTask(appName, taskId, assignee).subscribe( - () => { }, + () => {}, (error) => { expect(error).toBe('AppName/TaskId not configured'); done(); - }); + } + ); }); it('should throw error if taskId is not defined when claiming a task', (done) => { @@ -157,11 +161,12 @@ describe('Task Cloud Service', () => { const assignee = 'user12'; requestSpy.and.callFake(returnFakeTaskDetailsResults); service.claimTask(appName, taskId, assignee).subscribe( - () => { }, + () => {}, (error) => { expect(error).toBe('AppName/TaskId not configured'); done(); - }); + } + ); }); it('should return the task details when unclaiming a task', (done) => { @@ -182,11 +187,12 @@ describe('Task Cloud Service', () => { const taskId = '68d54a8f'; requestSpy.and.callFake(returnFakeTaskDetailsResults); service.unclaimTask(appName, taskId).subscribe( - () => { }, + () => {}, (error) => { expect(error).toBe('AppName/TaskId not configured'); done(); - }); + } + ); }); it('should throw error if taskId is not defined when unclaiming a task', (done) => { @@ -194,11 +200,12 @@ describe('Task Cloud Service', () => { const taskId = null; requestSpy.and.callFake(returnFakeTaskDetailsResults); service.unclaimTask(appName, taskId).subscribe( - () => { }, + () => {}, (error) => { expect(error).toBe('AppName/TaskId not configured'); done(); - }); + } + ); }); it('should return the task details when querying by id', (done) => { @@ -219,11 +226,12 @@ describe('Task Cloud Service', () => { const taskId = '68d54a8f'; requestSpy.and.callFake(returnFakeTaskDetailsResults); service.getTaskById(appName, taskId).subscribe( - () => { }, + () => {}, (error) => { expect(error).toBe('AppName/TaskId not configured'); done(); - }); + } + ); }); it('should throw error if taskId is not defined when querying by id', (done) => { @@ -231,11 +239,12 @@ describe('Task Cloud Service', () => { const taskId = null; requestSpy.and.callFake(returnFakeTaskDetailsResults); service.getTaskById(appName, taskId).subscribe( - () => { }, + () => {}, (error) => { expect(error).toBe('AppName/TaskId not configured'); done(); - }); + } + ); }); it('should throw error if appName is not defined when updating a task', (done) => { @@ -244,11 +253,12 @@ describe('Task Cloud Service', () => { const updatePayload = { description: 'New description' }; requestSpy.and.callFake(returnFakeTaskDetailsResults); service.updateTask(appName, taskId, updatePayload).subscribe( - () => { }, + () => {}, (error) => { expect(error).toBe('AppName/TaskId not configured'); done(); - }); + } + ); }); it('should throw error if taskId is not defined when updating a task', (done) => { @@ -257,11 +267,12 @@ describe('Task Cloud Service', () => { const updatePayload = { description: 'New description' }; requestSpy.and.callFake(returnFakeTaskDetailsResults); service.updateTask(appName, taskId, updatePayload).subscribe( - () => { }, + () => {}, (error) => { expect(error).toBe('AppName/TaskId not configured'); done(); - }); + } + ); }); it('should return the task details when updating a task', (done) => { @@ -284,11 +295,12 @@ describe('Task Cloud Service', () => { const updatePayload = { description: 'New description' }; requestSpy.and.callFake(returnFakeTaskDetailsResults); service.updateTask(appName, taskId, updatePayload).subscribe( - () => { }, + () => {}, (error) => { expect(error).toBe('AppName/TaskId not configured'); done(); - }); + } + ); }); it('should throw error if taskId is not defined updating a task', (done) => { @@ -297,11 +309,12 @@ describe('Task Cloud Service', () => { const updatePayload = { description: 'New description' }; requestSpy.and.callFake(returnFakeTaskDetailsResults); service.updateTask(appName, taskId, updatePayload).subscribe( - () => { }, + () => {}, (error) => { expect(error).toBe('AppName/TaskId not configured'); done(); - }); + } + ); }); it('should return the candidate users by appName and taskId', (done) => { @@ -322,22 +335,20 @@ describe('Task Cloud Service', () => { const appName = null; const taskId = '68d54a8f'; requestSpy.and.callFake(returnFakeCandidateUsersResults); - service.getCandidateUsers(appName, taskId).subscribe( - (res: any[]) => { - expect(res.length).toBe(0); - done(); - }); + service.getCandidateUsers(appName, taskId).subscribe((res: any[]) => { + expect(res.length).toBe(0); + done(); + }); }); it('should log message and return empty array if taskId is not defined when fetching candidate users', (done) => { const appName = 'task-app'; const taskId = null; requestSpy.and.callFake(returnFakeCandidateUsersResults); - service.getCandidateUsers(appName, taskId).subscribe( - (res: any[]) => { - expect(res.length).toBe(0); - done(); - }); + service.getCandidateUsers(appName, taskId).subscribe((res: any[]) => { + expect(res.length).toBe(0); + done(); + }); }); it('should return the candidate groups by appName and taskId', (done) => { @@ -358,33 +369,30 @@ describe('Task Cloud Service', () => { const appName = null; const taskId = '68d54a8f'; requestSpy.and.callFake(returnFakeCandidateGroupResults); - service.getCandidateGroups(appName, taskId).subscribe( - (res: any[]) => { - expect(res.length).toBe(0); - done(); - }); + service.getCandidateGroups(appName, taskId).subscribe((res: any[]) => { + expect(res.length).toBe(0); + done(); + }); }); it('should log message and return empty array if taskId is not defined when fetching candidate groups', (done) => { const appName = 'task-app'; const taskId = null; requestSpy.and.callFake(returnFakeCandidateGroupResults); - service.getCandidateGroups(appName, taskId).subscribe( - (res: any[]) => { - expect(res.length).toBe(0); - done(); - }); + service.getCandidateGroups(appName, taskId).subscribe((res: any[]) => { + expect(res.length).toBe(0); + done(); + }); }); it('should call assign api and return updated task details', (done) => { const appName = 'task-app'; const taskId = '68d54a8f'; requestSpy.and.callFake(returnFakeTaskDetailsResults); - service.assign(appName, taskId, 'Phil Woods').subscribe( - (res) => { - expect(res.assignee).toBe('Phil Woods'); - done(); - }); + service.assign(appName, taskId, 'Phil Woods').subscribe((res) => { + expect(res.assignee).toBe('Phil Woods'); + done(); + }); }); it('should throw error if appName is not defined when changing task assignee', (done) => { @@ -392,11 +400,12 @@ describe('Task Cloud Service', () => { const taskId = '68d54a8f'; requestSpy.and.callFake(returnFakeTaskDetailsResults); service.assign(appName, taskId, 'mock-assignee').subscribe( - () => { }, + () => {}, (error) => { expect(error).toBe('AppName/TaskId not configured'); done(); - }); + } + ); }); it('should throw error if taskId is not defined when changing task assignee', (done) => { @@ -404,11 +413,11 @@ describe('Task Cloud Service', () => { const taskId = ''; requestSpy.and.callFake(returnFakeTaskDetailsResults); service.assign(appName, taskId, 'mock-assignee').subscribe( - () => { }, + () => {}, (error) => { expect(error).toBe('AppName/TaskId not configured'); done(); - }); + } + ); }); - }); diff --git a/lib/process-services-cloud/src/lib/task/services/task-cloud.service.ts b/lib/process-services-cloud/src/lib/task/services/task-cloud.service.ts index 0a1ca96f6ec..e4be2e8293f 100644 --- a/lib/process-services-cloud/src/lib/task/services/task-cloud.service.ts +++ b/lib/process-services-cloud/src/lib/task/services/task-cloud.service.ts @@ -18,7 +18,7 @@ import { Injectable } from '@angular/core'; import { CardViewArrayItem, TranslationService } from '@alfresco/adf-core'; import { throwError, Observable, of, Subject } from 'rxjs'; -import { catchError, map } from 'rxjs/operators'; +import { map } from 'rxjs/operators'; import { TaskDetailsCloudModel, StartTaskCloudResponseModel, @@ -39,14 +39,9 @@ import { AdfHttpClient } from '@alfresco/adf-core/api'; providedIn: 'root' }) export class TaskCloudService extends BaseCloudService implements TaskCloudServiceInterface { - dataChangesDetected$ = new Subject(); - constructor( - private translateService: TranslationService, - private identityUserService: IdentityUserService, - adfHttpClient: AdfHttpClient - ) { + constructor(private translateService: TranslationService, private identityUserService: IdentityUserService, adfHttpClient: AdfHttpClient) { super(adfHttpClient); } @@ -64,7 +59,6 @@ export class TaskCloudService extends BaseCloudService implements TaskCloudServi return this.post(url, payload); } else { - this.logService.error('AppName and TaskId are mandatory for complete a task'); return throwError('AppName/TaskId not configured'); } } @@ -89,7 +83,11 @@ export class TaskCloudService extends BaseCloudService implements TaskCloudServi return taskDetails && taskDetails.status === TASK_ASSIGNED_STATE && this.isAssignedToMe(taskDetails.assignee); } - isAssigneePropertyClickable(taskDetails: TaskDetailsCloudModel, candidateUsers: CardViewArrayItem[], candidateGroups: CardViewArrayItem[]): boolean { + isAssigneePropertyClickable( + taskDetails: TaskDetailsCloudModel, + candidateUsers: CardViewArrayItem[], + candidateGroups: CardViewArrayItem[] + ): boolean { let isClickable = false; const states = [TASK_ASSIGNED_STATE]; if (candidateUsers?.length || candidateGroups?.length) { @@ -105,9 +103,7 @@ export class TaskCloudService extends BaseCloudService implements TaskCloudServi * @returns Boolean value if the task can be completed */ canClaimTask(taskDetails: TaskDetailsCloudModel): boolean { - return taskDetails?.status === TASK_CREATED_STATE && - taskDetails?.permissions.includes(TASK_CLAIM_PERMISSION) && - !taskDetails?.standalone; + return taskDetails?.status === TASK_CREATED_STATE && taskDetails?.permissions.includes(TASK_CLAIM_PERMISSION) && !taskDetails?.standalone; } /** @@ -118,10 +114,12 @@ export class TaskCloudService extends BaseCloudService implements TaskCloudServi */ canUnclaimTask(taskDetails: TaskDetailsCloudModel): boolean { const currentUser = this.identityUserService.getCurrentUserInfo().username; - return taskDetails?.status === TASK_ASSIGNED_STATE && - taskDetails?.assignee === currentUser && - taskDetails?.permissions.includes(TASK_RELEASE_PERMISSION) && - !taskDetails?.standalone; + return ( + taskDetails?.status === TASK_ASSIGNED_STATE && + taskDetails?.assignee === currentUser && + taskDetails?.permissions.includes(TASK_RELEASE_PERMISSION) && + !taskDetails?.standalone + ); } /** @@ -143,7 +141,6 @@ export class TaskCloudService extends BaseCloudService implements TaskCloudServi }) ); } else { - this.logService.error('AppName and TaskId are mandatory for querying a task'); return throwError('AppName/TaskId not configured'); } } @@ -166,7 +163,6 @@ export class TaskCloudService extends BaseCloudService implements TaskCloudServi }) ); } else { - this.logService.error('AppName and TaskId are mandatory for querying a task'); return throwError('AppName/TaskId not configured'); } } @@ -182,30 +178,24 @@ export class TaskCloudService extends BaseCloudService implements TaskCloudServi if ((appName || appName === '') && taskId) { const queryUrl = `${this.getBasePath(appName)}/query/v1/tasks/${taskId}`; - return this.get(queryUrl).pipe( - map((res: any) => res.entry) - ); + return this.get(queryUrl).pipe(map((res: any) => res.entry)); } else { - this.logService.error('AppName and TaskId are mandatory for querying a task'); return throwError('AppName/TaskId not configured'); } } - /** - * Creates a new standalone task. - * - * @param startTaskRequest request model - * @param appName application name - * @returns Details of the newly created task - */ + /** + * Creates a new standalone task. + * + * @param startTaskRequest request model + * @param appName application name + * @returns Details of the newly created task + */ createNewTask(startTaskRequest: StartTaskCloudRequestModel, appName: string): Observable { const queryUrl = `${this.getBasePath(appName)}/rb/v1/tasks`; const payload = JSON.stringify(new StartTaskCloudRequestModel(startTaskRequest)); - return this.post(queryUrl, payload) - .pipe( - map(response => response.entry) - ); + return this.post(queryUrl, payload).pipe(map((response) => response.entry)); } /** @@ -221,11 +211,8 @@ export class TaskCloudService extends BaseCloudService implements TaskCloudServi payload.payloadType = 'UpdateTaskPayload'; const queryUrl = `${this.getBasePath(appName)}/rb/v1/tasks/${taskId}`; - return this.put(queryUrl, payload).pipe( - map((res: any) => res.entry) - ); + return this.put(queryUrl, payload).pipe(map((res: any) => res.entry)); } else { - this.logService.error('AppName and TaskId are mandatory for querying a task'); return throwError('AppName/TaskId not configured'); } } @@ -240,11 +227,8 @@ export class TaskCloudService extends BaseCloudService implements TaskCloudServi getCandidateUsers(appName: string, taskId: string): Observable { if ((appName || appName === '') && taskId) { const queryUrl = `${this.getBasePath(appName)}/query/v1/tasks/${taskId}/candidate-users`; - return this.get(queryUrl).pipe( - catchError((err) => this.handleError(err)) - ); + return this.get(queryUrl); } else { - this.logService.error('AppName and TaskId are mandatory to get candidate user'); return of([]); } } @@ -261,7 +245,6 @@ export class TaskCloudService extends BaseCloudService implements TaskCloudServi const queryUrl = `${this.getBasePath(appName)}/query/v1/tasks/${taskId}/candidate-groups`; return this.get(queryUrl); } else { - this.logService.error('AppName and TaskId are mandatory to get candidate groups'); return of([]); } } @@ -276,11 +259,8 @@ export class TaskCloudService extends BaseCloudService implements TaskCloudServi if (appName || appName === '') { const url = `${this.getBasePath(appName)}/rb/v1/process-definitions`; - return this.get(url).pipe( - map((res: any) => res.list.entries.map((processDefs) => new ProcessDefinitionCloud(processDefs.entry))) - ); + return this.get(url).pipe(map((res: any) => res.list.entries.map((processDefs) => new ProcessDefinitionCloud(processDefs.entry)))); } else { - this.logService.error('AppName is mandatory for querying task'); return throwError('AppName not configured'); } } @@ -298,17 +278,14 @@ export class TaskCloudService extends BaseCloudService implements TaskCloudServi const payLoad = { assignee, taskId, payloadType: 'AssignTaskPayload' }; const url = `${this.getBasePath(appName)}/rb/v1/tasks/${taskId}/assign`; - return this.post(url, payLoad).pipe( - map((res: any) => res.entry) - ); + return this.post(url, payLoad).pipe(map((res: any) => res.entry)); } else { - this.logService.error('AppName and TaskId are mandatory to change/update the task assignee'); return throwError('AppName/TaskId not configured'); } - } + } getPriorityLabel(priority: number): string { - const priorityItem = this.priorities.find(item => item.value === priority.toString()) || this.priorities[0]; + const priorityItem = this.priorities.find((item) => item.value === priority.toString()) || this.priorities[0]; return this.translateService.instant(priorityItem.label); } @@ -320,9 +297,4 @@ export class TaskCloudService extends BaseCloudService implements TaskCloudServi const currentUser = this.identityUserService.getCurrentUserInfo().username; return assignee === currentUser; } - - private handleError(error?: any) { - this.logService.error(error); - return throwError(error || 'Server error'); - } } diff --git a/lib/process-services-cloud/src/lib/task/start-task/components/start-task-cloud.component.spec.ts b/lib/process-services-cloud/src/lib/task/start-task/components/start-task-cloud.component.spec.ts index 0923d639198..4abd451d73f 100644 --- a/lib/process-services-cloud/src/lib/task/start-task/components/start-task-cloud.component.spec.ts +++ b/lib/process-services-cloud/src/lib/task/start-task/components/start-task-cloud.component.spec.ts @@ -25,12 +25,10 @@ import { ProcessServiceCloudTestingModule } from './../../../testing/process-ser import { FormDefinitionSelectorCloudService } from '../../../form/services/form-definition-selector-cloud.service'; import { TaskCloudService } from '../../services/task-cloud.service'; import { StartTaskCloudRequestModel } from '../models/start-task-cloud-request.model'; -import { TranslateModule } from '@ngx-translate/core'; import { IdentityUserService } from '../../../people/services/identity-user.service'; import { IdentityUserModel } from '../../../people/models/identity-user.model'; describe('StartTaskCloudComponent', () => { - let component: StartTaskCloudComponent; let fixture: ComponentFixture; let service: TaskCloudService; @@ -48,15 +46,12 @@ describe('StartTaskCloudComponent', () => { reply: jasmine.createSpy('reply') }; - const mockUser: IdentityUserModel = {username: 'currentUser', firstName: 'Test', lastName: 'User', email: 'currentUser@test.com'}; + const mockUser: IdentityUserModel = { username: 'currentUser', firstName: 'Test', lastName: 'User', email: 'currentUser@test.com' }; beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - ProcessServiceCloudTestingModule - ], - schemas: [ CUSTOM_ELEMENTS_SCHEMA ] + imports: [ProcessServiceCloudTestingModule], + schemas: [CUSTOM_ELEMENTS_SCHEMA] }); fixture = TestBed.createComponent(StartTaskCloudComponent); component = fixture.componentInstance; @@ -74,7 +69,6 @@ describe('StartTaskCloudComponent', () => { }); describe('create task', () => { - it('should create new task when start button is clicked', async () => { const successSpy = spyOn(component.success, 'emit'); component.taskForm.controls['name'].setValue('fakeName'); @@ -143,7 +137,7 @@ describe('StartTaskCloudComponent', () => { createTaskButton.click(); fixture.detectChanges(); fixture.whenStable().then(() => { - const taskRequest = new StartTaskCloudRequestModel({ name: 'fakeName', assignee: 'currentUser', candidateGroups: []}); + const taskRequest = new StartTaskCloudRequestModel({ name: 'fakeName', assignee: 'currentUser', candidateGroups: [] }); expect(createNewTaskSpy).toHaveBeenCalledWith(taskRequest, 'fakeAppName'); done(); }); @@ -157,7 +151,7 @@ describe('StartTaskCloudComponent', () => { createTaskButton.click(); fixture.detectChanges(); fixture.whenStable().then(() => { - const taskRequest = new StartTaskCloudRequestModel({ name: 'fakeName', assignee: 'currentUser', candidateGroups: []}); + const taskRequest = new StartTaskCloudRequestModel({ name: 'fakeName', assignee: 'currentUser', candidateGroups: [] }); expect(createNewTaskSpy).toHaveBeenCalledWith(taskRequest, 'fakeAppName'); done(); }); diff --git a/lib/process-services-cloud/src/lib/task/start-task/components/start-task-cloud.component.ts b/lib/process-services-cloud/src/lib/task/start-task/components/start-task-cloud.component.ts index 70c1c965acd..0e39ffdc31f 100644 --- a/lib/process-services-cloud/src/lib/task/start-task/components/start-task-cloud.component.ts +++ b/lib/process-services-cloud/src/lib/task/start-task/components/start-task-cloud.component.ts @@ -19,12 +19,7 @@ import { Component, EventEmitter, Input, OnInit, Output, ViewEncapsulation, OnDe import { DateAdapter, MAT_DATE_FORMATS } from '@angular/material/core'; import { Observable, Subject } from 'rxjs'; import { UntypedFormBuilder, Validators, UntypedFormGroup, UntypedFormControl } from '@angular/forms'; -import { - DateFnsUtils, - LogService, - UserPreferencesService, - UserPreferenceValues -} from '@alfresco/adf-core'; +import { DateFnsUtils, UserPreferencesService, UserPreferenceValues } from '@alfresco/adf-core'; import { PeopleCloudComponent } from '../../../people/components/people-cloud.component'; import { GroupCloudComponent } from '../../../group/components/group-cloud.component'; import { TaskCloudService } from '../../services/task-cloud.service'; @@ -45,7 +40,8 @@ const DATE_FORMAT: string = 'dd/MM/yyyy'; styleUrls: ['./start-task-cloud.component.scss'], providers: [ { provide: DateAdapter, useClass: DateFnsAdapter }, - { provide: MAT_DATE_FORMATS, useValue: MAT_DATE_FNS_FORMATS }], + { provide: MAT_DATE_FORMATS, useValue: MAT_DATE_FNS_FORMATS } + ], encapsulation: ViewEncapsulation.None }) export class StartTaskCloudComponent implements OnInit, OnDestroy { @@ -105,19 +101,19 @@ export class StartTaskCloudComponent implements OnInit, OnDestroy { private groupForm = new UntypedFormControl(''); private onDestroy$ = new Subject(); - constructor(private taskService: TaskCloudService, - private dateAdapter: DateAdapter, - private userPreferencesService: UserPreferencesService, - private formBuilder: UntypedFormBuilder, - private identityUserService: IdentityUserService, - private logService: LogService) { - } + constructor( + private taskService: TaskCloudService, + private dateAdapter: DateAdapter, + private userPreferencesService: UserPreferencesService, + private formBuilder: UntypedFormBuilder, + private identityUserService: IdentityUserService + ) {} ngOnInit() { this.userPreferencesService .select(UserPreferenceValues.Locale) .pipe(takeUntil(this.onDestroy$)) - .subscribe(locale => this.dateAdapter.setLocale(DateFnsUtils.getLocaleFromString(locale))); + .subscribe((locale) => this.dateAdapter.setLocale(DateFnsUtils.getLocaleFromString(locale))); this.loadCurrentUser(); this.buildForm(); this.loadDefaultPriorities(); @@ -162,17 +158,16 @@ export class StartTaskCloudComponent implements OnInit, OnDestroy { } private createNewTask(newTask: StartTaskCloudRequestModel) { - this.taskService.createNewTask(newTask, this.appName) - .subscribe( - (res: any) => { - this.submitted = false; - this.success.emit(res); - }, - (err) => { - this.submitted = false; - this.error.emit(err); - this.logService.error('An error occurred while creating new task'); - }); + this.taskService.createNewTask(newTask, this.appName).subscribe( + (res: any) => { + this.submitted = false; + this.success.emit(res); + }, + (err) => { + this.submitted = false; + this.error.emit(err); + } + ); } public onCancel() { @@ -212,11 +207,7 @@ export class StartTaskCloudComponent implements OnInit, OnDestroy { } canStartTask(): boolean { - return !(this.dateError || - !this.taskForm.valid || - this.submitted || - this.assignee.hasError() || - this.candidateGroups.hasError()); + return !(this.dateError || !this.taskForm.valid || this.submitted || this.assignee.hasError() || this.candidateGroups.hasError()); } public whitespaceValidator(control: UntypedFormControl) { diff --git a/lib/process-services-cloud/src/lib/task/start-task/services/start-task-cloud.service.spec.ts b/lib/process-services-cloud/src/lib/task/start-task/services/start-task-cloud.service.spec.ts index 6db616895cd..1b638302181 100644 --- a/lib/process-services-cloud/src/lib/task/start-task/services/start-task-cloud.service.spec.ts +++ b/lib/process-services-cloud/src/lib/task/start-task/services/start-task-cloud.service.spec.ts @@ -21,53 +21,46 @@ import { taskDetailsMock } from '../mock/task-details.mock'; import { TaskDetailsCloudModel } from '../models/task-details-cloud.model'; import { HttpErrorResponse } from '@angular/common/http'; import { TaskCloudService } from '../../services/task-cloud.service'; -import { TranslateModule } from '@ngx-translate/core'; import { ProcessServiceCloudTestingModule } from './../../../testing/process-service-cloud.testing.module'; describe('StartTaskCloudService', () => { - let service: TaskCloudService; const fakeAppName: string = 'fake-app'; beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - ProcessServiceCloudTestingModule - ] + imports: [ProcessServiceCloudTestingModule] }); service = TestBed.inject(TaskCloudService); }); it('should able to create a new task ', (done) => { - spyOn(service, 'createNewTask').and.returnValue(of({id: 'fake-id', name: 'fake-name'})); - service.createNewTask(taskDetailsMock, fakeAppName).subscribe( - (res: TaskDetailsCloudModel) => { - expect(res).toBeDefined(); - expect(res.id).toEqual('fake-id'); - expect(res.name).toEqual('fake-name'); - done(); - } - ); + spyOn(service, 'createNewTask').and.returnValue(of({ id: 'fake-id', name: 'fake-name' })); + service.createNewTask(taskDetailsMock, fakeAppName).subscribe((res: TaskDetailsCloudModel) => { + expect(res).toBeDefined(); + expect(res.id).toEqual('fake-id'); + expect(res.name).toEqual('fake-name'); + done(); + }); }); it('Should not able to create a task if error occurred', () => { const errorResponse = new HttpErrorResponse({ error: 'Mock Error', - status: 404, statusText: 'Not Found' + status: 404, + statusText: 'Not Found' }); spyOn(service, 'createNewTask').and.returnValue(throwError(errorResponse)); - service.createNewTask(taskDetailsMock, fakeAppName) - .subscribe( - () => { - fail('expected an error, not applications'); - }, - (error) => { - expect(error.status).toEqual(404); - expect(error.statusText).toEqual('Not Found'); - expect(error.error).toEqual('Mock Error'); - } - ); + service.createNewTask(taskDetailsMock, fakeAppName).subscribe( + () => { + fail('expected an error, not applications'); + }, + (error) => { + expect(error.status).toEqual(404); + expect(error.statusText).toEqual('Not Found'); + expect(error.error).toEqual('Mock Error'); + } + ); }); }); diff --git a/lib/process-services-cloud/src/lib/task/task-filters/components/edit-task-filters/edit-service-task-filter-cloud.component.spec.ts b/lib/process-services-cloud/src/lib/task/task-filters/components/edit-task-filters/edit-service-task-filter-cloud.component.spec.ts index 8f96370f029..8897320d404 100644 --- a/lib/process-services-cloud/src/lib/task/task-filters/components/edit-task-filters/edit-service-task-filter-cloud.component.spec.ts +++ b/lib/process-services-cloud/src/lib/task/task-filters/components/edit-task-filters/edit-service-task-filter-cloud.component.spec.ts @@ -28,7 +28,6 @@ import { TaskFiltersCloudModule } from '../../task-filters-cloud.module'; import { ServiceTaskFilterCloudService } from '../../services/service-task-filter-cloud.service'; import { TaskCloudService } from '../../../services/task-cloud.service'; import { fakeServiceFilter } from '../../mock/task-filters-cloud.mock'; -import { TranslateModule } from '@ngx-translate/core'; import { EditServiceTaskFilterCloudComponent } from './edit-service-task-filter-cloud.component'; import { MatIconTestingModule } from '@angular/material/icon/testing'; import { ProcessDefinitionCloud } from '../../../../models/process-definition-cloud.model'; @@ -55,7 +54,7 @@ describe('EditServiceTaskFilterCloudComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [TranslateModule.forRoot(), ProcessServiceCloudTestingModule, TaskFiltersCloudModule, MatIconTestingModule], + imports: [ProcessServiceCloudTestingModule, TaskFiltersCloudModule, MatIconTestingModule], providers: [MatDialog, { provide: TASK_FILTERS_SERVICE_TOKEN, useClass: LocalPreferenceCloudService }] }); fixture = TestBed.createComponent(EditServiceTaskFilterCloudComponent); diff --git a/lib/process-services-cloud/src/lib/task/task-filters/components/edit-task-filters/edit-task-filter-cloud.component.spec.ts b/lib/process-services-cloud/src/lib/task/task-filters/components/edit-task-filters/edit-task-filter-cloud.component.spec.ts index 5d5bc75bcaf..2e369131967 100644 --- a/lib/process-services-cloud/src/lib/task/task-filters/components/edit-task-filters/edit-task-filter-cloud.component.spec.ts +++ b/lib/process-services-cloud/src/lib/task/task-filters/components/edit-task-filters/edit-task-filter-cloud.component.spec.ts @@ -30,7 +30,6 @@ import { EditTaskFilterCloudComponent } from './edit-task-filter-cloud.component import { TaskFilterCloudService } from '../../services/task-filter-cloud.service'; import { TaskCloudService } from '../../../services/task-cloud.service'; import { fakeFilter } from '../../mock/task-filters-cloud.mock'; -import { TranslateModule } from '@ngx-translate/core'; import { DateCloudFilterType } from '../../../../models/date-cloud-filter.model'; import { AssignmentType, TaskFilterCloudModel, TaskStatusFilter } from '../../models/filter-cloud.model'; import { PeopleCloudModule } from '../../../../people/people-cloud.module'; @@ -75,7 +74,7 @@ describe('EditTaskFilterCloudComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [TranslateModule.forRoot(), ProcessServiceCloudTestingModule, TaskFiltersCloudModule, PeopleCloudModule, MatIconTestingModule], + imports: [ProcessServiceCloudTestingModule, TaskFiltersCloudModule, PeopleCloudModule, MatIconTestingModule], providers: [MatDialog, { provide: TASK_FILTERS_SERVICE_TOKEN, useClass: LocalPreferenceCloudService }] }); fixture = TestBed.createComponent(EditTaskFilterCloudComponent); diff --git a/lib/process-services-cloud/src/lib/task/task-filters/components/service-task-filters-cloud.component.spec.ts b/lib/process-services-cloud/src/lib/task/task-filters/components/service-task-filters-cloud.component.spec.ts index 26b47c8564d..75e2638fb7c 100644 --- a/lib/process-services-cloud/src/lib/task/task-filters/components/service-task-filters-cloud.component.spec.ts +++ b/lib/process-services-cloud/src/lib/task/task-filters/components/service-task-filters-cloud.component.spec.ts @@ -24,7 +24,6 @@ import { By } from '@angular/platform-browser'; import { ProcessServiceCloudTestingModule } from '../../../testing/process-service-cloud.testing.module'; import { TaskFiltersCloudModule } from '../task-filters-cloud.module'; import { fakeGlobalServiceFilters } from '../mock/task-filters-cloud.mock'; -import { TranslateModule } from '@ngx-translate/core'; import { ServiceTaskFilterCloudService } from '../services/service-task-filter-cloud.service'; import { ServiceTaskFiltersCloudComponent } from './service-task-filters-cloud.component'; @@ -37,14 +36,8 @@ describe('ServiceTaskFiltersCloudComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - ProcessServiceCloudTestingModule, - TaskFiltersCloudModule - ], - providers: [ - { provide: TASK_FILTERS_SERVICE_TOKEN, useClass: LocalPreferenceCloudService } - ] + imports: [ProcessServiceCloudTestingModule, TaskFiltersCloudModule], + providers: [{ provide: TASK_FILTERS_SERVICE_TOKEN, useClass: LocalPreferenceCloudService }] }); fixture = TestBed.createComponent(ServiceTaskFiltersCloudComponent); component = fixture.componentInstance; @@ -119,7 +112,7 @@ describe('ServiceTaskFiltersCloudComponent', () => { const change = new SimpleChange(null, appName, true); let lastValue: any; - component.error.subscribe((err) => lastValue = err); + component.error.subscribe((err) => (lastValue = err)); component.ngOnChanges({ appName: change }); fixture.detectChanges(); diff --git a/lib/process-services-cloud/src/lib/task/task-filters/components/task-assignment-filter/task-assignment-filter.component.spec.ts b/lib/process-services-cloud/src/lib/task/task-filters/components/task-assignment-filter/task-assignment-filter.component.spec.ts index 3997de89c04..9b2c077eec2 100644 --- a/lib/process-services-cloud/src/lib/task/task-filters/components/task-assignment-filter/task-assignment-filter.component.spec.ts +++ b/lib/process-services-cloud/src/lib/task/task-filters/components/task-assignment-filter/task-assignment-filter.component.spec.ts @@ -16,13 +16,10 @@ */ import { ComponentFixture, TestBed } from '@angular/core/testing'; -import { TranslationService, TranslationMock } from '@alfresco/adf-core'; -import { TranslateModule } from '@ngx-translate/core'; import { TaskAssignmentFilterCloudComponent } from './task-assignment-filter.component'; import { GroupCloudModule } from '../../../../group/group-cloud.module'; import { TaskFiltersCloudModule } from '../../task-filters-cloud.module'; import { AssignmentType, TaskStatusFilter } from '../../models/filter-cloud.model'; -import { NoopAnimationsModule } from '@angular/platform-browser/animations'; import { IdentityUserService } from '../../../../people/services/identity-user.service'; import { By } from '@angular/platform-browser'; import { DebugElement, SimpleChange } from '@angular/core'; @@ -32,6 +29,7 @@ import { HarnessLoader } from '@angular/cdk/testing'; import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed'; import { MatSelectHarness } from '@angular/material/select/testing'; import { MatFormFieldHarness } from '@angular/material/form-field/testing'; +import { ProcessServiceCloudTestingModule } from '../../../../testing/process-service-cloud.testing.module'; describe('TaskAssignmentFilterComponent', () => { let component: TaskAssignmentFilterCloudComponent; @@ -60,15 +58,7 @@ describe('TaskAssignmentFilterComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - GroupCloudModule, - TaskFiltersCloudModule, - NoopAnimationsModule - ], - providers: [ - { provide: TranslationService, useClass: TranslationMock } - ] + imports: [ProcessServiceCloudTestingModule, GroupCloudModule, TaskFiltersCloudModule] }); }); @@ -132,7 +122,7 @@ describe('TaskAssignmentFilterComponent', () => { it('should have floating labels when values are present', async () => { const inputLabelsNodes = await loader.getAllHarnesses(MatFormFieldHarness); - inputLabelsNodes.forEach(async labelNode => { + inputLabelsNodes.forEach(async (labelNode) => { expect(await labelNode.isLabelFloating()).toBeTruthy(); }); }); @@ -148,21 +138,21 @@ describe('TaskAssignmentFilterComponent', () => { it('should CREATED status set assignment type to UNASSIGNED', () => { const createdStatusChange = new SimpleChange(null, TaskStatusFilter.CREATED, true); - component.ngOnChanges({status: createdStatusChange}); + component.ngOnChanges({ status: createdStatusChange }); expect(component.assignmentType).toEqual(AssignmentType.UNASSIGNED); }); it('should ASSIGNED status set assignment type to ASSIGNED_TO', () => { const createdStatusChange = new SimpleChange(null, TaskStatusFilter.ASSIGNED, true); - component.ngOnChanges({status: createdStatusChange}); + component.ngOnChanges({ status: createdStatusChange }); expect(component.assignmentType).toEqual(AssignmentType.ASSIGNED_TO); }); it('should ALL status set assignment type to NONE', () => { const createdStatusChange = new SimpleChange(null, TaskStatusFilter.ALL, true); - component.ngOnChanges({status: createdStatusChange}); + component.ngOnChanges({ status: createdStatusChange }); expect(component.assignmentType).toEqual(AssignmentType.NONE); }); @@ -182,7 +172,7 @@ describe('TaskAssignmentFilterComponent', () => { label: 'mock-filter', value: { assignedUsers: mockFoodUsers }, type: 'assignment', - attributes: { assignedUsers: 'assignedUsers', candidateGroups: 'candidateGroups'} + attributes: { assignedUsers: 'assignedUsers', candidateGroups: 'candidateGroups' } }; fixture.detectChanges(); @@ -195,7 +185,7 @@ describe('TaskAssignmentFilterComponent', () => { label: 'mock-filter', value: { candidateGroups: mockFoodGroups }, type: 'assignment', - attributes: { assignedUsers: 'assignedUsers', candidateGroups: 'candidateGroups'} + attributes: { assignedUsers: 'assignedUsers', candidateGroups: 'candidateGroups' } }; fixture.detectChanges(); @@ -208,7 +198,7 @@ describe('TaskAssignmentFilterComponent', () => { label: 'mock-filter', value: {}, type: 'assignment', - attributes: { assignedUsers: 'assignedUsers', candidateGroups: 'candidateGroups'} + attributes: { assignedUsers: 'assignedUsers', candidateGroups: 'candidateGroups' } }; fixture.detectChanges(); diff --git a/lib/process-services-cloud/src/lib/task/task-filters/components/task-filter-dialog/task-filter-dialog-cloud.component.spec.ts b/lib/process-services-cloud/src/lib/task/task-filters/components/task-filter-dialog/task-filter-dialog-cloud.component.spec.ts index 0905f9f1fef..bfba91cf8a6 100644 --- a/lib/process-services-cloud/src/lib/task/task-filters/components/task-filter-dialog/task-filter-dialog-cloud.component.spec.ts +++ b/lib/process-services-cloud/src/lib/task/task-filters/components/task-filter-dialog/task-filter-dialog-cloud.component.spec.ts @@ -20,7 +20,6 @@ import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog'; import { TaskFilterDialogCloudComponent } from './task-filter-dialog-cloud.component'; import { TaskFiltersCloudModule } from '../../task-filters-cloud.module'; import { ProcessServiceCloudTestingModule } from '../../../../testing/process-service-cloud.testing.module'; -import { TranslateModule } from '@ngx-translate/core'; describe('TaskFilterDialogCloudComponent', () => { let component: TaskFilterDialogCloudComponent; @@ -32,16 +31,12 @@ describe('TaskFilterDialogCloudComponent', () => { }; const mockDialogData = { - data: {name: 'Mock-Title'} + data: { name: 'Mock-Title' } }; beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - ProcessServiceCloudTestingModule, - TaskFiltersCloudModule - ], + imports: [ProcessServiceCloudTestingModule, TaskFiltersCloudModule], providers: [ { provide: MatDialogRef, useValue: mockDialogRef }, { provide: MAT_DIALOG_DATA, useValue: mockDialogData } diff --git a/lib/process-services-cloud/src/lib/task/task-form/components/task-form-cloud.component.spec.ts b/lib/process-services-cloud/src/lib/task/task-form/components/task-form-cloud.component.spec.ts index 14fe35c024e..2d913adc97b 100644 --- a/lib/process-services-cloud/src/lib/task/task-form/components/task-form-cloud.component.spec.ts +++ b/lib/process-services-cloud/src/lib/task/task-form/components/task-form-cloud.component.spec.ts @@ -31,7 +31,6 @@ import { TASK_VIEW_PERMISSION } from '../../start-task/models/task-details-cloud.model'; import { TaskCloudService } from '../../services/task-cloud.service'; -import { TranslateModule } from '@ngx-translate/core'; import { IdentityUserService } from '../../../people/services/identity-user.service'; import { HarnessLoader } from '@angular/cdk/testing'; import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed'; @@ -68,7 +67,7 @@ describe('TaskFormCloudComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [TranslateModule.forRoot(), ProcessServiceCloudTestingModule], + imports: [ProcessServiceCloudTestingModule], declarations: [FormCloudComponent] }); taskDetails.status = TASK_ASSIGNED_STATE; diff --git a/lib/process-services-cloud/src/lib/task/task-header/components/task-header-cloud.component.spec.ts b/lib/process-services-cloud/src/lib/task/task-header/components/task-header-cloud.component.spec.ts index e0958549f24..1bbc972d477 100644 --- a/lib/process-services-cloud/src/lib/task/task-header/components/task-header-cloud.component.spec.ts +++ b/lib/process-services-cloud/src/lib/task/task-header/components/task-header-cloud.component.spec.ts @@ -31,7 +31,6 @@ import { taskDetailsWithParentTaskIdMock, createdTaskDetailsCloudMock } from '../mocks/task-details-cloud.mock'; -import { TranslateModule } from '@ngx-translate/core'; import { MatSelectModule } from '@angular/material/select'; import { HarnessLoader } from '@angular/cdk/testing'; import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed'; @@ -62,12 +61,7 @@ describe('TaskHeaderCloudComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - ProcessServiceCloudTestingModule, - TaskHeaderCloudModule, - MatSelectModule - ] + imports: [ProcessServiceCloudTestingModule, TaskHeaderCloudModule, MatSelectModule] }); appConfigService = TestBed.inject(AppConfigService); appConfigService.config = { @@ -94,7 +88,6 @@ describe('TaskHeaderCloudComponent', () => { }); describe('Task Details', () => { - beforeEach(() => { component.ngOnChanges(); }); @@ -225,7 +218,6 @@ describe('TaskHeaderCloudComponent', () => { }); describe('Task with parentTaskId', () => { - beforeEach(() => { getTaskByIdSpy.and.returnValue(of(taskDetailsWithParentTaskIdMock)); component.ngOnChanges(); @@ -253,7 +245,6 @@ describe('TaskHeaderCloudComponent', () => { }); describe('Assigned Task', () => { - beforeEach(() => { getTaskByIdSpy.and.returnValue(of(assignedTaskDetailsCloudMock)); component.ngOnChanges(); @@ -277,7 +268,9 @@ describe('TaskHeaderCloudComponent', () => { it('should render defined edit icon for assignee property if the task in assigned state and shared among candidate users', async () => { fixture.detectChanges(); await fixture.whenStable(); - const value = fixture.debugElement.query(By.css(`[data-automation-id="header-assignee"] [data-automation-id="card-textitem-clickable-icon-assignee"]`)); + const value = fixture.debugElement.query( + By.css(`[data-automation-id="header-assignee"] [data-automation-id="card-textitem-clickable-icon-assignee"]`) + ); expect(value).not.toBeNull(); expect(value.nativeElement.innerText).toBe('create'); }); @@ -289,29 +282,41 @@ describe('TaskHeaderCloudComponent', () => { fixture.detectChanges(); await fixture.whenStable(); - const editIcon = fixture.debugElement.query(By.css(`[data-automation-id="header-assignee"] [data-automation-id="card-textitem-clickable-icon-assignee"]`)); + const editIcon = fixture.debugElement.query( + By.css(`[data-automation-id="header-assignee"] [data-automation-id="card-textitem-clickable-icon-assignee"]`) + ); expect(editIcon).toBeNull(); }); it('should not render defined edit icon for assignee property if the task in assigned state and shared among candidate groups', async () => { - component.candidateGroups = [{ value: 'mock-group-1', icon: 'edit' }, { value: 'mock-group-2', icon: 'edit' }]; + component.candidateGroups = [ + { value: 'mock-group-1', icon: 'edit' }, + { value: 'mock-group-2', icon: 'edit' } + ]; component.candidateUsers = []; fixture.detectChanges(); await fixture.whenStable(); - const value = fixture.debugElement.query(By.css(`[data-automation-id="header-assignee"] [data-automation-id="card-textitem-clickable-icon-assignee"]`)); + const value = fixture.debugElement.query( + By.css(`[data-automation-id="header-assignee"] [data-automation-id="card-textitem-clickable-icon-assignee"]`) + ); expect(value).not.toBeNull(); expect(value.nativeElement.innerText).toBe('create'); }); it('should not render defined edit icon for assignee property if the task in created state and shared among condidate groups', async () => { getTaskByIdSpy.and.returnValue(of(createdTaskDetailsCloudMock)); - component.candidateGroups = [{ value: 'mock-group-1', icon: 'edit' }, { value: 'mock-group-2', icon: 'edit' }]; + component.candidateGroups = [ + { value: 'mock-group-1', icon: 'edit' }, + { value: 'mock-group-2', icon: 'edit' } + ]; component.candidateUsers = []; component.ngOnChanges(); fixture.detectChanges(); await fixture.whenStable(); - const editIcon = fixture.debugElement.query(By.css(`[data-automation-id="header-assignee"] [data-automation-id="card-textitem-clickable-icon-assignee"]`)); + const editIcon = fixture.debugElement.query( + By.css(`[data-automation-id="header-assignee"] [data-automation-id="card-textitem-clickable-icon-assignee"]`) + ); expect(editIcon).toBeNull(); }); @@ -331,7 +336,6 @@ describe('TaskHeaderCloudComponent', () => { }); describe('Created Task', () => { - beforeEach(() => { getTaskByIdSpy.and.returnValue(of(createdStateTaskDetailsCloudMock)); isTaskEditableSpy.and.returnValue(false); @@ -362,7 +366,6 @@ describe('TaskHeaderCloudComponent', () => { }); describe('Completed Task', () => { - beforeEach(() => { getTaskByIdSpy.and.returnValue(of(completedTaskDetailsCloudMock)); isTaskEditableSpy.and.returnValue(false); @@ -384,7 +387,6 @@ describe('TaskHeaderCloudComponent', () => { }); describe('Suspended Task', () => { - beforeEach(() => { getTaskByIdSpy.and.returnValue(of(suspendedTaskDetailsCloudMock)); isTaskEditableSpy.and.returnValue(false); @@ -406,7 +408,6 @@ describe('TaskHeaderCloudComponent', () => { }); describe('Task with candidates', () => { - it('should display candidate groups', async () => { component.ngOnChanges(); fixture.detectChanges(); @@ -459,7 +460,6 @@ describe('TaskHeaderCloudComponent', () => { }); describe('Config properties', () => { - it('should show only the properties from the configuration file', async () => { appConfigService.config = { 'adf-cloud-task-header': { @@ -508,7 +508,6 @@ describe('TaskHeaderCloudComponent', () => { }); describe('Task errors', () => { - it('should emit an error when task can not be found', (done) => { getTaskByIdSpy.and.returnValue(throwError('Task not found')); @@ -523,7 +522,7 @@ describe('TaskHeaderCloudComponent', () => { }); it('should emit an error when app name and/or task id are not provided', (done) => { - component.error.subscribe( (err) => { + component.error.subscribe((err) => { expect(err).toEqual('App Name and Task Id are mandatory'); done(); }); diff --git a/lib/process-services-cloud/src/lib/task/task-list/components/service-task-list-cloud.component.spec.ts b/lib/process-services-cloud/src/lib/task/task-list/components/service-task-list-cloud.component.spec.ts index 074d02d347e..71b73ea1353 100644 --- a/lib/process-services-cloud/src/lib/task/task-list/components/service-task-list-cloud.component.spec.ts +++ b/lib/process-services-cloud/src/lib/task/task-list/components/service-task-list-cloud.component.spec.ts @@ -23,7 +23,6 @@ import { ServiceTaskListCloudComponent } from './service-task-list-cloud.compone import { fakeServiceTask, fakeCustomSchema } from '../mock/fake-task-response.mock'; import { of } from 'rxjs'; import { ProcessServiceCloudTestingModule } from '../../../testing/process-service-cloud.testing.module'; -import { TranslateModule } from '@ngx-translate/core'; import { TaskListCloudSortingModel } from '../../../models/task-list-sorting.model'; import { shareReplay, skip } from 'rxjs/operators'; import { ServiceTaskListCloudService } from '../services/service-task-list-cloud.service'; @@ -80,7 +79,7 @@ describe('ServiceTaskListCloudComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [TranslateModule.forRoot(), ProcessServiceCloudTestingModule], + imports: [ProcessServiceCloudTestingModule], declarations: [EmptyTemplateComponent] }); appConfig = TestBed.inject(AppConfigService); @@ -357,7 +356,7 @@ describe('ServiceTaskListCloudComponent: Injecting custom columns for task list beforeEach(() => { TestBed.configureTestingModule({ - imports: [TranslateModule.forRoot(), ProcessServiceCloudTestingModule], + imports: [ProcessServiceCloudTestingModule], declarations: [CustomTaskListComponent, CustomCopyContentTaskListComponent] }); @@ -415,7 +414,7 @@ describe('ServiceTaskListCloudComponent: Copy cell content directive from app.co beforeEach(() => { TestBed.configureTestingModule({ - imports: [TranslateModule.forRoot(), ProcessServiceCloudTestingModule] + imports: [ProcessServiceCloudTestingModule] }); appConfig = TestBed.inject(AppConfigService); serviceTaskListCloudService = TestBed.inject(ServiceTaskListCloudService); diff --git a/lib/process-services-cloud/src/lib/task/task-list/components/task-list-cloud.component.spec.ts b/lib/process-services-cloud/src/lib/task/task-list/components/task-list-cloud.component.spec.ts index 7b3d5f083c8..914db127fbf 100644 --- a/lib/process-services-cloud/src/lib/task/task-list/components/task-list-cloud.component.spec.ts +++ b/lib/process-services-cloud/src/lib/task/task-list/components/task-list-cloud.component.spec.ts @@ -18,32 +18,17 @@ import { Component, SimpleChange, ViewChild } from '@angular/core'; import { ComponentFixture, TestBed } from '@angular/core/testing'; import { By } from '@angular/platform-browser'; -import { - AppConfigService, - DataRowEvent, - ObjectDataRow, - User, - DataColumn, - ColumnsSelectorComponent, - AlfrescoApiService, - AlfrescoApiServiceMock, - AppConfigServiceMock, - TranslationService, - TranslationMock -} from '@alfresco/adf-core'; +import { AppConfigService, DataRowEvent, ObjectDataRow, User, DataColumn, ColumnsSelectorComponent } from '@alfresco/adf-core'; import { TaskListCloudService } from '../services/task-list-cloud.service'; import { TaskListCloudComponent } from './task-list-cloud.component'; import { fakeGlobalTasks, fakeCustomSchema, fakeGlobalTask } from '../mock/fake-task-response.mock'; import { of } from 'rxjs'; import { ProcessServiceCloudTestingModule } from '../../../testing/process-service-cloud.testing.module'; -import { TranslateModule } from '@ngx-translate/core'; import { TaskListCloudSortingModel } from '../../../models/task-list-sorting.model'; import { shareReplay, skip } from 'rxjs/operators'; import { TaskListCloudServiceInterface } from '../../../services/task-list-cloud.service.interface'; import { TASK_LIST_CLOUD_TOKEN, TASK_LIST_PREFERENCES_SERVICE_TOKEN } from '../../../services/cloud-token.service'; import { TaskListCloudModule } from '../task-list-cloud.module'; -import { HttpClientModule } from '@angular/common/http'; -import { NoopAnimationsModule } from '@angular/platform-browser/animations'; import { PreferenceCloudServiceInterface } from '../../../services/preference-cloud.interface'; import { HarnessLoader } from '@angular/cdk/testing'; import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed'; @@ -117,7 +102,7 @@ describe('TaskListCloudComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [TranslateModule.forRoot(), ProcessServiceCloudTestingModule], + imports: [ProcessServiceCloudTestingModule], providers: [ { provide: TASK_LIST_CLOUD_TOKEN, @@ -515,7 +500,7 @@ describe('TaskListCloudComponent: Injecting custom colums for tasklist - CustomT beforeEach(() => { TestBed.configureTestingModule({ - imports: [TranslateModule.forRoot(), ProcessServiceCloudTestingModule], + imports: [ProcessServiceCloudTestingModule], declarations: [CustomTaskListComponent, CustomCopyContentTaskListComponent] }); taskListCloudService = TestBed.inject(TASK_LIST_CLOUD_TOKEN); @@ -569,12 +554,7 @@ describe('TaskListCloudComponent: Creating an empty custom template - EmptyTempl beforeEach(() => { TestBed.configureTestingModule({ - imports: [HttpClientModule, NoopAnimationsModule, TranslateModule.forRoot(), TaskListCloudModule], - providers: [ - { provide: AlfrescoApiService, useClass: AlfrescoApiServiceMock }, - { provide: AppConfigService, useClass: AppConfigServiceMock }, - { provide: TranslationService, useClass: TranslationMock } - ] + imports: [ProcessServiceCloudTestingModule, TaskListCloudModule] }); taskListCloudService = TestBed.inject(TASK_LIST_CLOUD_TOKEN); const emptyList = { list: { entries: [] } }; @@ -606,7 +586,7 @@ describe('TaskListCloudComponent: Copy cell content directive from app.config sp beforeEach(() => { TestBed.configureTestingModule({ - imports: [TranslateModule.forRoot(), ProcessServiceCloudTestingModule] + imports: [ProcessServiceCloudTestingModule] }); appConfig = TestBed.inject(AppConfigService); taskListCloudService = TestBed.inject(TASK_LIST_CLOUD_TOKEN); diff --git a/lib/process-services-cloud/src/lib/task/task-list/services/service-task-list-cloud.service.spec.ts b/lib/process-services-cloud/src/lib/task/task-list/services/service-task-list-cloud.service.spec.ts index 0ae7729b3f0..6f94ad60fe1 100644 --- a/lib/process-services-cloud/src/lib/task/task-list/services/service-task-list-cloud.service.spec.ts +++ b/lib/process-services-cloud/src/lib/task/task-list/services/service-task-list-cloud.service.spec.ts @@ -16,7 +16,6 @@ */ import { TestBed } from '@angular/core/testing'; -import { LogService } from '@alfresco/adf-core'; import { ServiceTaskListCloudService } from './service-task-list-cloud.service'; import { ServiceTaskQueryCloudRequestModel } from '../models/service-task-cloud.model'; import { ProcessServiceCloudTestingModule } from '../../../testing/process-service-cloud.testing.module'; @@ -24,10 +23,8 @@ import { of } from 'rxjs'; import { AdfHttpClient } from '@alfresco/adf-core/api'; describe('Activiti ServiceTaskList Cloud Service', () => { - let service: ServiceTaskListCloudService; let adfHttpClient: AdfHttpClient; - let logService: LogService; let requestSpy: jasmine.Spy; const returnCallQueryParameters = (_queryUrl, options) => Promise.resolve(options.queryParams); @@ -36,13 +33,10 @@ describe('Activiti ServiceTaskList Cloud Service', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - ProcessServiceCloudTestingModule - ] + imports: [ProcessServiceCloudTestingModule] }); adfHttpClient = TestBed.inject(AdfHttpClient); service = TestBed.inject(ServiceTaskListCloudService); - logService = TestBed.inject(LogService); requestSpy = spyOn(adfHttpClient, 'request'); }); @@ -72,8 +66,14 @@ describe('Activiti ServiceTaskList Cloud Service', () => { it('should concat the sorting to append as parameters', (done) => { const taskRequest = { - appName: 'fakeName', skipCount: 0, maxItems: 20, service: 'fake-service', - sorting: [{ orderBy: 'NAME', direction: 'DESC' }, { orderBy: 'TITLE', direction: 'ASC' }] + appName: 'fakeName', + skipCount: 0, + maxItems: 20, + service: 'fake-service', + sorting: [ + { orderBy: 'NAME', direction: 'DESC' }, + { orderBy: 'TITLE', direction: 'ASC' } + ] } as ServiceTaskQueryCloudRequestModel; requestSpy.and.callFake(returnCallQueryParameters); service.getServiceTaskByRequest(taskRequest).subscribe((res) => { @@ -88,7 +88,7 @@ describe('Activiti ServiceTaskList Cloud Service', () => { const taskRequest = { appName: null } as ServiceTaskQueryCloudRequestModel; requestSpy.and.callFake(returnCallUrl); service.getServiceTaskByRequest(taskRequest).subscribe( - () => { }, + () => {}, (error) => { expect(error).toBe('Appname not configured'); done(); @@ -97,16 +97,11 @@ describe('Activiti ServiceTaskList Cloud Service', () => { }); describe('run replayServiceTaskRequest method', () => { - - let logServiceErrorSpy: jasmine.Spy; - beforeEach(() => { spyOn(service, 'getBasePath').and.returnValue('http://localhost/fakeName'); requestSpy.and.callFake(returnCallUrl); - logServiceErrorSpy = spyOn(logService, 'error'); }); - it('should execute post method if all parameters are provided', async () => { const expected = { expectedQueryUrl: 'http://localhost/fakeName/rb/admin/v1/executions/executionId_1/replay/service-task', @@ -119,49 +114,54 @@ describe('Activiti ServiceTaskList Cloud Service', () => { const params = ['fakeName', 'executionId_1', 'flowNodeId_1'] as const; await service.replayServiceTaskRequest(...params).toPromise(); expect(spyOnPost).toHaveBeenCalledWith(expected.expectedQueryUrl, expected.expectedPayload); - expect(logServiceErrorSpy).not.toHaveBeenCalled(); - }); it('should throw an exeption and execute logService error if appName is null', (done) => { const expectedErrorMessage = 'Appname/executionId/flowNodeId not configured'; const params = [null, 'executionId_1', 'flowNodeId_1'] as const; - service.replayServiceTaskRequest(...params).toPromise().catch((error) => { - expect(error).toEqual(expectedErrorMessage); - expect(logServiceErrorSpy).toHaveBeenCalled(); - done(); - }); + service + .replayServiceTaskRequest(...params) + .toPromise() + .catch((error) => { + expect(error).toEqual(expectedErrorMessage); + done(); + }); }); it('should throw an exeption and execute logService error if executionId is null', (done) => { const expectedErrorMessage = 'Appname/executionId/flowNodeId not configured'; const params = ['fakeName', null, 'flowNodeId_1'] as const; - service.replayServiceTaskRequest(...params).toPromise().catch((error) => { - expect(error).toEqual(expectedErrorMessage); - expect(logServiceErrorSpy).toHaveBeenCalled(); - done(); - }); + service + .replayServiceTaskRequest(...params) + .toPromise() + .catch((error) => { + expect(error).toEqual(expectedErrorMessage); + done(); + }); }); it('should throw an exeption and execute logService error if flowNodeId is null', (done) => { const expectedErrorMessage = 'Appname/executionId/flowNodeId not configured'; const params = ['fakeName', 'executionId_1', null] as const; - service.replayServiceTaskRequest(...params).toPromise().catch((error) => { - expect(error).toEqual(expectedErrorMessage); - expect(logServiceErrorSpy).toHaveBeenCalled(); - done(); - }); + service + .replayServiceTaskRequest(...params) + .toPromise() + .catch((error) => { + expect(error).toEqual(expectedErrorMessage); + done(); + }); }); it('should throw an exeption and execute logService error if appName, executionId and flowNodeId are null', (done) => { const expectedErrorMessage = 'Appname/executionId/flowNodeId not configured'; const params = [null, null, null] as const; - service.replayServiceTaskRequest(...params).toPromise().catch((error) => { - expect(error).toEqual(expectedErrorMessage); - expect(logServiceErrorSpy).toHaveBeenCalled(); - done(); - }); + service + .replayServiceTaskRequest(...params) + .toPromise() + .catch((error) => { + expect(error).toEqual(expectedErrorMessage); + done(); + }); }); }); - }); diff --git a/lib/process-services-cloud/src/lib/task/task-list/services/service-task-list-cloud.service.ts b/lib/process-services-cloud/src/lib/task/task-list/services/service-task-list-cloud.service.ts index 789cf4d45bc..130b2d7db95 100644 --- a/lib/process-services-cloud/src/lib/task/task-list/services/service-task-list-cloud.service.ts +++ b/lib/process-services-cloud/src/lib/task/task-list/services/service-task-list-cloud.service.ts @@ -40,7 +40,6 @@ export class ServiceTaskListCloudService extends BaseCloudService { } return this.get(queryUrl, queryParams); } else { - this.logService.error('Appname is mandatory for querying task'); return throwError('Appname not configured'); } } @@ -55,11 +54,8 @@ export class ServiceTaskListCloudService extends BaseCloudService { getServiceTaskStatus(appName: string, serviceTaskId: string): Observable { if (appName) { const queryUrl = `${this.getBasePath(appName)}/query/admin/v1/service-tasks/${serviceTaskId}/integration-context`; - return this.get(queryUrl).pipe( - map((response: any) => response.entry) - ); + return this.get(queryUrl).pipe(map((response: any) => response.entry)); } else { - this.logService.error('Appname is mandatory for querying task'); return throwError('Appname not configured'); } } @@ -78,7 +74,6 @@ export class ServiceTaskListCloudService extends BaseCloudService { const queryUrl = `${this.getBasePath(appName)}/rb/admin/v1/executions/${executionId}/replay/service-task`; return this.post(queryUrl, payload); } else { - this.logService.error('Appname, executionId and flowNodeId are mandatory to replaying a service task'); return throwError('Appname/executionId/flowNodeId not configured'); } } @@ -86,9 +81,11 @@ export class ServiceTaskListCloudService extends BaseCloudService { protected buildQueryParams(requestNode: ServiceTaskQueryCloudRequestModel): any { const queryParam: any = {}; for (const property in requestNode) { - if (Object.prototype.hasOwnProperty.call(requestNode, property) && + if ( + Object.prototype.hasOwnProperty.call(requestNode, property) && !this.isExcludedField(property) && - this.isPropertyValueValid(requestNode, property)) { + this.isPropertyValueValid(requestNode, property) + ) { queryParam[property] = requestNode[property]; } } diff --git a/lib/process-services-cloud/src/lib/task/task-list/services/task-list-cloud.service.spec.ts b/lib/process-services-cloud/src/lib/task/task-list/services/task-list-cloud.service.spec.ts index 502baf5caee..d35a7f06922 100644 --- a/lib/process-services-cloud/src/lib/task/task-list/services/task-list-cloud.service.spec.ts +++ b/lib/process-services-cloud/src/lib/task/task-list/services/task-list-cloud.service.spec.ts @@ -19,11 +19,9 @@ import { TestBed } from '@angular/core/testing'; import { TaskListCloudService } from './task-list-cloud.service'; import { TaskQueryCloudRequestModel } from '../../../models/filter-cloud-model'; import { ProcessServiceCloudTestingModule } from '../../../testing/process-service-cloud.testing.module'; -import { TranslateModule } from '@ngx-translate/core'; import { AdfHttpClient } from '@alfresco/adf-core/api'; describe('TaskListCloudService', () => { - let service: TaskListCloudService; let adfHttpClient: AdfHttpClient; let requestSpy: jasmine.Spy; @@ -34,10 +32,7 @@ describe('TaskListCloudService', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - ProcessServiceCloudTestingModule - ] + imports: [ProcessServiceCloudTestingModule] }); adfHttpClient = TestBed.inject(AdfHttpClient); service = TestBed.inject(TaskListCloudService); @@ -69,8 +64,16 @@ describe('TaskListCloudService', () => { }); it('should concat the sorting to append as parameters', (done) => { - const taskRequest = { appName: 'fakeName', skipCount: 0, maxItems: 20, service: 'fake-service', - sorting: [{ orderBy: 'NAME', direction: 'DESC'}, { orderBy: 'TITLE', direction: 'ASC'}] } as TaskQueryCloudRequestModel; + const taskRequest = { + appName: 'fakeName', + skipCount: 0, + maxItems: 20, + service: 'fake-service', + sorting: [ + { orderBy: 'NAME', direction: 'DESC' }, + { orderBy: 'TITLE', direction: 'ASC' } + ] + } as TaskQueryCloudRequestModel; requestSpy.and.callFake(returnCallQueryParameters); service.getTaskByRequest(taskRequest).subscribe((res) => { expect(res).toBeDefined(); @@ -84,7 +87,7 @@ describe('TaskListCloudService', () => { const taskRequest = { appName: null } as TaskQueryCloudRequestModel; requestSpy.and.callFake(returnCallUrl); service.getTaskByRequest(taskRequest).subscribe( - () => { }, + () => {}, (error) => { expect(error).toBe('Appname not configured'); done(); diff --git a/lib/process-services-cloud/src/lib/task/task-list/services/task-list-cloud.service.ts b/lib/process-services-cloud/src/lib/task/task-list/services/task-list-cloud.service.ts index 4c0975e6cf3..5dc78e7b16a 100644 --- a/lib/process-services-cloud/src/lib/task/task-list/services/task-list-cloud.service.ts +++ b/lib/process-services-cloud/src/lib/task/task-list/services/task-list-cloud.service.ts @@ -52,7 +52,6 @@ export class TaskListCloudService extends BaseCloudService implements TaskListCl }) ); } else { - this.logService.error('Appname is mandatory for querying task'); return throwError('Appname not configured'); } } diff --git a/lib/process-services/src/lib/app-list/apps-list.component.spec.ts b/lib/process-services/src/lib/app-list/apps-list.component.spec.ts index bf5747632df..77cb023561f 100644 --- a/lib/process-services/src/lib/app-list/apps-list.component.spec.ts +++ b/lib/process-services/src/lib/app-list/apps-list.component.spec.ts @@ -23,7 +23,6 @@ import { of, throwError } from 'rxjs'; import { defaultApp, deployedApps, nonDeployedApps } from '../mock/apps-list.mock'; import { AppsListComponent, APP_LIST_LAYOUT_GRID, APP_LIST_LAYOUT_LIST } from './apps-list.component'; import { ProcessTestingModule } from '../testing/process.testing.module'; -import { TranslateModule } from '@ngx-translate/core'; import { AppDefinitionRepresentationModel } from '../task-list'; import { HarnessLoader } from '@angular/cdk/testing'; import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed'; @@ -50,7 +49,7 @@ describe('AppsListComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [TranslateModule.forRoot(), ProcessTestingModule], + imports: [ProcessTestingModule], declarations: [CustomEmptyAppListTemplateComponent] }); fixture = TestBed.createComponent(AppsListComponent); diff --git a/lib/process-services/src/lib/app-list/select-apps-dialog.component.spec.ts b/lib/process-services/src/lib/app-list/select-apps-dialog.component.spec.ts index d588f86edb0..0d8d758aa4c 100644 --- a/lib/process-services/src/lib/app-list/select-apps-dialog.component.spec.ts +++ b/lib/process-services/src/lib/app-list/select-apps-dialog.component.spec.ts @@ -22,10 +22,8 @@ import { OverlayContainer } from '@angular/cdk/overlay'; import { AppsProcessService } from './services/apps-process.service'; import { deployedApps } from '../mock/apps-list.mock'; import { of } from 'rxjs'; - import { SelectAppsDialogComponent } from './select-apps-dialog.component'; import { ProcessTestingModule } from '../testing/process.testing.module'; -import { TranslateModule } from '@ngx-translate/core'; @Component({ selector: 'adf-dialog-test', @@ -59,10 +57,7 @@ describe('Select app dialog', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - ProcessTestingModule - ], + imports: [ProcessTestingModule], declarations: [DialogSelectAppTestComponent], providers: [ { @@ -89,9 +84,7 @@ describe('Select app dialog', () => { service = TestBed.inject(AppsProcessService); - spyOn(service, 'getDeployedApplications').and.returnValue( - of(deployedApps) - ); + spyOn(service, 'getDeployedApplications').and.returnValue(of(deployedApps)); }); describe('Dialog', () => { @@ -102,16 +95,8 @@ describe('Select app dialog', () => { it('should init title and dropdown', () => { component.startProcessAction(); - expect( - overlayContainerElement.querySelector( - '.adf-select-app-dialog-title' - ) - ).toBeDefined(); - expect( - overlayContainerElement.querySelector( - '.adf-select-app-dialog-dropdown' - ) - ).toBeDefined(); + expect(overlayContainerElement.querySelector('.adf-select-app-dialog-title')).toBeDefined(); + expect(overlayContainerElement.querySelector('.adf-select-app-dialog-dropdown')).toBeDefined(); }); }); }); diff --git a/lib/process-services/src/lib/app-list/services/apps-process.service.spec.ts b/lib/process-services/src/lib/app-list/services/apps-process.service.spec.ts index 6b3c37269a3..250c59872c2 100644 --- a/lib/process-services/src/lib/app-list/services/apps-process.service.spec.ts +++ b/lib/process-services/src/lib/app-list/services/apps-process.service.spec.ts @@ -19,20 +19,15 @@ import { TestBed } from '@angular/core/testing'; import { fakeApps } from '../mocks/apps-service.mock'; import { AppsProcessService } from './apps-process.service'; import { CoreTestingModule } from '@alfresco/adf-core'; -import { TranslateModule } from '@ngx-translate/core'; declare let jasmine: any; describe('AppsProcessService', () => { - let service: AppsProcessService; beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - CoreTestingModule - ] + imports: [CoreTestingModule] }); service = TestBed.inject(AppsProcessService); jasmine.Ajax.install(); @@ -43,19 +38,17 @@ describe('AppsProcessService', () => { }); it('should get the deployed apps ', (done) => { - service.getDeployedApplications().subscribe( - (res: any) => { - expect(res).toBeDefined(); - expect(res.length).toEqual(2); - expect(res[0].name).toEqual('Sales-Fakes-App'); - expect(res[0].description).toEqual('desc-fake1'); - expect(res[0].deploymentId).toEqual('111'); - expect(res[1].name).toEqual('health-care-Fake'); - expect(res[1].description).toEqual('desc-fake2'); - expect(res[1].deploymentId).toEqual('444'); - done(); - } - ); + service.getDeployedApplications().subscribe((res: any) => { + expect(res).toBeDefined(); + expect(res.length).toEqual(2); + expect(res[0].name).toEqual('Sales-Fakes-App'); + expect(res[0].description).toEqual('desc-fake1'); + expect(res[0].deploymentId).toEqual('111'); + expect(res[1].name).toEqual('health-care-Fake'); + expect(res[1].description).toEqual('desc-fake2'); + expect(res[1].deploymentId).toEqual('444'); + done(); + }); jasmine.Ajax.requests.mostRecent().respondWith({ status: 200, @@ -65,15 +58,13 @@ describe('AppsProcessService', () => { }); it('should get the filter deployed app ', (done) => { - service.getDeployedApplicationsByName('health-care-Fake').subscribe( - (res: any) => { - expect(res).toBeDefined(); - expect(res.name).toEqual('health-care-Fake'); - expect(res.description).toEqual('desc-fake2'); - expect(res.deploymentId).toEqual('444'); - done(); - } - ); + service.getDeployedApplicationsByName('health-care-Fake').subscribe((res: any) => { + expect(res).toBeDefined(); + expect(res.name).toEqual('health-care-Fake'); + expect(res.description).toEqual('desc-fake2'); + expect(res.deploymentId).toEqual('444'); + done(); + }); jasmine.Ajax.requests.mostRecent().respondWith({ status: 200, @@ -83,15 +74,13 @@ describe('AppsProcessService', () => { }); it('should get the deployed app details by id ', (done) => { - service.getApplicationDetailsById(1).subscribe( - (app: any) => { - expect(app).toBeDefined(); - expect(app.name).toEqual('Sales-Fakes-App'); - expect(app.description).toEqual('desc-fake1'); - expect(app.deploymentId).toEqual('111'); - done(); - } - ); + service.getApplicationDetailsById(1).subscribe((app: any) => { + expect(app).toBeDefined(); + expect(app.name).toEqual('Sales-Fakes-App'); + expect(app.description).toEqual('desc-fake1'); + expect(app.deploymentId).toEqual('111'); + done(); + }); jasmine.Ajax.requests.mostRecent().respondWith({ status: 200, diff --git a/lib/process-services/src/lib/attachment/create-process-attachment.component.spec.ts b/lib/process-services/src/lib/attachment/create-process-attachment.component.spec.ts index 16fc77811ab..4f44d3002e8 100644 --- a/lib/process-services/src/lib/attachment/create-process-attachment.component.spec.ts +++ b/lib/process-services/src/lib/attachment/create-process-attachment.component.spec.ts @@ -19,12 +19,10 @@ import { SimpleChange } from '@angular/core'; import { ComponentFixture, TestBed } from '@angular/core/testing'; import { CreateProcessAttachmentComponent } from './create-process-attachment.component'; import { ProcessTestingModule } from '../testing/process.testing.module'; -import { TranslateModule } from '@ngx-translate/core'; declare let jasmine: any; describe('CreateProcessAttachmentComponent', () => { - let component: CreateProcessAttachmentComponent; let fixture: ComponentFixture; let element: HTMLElement; @@ -49,10 +47,7 @@ describe('CreateProcessAttachmentComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - ProcessTestingModule - ] + imports: [ProcessTestingModule] }); fixture = TestBed.createComponent(CreateProcessAttachmentComponent); component = fixture.componentInstance; diff --git a/lib/process-services/src/lib/attachment/create-task-attachment.component.spec.ts b/lib/process-services/src/lib/attachment/create-task-attachment.component.spec.ts index b41f608adbf..88c35d43ee6 100644 --- a/lib/process-services/src/lib/attachment/create-task-attachment.component.spec.ts +++ b/lib/process-services/src/lib/attachment/create-task-attachment.component.spec.ts @@ -20,7 +20,6 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; import { of } from 'rxjs'; import { AttachmentComponent } from './create-task-attachment.component'; import { ProcessTestingModule } from '../testing/process.testing.module'; -import { TranslateModule } from '@ngx-translate/core'; import { ProcessContentService } from '../form/services/process-content.service'; describe('AttachmentComponent', () => { @@ -31,7 +30,7 @@ describe('AttachmentComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [TranslateModule.forRoot(), ProcessTestingModule] + imports: [ProcessTestingModule] }); fixture = TestBed.createComponent(AttachmentComponent); component = fixture.componentInstance; diff --git a/lib/process-services/src/lib/attachment/process-attachment-list.component.spec.ts b/lib/process-services/src/lib/attachment/process-attachment-list.component.spec.ts index 6f875dd47b8..6af2023fe05 100644 --- a/lib/process-services/src/lib/attachment/process-attachment-list.component.spec.ts +++ b/lib/process-services/src/lib/attachment/process-attachment-list.component.spec.ts @@ -21,7 +21,6 @@ import { By } from '@angular/platform-browser'; import { of, throwError } from 'rxjs'; import { ProcessAttachmentListComponent } from './process-attachment-list.component'; import { ProcessTestingModule } from '../testing/process.testing.module'; -import { TranslateModule } from '@ngx-translate/core'; import { mockEmittedProcessAttachments, mockProcessAttachments } from '../mock/process/process-attachments.mock'; import { ProcessContentService } from '../form/services/process-content.service'; import { HarnessLoader } from '@angular/cdk/testing'; @@ -37,7 +36,7 @@ describe('ProcessAttachmentListComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [TranslateModule.forRoot(), ProcessTestingModule] + imports: [ProcessTestingModule] }); fixture = TestBed.createComponent(ProcessAttachmentListComponent); component = fixture.componentInstance; @@ -255,7 +254,7 @@ describe('Custom CustomEmptyTemplateComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [TranslateModule.forRoot(), ProcessTestingModule], + imports: [ProcessTestingModule], declarations: [CustomEmptyTemplateComponent], schemas: [CUSTOM_ELEMENTS_SCHEMA] }); diff --git a/lib/process-services/src/lib/attachment/task-attachment-list.component.spec.ts b/lib/process-services/src/lib/attachment/task-attachment-list.component.spec.ts index 995bf21622b..417f6029801 100644 --- a/lib/process-services/src/lib/attachment/task-attachment-list.component.spec.ts +++ b/lib/process-services/src/lib/attachment/task-attachment-list.component.spec.ts @@ -21,7 +21,6 @@ import { By } from '@angular/platform-browser'; import { of, throwError } from 'rxjs'; import { TaskAttachmentListComponent } from './task-attachment-list.component'; import { ProcessTestingModule } from '../testing/process.testing.module'; -import { TranslateModule } from '@ngx-translate/core'; import { mockEmittedTaskAttachments, mockTaskAttachments } from '../mock/task/task-attachments.mock'; import { ProcessContentService } from '../form/services/process-content.service'; import { HarnessLoader } from '@angular/cdk/testing'; @@ -29,7 +28,6 @@ import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed'; import { MatMenuItemHarness } from '@angular/material/menu/testing'; describe('TaskAttachmentList', () => { - let component: TaskAttachmentListComponent; let fixture: ComponentFixture; let service: ProcessContentService; @@ -42,10 +40,7 @@ describe('TaskAttachmentList', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - ProcessTestingModule - ], + imports: [ProcessTestingModule], schemas: [NO_ERRORS_SCHEMA] }); fixture = TestBed.createComponent(TaskAttachmentListComponent); @@ -123,12 +118,14 @@ describe('TaskAttachmentList', () => { }); it('should show the empty default message when has no custom template', async () => { - getTaskRelatedContentSpy.and.returnValue(of({ - size: 0, - total: 0, - start: 0, - data: [] - })); + getTaskRelatedContentSpy.and.returnValue( + of({ + size: 0, + total: 0, + start: 0, + data: [] + }) + ); const change = new SimpleChange(null, '123', true); component.ngOnChanges({ taskId: change }); component.hasCustomTemplate = false; @@ -180,12 +177,14 @@ describe('TaskAttachmentList', () => { }); it('should show the empty list component when the attachments list is empty', async () => { - getTaskRelatedContentSpy.and.returnValue(of({ - size: 0, - total: 0, - start: 0, - data: [] - })); + getTaskRelatedContentSpy.and.returnValue( + of({ + size: 0, + total: 0, + start: 0, + data: [] + }) + ); const change = new SimpleChange(null, '123', true); component.ngOnChanges({ taskId: change }); @@ -196,19 +195,23 @@ describe('TaskAttachmentList', () => { }); it('should show the empty list component when the attachments list is empty for completed task', async () => { - getTaskRelatedContentSpy.and.returnValue(of({ - size: 0, - total: 0, - start: 0, - data: [] - })); + getTaskRelatedContentSpy.and.returnValue( + of({ + size: 0, + total: 0, + start: 0, + data: [] + }) + ); const change = new SimpleChange(null, '123', true); component.ngOnChanges({ taskId: change }); component.disabled = true; fixture.whenStable().then(() => { fixture.detectChanges(); - expect(fixture.nativeElement.querySelector('div[adf-empty-list-header]').innerText.trim()).toEqual('ADF_TASK_LIST.ATTACHMENT.EMPTY.HEADER'); + expect(fixture.nativeElement.querySelector('div[adf-empty-list-header]').innerText.trim()).toEqual( + 'ADF_TASK_LIST.ATTACHMENT.EMPTY.HEADER' + ); }); }); @@ -229,7 +232,6 @@ describe('TaskAttachmentList', () => { }); describe('change detection', () => { - let change: SimpleChange; let nullChange: SimpleChange; @@ -263,7 +265,6 @@ describe('TaskAttachmentList', () => { }); describe('Delete attachments', () => { - beforeEach(() => { component.taskId = '123'; fixture.whenStable(); @@ -289,18 +290,14 @@ describe('TaskAttachmentList', () => { ` }) -class CustomEmptyTemplateComponent { -} +class CustomEmptyTemplateComponent {} describe('Custom CustomEmptyTemplateComponent', () => { let fixture: ComponentFixture; beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - ProcessTestingModule - ], + imports: [ProcessTestingModule], declarations: [CustomEmptyTemplateComponent], schemas: [CUSTOM_ELEMENTS_SCHEMA] }); diff --git a/lib/process-services/src/lib/common/services/people-process.service.spec.ts b/lib/process-services/src/lib/common/services/people-process.service.spec.ts index 43dd9942d4c..3d9a3312c7d 100644 --- a/lib/process-services/src/lib/common/services/people-process.service.spec.ts +++ b/lib/process-services/src/lib/common/services/people-process.service.spec.ts @@ -19,7 +19,6 @@ import { fakeAsync, TestBed } from '@angular/core/testing'; import { UserProcessModel } from '../models/user-process.model'; import { PeopleProcessService } from './people-process.service'; import { CoreTestingModule } from '@alfresco/adf-core'; -import { TranslateModule } from '@ngx-translate/core'; declare let jasmine: any; @@ -42,21 +41,16 @@ const fakeInvolveUserList: UserProcessModel[] = [firstInvolvedUser, secondInvolv const errorResponse = { error: new Error('Unsuccessful HTTP response') }; describe('PeopleProcessService', () => { - let service: PeopleProcessService; beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - CoreTestingModule - ] + imports: [CoreTestingModule] }); service = TestBed.inject(PeopleProcessService); }); describe('when user is logged in', () => { - beforeEach(() => { jasmine.Ajax.install(); }); @@ -66,36 +60,34 @@ describe('PeopleProcessService', () => { }); it('should be able to retrieve people to involve in the task', fakeAsync(() => { - service.getWorkflowUsers('fake-task-id', 'fake-filter').subscribe( - (users: UserProcessModel[]) => { - expect(users).toBeDefined(); - expect(users.length).toBe(2); - expect(users[0].id).toEqual(1); - expect(users[0].email).toEqual('fake-user1@fake.com'); - expect(users[0].firstName).toEqual('fakeName1'); - expect(users[0].lastName).toEqual('fakeLast1'); - }); + service.getWorkflowUsers('fake-task-id', 'fake-filter').subscribe((users: UserProcessModel[]) => { + expect(users).toBeDefined(); + expect(users.length).toBe(2); + expect(users[0].id).toEqual(1); + expect(users[0].email).toEqual('fake-user1@fake.com'); + expect(users[0].firstName).toEqual('fakeName1'); + expect(users[0].lastName).toEqual('fakeLast1'); + }); jasmine.Ajax.requests.mostRecent().respondWith({ status: 200, contentType: 'json', - responseText: {data: fakeInvolveUserList} + responseText: { data: fakeInvolveUserList } }); })); it('should be able to get people images for people retrieved', fakeAsync(() => { - service.getWorkflowUsers('fake-task-id', 'fake-filter').subscribe( - (users: UserProcessModel[]) => { - expect(users).toBeDefined(); - expect(users.length).toBe(2); - expect(service.getUserImage(users[0])).toContain('/users/' + users[0].id + '/picture'); - expect(service.getUserImage(users[1])).toContain('/users/' + users[1].id + '/picture'); - }); + service.getWorkflowUsers('fake-task-id', 'fake-filter').subscribe((users: UserProcessModel[]) => { + expect(users).toBeDefined(); + expect(users.length).toBe(2); + expect(service.getUserImage(users[0])).toContain('/users/' + users[0].id + '/picture'); + expect(service.getUserImage(users[1])).toContain('/users/' + users[1].id + '/picture'); + }); jasmine.Ajax.requests.mostRecent().respondWith({ status: 200, contentType: 'json', - responseText: {data: fakeInvolveUserList} + responseText: { data: fakeInvolveUserList } }); })); @@ -106,11 +98,10 @@ describe('PeopleProcessService', () => { }); it('should return empty list when there are no users to involve', fakeAsync(() => { - service.getWorkflowUsers('fake-task-id', 'fake-filter').subscribe( - (users: UserProcessModel[]) => { - expect(users).toBeDefined(); - expect(users.length).toBe(0); - }); + service.getWorkflowUsers('fake-task-id', 'fake-filter').subscribe((users: UserProcessModel[]) => { + expect(users).toBeDefined(); + expect(users.length).toBe(0); + }); jasmine.Ajax.requests.mostRecent().respondWith({ status: 200, @@ -120,10 +111,12 @@ describe('PeopleProcessService', () => { })); it('getWorkflowUsers catch errors call', fakeAsync(() => { - service.getWorkflowUsers('fake-task-id', 'fake-filter').subscribe(() => { - }, (error) => { - expect(error).toEqual(errorResponse); - }); + service.getWorkflowUsers('fake-task-id', 'fake-filter').subscribe( + () => {}, + (error) => { + expect(error).toEqual(errorResponse); + } + ); jasmine.Ajax.requests.mostRecent().respondWith({ status: 403 @@ -131,11 +124,10 @@ describe('PeopleProcessService', () => { })); it('should be able to involve people in the task', fakeAsync(() => { - service.involveUserWithTask('fake-task-id', 'fake-user-id').subscribe( - () => { - expect(jasmine.Ajax.requests.mostRecent().method).toBe('PUT'); - expect(jasmine.Ajax.requests.mostRecent().url).toContain('tasks/fake-task-id/action/involve'); - }); + service.involveUserWithTask('fake-task-id', 'fake-user-id').subscribe(() => { + expect(jasmine.Ajax.requests.mostRecent().method).toBe('PUT'); + expect(jasmine.Ajax.requests.mostRecent().url).toContain('tasks/fake-task-id/action/involve'); + }); jasmine.Ajax.requests.mostRecent().respondWith({ status: 200 @@ -143,10 +135,12 @@ describe('PeopleProcessService', () => { })); it('involveUserWithTask catch errors call', fakeAsync(() => { - service.involveUserWithTask('fake-task-id', 'fake-user-id').subscribe(() => { - }, (error) => { - expect(error).toEqual(errorResponse); - }); + service.involveUserWithTask('fake-task-id', 'fake-user-id').subscribe( + () => {}, + (error) => { + expect(error).toEqual(errorResponse); + } + ); jasmine.Ajax.requests.mostRecent().respondWith({ status: 403 @@ -154,11 +148,10 @@ describe('PeopleProcessService', () => { })); it('should be able to remove involved people from task', fakeAsync(() => { - service.removeInvolvedUser('fake-task-id', 'fake-user-id').subscribe( - () => { - expect(jasmine.Ajax.requests.mostRecent().method).toBe('PUT'); - expect(jasmine.Ajax.requests.mostRecent().url).toContain('tasks/fake-task-id/action/remove-involved'); - }); + service.removeInvolvedUser('fake-task-id', 'fake-user-id').subscribe(() => { + expect(jasmine.Ajax.requests.mostRecent().method).toBe('PUT'); + expect(jasmine.Ajax.requests.mostRecent().url).toContain('tasks/fake-task-id/action/remove-involved'); + }); jasmine.Ajax.requests.mostRecent().respondWith({ status: 200 @@ -166,10 +159,12 @@ describe('PeopleProcessService', () => { })); it('removeInvolvedUser catch errors call', fakeAsync(() => { - service.removeInvolvedUser('fake-task-id', 'fake-user-id').subscribe(() => { - }, (error) => { - expect(error).toEqual(errorResponse); - }); + service.removeInvolvedUser('fake-task-id', 'fake-user-id').subscribe( + () => {}, + (error) => { + expect(error).toEqual(errorResponse); + } + ); jasmine.Ajax.requests.mostRecent().respondWith({ status: 403 diff --git a/lib/process-services/src/lib/form/form.component.spec.ts b/lib/process-services/src/lib/form/form.component.spec.ts index e80cdc13569..652377159e3 100644 --- a/lib/process-services/src/lib/form/form.component.spec.ts +++ b/lib/process-services/src/lib/form/form.component.spec.ts @@ -15,35 +15,32 @@ * limitations under the License. */ -import { - SimpleChange, - ComponentFactoryResolver, - Injector, - NgModule, - Component, - ViewChild, - DebugElement -} from '@angular/core'; +import { SimpleChange, ComponentFactoryResolver, Injector, NgModule, Component, ViewChild, DebugElement } from '@angular/core'; import { By } from '@angular/platform-browser'; import { TaskRepresentation } from '@alfresco/js-api'; import { TestBed, ComponentFixture } from '@angular/core/testing'; import { Observable, of, throwError } from 'rxjs'; import { - FormFieldModel, FormFieldTypes, FormModel, FormOutcomeEvent, FormOutcomeModel, - FormService, WidgetVisibilityService, ContainerModel, fakeForm + FormFieldModel, + FormFieldTypes, + FormModel, + FormOutcomeEvent, + FormOutcomeModel, + FormService, + WidgetVisibilityService, + ContainerModel, + fakeForm } from '@alfresco/adf-core'; -import{ NodeMetadata, NodesApiService } from '@alfresco/adf-content-services'; +import { NodeMetadata, NodesApiService } from '@alfresco/adf-content-services'; import { FormComponent } from './form.component'; import { ProcessFormRenderingService } from './process-form-rendering.service'; import { ProcessTestingModule } from '../testing/process.testing.module'; -import { TranslateModule } from '@ngx-translate/core'; import { TaskFormService } from './services/task-form.service'; import { TaskService } from './services/task.service'; import { EditorService } from './services/editor.service'; import { ModelService } from './services/model.service'; describe('FormComponent', () => { - let fixture: ComponentFixture; let formComponent: FormComponent; @@ -60,7 +57,7 @@ describe('FormComponent', () => { selector: 'adf-custom-widget', template: '
' }) - // eslint-disable-next-line @angular-eslint/component-class-suffix + // eslint-disable-next-line @angular-eslint/component-class-suffix class CustomWidget { typeId = 'CustomWidget'; } @@ -69,8 +66,7 @@ describe('FormComponent', () => { declarations: [CustomWidget], exports: [CustomWidget] }) - class CustomUploadModule { - } + class CustomUploadModule {} const buildWidget = (type: string, injector: Injector): any => { const resolver = formRenderingService.getComponentTypeResolver(type); @@ -85,11 +81,7 @@ describe('FormComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - ProcessTestingModule, - CustomUploadModule - ] + imports: [ProcessTestingModule, CustomUploadModule] }); visibilityService = TestBed.inject(WidgetVisibilityService); spyOn(visibilityService, 'refreshVisibility').and.stub(); @@ -170,14 +162,14 @@ describe('FormComponent', () => { it('should enable custom outcome buttons', () => { const formModel = new FormModel(); formComponent.form = formModel; - const outcome = new FormOutcomeModel(formModel, {id: 'action1', name: 'Action 1'}); + const outcome = new FormOutcomeModel(formModel, { id: 'action1', name: 'Action 1' }); expect(formComponent.isOutcomeButtonVisible(outcome, formComponent.form.readOnly)).toBeTruthy(); }); it('should allow controlling [complete] button visibility', () => { const formModel = new FormModel(); formComponent.form = formModel; - const outcome = new FormOutcomeModel(formModel, {id: '$save', name: FormOutcomeModel.SAVE_ACTION}); + const outcome = new FormOutcomeModel(formModel, { id: '$save', name: FormOutcomeModel.SAVE_ACTION }); formComponent.showSaveButton = true; expect(formComponent.isOutcomeButtonVisible(outcome, formComponent.form.readOnly)).toBeTruthy(); @@ -190,7 +182,7 @@ describe('FormComponent', () => { const formModel = new FormModel(); formModel.readOnly = true; formComponent.form = formModel; - const outcome = new FormOutcomeModel(formModel, {id: '$complete', name: FormOutcomeModel.COMPLETE_ACTION}); + const outcome = new FormOutcomeModel(formModel, { id: '$complete', name: FormOutcomeModel.COMPLETE_ACTION }); formComponent.showCompleteButton = true; expect(formComponent.isOutcomeButtonVisible(outcome, formComponent.form.readOnly)).toBeTruthy(); @@ -200,23 +192,23 @@ describe('FormComponent', () => { const formModel = new FormModel(); formModel.readOnly = true; formComponent.form = formModel; - const outcome = new FormOutcomeModel(formModel, {id: '$save', name: FormOutcomeModel.SAVE_ACTION}); + const outcome = new FormOutcomeModel(formModel, { id: '$save', name: FormOutcomeModel.SAVE_ACTION }); formComponent.showSaveButton = true; expect(formComponent.isOutcomeButtonVisible(outcome, formComponent.form.readOnly)).toBeFalsy(); }); it('should show [custom-outcome] button with readOnly form and selected custom-outcome', () => { - const formModel = new FormModel({selectedOutcome: 'custom-outcome'}); + const formModel = new FormModel({ selectedOutcome: 'custom-outcome' }); formModel.readOnly = true; formComponent.form = formModel; - let outcome = new FormOutcomeModel(formModel, {id: '$customoutome', name: 'custom-outcome'}); + let outcome = new FormOutcomeModel(formModel, { id: '$customoutome', name: 'custom-outcome' }); formComponent.showCompleteButton = true; formComponent.showSaveButton = true; expect(formComponent.isOutcomeButtonVisible(outcome, formComponent.form.readOnly)).toBeTruthy(); - outcome = new FormOutcomeModel(formModel, {id: '$customoutome2', name: 'custom-outcome2'}); + outcome = new FormOutcomeModel(formModel, { id: '$customoutome2', name: 'custom-outcome2' }); expect(formComponent.isOutcomeButtonVisible(outcome, formComponent.form.readOnly)).toBeFalsy(); }); @@ -224,7 +216,7 @@ describe('FormComponent', () => { const formModel = new FormModel(); formModel.readOnly = false; formComponent.form = formModel; - const outcome = new FormOutcomeModel(formModel, {id: '$save', name: FormOutcomeModel.COMPLETE_ACTION}); + const outcome = new FormOutcomeModel(formModel, { id: '$save', name: FormOutcomeModel.COMPLETE_ACTION }); formComponent.showCompleteButton = true; expect(formComponent.isOutcomeButtonVisible(outcome, formComponent.form.readOnly)).toBeTruthy(); @@ -287,7 +279,7 @@ describe('FormComponent', () => { const taskId = ''; const change = new SimpleChange(null, taskId, true); - formComponent.ngOnChanges({taskId: change}); + formComponent.ngOnChanges({ taskId: change }); expect(formComponent.getFormByTaskId).toHaveBeenCalledWith(taskId); }); @@ -297,7 +289,7 @@ describe('FormComponent', () => { const formId = '123'; const change = new SimpleChange(null, formId, true); - formComponent.ngOnChanges({formId: change}); + formComponent.ngOnChanges({ formId: change }); expect(formComponent.getFormDefinitionByFormId).toHaveBeenCalledWith(formId); }); @@ -307,7 +299,7 @@ describe('FormComponent', () => { const formName = '
'; const change = new SimpleChange(null, formName, true); - formComponent.ngOnChanges({formName: change}); + formComponent.ngOnChanges({ formName: change }); expect(formComponent.getFormDefinitionByFormName).toHaveBeenCalledWith(formName); }); @@ -332,7 +324,7 @@ describe('FormComponent', () => { spyOn(formComponent, 'getFormDefinitionByFormId').and.stub(); spyOn(formComponent, 'getFormDefinitionByFormName').and.stub(); - formComponent.ngOnChanges({tag: new SimpleChange(null, 'hello world', true)}); + formComponent.ngOnChanges({ tag: new SimpleChange(null, 'hello world', true) }); expect(formComponent.getFormByTaskId).not.toHaveBeenCalled(); expect(formComponent.getFormDefinitionByFormId).not.toHaveBeenCalled(); @@ -342,11 +334,11 @@ describe('FormComponent', () => { it('should complete form on custom outcome click', () => { const formModel = new FormModel(); const outcomeName = 'Custom Action'; - const outcome = new FormOutcomeModel(formModel, {id: 'custom1', name: outcomeName}); + const outcome = new FormOutcomeModel(formModel, { id: 'custom1', name: outcomeName }); let saved = false; formComponent.form = formModel; - formComponent.formSaved.subscribe(() => saved = true); + formComponent.formSaved.subscribe(() => (saved = true)); spyOn(formComponent, 'completeTaskForm').and.stub(); const result = formComponent.onOutcomeClicked(outcome); @@ -397,7 +389,7 @@ describe('FormComponent', () => { let saved = false; formComponent.form = formModel; - formComponent.formSaved.subscribe(() => saved = true); + formComponent.formSaved.subscribe(() => (saved = true)); const result = formComponent.onOutcomeClicked(outcome); expect(result).toBeTruthy(); @@ -407,7 +399,7 @@ describe('FormComponent', () => { it('should do nothing when clicking outcome for readonly form', () => { const formModel = new FormModel(); const outcomeName = 'Custom Action'; - const outcome = new FormOutcomeModel(formModel, {id: 'custom1', name: outcomeName}); + const outcome = new FormOutcomeModel(formModel, { id: 'custom1', name: outcomeName }); formComponent.form = formModel; spyOn(formComponent, 'completeTaskForm').and.stub(); @@ -426,7 +418,7 @@ describe('FormComponent', () => { it('should require loaded form when clicking outcome', () => { const formModel = new FormModel(); const outcomeName = 'Custom Action'; - const outcome = new FormOutcomeModel(formModel, {id: 'custom1', name: outcomeName}); + const outcome = new FormOutcomeModel(formModel, { id: 'custom1', name: outcomeName }); formComponent.readOnly = false; formComponent.form = null; @@ -435,7 +427,7 @@ describe('FormComponent', () => { it('should not execute unknown system outcome', () => { const formModel = new FormModel(); - const outcome = new FormOutcomeModel(formModel, {id: 'unknown', name: 'Unknown', isSystem: true}); + const outcome = new FormOutcomeModel(formModel, { id: 'unknown', name: 'Unknown', isSystem: true }); formComponent.form = formModel; expect(formComponent.onOutcomeClicked(outcome)).toBeFalsy(); @@ -443,22 +435,25 @@ describe('FormComponent', () => { it('should require custom action name to complete form', () => { const formModel = new FormModel(); - let outcome = new FormOutcomeModel(formModel, {id: 'custom'}); + let outcome = new FormOutcomeModel(formModel, { id: 'custom' }); formComponent.form = formModel; expect(formComponent.onOutcomeClicked(outcome)).toBeFalsy(); - outcome = new FormOutcomeModel(formModel, {id: 'custom', name: 'Custom'}); + outcome = new FormOutcomeModel(formModel, { id: 'custom', name: 'Custom' }); spyOn(formComponent, 'completeTaskForm').and.stub(); expect(formComponent.onOutcomeClicked(outcome)).toBeTruthy(); }); it('should fetch and parse form by task id', (done) => { spyOn(taskService, 'getTask').and.returnValue(of({} as TaskRepresentation)); - spyOn(taskFormService, 'getTaskForm').and.callFake((currentTaskId) => new Observable((observer) => { - observer.next({taskId: currentTaskId}); - observer.complete(); - })); + spyOn(taskFormService, 'getTaskForm').and.callFake( + (currentTaskId) => + new Observable((observer) => { + observer.next({ taskId: currentTaskId }); + observer.complete(); + }) + ); const taskId = '456'; formComponent.formLoaded.subscribe(() => { @@ -487,10 +482,13 @@ describe('FormComponent', () => { it('should apply readonly state when getting form by task id', (done) => { spyOn(taskService, 'getTask').and.returnValue(of({} as TaskRepresentation)); - spyOn(taskFormService, 'getTaskForm').and.callFake((taskId) => new Observable((observer) => { - observer.next({taskId}); - observer.complete(); - })); + spyOn(taskFormService, 'getTaskForm').and.callFake( + (taskId) => + new Observable((observer) => { + observer.next({ taskId }); + observer.complete(); + }) + ); formComponent.readOnly = true; formComponent.getFormByTaskId('123').then(() => { @@ -501,14 +499,17 @@ describe('FormComponent', () => { }); it('should fetch and parse form definition by id', () => { - spyOn(editorService, 'getFormDefinitionById').and.callFake((currentFormId) => new Observable((observer) => { - observer.next({id: currentFormId}); - observer.complete(); - })); + spyOn(editorService, 'getFormDefinitionById').and.callFake( + (currentFormId) => + new Observable((observer) => { + observer.next({ id: currentFormId }); + observer.complete(); + }) + ); const formId = 456; let loaded = false; - formComponent.formLoaded.subscribe(() => loaded = true); + formComponent.formLoaded.subscribe(() => (loaded = true)); expect(formComponent.form).toBeUndefined(); formComponent.getFormDefinitionByFormId(formId); @@ -529,19 +530,25 @@ describe('FormComponent', () => { }); it('should fetch and parse form definition by form name', () => { - spyOn(modelService, 'getFormDefinitionByName').and.callFake((currentFormName) => new Observable((observer) => { - observer.next(currentFormName); - observer.complete(); - })); + spyOn(modelService, 'getFormDefinitionByName').and.callFake( + (currentFormName) => + new Observable((observer) => { + observer.next(currentFormName); + observer.complete(); + }) + ); - spyOn(editorService, 'getFormDefinitionById').and.callFake((currentFormName) => new Observable((observer) => { - observer.next({name: currentFormName}); - observer.complete(); - })); + spyOn(editorService, 'getFormDefinitionById').and.callFake( + (currentFormName) => + new Observable((observer) => { + observer.next({ name: currentFormName }); + observer.complete(); + }) + ); const formName = ''; let loaded = false; - formComponent.formLoaded.subscribe(() => loaded = true); + formComponent.formLoaded.subscribe(() => (loaded = true)); expect(formComponent.form).toBeUndefined(); formComponent.getFormDefinitionByFormName(formName); @@ -553,10 +560,13 @@ describe('FormComponent', () => { }); it('should save task form and raise corresponding event', () => { - spyOn(taskFormService, 'saveTaskForm').and.callFake(() => new Observable((observer) => { - observer.next(); - observer.complete(); - })); + spyOn(taskFormService, 'saveTaskForm').and.callFake( + () => + new Observable((observer) => { + observer.next(); + observer.complete(); + }) + ); let saved = false; let savedForm = null; @@ -567,10 +577,7 @@ describe('FormComponent', () => { const formModel = new FormModel({ taskId: '123', - fields: [ - {id: 'field1'}, - {id: 'field2'} - ] + fields: [{ id: 'field1' }, { id: 'field2' }] }); formComponent.form = formModel; formComponent.saveTaskForm(); @@ -585,7 +592,7 @@ describe('FormComponent', () => { spyOn(taskFormService, 'saveTaskForm').and.callFake(() => throwError(error)); spyOn(formComponent, 'handleError').and.stub(); - formComponent.form = new FormModel({taskId: '123'}); + formComponent.form = new FormModel({ taskId: '123' }); formComponent.saveTaskForm(); expect(formComponent.handleError).toHaveBeenCalledWith(error); @@ -616,21 +623,21 @@ describe('FormComponent', () => { }); it('should complete form and raise corresponding event', () => { - spyOn(taskFormService, 'completeTaskForm').and.callFake(() => new Observable((observer) => { - observer.next(); - observer.complete(); - })); + spyOn(taskFormService, 'completeTaskForm').and.callFake( + () => + new Observable((observer) => { + observer.next(); + observer.complete(); + }) + ); const outcome = 'complete'; let completed = false; - formComponent.formCompleted.subscribe(() => completed = true); + formComponent.formCompleted.subscribe(() => (completed = true)); const formModel = new FormModel({ taskId: '123', - fields: [ - {id: 'field1'}, - {id: 'field2'} - ] + fields: [{ id: 'field1' }, { id: 'field2' }] }); formComponent.form = formModel; @@ -647,9 +654,7 @@ describe('FormComponent', () => { it('should parse form from json', () => { const form = formComponent.parseForm({ id: 1, - fields: [ - {id: 'field1', type: FormFieldTypes.CONTAINER} - ] + fields: [{ id: 'field1', type: FormFieldTypes.CONTAINER }] }); expect(form).toBeDefined(); @@ -661,12 +666,11 @@ describe('FormComponent', () => { it('should provide outcomes for form definition', () => { spyOn(formComponent, 'getFormDefinitionOutcomes').and.callThrough(); - const form = formComponent.parseForm({id: 1}); + const form = formComponent.parseForm({ id: 1 }); expect(formComponent.getFormDefinitionOutcomes).toHaveBeenCalledWith(form); }); it('should prevent default outcome execution', () => { - const outcome = new FormOutcomeModel(new FormModel(), { id: FormComponent.CUSTOM_OUTCOME_ID, name: 'Custom' @@ -704,7 +708,6 @@ describe('FormComponent', () => { }); it('should check visibility only if field with form provided', () => { - formComponent.checkVisibility(null); expect(visibilityService.refreshVisibility).not.toHaveBeenCalled(); @@ -719,14 +722,12 @@ describe('FormComponent', () => { it('should load form for ecm node', () => { const metadata = {}; - spyOn(nodeService, 'getNodeMetadata').and.returnValue( - of(new NodeMetadata(metadata, null)) - ); + spyOn(nodeService, 'getNodeMetadata').and.returnValue(of(new NodeMetadata(metadata, null))); spyOn(formComponent, 'loadFormFromActiviti').and.stub(); const nodeId = ''; const change = new SimpleChange(null, nodeId, false); - formComponent.ngOnChanges({nodeId: change}); + formComponent.ngOnChanges({ nodeId: change }); expect(nodeService.getNodeMetadata).toHaveBeenCalledWith(nodeId); expect(formComponent.loadFormFromActiviti).toHaveBeenCalled(); @@ -946,10 +947,10 @@ describe('FormComponent', () => { id: 'option_2', name: 'test2' }; - formValues.radio = {id: 'option_2', name: 'Option 2'}; + formValues.radio = { id: 'option_2', name: 'Option 2' }; const change = new SimpleChange(null, formValues, false); formComponent.data = formValues; - formComponent.ngOnChanges({data: change}); + formComponent.ngOnChanges({ data: change }); formFields = formComponent.form.getFormFields(); dropdownField = formFields.find((field) => field.id === 'dropdownId'); @@ -969,7 +970,7 @@ describe('FormComponent', () => { formValues.radio = 'option_3'; const change = new SimpleChange(null, formValues, false); formComponent.data = formValues; - formComponent.ngOnChanges({data: change}); + formComponent.ngOnChanges({ data: change }); formFields = formComponent.form.getFormFields(); radioFieldById = formFields.find((field) => field.id === 'radio'); @@ -979,55 +980,38 @@ describe('FormComponent', () => { @Component({ selector: 'adf-form-with-custom-outcomes', - template: ` - - - - - - ` + template: ` + + + + + ` }) - class FormWithCustomOutComesComponent { - - @ViewChild('adfForm', {static: true}) + @ViewChild('adfForm', { static: true }) adfForm: FormComponent; - onCustomButtonOneClick() { - } + onCustomButtonOneClick() {} - onCustomButtonTwoClick() { - } + onCustomButtonTwoClick() {} } describe('FormWithCustomOutComesComponent', () => { - let fixture: ComponentFixture; let customComponent: FormWithCustomOutComesComponent; let debugElement: DebugElement; beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - ProcessTestingModule - ], + imports: [ProcessTestingModule], declarations: [FormWithCustomOutComesComponent] }); fixture = TestBed.createComponent(FormWithCustomOutComesComponent); customComponent = fixture.componentInstance; debugElement = fixture.debugElement; const formRepresentation = { - fields: [ - {id: 'container1'} - ], - outcomes: [ - {id: 'outcome-1', name: 'outcome 1'} - ] + fields: [{ id: 'container1' }], + outcomes: [{ id: 'outcome-1', name: 'outcome 1' }] }; const form = new FormModel(formRepresentation); diff --git a/lib/process-services/src/lib/form/form.component.visibility.spec.ts b/lib/process-services/src/lib/form/form.component.visibility.spec.ts index 365586cd412..44ffd78093e 100644 --- a/lib/process-services/src/lib/form/form.component.visibility.spec.ts +++ b/lib/process-services/src/lib/form/form.component.visibility.spec.ts @@ -31,7 +31,6 @@ import { } from '@alfresco/adf-core'; import { FormComponent } from './form.component'; import { ProcessTestingModule } from '../testing/process.testing.module'; -import { TranslateModule } from '@ngx-translate/core'; import { TaskService } from './services/task.service'; import { TaskFormService } from './services/task-form.service'; import { TaskRepresentation } from '@alfresco/js-api'; @@ -48,7 +47,7 @@ describe('FormComponent UI and visibility', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [TranslateModule.forRoot(), ProcessTestingModule], + imports: [ProcessTestingModule], schemas: [CUSTOM_ELEMENTS_SCHEMA] }); fixture = TestBed.createComponent(FormComponent); diff --git a/lib/process-services/src/lib/form/services/activiti-alfresco.service.ts b/lib/process-services/src/lib/form/services/activiti-alfresco.service.ts index 07677c043ff..a7c3c3aec84 100644 --- a/lib/process-services/src/lib/form/services/activiti-alfresco.service.ts +++ b/lib/process-services/src/lib/form/services/activiti-alfresco.service.ts @@ -15,10 +15,17 @@ * limitations under the License. */ -import { AlfrescoApiService, LogService, ExternalContent } from '@alfresco/adf-core'; +import { AlfrescoApiService, ExternalContent } from '@alfresco/adf-core'; import { SitesService } from '@alfresco/adf-content-services'; import { Injectable } from '@angular/core'; -import { IntegrationAlfrescoOnPremiseApi, Node, RelatedContentRepresentation, ActivitiContentApi, AlfrescoEndpointRepresentation, AlfrescoContentRepresentation } from '@alfresco/js-api'; +import { + IntegrationAlfrescoOnPremiseApi, + Node, + RelatedContentRepresentation, + ActivitiContentApi, + AlfrescoEndpointRepresentation, + AlfrescoContentRepresentation +} from '@alfresco/js-api'; import { Observable, from, throwError } from 'rxjs'; import { map, catchError } from 'rxjs/operators'; @@ -42,7 +49,7 @@ export class ActivitiContentService { return this._contentApi; } - constructor(private apiService: AlfrescoApiService, private logService: LogService, private sitesService: SitesService) {} + constructor(private apiService: AlfrescoApiService, private sitesService: SitesService) {} /** * Returns a list of child nodes below the specified folder @@ -54,7 +61,7 @@ export class ActivitiContentService { getAlfrescoNodes(accountId: string, folderId: string): Observable { const accountShortId = accountId.replace('alfresco-', ''); return from(this.integrationAlfrescoOnPremiseApi.getContentInFolder(accountShortId, folderId)).pipe( - map(res => res?.data || []), + map((res) => res?.data || []), catchError((err) => this.handleError(err)) ); } @@ -72,7 +79,7 @@ export class ActivitiContentService { includeAccounts: includeAccount ? includeAccount : true }; return from(this.integrationAlfrescoOnPremiseApi.getRepositories(opts)).pipe( - map(res => res?.data || []), + map((res) => res?.data || []), catchError((err) => this.handleError(err)) ); } @@ -95,7 +102,7 @@ export class ActivitiContentService { sourceId: node.id + '@' + siteId }) ).pipe( - map(res => res || {}), + map((res) => res || {}), catchError((err) => this.handleError(err)) ); } @@ -110,7 +117,7 @@ export class ActivitiContentService { link: node.isLink }; return from(this.contentApi.createTemporaryRelatedContent(params)).pipe( - map(res => res || {}), + map((res) => res || {}), catchError((err) => this.handleError(err)) ); } @@ -124,7 +131,6 @@ export class ActivitiContentService { ? `${error.status} - ${error.statusText}` : ActivitiContentService.GENERIC_ERROR_MESSAGE; } - this.logService.error(errMsg); return throwError(errMsg); } } diff --git a/lib/process-services/src/lib/form/services/ecm-model.service.spec.ts b/lib/process-services/src/lib/form/services/ecm-model.service.spec.ts index 7829b1c3827..51a560f40ca 100644 --- a/lib/process-services/src/lib/form/services/ecm-model.service.spec.ts +++ b/lib/process-services/src/lib/form/services/ecm-model.service.spec.ts @@ -19,7 +19,6 @@ import { Observable } from 'rxjs'; import { FormModel, CoreTestingModule } from '@alfresco/adf-core'; import { EcmModelService } from './ecm-model.service'; import { TestBed } from '@angular/core/testing'; -import { TranslateModule } from '@ngx-translate/core'; declare let jasmine: any; @@ -28,10 +27,7 @@ describe('EcmModelService', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - CoreTestingModule - ] + imports: [CoreTestingModule] }); service = TestBed.inject(EcmModelService); jasmine.Ajax.install(); @@ -55,7 +51,6 @@ describe('EcmModelService', () => { }); it('Should fetch ECM types', (done) => { - const modelName = 'modelTest'; service.getEcmType(modelName).subscribe(() => { @@ -71,7 +66,6 @@ describe('EcmModelService', () => { }); it('Should create ECM types', (done) => { - const typeName = 'typeTest'; service.createEcmType(typeName, EcmModelService.MODEL_NAME, EcmModelService.TYPE_MODEL).subscribe(() => { @@ -90,7 +84,6 @@ describe('EcmModelService', () => { }); it('Should create ECM types with a clean and preserve real name in the title', (done) => { - const typeName = 'typeTest:testName@#$*!'; const cleanName = 'testName'; @@ -110,7 +103,6 @@ describe('EcmModelService', () => { }); it('Should add property to a type', (done) => { - const typeName = 'typeTest'; const formFields = { values: { @@ -120,24 +112,29 @@ describe('EcmModelService', () => { }; service.addPropertyToAType(EcmModelService.MODEL_NAME, typeName, formFields).subscribe(() => { - expect(jasmine.Ajax.requests.mostRecent().url.endsWith('1/cmm/' + EcmModelService.MODEL_NAME + '/types/' + typeName + '?select=props')).toBeTruthy(); - expect(JSON.parse(jasmine.Ajax.requests.mostRecent().params).properties).toEqual([{ - name: 'test', - title: 'test', - description: 'test', - dataType: 'd:text', - multiValued: false, - mandatory: false, - mandatoryEnforced: false - }, { - name: 'test2', - title: 'test2', - description: 'test2', - dataType: 'd:text', - multiValued: false, - mandatory: false, - mandatoryEnforced: false - }]); + expect( + jasmine.Ajax.requests.mostRecent().url.endsWith('1/cmm/' + EcmModelService.MODEL_NAME + '/types/' + typeName + '?select=props') + ).toBeTruthy(); + expect(JSON.parse(jasmine.Ajax.requests.mostRecent().params).properties).toEqual([ + { + name: 'test', + title: 'test', + description: 'test', + dataType: 'd:text', + multiValued: false, + mandatory: false, + mandatoryEnforced: false + }, + { + name: 'test2', + title: 'test2', + description: 'test2', + dataType: 'd:text', + multiValued: false, + mandatory: false, + mandatoryEnforced: false + } + ]); done(); }); @@ -149,7 +146,6 @@ describe('EcmModelService', () => { }); it('Should add property to a type and clean name type', (done) => { - const typeName = 'typeTest:testName@#$*!'; const cleanName = 'testName'; const formFields = { @@ -160,24 +156,29 @@ describe('EcmModelService', () => { }; service.addPropertyToAType(EcmModelService.MODEL_NAME, typeName, formFields).subscribe(() => { - expect(jasmine.Ajax.requests.mostRecent().url.endsWith('1/cmm/' + EcmModelService.MODEL_NAME + '/types/' + cleanName + '?select=props')).toBeTruthy(); - expect(JSON.parse(jasmine.Ajax.requests.mostRecent().params).properties).toEqual([{ - name: 'test', - title: 'test', - description: 'test', - dataType: 'd:text', - multiValued: false, - mandatory: false, - mandatoryEnforced: false - }, { - name: 'test2', - title: 'test2', - description: 'test2', - dataType: 'd:text', - multiValued: false, - mandatory: false, - mandatoryEnforced: false - }]); + expect( + jasmine.Ajax.requests.mostRecent().url.endsWith('1/cmm/' + EcmModelService.MODEL_NAME + '/types/' + cleanName + '?select=props') + ).toBeTruthy(); + expect(JSON.parse(jasmine.Ajax.requests.mostRecent().params).properties).toEqual([ + { + name: 'test', + title: 'test', + description: 'test', + dataType: 'd:text', + multiValued: false, + mandatory: false, + mandatoryEnforced: false + }, + { + name: 'test2', + title: 'test2', + description: 'test2', + dataType: 'd:text', + multiValued: false, + mandatory: false, + mandatoryEnforced: false + } + ]); done(); }); @@ -189,7 +190,6 @@ describe('EcmModelService', () => { }); it('Should create ECM model', (done) => { - service.createEcmModel(EcmModelService.MODEL_NAME, EcmModelService.MODEL_NAMESPACE).subscribe(() => { expect(jasmine.Ajax.requests.mostRecent().url.endsWith('alfresco/versions/1/cmm')).toBeTruthy(); expect(JSON.parse(jasmine.Ajax.requests.mostRecent().params).status).toEqual('DRAFT'); @@ -204,9 +204,10 @@ describe('EcmModelService', () => { }); it('Should activate ECM model', (done) => { - service.activeEcmModel(EcmModelService.MODEL_NAME).subscribe(() => { - expect(jasmine.Ajax.requests.mostRecent().url.endsWith('alfresco/versions/1/cmm/' + EcmModelService.MODEL_NAME + '?select=status')).toBeTruthy(); + expect( + jasmine.Ajax.requests.mostRecent().url.endsWith('alfresco/versions/1/cmm/' + EcmModelService.MODEL_NAME + '?select=status') + ).toBeTruthy(); expect(JSON.parse(jasmine.Ajax.requests.mostRecent().params).status).toEqual('ACTIVE'); done(); }); @@ -219,15 +220,21 @@ describe('EcmModelService', () => { }); it('Should create an ECM type with properties', (done) => { - spyOn(service, 'createEcmType').and.callFake(() => new Observable((observer) => { - observer.next(); - observer.complete(); - })); - - spyOn(service, 'addPropertyToAType').and.callFake(() => new Observable((observer) => { - observer.next(); - observer.complete(); - })); + spyOn(service, 'createEcmType').and.callFake( + () => + new Observable((observer) => { + observer.next(); + observer.complete(); + }) + ); + + spyOn(service, 'addPropertyToAType').and.callFake( + () => + new Observable((observer) => { + observer.next(); + observer.complete(); + }) + ); service.createEcmTypeWithProperties('nameType', new FormModel()).subscribe(() => { expect(service.createEcmType).toHaveBeenCalled(); @@ -237,15 +244,21 @@ describe('EcmModelService', () => { }); it('Should return the already existing type', (done) => { - spyOn(service, 'searchEcmType').and.callFake(() => new Observable((observer) => { - observer.next({test: 'I-EXIST'}); - observer.complete(); - })); - - spyOn(service, 'createEcmTypeWithProperties').and.callFake(() => new Observable((observer) => { - observer.next(); - observer.complete(); - })); + spyOn(service, 'searchEcmType').and.callFake( + () => + new Observable((observer) => { + observer.next({ test: 'I-EXIST' }); + observer.complete(); + }) + ); + + spyOn(service, 'createEcmTypeWithProperties').and.callFake( + () => + new Observable((observer) => { + observer.next(); + observer.complete(); + }) + ); service.saveFomType('nameType', new FormModel()).subscribe(() => { expect(service.searchEcmType).toHaveBeenCalled(); @@ -255,15 +268,21 @@ describe('EcmModelService', () => { }); it('Should create an ECM type with properties if the ecm Type is not defined already', (done) => { - spyOn(service, 'searchEcmType').and.callFake(() => new Observable((observer) => { - observer.next(); - observer.complete(); - })); - - spyOn(service, 'createEcmTypeWithProperties').and.callFake(() => new Observable((observer) => { - observer.next(); - observer.complete(); - })); + spyOn(service, 'searchEcmType').and.callFake( + () => + new Observable((observer) => { + observer.next(); + observer.complete(); + }) + ); + + spyOn(service, 'createEcmTypeWithProperties').and.callFake( + () => + new Observable((observer) => { + observer.next(); + observer.complete(); + }) + ); service.saveFomType('nameType', new FormModel()).subscribe(() => { expect(service.searchEcmType).toHaveBeenCalled(); @@ -273,15 +292,21 @@ describe('EcmModelService', () => { }); it('Should create an ECM model for the activiti if not defined already', (done) => { - spyOn(service, 'searchActivitiEcmModel').and.callFake(() => new Observable((observer) => { - observer.next(); - observer.complete(); - })); - - spyOn(service, 'createActivitiEcmModel').and.callFake(() => new Observable((observer) => { - observer.next(); - observer.complete(); - })); + spyOn(service, 'searchActivitiEcmModel').and.callFake( + () => + new Observable((observer) => { + observer.next(); + observer.complete(); + }) + ); + + spyOn(service, 'createActivitiEcmModel').and.callFake( + () => + new Observable((observer) => { + observer.next(); + observer.complete(); + }) + ); service.createEcmTypeForActivitiForm('nameType', new FormModel()).subscribe(() => { expect(service.searchActivitiEcmModel).toHaveBeenCalled(); @@ -291,15 +316,21 @@ describe('EcmModelService', () => { }); it('If a model for the activiti is already define has to save the new type', (done) => { - spyOn(service, 'searchActivitiEcmModel').and.callFake(() => new Observable((observer) => { - observer.next({test: 'I-EXIST'}); - observer.complete(); - })); - - spyOn(service, 'saveFomType').and.callFake(() => new Observable((observer) => { - observer.next(); - observer.complete(); - })); + spyOn(service, 'searchActivitiEcmModel').and.callFake( + () => + new Observable((observer) => { + observer.next({ test: 'I-EXIST' }); + observer.complete(); + }) + ); + + spyOn(service, 'saveFomType').and.callFake( + () => + new Observable((observer) => { + observer.next(); + observer.complete(); + }) + ); service.createEcmTypeForActivitiForm('nameType', new FormModel()).subscribe(() => { expect(service.searchActivitiEcmModel).toHaveBeenCalled(); diff --git a/lib/process-services/src/lib/form/services/ecm-model.service.ts b/lib/process-services/src/lib/form/services/ecm-model.service.ts index e21e3a4e50d..94996076d6c 100644 --- a/lib/process-services/src/lib/form/services/ecm-model.service.ts +++ b/lib/process-services/src/lib/form/services/ecm-model.service.ts @@ -15,8 +15,8 @@ * limitations under the License. */ -import { AlfrescoApiService, LogService, FormModel } from '@alfresco/adf-core'; -import { Injectable } from '@angular/core'; +import { AlfrescoApiService, FormModel } from '@alfresco/adf-core'; +import { EventEmitter, Injectable } from '@angular/core'; import { Observable, from } from 'rxjs'; import { map, catchError } from 'rxjs/operators'; import { CustomModelApi } from '@alfresco/js-api'; @@ -29,13 +29,15 @@ export class EcmModelService { public static MODEL_NAME: string = 'activitiFormsModel'; public static TYPE_MODEL: string = 'cm:folder'; + error = new EventEmitter(); + private _customModelApi: CustomModelApi; get customModelApi(): CustomModelApi { this._customModelApi = this._customModelApi ?? new CustomModelApi(this.apiService.getInstance()); return this._customModelApi; } - constructor(private apiService: AlfrescoApiService, private logService: LogService) {} + constructor(private apiService: AlfrescoApiService) {} public createEcmTypeForActivitiForm(formName: string, form: FormModel): Observable { return new Observable((observer) => { @@ -67,11 +69,9 @@ export class EcmModelService { createActivitiEcmModel(formName: string, form: FormModel): Observable { return new Observable((observer) => { this.createEcmModel(EcmModelService.MODEL_NAME, EcmModelService.MODEL_NAMESPACE).subscribe( - (model) => { - this.logService.info('model created', model); + () => { this.activeEcmModel(EcmModelService.MODEL_NAME).subscribe( - (modelActive) => { - this.logService.info('model active', modelActive); + () => { this.createEcmTypeWithProperties(formName, form).subscribe((typeCreated) => { observer.next(typeCreated); observer.complete(); @@ -89,7 +89,6 @@ export class EcmModelService { return new Observable((observer) => { this.searchEcmType(formName, EcmModelService.MODEL_NAME).subscribe( (ecmType) => { - this.logService.info('custom types', ecmType); if (!ecmType) { this.createEcmTypeWithProperties(formName, form).subscribe((typeCreated) => { observer.next(typeCreated); @@ -109,10 +108,8 @@ export class EcmModelService { return new Observable((observer) => { this.createEcmType(formName, EcmModelService.MODEL_NAME, EcmModelService.TYPE_MODEL).subscribe( (typeCreated) => { - this.logService.info('type Created', typeCreated); this.addPropertyToAType(EcmModelService.MODEL_NAME, formName, form).subscribe( - (propertyAdded) => { - this.logService.info('property Added', propertyAdded); + () => { observer.next(typeCreated); observer.complete(); }, @@ -206,6 +203,6 @@ export class EcmModelService { } private handleError(err: any): any { - this.logService.error(err); + this.error.next(err); } } diff --git a/lib/process-services/src/lib/form/services/editor.service.ts b/lib/process-services/src/lib/form/services/editor.service.ts index c89e4cbae6d..460cd70df99 100644 --- a/lib/process-services/src/lib/form/services/editor.service.ts +++ b/lib/process-services/src/lib/form/services/editor.service.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { AlfrescoApiService, LogService } from '@alfresco/adf-core'; +import { AlfrescoApiService } from '@alfresco/adf-core'; import { Injectable } from '@angular/core'; import { Observable, from, throwError } from 'rxjs'; import { FormModelsApi } from '@alfresco/js-api'; @@ -26,7 +26,6 @@ import { FormDefinitionModel } from '../model/form-definition.model'; providedIn: 'root' }) export class EditorService { - static UNKNOWN_ERROR_MESSAGE: string = 'Unknown error'; static GENERIC_ERROR_MESSAGE: string = 'Server error'; @@ -36,8 +35,7 @@ export class EditorService { return this._editorApi; } - constructor(private apiService: AlfrescoApiService, private logService: LogService) { - } + constructor(private apiService: AlfrescoApiService) {} /** * Saves a form. @@ -47,9 +45,7 @@ export class EditorService { * @returns Data for the saved form */ saveForm(formId: number, formModel: FormDefinitionModel): Observable { - return from( - this.editorApi.saveForm(formId, formModel) - ); + return from(this.editorApi.saveForm(formId, formModel)); } /** @@ -59,11 +55,10 @@ export class EditorService { * @returns Form definition */ getFormDefinitionById(formId: number): Observable { - return from(this.editorApi.getForm(formId)) - .pipe( - map(this.toJson), - catchError((err) => this.handleError(err)) - ); + return from(this.editorApi.getForm(formId)).pipe( + map(this.toJson), + catchError((err) => this.handleError(err)) + ); } /** @@ -88,11 +83,8 @@ export class EditorService { private handleError(error: any): Observable { let errMsg = EditorService.UNKNOWN_ERROR_MESSAGE; if (error) { - errMsg = (error.message) ? error.message : - error.status ? `${error.status} - ${error.statusText}` : EditorService.GENERIC_ERROR_MESSAGE; + errMsg = error.message ? error.message : error.status ? `${error.status} - ${error.statusText}` : EditorService.GENERIC_ERROR_MESSAGE; } - this.logService.error(errMsg); return throwError(errMsg); } - } diff --git a/lib/process-services/src/lib/form/services/model.service.ts b/lib/process-services/src/lib/form/services/model.service.ts index be1273d187b..2310fefa901 100644 --- a/lib/process-services/src/lib/form/services/model.service.ts +++ b/lib/process-services/src/lib/form/services/model.service.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { AlfrescoApiService, LogService } from '@alfresco/adf-core'; +import { AlfrescoApiService } from '@alfresco/adf-core'; import { Injectable } from '@angular/core'; import { Observable, from, throwError } from 'rxjs'; import { ModelsApi } from '@alfresco/js-api'; @@ -34,7 +34,7 @@ export class ModelService { return this._modelsApi; } - constructor(private apiService: AlfrescoApiService, private logService: LogService) {} + constructor(private apiService: AlfrescoApiService) {} /** * Create a Form. @@ -141,7 +141,6 @@ export class ModelService { if (error) { errMsg = error.message ? error.message : error.status ? `${error.status} - ${error.statusText}` : ModelService.GENERIC_ERROR_MESSAGE; } - this.logService.error(errMsg); return throwError(errMsg); } } diff --git a/lib/process-services/src/lib/form/services/process-content.service.spec.ts b/lib/process-services/src/lib/form/services/process-content.service.spec.ts index ab31bf4e4d6..0d9d30dd77d 100644 --- a/lib/process-services/src/lib/form/services/process-content.service.spec.ts +++ b/lib/process-services/src/lib/form/services/process-content.service.spec.ts @@ -18,7 +18,6 @@ import { TestBed } from '@angular/core/testing'; import { of } from 'rxjs'; import { ProcessContentService } from './process-content.service'; -import { TranslateModule } from '@ngx-translate/core'; import { CoreTestingModule } from '@alfresco/adf-core'; declare let jasmine: any; @@ -67,10 +66,7 @@ describe('ProcessContentService', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - CoreTestingModule - ] + imports: [CoreTestingModule] }); service = TestBed.inject(ProcessContentService); }); @@ -108,7 +104,7 @@ describe('ProcessContentService', () => { id: 8, name: 'fake.zip', created: 1494595697381, - createdBy: {id: 2, firstName: 'user', lastName: 'user', email: 'user@user.com'}, + createdBy: { id: 2, firstName: 'user', lastName: 'user', email: 'user@user.com' }, relatedContent: true, contentAvailable: true, link: false, @@ -121,7 +117,7 @@ describe('ProcessContentService', () => { id: 9, name: 'fake.jpg', created: 1494595655381, - createdBy: {id: 2, firstName: 'user', lastName: 'user', email: 'user@user.com'}, + createdBy: { id: 2, firstName: 'user', lastName: 'user', email: 'user@user.com' }, relatedContent: true, contentAvailable: true, link: false, diff --git a/lib/process-services/src/lib/form/services/process-definition.service.ts b/lib/process-services/src/lib/form/services/process-definition.service.ts index a388f730cfe..1b00e1d5293 100644 --- a/lib/process-services/src/lib/form/services/process-definition.service.ts +++ b/lib/process-services/src/lib/form/services/process-definition.service.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { AlfrescoApiService, FormFieldOption, LogService } from '@alfresco/adf-core'; +import { AlfrescoApiService, FormFieldOption } from '@alfresco/adf-core'; import { Injectable } from '@angular/core'; import { Observable, from, throwError } from 'rxjs'; import { ProcessDefinitionsApi } from '@alfresco/js-api'; @@ -35,7 +35,7 @@ export class ProcessDefinitionService { return this._processDefinitionsApi; } - constructor(private apiService: AlfrescoApiService, private logService: LogService) {} + constructor(private apiService: AlfrescoApiService) {} /** * Gets values of fields populated by a REST backend using a process ID. @@ -90,7 +90,6 @@ export class ProcessDefinitionService { ? `${error.status} - ${error.statusText}` : ProcessDefinitionService.GENERIC_ERROR_MESSAGE; } - this.logService.error(errMsg); return throwError(errMsg); } } diff --git a/lib/process-services/src/lib/form/services/task-form.service.ts b/lib/process-services/src/lib/form/services/task-form.service.ts index 9b5a50fe27c..d0114324be1 100644 --- a/lib/process-services/src/lib/form/services/task-form.service.ts +++ b/lib/process-services/src/lib/form/services/task-form.service.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { AlfrescoApiService, FormFieldOption, FormValues, LogService, TaskProcessVariableModel } from '@alfresco/adf-core'; +import { AlfrescoApiService, FormFieldOption, FormValues, TaskProcessVariableModel } from '@alfresco/adf-core'; import { Injectable } from '@angular/core'; import { from, Observable, throwError } from 'rxjs'; import { CompleteFormRepresentation, SaveFormRepresentation, TaskFormsApi } from '@alfresco/js-api'; @@ -35,7 +35,7 @@ export class TaskFormService { return this._taskFormsApi; } - constructor(private apiService: AlfrescoApiService, private logService: LogService) {} + constructor(private apiService: AlfrescoApiService) {} /** * Saves a task form. @@ -134,7 +134,6 @@ export class TaskFormService { if (error) { errMsg = error.message ? error.message : error.status ? `${error.status} - ${error.statusText}` : TaskFormService.GENERIC_ERROR_MESSAGE; } - this.logService.error(errMsg); return throwError(errMsg); } } diff --git a/lib/process-services/src/lib/form/services/task.service.ts b/lib/process-services/src/lib/form/services/task.service.ts index abf4ef77329..c9bda8e6d3e 100644 --- a/lib/process-services/src/lib/form/services/task.service.ts +++ b/lib/process-services/src/lib/form/services/task.service.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { AlfrescoApiService, LogService } from '@alfresco/adf-core'; +import { AlfrescoApiService } from '@alfresco/adf-core'; import { Injectable } from '@angular/core'; import { Observable, from, throwError } from 'rxjs'; import { TaskRepresentation, TasksApi } from '@alfresco/js-api'; @@ -25,7 +25,6 @@ import { catchError, map } from 'rxjs/operators'; providedIn: 'root' }) export class TaskService { - static UNKNOWN_ERROR_MESSAGE: string = 'Unknown error'; static GENERIC_ERROR_MESSAGE: string = 'Server error'; @@ -35,9 +34,7 @@ export class TaskService { return this._taskApi; } - constructor(private apiService: AlfrescoApiService, private logService: LogService) { - } - + constructor(private apiService: AlfrescoApiService) {} /** * Gets a task. @@ -46,11 +43,10 @@ export class TaskService { * @returns Task info */ getTask(taskId: string): Observable { - return from(this.taskApi.getTask(taskId)) - .pipe( - map(this.toJson), - catchError((err) => this.handleError(err)) - ); + return from(this.taskApi.getTask(taskId)).pipe( + map(this.toJson), + catchError((err) => this.handleError(err)) + ); } /** @@ -75,11 +71,8 @@ export class TaskService { private handleError(error: any): Observable { let errMsg = TaskService.UNKNOWN_ERROR_MESSAGE; if (error) { - errMsg = (error.message) ? error.message : - error.status ? `${error.status} - ${error.statusText}` : TaskService.GENERIC_ERROR_MESSAGE; + errMsg = error.message ? error.message : error.status ? `${error.status} - ${error.statusText}` : TaskService.GENERIC_ERROR_MESSAGE; } - this.logService.error(errMsg); return throwError(errMsg); } - } diff --git a/lib/process-services/src/lib/form/start-form.component.spec.ts b/lib/process-services/src/lib/form/start-form.component.spec.ts index 21f89da4e00..43779f07659 100644 --- a/lib/process-services/src/lib/form/start-form.component.spec.ts +++ b/lib/process-services/src/lib/form/start-form.component.spec.ts @@ -19,14 +19,22 @@ import { CUSTOM_ELEMENTS_SCHEMA, SimpleChange } from '@angular/core'; import { ComponentFixture, TestBed } from '@angular/core/testing'; import { of } from 'rxjs'; import { - startFormDateWidgetMock, startFormDropdownDefinitionMock, - startFormTextDefinitionMock, startMockForm, startMockFormWithTab, - startFormAmountWidgetMock, startFormNumberWidgetMock, startFormRadioButtonWidgetMock, - taskFormSingleUploadMock, taskFormMultipleUploadMock, preselectedSingleNode, preselectedMultipleNodes + startFormDateWidgetMock, + startFormDropdownDefinitionMock, + startFormTextDefinitionMock, + startMockForm, + startMockFormWithTab, + startFormAmountWidgetMock, + startFormNumberWidgetMock, + startFormRadioButtonWidgetMock, + taskFormSingleUploadMock, + taskFormMultipleUploadMock, + preselectedSingleNode, + preselectedMultipleNodes } from './start-form.component.mock'; import { StartFormComponent } from './start-form.component'; import { WidgetVisibilityService, FormModel, FormOutcomeModel } from '@alfresco/adf-core'; -import { TranslateService, TranslateModule } from '@ngx-translate/core'; +import { TranslateService } from '@ngx-translate/core'; import { ProcessTestingModule } from '../testing/process.testing.module'; import { ProcessService } from '../process-list/services/process.service'; import { HarnessLoader } from '@angular/cdk/testing'; @@ -36,7 +44,6 @@ import { MatCardHarness } from '@angular/material/card/testing'; import { MatButtonHarness } from '@angular/material/button/testing'; describe('StartFormComponent', () => { - let component: StartFormComponent; let fixture: ComponentFixture; let getStartFormSpy: jasmine.Spy; @@ -50,10 +57,7 @@ describe('StartFormComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - ProcessTestingModule - ], + imports: [ProcessTestingModule], schemas: [CUSTOM_ELEMENTS_SCHEMA] }); fixture = TestBed.createComponent(StartFormComponent); @@ -63,9 +67,11 @@ describe('StartFormComponent', () => { visibilityService = TestBed.inject(WidgetVisibilityService); translate = TestBed.inject(TranslateService); - getStartFormSpy = spyOn(processService, 'getStartFormDefinition').and.returnValue(of({ - processDefinitionName: 'my:process' - })); + getStartFormSpy = spyOn(processService, 'getStartFormDefinition').and.returnValue( + of({ + processDefinitionName: 'my:process' + }) + ); spyOn(translate, 'instant').and.callFake((key) => key); spyOn(translate, 'get').and.callFake((key) => of(key)); @@ -122,14 +128,18 @@ describe('StartFormComponent', () => { }); it('should show outcome buttons by default', () => { - getStartFormSpy.and.returnValue(of({ - id: '1', - processDefinitionName: 'my:process', - outcomes: [{ - id: 'approve', - name: 'Approve' - }] - })); + getStartFormSpy.and.returnValue( + of({ + id: '1', + processDefinitionName: 'my:process', + outcomes: [ + { + id: 'approve', + name: 'Approve' + } + ] + }) + ); component.processDefinitionId = exampleId1; component.ngOnInit(); component.ngOnChanges({ processDefinitionId: new SimpleChange(exampleId1, exampleId2, true) }); @@ -138,14 +148,18 @@ describe('StartFormComponent', () => { }); it('should show outcome buttons if showOutcomeButtons is true', () => { - getStartFormSpy.and.returnValue(of({ - id: '1', - processDefinitionName: 'my:process', - outcomes: [{ - id: 'approve', - name: 'Approve' - }] - })); + getStartFormSpy.and.returnValue( + of({ + id: '1', + processDefinitionName: 'my:process', + outcomes: [ + { + id: 'approve', + name: 'Approve' + } + ] + }) + ); component.processDefinitionId = exampleId1; component.showOutcomeButtons = true; component.ngOnChanges({ processDefinitionId: new SimpleChange(exampleId1, exampleId2, true) }); @@ -164,7 +178,6 @@ describe('StartFormComponent', () => { }); describe('Display widgets', () => { - it('should be able to display a textWidget from a process definition', async () => { getStartFormSpy.and.returnValue(of(startFormTextDefinitionMock)); component.processDefinitionId = exampleId1; @@ -387,7 +400,6 @@ describe('StartFormComponent', () => { }); describe('OutCome Actions', () => { - it('should not enable outcome button when model missing', () => { expect(component.isOutcomeButtonVisible(null, false)).toBeFalsy(); }); diff --git a/lib/process-services/src/lib/form/widgets/content-widget/attach-file-widget-dialog.component.spec.ts b/lib/process-services/src/lib/form/widgets/content-widget/attach-file-widget-dialog.component.spec.ts index 5c674c8c61b..3d730329606 100644 --- a/lib/process-services/src/lib/form/widgets/content-widget/attach-file-widget-dialog.component.spec.ts +++ b/lib/process-services/src/lib/form/widgets/content-widget/attach-file-widget-dialog.component.spec.ts @@ -26,11 +26,9 @@ import { AttachFileWidgetDialogComponentData } from './attach-file-widget-dialog import { of, throwError } from 'rxjs'; import { By } from '@angular/platform-browser'; import { Node, SiteEntry, NodeEntry, SitePaging, SitePagingList } from '@alfresco/js-api'; -import { TranslateModule } from '@ngx-translate/core'; import { OidcAuthenticationService } from 'lib/core/src/lib/auth/services/oidc-authentication.service'; describe('AttachFileWidgetDialogComponent', () => { - let widget: AttachFileWidgetDialogComponent; let fixture: ComponentFixture; const data: AttachFileWidgetDialogComponentData = { @@ -54,11 +52,7 @@ describe('AttachFileWidgetDialogComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - ContentModule.forRoot(), - ProcessTestingModule - ], + imports: [ContentModule.forRoot(), ProcessTestingModule], providers: [ { provide: OidcAuthenticationService, useValue: {} }, { provide: MAT_DIALOG_DATA, useValue: data }, @@ -78,7 +72,9 @@ describe('AttachFileWidgetDialogComponent', () => { spyOn(documentListService, 'getFolderNode').and.returnValue(of({ entry: { path: { elements: [] } } } as NodeEntry)); spyOn(documentListService, 'getFolder').and.returnValue(throwError('No results for test')); - spyOn(nodeService, 'getNode').and.returnValue(of(new Node({ id: 'fake-node', path: { elements: [{ nodeType: 'st:site', name: 'fake-site'}] } }))); + spyOn(nodeService, 'getNode').and.returnValue( + of(new Node({ id: 'fake-node', path: { elements: [{ nodeType: 'st:site', name: 'fake-site' }] } })) + ); spyOn(siteService, 'getSite').and.returnValue(of(fakeSite)); spyOn(siteService, 'getSites').and.returnValue(of(new SitePaging({ list: new SitePagingList({ entries: [] }) }))); @@ -95,7 +91,6 @@ describe('AttachFileWidgetDialogComponent', () => { }); describe('When is not logged in', () => { - beforeEach(() => { fixture.detectChanges(); isLogged = false; @@ -109,7 +104,7 @@ describe('AttachFileWidgetDialogComponent', () => { }); it('should be able to login', (done) => { - spyOn(basicAlfrescoAuthService, 'login').and.returnValue(of({ type: 'type', ticket: 'ticket'})); + spyOn(basicAlfrescoAuthService, 'login').and.returnValue(of({ type: 'type', ticket: 'ticket' })); isLogged = true; let loginButton: HTMLButtonElement = element.querySelector('[data-automation-id="attach-file-dialog-actions-login"]'); const usernameInput: HTMLInputElement = element.querySelector('#username'); @@ -129,10 +124,9 @@ describe('AttachFileWidgetDialogComponent', () => { done(); }); }); - }); + }); describe('When is logged in', () => { - let contentNodePanel; beforeEach(() => { @@ -154,7 +148,7 @@ describe('AttachFileWidgetDialogComponent', () => { expect(nodeList[0].isFile).toBeTruthy(); done(); }); - const fakeNode: Node = new Node({ id: 'fake', isFile: true}); + const fakeNode: Node = new Node({ id: 'fake', isFile: true }); contentNodePanel.componentInstance.select.emit([fakeNode]); fixture.detectChanges(); fixture.whenStable().then(() => { @@ -164,10 +158,10 @@ describe('AttachFileWidgetDialogComponent', () => { }); it('[C594015] should not be able to choose a folder', () => { - spyOn(widget,'onSelect'); - const fakeFolderNode: Node = new Node({ id: 'fakeFolder', isFile: false, isFolder: true}); + spyOn(widget, 'onSelect'); + const fakeFolderNode: Node = new Node({ id: 'fakeFolder', isFile: false, isFolder: true }); - contentNodePanel.componentInstance.onCurrentSelection([ { entry: fakeFolderNode }]); + contentNodePanel.componentInstance.onCurrentSelection([{ entry: fakeFolderNode }]); fixture.detectChanges(); const chooseButton: HTMLButtonElement = element.querySelector('[data-automation-id="attach-file-dialog-actions-choose"]'); @@ -184,11 +178,11 @@ describe('AttachFileWidgetDialogComponent', () => { expect(titleElement).not.toBeNull(); expect(titleElement.nativeElement.innerText).toBe('ATTACH-FILE.ACTIONS.CHOOSE_ITEM'); }); - }); + }); describe('login only', () => { beforeEach(() => { - spyOn(basicAlfrescoAuthService, 'login').and.returnValue(of({ type: 'type', ticket: 'ticket'})); + spyOn(basicAlfrescoAuthService, 'login').and.returnValue(of({ type: 'type', ticket: 'ticket' })); spyOn(matDialogRef, 'close').and.callThrough(); fixture.detectChanges(); widget.data.loginOnly = true; @@ -223,9 +217,8 @@ describe('AttachFileWidgetDialogComponent', () => { }); describe('Attach button', () => { - beforeEach(() => { - isLogged = true; + isLogged = true; }); it('should be disabled by default', () => { diff --git a/lib/process-services/src/lib/form/widgets/content-widget/attach-file-widget-dialog.service.spec.ts b/lib/process-services/src/lib/form/widgets/content-widget/attach-file-widget-dialog.service.spec.ts index 744b120236e..20f6900b416 100644 --- a/lib/process-services/src/lib/form/widgets/content-widget/attach-file-widget-dialog.service.spec.ts +++ b/lib/process-services/src/lib/form/widgets/content-widget/attach-file-widget-dialog.service.spec.ts @@ -20,11 +20,9 @@ import { MatDialog } from '@angular/material/dialog'; import { AttachFileWidgetDialogService } from './attach-file-widget-dialog.service'; import { Subject, of } from 'rxjs'; import { ProcessTestingModule } from '../../../testing/process.testing.module'; -import { TranslateModule } from '@ngx-translate/core'; import { AlfrescoEndpointRepresentation } from '@alfresco/js-api'; describe('AttachFileWidgetDialogService', () => { - let service: AttachFileWidgetDialogService; let materialDialog: MatDialog; let spyOnDialogOpen: jasmine.Spy; @@ -32,10 +30,7 @@ describe('AttachFileWidgetDialogService', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - ProcessTestingModule - ] + imports: [ProcessTestingModule] }); service = TestBed.inject(AttachFileWidgetDialogService); materialDialog = TestBed.inject(MatDialog); @@ -61,7 +56,7 @@ describe('AttachFileWidgetDialogService', () => { }); it('should attach predicate on dialog opening which accepts only file nodes', () => { - const spyOnOpenLoginDialog = spyOn((service as any), 'openLoginDialog'); + const spyOnOpenLoginDialog = spyOn(service as any, 'openLoginDialog'); service.openLogin(mockRepository, 'fake-action'); diff --git a/lib/process-services/src/lib/form/widgets/content-widget/attach-file-widget.component.spec.ts b/lib/process-services/src/lib/form/widgets/content-widget/attach-file-widget.component.spec.ts index 5cb3e4c9751..7d83a3ab343 100644 --- a/lib/process-services/src/lib/form/widgets/content-widget/attach-file-widget.component.spec.ts +++ b/lib/process-services/src/lib/form/widgets/content-widget/attach-file-widget.component.spec.ts @@ -23,7 +23,6 @@ import { ContentNodeDialogService, ContentModule } from '@alfresco/adf-content-s import { of } from 'rxjs'; import { Node } from '@alfresco/js-api'; import { ProcessTestingModule } from '../../../testing/process.testing.module'; -import { TranslateModule } from '@ngx-translate/core'; import { AttachFileWidgetDialogService } from './attach-file-widget-dialog.service'; import { ActivitiContentService } from '../../services/activiti-alfresco.service'; import { ProcessContentService } from '../../services/process-content.service'; @@ -145,7 +144,7 @@ describe('AttachFileWidgetComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [TranslateModule.forRoot(), ProcessTestingModule, ContentModule.forRoot()] + imports: [ProcessTestingModule, ContentModule.forRoot()] }); fixture = TestBed.createComponent(AttachFileWidgetComponent); widget = fixture.componentInstance; diff --git a/lib/process-services/src/lib/form/widgets/content-widget/attach-file-widget.component.ts b/lib/process-services/src/lib/form/widgets/content-widget/attach-file-widget.component.ts index c75fe739c6f..a261e7d8ccb 100644 --- a/lib/process-services/src/lib/form/widgets/content-widget/attach-file-widget.component.ts +++ b/lib/process-services/src/lib/form/widgets/content-widget/attach-file-widget.component.ts @@ -18,7 +18,7 @@ /* eslint-disable @angular-eslint/component-selector */ import { Component, OnDestroy, OnInit, ViewEncapsulation } from '@angular/core'; -import { AppConfigService, AppConfigValues, DownloadService, FormService, LogService, ThumbnailService } from '@alfresco/adf-core'; +import { AppConfigService, AppConfigValues, DownloadService, FormService, ThumbnailService } from '@alfresco/adf-core'; import { ContentNodeDialogService, ContentService } from '@alfresco/adf-content-services'; import { AlfrescoEndpointRepresentation, Node, NodeChildAssociation, RelatedContentRepresentation } from '@alfresco/js-api'; import { from, of, Subject, zip } from 'rxjs'; @@ -53,7 +53,6 @@ export class AttachFileWidgetComponent extends UploadWidgetComponent implements constructor( public formService: FormService, - private logger: LogService, public thumbnails: ThumbnailService, public processContentService: ProcessContentService, private activitiContentService: ActivitiContentService, @@ -63,7 +62,7 @@ export class AttachFileWidgetComponent extends UploadWidgetComponent implements private downloadService: DownloadService, private attachDialogService: AttachFileWidgetDialogService ) { - super(formService, logger, thumbnails, processContentService); + super(formService, thumbnails, processContentService); } ngOnInit() { @@ -152,7 +151,6 @@ export class AttachFileWidgetComponent extends UploadWidgetComponent implements onAttachFileClicked(file: any) { if (file.isExternal || !file.contentAvailable) { - this.logger.info(`The file ${file.name} comes from an external source and cannot be showed at this moment`); return; } if (this.isTemporaryFile(file)) { @@ -188,9 +186,7 @@ export class AttachFileWidgetComponent extends UploadWidgetComponent implements (blob: Blob) => { this.downloadService.downloadBlob(blob, file.name); }, - () => { - this.logger.error('Impossible retrieve content for download'); - } + () => {} ); } } @@ -248,9 +244,7 @@ export class AttachFileWidgetComponent extends UploadWidgetComponent implements res['isExternal'] = isExternal; filesSaved.push(res); }, - (error) => { - this.logger.error(error); - }, + () => {}, () => { const previousFiles = this.field.value ? this.field.value : []; this.field.value = [...previousFiles, ...filesSaved]; diff --git a/lib/process-services/src/lib/form/widgets/content-widget/attach-folder-widget.component.spec.ts b/lib/process-services/src/lib/form/widgets/content-widget/attach-folder-widget.component.spec.ts index 8a44b4a7811..3bcbaf7520f 100644 --- a/lib/process-services/src/lib/form/widgets/content-widget/attach-folder-widget.component.spec.ts +++ b/lib/process-services/src/lib/form/widgets/content-widget/attach-folder-widget.component.spec.ts @@ -23,7 +23,6 @@ import { ContentNodeDialogService, NodesApiService } from '@alfresco/adf-content import { of } from 'rxjs'; import { Node } from '@alfresco/js-api'; import { ProcessTestingModule } from '../../../testing/process.testing.module'; -import { TranslateModule } from '@ngx-translate/core'; const fakeNode = { id: 'fake', @@ -50,7 +49,7 @@ describe('AttachFolderWidgetComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [TranslateModule.forRoot(), ProcessTestingModule] + imports: [ProcessTestingModule] }); fixture = TestBed.createComponent(AttachFolderWidgetComponent); widget = fixture.componentInstance; diff --git a/lib/process-services/src/lib/form/widgets/document/content.widget.spec.ts b/lib/process-services/src/lib/form/widgets/document/content.widget.spec.ts index f239b3a6103..8893db0f9cd 100644 --- a/lib/process-services/src/lib/form/widgets/document/content.widget.spec.ts +++ b/lib/process-services/src/lib/form/widgets/document/content.widget.spec.ts @@ -21,13 +21,11 @@ import { By } from '@angular/platform-browser'; import { ContentLinkModel, CoreTestingModule, DownloadService } from '@alfresco/adf-core'; import { of } from 'rxjs'; import { ContentWidgetComponent } from './content.widget'; -import { TranslateModule } from '@ngx-translate/core'; import { ProcessContentService } from '../../services/process-content.service'; declare let jasmine: any; describe('ContentWidgetComponent', () => { - let component: ContentWidgetComponent; let fixture: ComponentFixture; let element: HTMLElement; @@ -37,33 +35,31 @@ describe('ContentWidgetComponent', () => { const createFakeImageBlob = () => { const data = atob('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg=='); - return new Blob([data], {type: 'image/png'}); + return new Blob([data], { type: 'image/png' }); }; const createFakePdfBlob = (): Blob => { const pdfData = atob( 'JVBERi0xLjcKCjEgMCBvYmogICUgZW50cnkgcG9pbnQKPDwKICAvVHlwZSAvQ2F0YWxvZwog' + - 'IC9QYWdlcyAyIDAgUgo+PgplbmRvYmoKCjIgMCBvYmoKPDwKICAvVHlwZSAvUGFnZXMKICAv' + - 'TWVkaWFCb3ggWyAwIDAgMjAwIDIwMCBdCiAgL0NvdW50IDEKICAvS2lkcyBbIDMgMCBSIF0K' + - 'Pj4KZW5kb2JqCgozIDAgb2JqCjw8CiAgL1R5cGUgL1BhZ2UKICAvUGFyZW50IDIgMCBSCiAg' + - 'L1Jlc291cmNlcyA8PAogICAgL0ZvbnQgPDwKICAgICAgL0YxIDQgMCBSIAogICAgPj4KICA+' + - 'PgogIC9Db250ZW50cyA1IDAgUgo+PgplbmRvYmoKCjQgMCBvYmoKPDwKICAvVHlwZSAvRm9u' + - 'dAogIC9TdWJ0eXBlIC9UeXBlMQogIC9CYXNlRm9udCAvVGltZXMtUm9tYW4KPj4KZW5kb2Jq' + - 'Cgo1IDAgb2JqICAlIHBhZ2UgY29udGVudAo8PAogIC9MZW5ndGggNDQKPj4Kc3RyZWFtCkJU' + - 'CjcwIDUwIFRECi9GMSAxMiBUZgooSGVsbG8sIHdvcmxkISkgVGoKRVQKZW5kc3RyZWFtCmVu' + - 'ZG9iagoKeHJlZgowIDYKMDAwMDAwMDAwMCA2NTUzNSBmIAowMDAwMDAwMDEwIDAwMDAwIG4g' + - 'CjAwMDAwMDAwNzkgMDAwMDAgbiAKMDAwMDAwMDE3MyAwMDAwMCBuIAowMDAwMDAwMzAxIDAw' + - 'MDAwIG4gCjAwMDAwMDAzODAgMDAwMDAgbiAKdHJhaWxlcgo8PAogIC9TaXplIDYKICAvUm9v' + - 'dCAxIDAgUgo+PgpzdGFydHhyZWYKNDkyCiUlRU9G'); - return new Blob([pdfData], {type: 'application/pdf'}); + 'IC9QYWdlcyAyIDAgUgo+PgplbmRvYmoKCjIgMCBvYmoKPDwKICAvVHlwZSAvUGFnZXMKICAv' + + 'TWVkaWFCb3ggWyAwIDAgMjAwIDIwMCBdCiAgL0NvdW50IDEKICAvS2lkcyBbIDMgMCBSIF0K' + + 'Pj4KZW5kb2JqCgozIDAgb2JqCjw8CiAgL1R5cGUgL1BhZ2UKICAvUGFyZW50IDIgMCBSCiAg' + + 'L1Jlc291cmNlcyA8PAogICAgL0ZvbnQgPDwKICAgICAgL0YxIDQgMCBSIAogICAgPj4KICA+' + + 'PgogIC9Db250ZW50cyA1IDAgUgo+PgplbmRvYmoKCjQgMCBvYmoKPDwKICAvVHlwZSAvRm9u' + + 'dAogIC9TdWJ0eXBlIC9UeXBlMQogIC9CYXNlRm9udCAvVGltZXMtUm9tYW4KPj4KZW5kb2Jq' + + 'Cgo1IDAgb2JqICAlIHBhZ2UgY29udGVudAo8PAogIC9MZW5ndGggNDQKPj4Kc3RyZWFtCkJU' + + 'CjcwIDUwIFRECi9GMSAxMiBUZgooSGVsbG8sIHdvcmxkISkgVGoKRVQKZW5kc3RyZWFtCmVu' + + 'ZG9iagoKeHJlZgowIDYKMDAwMDAwMDAwMCA2NTUzNSBmIAowMDAwMDAwMDEwIDAwMDAwIG4g' + + 'CjAwMDAwMDAwNzkgMDAwMDAgbiAKMDAwMDAwMDE3MyAwMDAwMCBuIAowMDAwMDAwMzAxIDAw' + + 'MDAwIG4gCjAwMDAwMDAzODAgMDAwMDAgbiAKdHJhaWxlcgo8PAogIC9TaXplIDYKICAvUm9v' + + 'dCAxIDAgUgo+PgpzdGFydHhyZWYKNDkyCiUlRU9G' + ); + return new Blob([pdfData], { type: 'application/pdf' }); }; beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - CoreTestingModule - ] + imports: [CoreTestingModule] }); downloadService = TestBed.inject(DownloadService); processContentService = TestBed.inject(ProcessContentService); @@ -110,7 +106,7 @@ describe('ContentWidgetComponent', () => { const contentId = 1; const change = new SimpleChange(null, contentId, true); - component.ngOnChanges({id: change}); + component.ngOnChanges({ id: change }); jasmine.Ajax.requests.mostRecent().respondWith({ status: 200, @@ -121,7 +117,9 @@ describe('ContentWidgetComponent', () => { created: 1490354907883, createdBy: { id: 2, - firstName: 'admin', lastName: 'admin', email: 'administrator@admin.com' + firstName: 'admin', + lastName: 'admin', + email: 'administrator@admin.com' }, relatedContent: false, contentAvailable: true, @@ -150,7 +148,7 @@ describe('ContentWidgetComponent', () => { const contentId = 1; const change = new SimpleChange(null, contentId, true); - component.ngOnChanges({id: change}); + component.ngOnChanges({ id: change }); jasmine.Ajax.requests.mostRecent().respondWith({ status: 200, @@ -161,7 +159,9 @@ describe('ContentWidgetComponent', () => { created: 1490354907883, createdBy: { id: 2, - firstName: 'admin', lastName: 'admin', email: 'administrator@admin.com' + firstName: 'admin', + lastName: 'admin', + email: 'administrator@admin.com' }, relatedContent: false, contentAvailable: true, @@ -175,10 +175,9 @@ describe('ContentWidgetComponent', () => { })); it('should show unsupported preview with unsupported file', fakeAsync(() => { - const contentId = 1; const change = new SimpleChange(null, contentId, true); - component.ngOnChanges({id: change}); + component.ngOnChanges({ id: change }); component.contentLoaded.subscribe(() => { fixture.detectChanges(); @@ -196,7 +195,9 @@ describe('ContentWidgetComponent', () => { created: 1490354907883, createdBy: { id: 2, - firstName: 'admin', lastName: 'admin', email: 'administrator@admin.com' + firstName: 'admin', + lastName: 'admin', + email: 'administrator@admin.com' }, relatedContent: false, contentAvailable: false, @@ -220,7 +221,9 @@ describe('ContentWidgetComponent', () => { created: 1490354907883, createdBy: { id: 2, - firstName: 'admin', lastName: 'admin', email: 'administrator@admin.com' + firstName: 'admin', + lastName: 'admin', + email: 'administrator@admin.com' }, relatedContent: false, contentAvailable: true, @@ -255,7 +258,9 @@ describe('ContentWidgetComponent', () => { created: 1490354907883, createdBy: { id: 2, - firstName: 'admin', lastName: 'admin', email: 'administrator@admin.com' + firstName: 'admin', + lastName: 'admin', + email: 'administrator@admin.com' }, relatedContent: false, contentAvailable: true, diff --git a/lib/process-services/src/lib/form/widgets/dropdown/dropdown.widget.spec.ts b/lib/process-services/src/lib/form/widgets/dropdown/dropdown.widget.spec.ts index dd2217a3675..ed505431380 100644 --- a/lib/process-services/src/lib/form/widgets/dropdown/dropdown.widget.spec.ts +++ b/lib/process-services/src/lib/form/widgets/dropdown/dropdown.widget.spec.ts @@ -19,7 +19,6 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; import { Observable, of } from 'rxjs'; import { WidgetVisibilityService, FormFieldOption, FormFieldModel, FormModel, FormFieldTypes, CoreTestingModule } from '@alfresco/adf-core'; import { DropdownWidgetComponent } from './dropdown.widget'; -import { TranslateModule } from '@ngx-translate/core'; import { TaskFormService } from '../../services/task-form.service'; import { ProcessDefinitionService } from '../../services/process-definition.service'; import { HarnessLoader } from '@angular/cdk/testing'; @@ -43,7 +42,7 @@ describe('DropdownWidgetComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [TranslateModule.forRoot(), CoreTestingModule] + imports: [CoreTestingModule] }); fixture = TestBed.createComponent(DropdownWidgetComponent); widget = fixture.componentInstance; diff --git a/lib/process-services/src/lib/form/widgets/dropdown/dropdown.widget.ts b/lib/process-services/src/lib/form/widgets/dropdown/dropdown.widget.ts index 15c41cf324b..7f90b9ed84a 100644 --- a/lib/process-services/src/lib/form/widgets/dropdown/dropdown.widget.ts +++ b/lib/process-services/src/lib/form/widgets/dropdown/dropdown.widget.ts @@ -18,7 +18,7 @@ /* eslint-disable @angular-eslint/component-selector */ import { Component, OnInit, ViewEncapsulation } from '@angular/core'; -import { FormService, FormFieldOption, WidgetComponent, LogService } from '@alfresco/adf-core'; +import { FormService, FormFieldOption, WidgetComponent } from '@alfresco/adf-core'; import { ProcessDefinitionService } from '../../services/process-definition.service'; import { TaskFormService } from '../../services/task-form.service'; @@ -40,12 +40,7 @@ import { TaskFormService } from '../../services/task-form.service'; encapsulation: ViewEncapsulation.None }) export class DropdownWidgetComponent extends WidgetComponent implements OnInit { - constructor( - public formService: FormService, - public taskFormService: TaskFormService, - public processDefinitionService: ProcessDefinitionService, - private logService: LogService - ) { + constructor(public formService: FormService, public taskFormService: TaskFormService, public processDefinitionService: ProcessDefinitionService) { super(formService); } @@ -60,31 +55,27 @@ export class DropdownWidgetComponent extends WidgetComponent implements OnInit { } getValuesByTaskId() { - this.taskFormService.getRestFieldValues(this.field.form.taskId, this.field.id).subscribe( - (formFieldOption) => { - const options = []; - if (this.field.emptyOption) { - options.push(this.field.emptyOption); - } - this.field.options = options.concat(formFieldOption || []); - this.field.updateForm(); - }, - (err) => this.handleError(err) - ); + this.taskFormService.getRestFieldValues(this.field.form.taskId, this.field.id).subscribe((formFieldOption) => { + const options = []; + if (this.field.emptyOption) { + options.push(this.field.emptyOption); + } + this.field.options = options.concat(formFieldOption || []); + this.field.updateForm(); + }); } getValuesByProcessDefinitionId() { - this.processDefinitionService.getRestFieldValuesByProcessId(this.field.form.processDefinitionId, this.field.id).subscribe( - (formFieldOption) => { + this.processDefinitionService + .getRestFieldValuesByProcessId(this.field.form.processDefinitionId, this.field.id) + .subscribe((formFieldOption) => { const options = []; if (this.field.emptyOption) { options.push(this.field.emptyOption); } this.field.options = options.concat(formFieldOption || []); this.field.updateForm(); - }, - (err) => this.handleError(err) - ); + }); } getOptionValue(option: FormFieldOption, fieldValue: string): string { @@ -97,10 +88,6 @@ export class DropdownWidgetComponent extends WidgetComponent implements OnInit { return optionValue; } - handleError(error: any) { - this.logService.error(error); - } - isReadOnlyType(): boolean { return this.field.type === 'readonly'; } diff --git a/lib/process-services/src/lib/form/widgets/dynamic-table/dynamic-table.widget.spec.ts b/lib/process-services/src/lib/form/widgets/dynamic-table/dynamic-table.widget.spec.ts index 09f11281c75..64f63f7f6e3 100644 --- a/lib/process-services/src/lib/form/widgets/dynamic-table/dynamic-table.widget.spec.ts +++ b/lib/process-services/src/lib/form/widgets/dynamic-table/dynamic-table.widget.spec.ts @@ -16,24 +16,16 @@ */ import { ComponentFixture, TestBed } from '@angular/core/testing'; -import { - FormFieldModel, - FormFieldTypes, - FormModel, - LogService, - FormService, - CoreTestingModule -} from '@alfresco/adf-core'; +import { FormFieldModel, FormFieldTypes, FormModel, FormService, CoreTestingModule } from '@alfresco/adf-core'; import { DynamicTableColumn } from './editors/models/dynamic-table-column.model'; import { DynamicTableRow } from './editors/models/dynamic-table-row.model'; import { DynamicTableWidgetComponent } from './dynamic-table.widget'; import { DynamicTableModel } from './editors/models/dynamic-table.widget.model'; -import { TranslateModule } from '@ngx-translate/core'; const fakeFormField = { id: 'fake-dynamic-table', name: 'fake-label', - value: [{1: 1, 2: 2, 3: 4}], + value: [{ 1: 1, 2: 2, 3: 4 }], required: false, readOnly: false, overrideId: false, @@ -72,23 +64,17 @@ const fakeFormField = { }; describe('DynamicTableWidgetComponent', () => { - let widget: DynamicTableWidgetComponent; let fixture: ComponentFixture; let element: HTMLElement; let table: DynamicTableModel; - let logService: LogService; let formService: FormService; beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - CoreTestingModule - ] + imports: [CoreTestingModule] }); const field = new FormFieldModel(new FormModel()); - logService = TestBed.inject(LogService); formService = TestBed.inject(FormService); table = new DynamicTableModel(field, formService); const changeDetectorSpy = jasmine.createSpyObj('cd', ['detectChanges']); @@ -109,7 +95,7 @@ describe('DynamicTableWidgetComponent', () => { }); it('should select row on click', () => { - const row = {selected: false} as DynamicTableRow; + const row = { selected: false } as DynamicTableRow; widget.onRowClicked(row); expect(row.selected).toBeTruthy(); @@ -117,7 +103,7 @@ describe('DynamicTableWidgetComponent', () => { }); it('should require table to select clicked row', () => { - const row = {selected: false} as DynamicTableRow; + const row = { selected: false } as DynamicTableRow; widget.content = null; widget.onRowClicked(row); @@ -125,7 +111,7 @@ describe('DynamicTableWidgetComponent', () => { }); it('should reset selected row', () => { - const row = {selected: false} as DynamicTableRow; + const row = { selected: false } as DynamicTableRow; widget.content.rows.push(row); widget.content.selectedRow = row; expect(widget.content.selectedRow).toBe(row); @@ -137,7 +123,7 @@ describe('DynamicTableWidgetComponent', () => { }); it('should check selection', () => { - const row = {selected: false} as DynamicTableRow; + const row = { selected: false } as DynamicTableRow; widget.content.rows.push(row); widget.content.selectedRow = row; expect(widget.hasSelection()).toBeTruthy(); @@ -215,7 +201,7 @@ describe('DynamicTableWidgetComponent', () => { expect(widget.editMode).toBeFalsy(); expect(widget.editRow).toBeFalsy(); - const row = {value: true} as DynamicTableRow; + const row = { value: true } as DynamicTableRow; widget.content.selectedRow = row; expect(widget.editSelection()).toBeTruthy(); @@ -225,7 +211,7 @@ describe('DynamicTableWidgetComponent', () => { }); it('should copy row', () => { - const row = {value: {opt: {key: '1', value: 1}}} as DynamicTableRow; + const row = { value: { opt: { key: '1', value: 1 } } } as DynamicTableRow; const copy = widget.copyRow(row); expect(copy.value).toEqual(row.value); }); @@ -237,14 +223,14 @@ describe('DynamicTableWidgetComponent', () => { it('should retrieve cell value', () => { const value = ''; - const row = {value: {key: value}} as DynamicTableRow; - const column = {id: 'key'} as DynamicTableColumn; + const row = { value: { key: value } } as DynamicTableRow; + const column = { id: 'key' } as DynamicTableColumn; expect(widget.getCellValue(row, column)).toBe(value); }); it('should save changes and add new row', () => { - const row = {isNew: true, value: {key: 'value'}} as DynamicTableRow; + const row = { isNew: true, value: { key: 'value' } } as DynamicTableRow; widget.editMode = true; widget.editRow = row; @@ -257,7 +243,7 @@ describe('DynamicTableWidgetComponent', () => { }); it('should save changes and update row', () => { - const row = {isNew: false, value: {key: 'value'}} as DynamicTableRow; + const row = { isNew: false, value: { key: 'value' } } as DynamicTableRow; widget.editMode = true; widget.editRow = row; widget.content.selectedRow = row; @@ -267,7 +253,6 @@ describe('DynamicTableWidgetComponent', () => { }); it('should require table to save changes', () => { - spyOn(logService, 'error').and.stub(); widget.editMode = true; widget.content = null; widget.onSaveChanges(); @@ -313,23 +298,22 @@ describe('DynamicTableWidgetComponent', () => { }); it('should prepend default currency for amount columns', () => { - const row = {value: {key: '100'}} as DynamicTableRow; - const column = {id: 'key', type: 'Amount'} as DynamicTableColumn; + const row = { value: { key: '100' } } as DynamicTableRow; + const column = { id: 'key', type: 'Amount' } as DynamicTableColumn; const actual = widget.getCellValue(row, column); expect(actual).toBe('$ 100'); }); it('should prepend custom currency for amount columns', () => { - const row = {value: {key: '100'}} as DynamicTableRow; - const column = {id: 'key', type: 'Amount', amountCurrency: 'GBP'} as DynamicTableColumn; + const row = { value: { key: '100' } } as DynamicTableRow; + const column = { id: 'key', type: 'Amount', amountCurrency: 'GBP' } as DynamicTableColumn; const actual = widget.getCellValue(row, column); expect(actual).toBe('GBP 100'); }); describe('when template is ready', () => { - beforeEach(() => { - widget.field = new FormFieldModel(new FormModel({taskId: 'fake-task-id'}), fakeFormField); + widget.field = new FormFieldModel(new FormModel({ taskId: 'fake-task-id' }), fakeFormField); widget.field.type = FormFieldTypes.DYNAMIC_TABLE; fixture.detectChanges(); diff --git a/lib/process-services/src/lib/form/widgets/dynamic-table/dynamic-table.widget.ts b/lib/process-services/src/lib/form/widgets/dynamic-table/dynamic-table.widget.ts index e4dbdf8a53c..f210d71cc8c 100644 --- a/lib/process-services/src/lib/form/widgets/dynamic-table/dynamic-table.widget.ts +++ b/lib/process-services/src/lib/form/widgets/dynamic-table/dynamic-table.widget.ts @@ -17,7 +17,7 @@ /* eslint-disable @angular-eslint/component-selector */ -import { LogService, WidgetVisibilityService, WidgetComponent, FormService } from '@alfresco/adf-core'; +import { WidgetVisibilityService, WidgetComponent, FormService } from '@alfresco/adf-core'; import { ChangeDetectorRef, Component, ElementRef, OnInit, ViewEncapsulation } from '@angular/core'; import { DynamicTableColumn } from './editors/models/dynamic-table-column.model'; import { DynamicTableRow } from './editors/models/dynamic-table-row.model'; @@ -41,8 +41,6 @@ import { DynamicTableModel } from './editors/models/dynamic-table.widget.model'; encapsulation: ViewEncapsulation.None }) export class DynamicTableWidgetComponent extends WidgetComponent implements OnInit { - ERROR_MODEL_NOT_FOUND = 'Table model not found'; - content: DynamicTableModel; editMode: boolean = false; @@ -54,7 +52,6 @@ export class DynamicTableWidgetComponent extends WidgetComponent implements OnIn public formService: FormService, public elementRef: ElementRef, private visibilityService: WidgetVisibilityService, - private logService: LogService, private cd: ChangeDetectorRef ) { super(formService); @@ -103,7 +100,7 @@ export class DynamicTableWidgetComponent extends WidgetComponent implements OnIn } } - private isEnterOrSpacePressed(keyCode) { + private isEnterOrSpacePressed(keyCode: number) { return this.selectArrayCode.indexOf(keyCode) !== -1; } @@ -179,8 +176,6 @@ export class DynamicTableWidgetComponent extends WidgetComponent implements OnIn this.content.selectedRow.value = this.copyObject(this.editRow.value); } this.content.flushValue(); - } else { - this.logService.error(this.ERROR_MODEL_NOT_FOUND); } this.editMode = false; this.forceFocusOnAddButton(); diff --git a/lib/process-services/src/lib/form/widgets/dynamic-table/editors/date/date.editor.spec.ts b/lib/process-services/src/lib/form/widgets/dynamic-table/editors/date/date.editor.spec.ts index 54aac3be896..7d794ec8db3 100644 --- a/lib/process-services/src/lib/form/widgets/dynamic-table/editors/date/date.editor.spec.ts +++ b/lib/process-services/src/lib/form/widgets/dynamic-table/editors/date/date.editor.spec.ts @@ -22,7 +22,6 @@ import { DynamicTableRow } from '../models/dynamic-table-row.model'; import { DynamicTableModel } from '../models/dynamic-table.widget.model'; import { DateEditorComponent } from './date.editor'; import { By } from '@angular/platform-browser'; -import { TranslateModule } from '@ngx-translate/core'; describe('DateEditorComponent', () => { let component: DateEditorComponent; @@ -33,16 +32,13 @@ describe('DateEditorComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - CoreTestingModule - ] + imports: [CoreTestingModule] }); fixture = TestBed.createComponent(DateEditorComponent); component = fixture.componentInstance; - row = {value: {date: '1879-03-14T00:00:00.000Z'}} as DynamicTableRow; - column = {id: 'date', type: 'Date'} as DynamicTableColumn; + row = { value: { date: '1879-03-14T00:00:00.000Z' } } as DynamicTableRow; + column = { id: 'date', type: 'Date' } as DynamicTableColumn; const field = new FormFieldModel(new FormModel()); table = new DynamicTableModel(field, null); table.rows.push(row); @@ -54,7 +50,7 @@ describe('DateEditorComponent', () => { describe('using Date Piker', () => { it('should update row value on change', () => { - const input = {value: '2016-03-14'} as any; + const input = { value: '2016-03-14' } as any; component.ngOnInit(); component.onDateChanged(input); @@ -75,7 +71,6 @@ describe('DateEditorComponent', () => { }); describe('user manual input', () => { - beforeEach(() => { spyOn(component, 'onDateChanged').and.callThrough(); spyOn(table, 'flushValue').and.callThrough(); diff --git a/lib/process-services/src/lib/form/widgets/dynamic-table/editors/datetime/datetime.editor.spec.ts b/lib/process-services/src/lib/form/widgets/dynamic-table/editors/datetime/datetime.editor.spec.ts index 16e241aa6a7..a321d1ed3b0 100644 --- a/lib/process-services/src/lib/form/widgets/dynamic-table/editors/datetime/datetime.editor.spec.ts +++ b/lib/process-services/src/lib/form/widgets/dynamic-table/editors/datetime/datetime.editor.spec.ts @@ -21,7 +21,6 @@ import { DynamicTableColumn } from '../models/dynamic-table-column.model'; import { DynamicTableRow } from '../models/dynamic-table-row.model'; import { DynamicTableModel } from '../models/dynamic-table.widget.model'; import { DateTimeEditorComponent } from './datetime.editor'; -import { TranslateModule } from '@ngx-translate/core'; describe('DateTimeEditorComponent', () => { let component: DateTimeEditorComponent; @@ -32,16 +31,13 @@ describe('DateTimeEditorComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - CoreTestingModule - ] + imports: [CoreTestingModule] }); fixture = TestBed.createComponent(DateTimeEditorComponent); component = fixture.componentInstance; - row = {value: {date: '1879-03-14T00:00:00.000Z'}} as DynamicTableRow; - column = {id: 'datetime', type: 'Datetime'} as DynamicTableColumn; + row = { value: { date: '1879-03-14T00:00:00.000Z' } } as DynamicTableRow; + column = { id: 'datetime', type: 'Datetime' } as DynamicTableColumn; const field = new FormFieldModel(new FormModel()); table = new DynamicTableModel(field, null); table.rows.push(row); diff --git a/lib/process-services/src/lib/form/widgets/dynamic-table/editors/dropdown/dropdown.editor.spec.ts b/lib/process-services/src/lib/form/widgets/dynamic-table/editors/dropdown/dropdown.editor.spec.ts index abbd30a4ee3..ef431a6b0da 100644 --- a/lib/process-services/src/lib/form/widgets/dynamic-table/editors/dropdown/dropdown.editor.spec.ts +++ b/lib/process-services/src/lib/form/widgets/dynamic-table/editors/dropdown/dropdown.editor.spec.ts @@ -16,8 +16,8 @@ */ import { ComponentFixture, TestBed } from '@angular/core/testing'; -import { Observable, of, throwError } from 'rxjs'; -import { FormFieldModel, FormModel, FormService, TranslationMock, TranslationService } from '@alfresco/adf-core'; +import { Observable, of } from 'rxjs'; +import { FormFieldModel, FormModel, FormService } from '@alfresco/adf-core'; import { DynamicTableColumnOption } from '../models/dynamic-table-column-option.model'; import { DynamicTableColumn } from '../models/dynamic-table-column.model'; import { DynamicTableRow } from '../models/dynamic-table-row.model'; @@ -29,12 +29,10 @@ import { MatSelectHarness } from '@angular/material/select/testing'; import { FormModule } from '../../../../form.module'; import { HarnessLoader } from '@angular/cdk/testing'; import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed'; -import { TranslateModule } from '@ngx-translate/core'; -import { CommonModule } from '@angular/common'; -import { NoopAnimationsModule } from '@angular/platform-browser/animations'; import { MatSelectModule } from '@angular/material/select'; import { MatFormFieldModule } from '@angular/material/form-field'; import { MatOptionModule } from '@angular/material/core'; +import { ProcessTestingModule } from '../../../../../testing/process.testing.module'; describe('DropdownEditorComponent', () => { let fixture: ComponentFixture; @@ -50,16 +48,7 @@ describe('DropdownEditorComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - CommonModule, - NoopAnimationsModule, - MatFormFieldModule, - MatSelectModule, - MatOptionModule, - FormModule - ], - providers: [{ provide: TranslationService, useClass: TranslationMock }] + imports: [ProcessTestingModule, MatFormFieldModule, MatSelectModule, MatOptionModule, FormModule] }); formService = TestBed.inject(FormService); taskFormService = TestBed.inject(TaskFormService); @@ -166,31 +155,6 @@ describe('DropdownEditorComponent', () => { expect(component.value).toBe(row.value[column.id]); }); - it('should handle REST error getting options with task id', () => { - column.optionType = 'rest'; - const error = 'error'; - - spyOn(taskFormService, 'getRestFieldValuesColumn').and.returnValue(throwError(error)); - spyOn(component, 'handleError').and.stub(); - - component.ngOnInit(); - expect(component.handleError).toHaveBeenCalledWith(error); - }); - - it('should handle REST error getting option with processDefinitionId', () => { - column.optionType = 'rest'; - const procForm = new FormModel({ processDefinitionId: '' }); - const procTable = new DynamicTableModel(new FormFieldModel(procForm, { id: '' }), formService); - component.table = procTable; - const error = 'error'; - - spyOn(processDefinitionService, 'getRestFieldValuesColumnByProcessId').and.returnValue(throwError(error)); - spyOn(component, 'handleError').and.stub(); - - fixture.detectChanges(); - expect(component.handleError).toHaveBeenCalledWith(error); - }); - it('should update row on value change', () => { const event = { value: 'two' }; component.onValueChanged(row, column, event); diff --git a/lib/process-services/src/lib/form/widgets/dynamic-table/editors/dropdown/dropdown.editor.ts b/lib/process-services/src/lib/form/widgets/dynamic-table/editors/dropdown/dropdown.editor.ts index b07086730a8..cf162e24018 100644 --- a/lib/process-services/src/lib/form/widgets/dynamic-table/editors/dropdown/dropdown.editor.ts +++ b/lib/process-services/src/lib/form/widgets/dynamic-table/editors/dropdown/dropdown.editor.ts @@ -17,7 +17,7 @@ /* eslint-disable @angular-eslint/component-selector */ -import { LogService, FormService, FormFieldModel } from '@alfresco/adf-core'; +import { FormService, FormFieldModel } from '@alfresco/adf-core'; import { Component, Input, OnInit } from '@angular/core'; import { DynamicTableColumnOption } from '../models/dynamic-table-column-option.model'; import { DynamicTableColumn } from '../models/dynamic-table-column.model'; @@ -47,8 +47,7 @@ export class DropdownEditorComponent implements OnInit { constructor( public formService: FormService, private taskFormService: TaskFormService, - private processDefinitionService: ProcessDefinitionService, - private logService: LogService + private processDefinitionService: ProcessDefinitionService ) {} ngOnInit() { @@ -68,25 +67,21 @@ export class DropdownEditorComponent implements OnInit { } getValuesByTaskId(field: FormFieldModel) { - this.taskFormService.getRestFieldValuesColumn(field.form.taskId, field.id, this.column.id).subscribe( - (dynamicTableColumnOption) => { - this.column.options = dynamicTableColumnOption || []; - this.options = this.column.options; - this.value = this.table.getCellValue(this.row, this.column); - }, - (err) => this.handleError(err) - ); + this.taskFormService.getRestFieldValuesColumn(field.form.taskId, field.id, this.column.id).subscribe((dynamicTableColumnOption) => { + this.column.options = dynamicTableColumnOption || []; + this.options = this.column.options; + this.value = this.table.getCellValue(this.row, this.column); + }); } getValuesByProcessDefinitionId(field: FormFieldModel) { - this.processDefinitionService.getRestFieldValuesColumnByProcessId(field.form.processDefinitionId, field.id, this.column.id).subscribe( - (dynamicTableColumnOption) => { + this.processDefinitionService + .getRestFieldValuesColumnByProcessId(field.form.processDefinitionId, field.id, this.column.id) + .subscribe((dynamicTableColumnOption) => { this.column.options = dynamicTableColumnOption || []; this.options = this.column.options; this.value = this.table.getCellValue(this.row, this.column); - }, - (err) => this.handleError(err) - ); + }); } onValueChanged(row: DynamicTableRow, column: DynamicTableColumn, event: any) { @@ -94,8 +89,4 @@ export class DropdownEditorComponent implements OnInit { value = column.options.find((opt) => opt.name === value); row.value[column.id] = value; } - - handleError(error: any) { - this.logService.error(error); - } } diff --git a/lib/process-services/src/lib/form/widgets/dynamic-table/editors/row-editor/row.editor.spec.ts b/lib/process-services/src/lib/form/widgets/dynamic-table/editors/row-editor/row.editor.spec.ts index 50a2c011a67..17f22e4bc02 100644 --- a/lib/process-services/src/lib/form/widgets/dynamic-table/editors/row-editor/row.editor.spec.ts +++ b/lib/process-services/src/lib/form/widgets/dynamic-table/editors/row-editor/row.editor.spec.ts @@ -15,17 +15,11 @@ * limitations under the License. */ -import { - FormFieldModel, - FormModel, - FormService, - CoreTestingModule -} from '@alfresco/adf-core'; +import { FormFieldModel, FormModel, FormService, CoreTestingModule } from '@alfresco/adf-core'; import { DynamicTableColumn } from '../models/dynamic-table-column.model'; import { DynamicTableRow } from '../models/dynamic-table-row.model'; import { DynamicTableModel } from '../models/dynamic-table.widget.model'; import { RowEditorComponent } from './row.editor'; -import { TranslateModule } from '@ngx-translate/core'; import { DynamicRowValidationSummary } from '../models/dynamic-row-validation-summary.model'; import { TestBed } from '@angular/core/testing'; @@ -34,10 +28,7 @@ describe('RowEditorComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - CoreTestingModule - ] + imports: [CoreTestingModule] }); component = new RowEditorComponent(); const field = new FormFieldModel(new FormModel()); @@ -68,9 +59,7 @@ describe('RowEditorComponent', () => { }); it('should emit [save] event', (done) => { - spyOn(component.table, 'validateRow').and.returnValue( - new DynamicRowValidationSummary({isValid: true, message: null}) - ); + spyOn(component.table, 'validateRow').and.returnValue(new DynamicRowValidationSummary({ isValid: true, message: null })); component.save.subscribe((event) => { expect(event.table).toBe(component.table); expect(event.row).toBe(component.row); @@ -81,11 +70,9 @@ describe('RowEditorComponent', () => { }); it('should not emit [save] event for invalid row', () => { - spyOn(component.table, 'validateRow').and.returnValue( - new DynamicRowValidationSummary({isValid: false, message: 'error'}) - ); + spyOn(component.table, 'validateRow').and.returnValue(new DynamicRowValidationSummary({ isValid: false, message: 'error' })); let raised = false; - component.save.subscribe(() => raised = true); + component.save.subscribe(() => (raised = true)); component.onSaveChanges(); expect(raised).toBeFalsy(); }); diff --git a/lib/process-services/src/lib/form/widgets/functional-group/functional-group.widget.spec.ts b/lib/process-services/src/lib/form/widgets/functional-group/functional-group.widget.spec.ts index 5fd951b0684..5205098529c 100644 --- a/lib/process-services/src/lib/form/widgets/functional-group/functional-group.widget.spec.ts +++ b/lib/process-services/src/lib/form/widgets/functional-group/functional-group.widget.spec.ts @@ -16,16 +16,9 @@ */ import { of, timer } from 'rxjs'; -import { - FormFieldModel, - FormModel, - GroupModel, - CoreTestingModule, - FormFieldTypes -} from '@alfresco/adf-core'; +import { FormFieldModel, FormModel, GroupModel, CoreTestingModule, FormFieldTypes } from '@alfresco/adf-core'; import { FunctionalGroupWidgetComponent } from './functional-group.widget'; import { ComponentFixture, TestBed } from '@angular/core/testing'; -import { TranslateModule } from '@ngx-translate/core'; import { PeopleProcessService } from '../../../common/services/people-process.service'; describe('FunctionalGroupWidgetComponent', () => { @@ -35,16 +28,13 @@ describe('FunctionalGroupWidgetComponent', () => { let getWorkflowGroupsSpy: jasmine.Spy; let element: HTMLElement; const groups: GroupModel[] = [ - {id: '1', name: 'group 1'}, - {id: '2', name: 'group 2'} + { id: '1', name: 'group 1' }, + { id: '2', name: 'group 2' } ]; beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - CoreTestingModule - ] + imports: [CoreTestingModule] }); peopleProcessService = TestBed.inject(PeopleProcessService); getWorkflowGroupsSpy = spyOn(peopleProcessService, 'getWorkflowGroups').and.returnValue(of([])); @@ -79,7 +69,7 @@ describe('FunctionalGroupWidgetComponent', () => { }; it('should setup text from underlying field on init', async () => { - const group: GroupModel = {name: 'group-1'}; + const group: GroupModel = { name: 'group-1' }; component.field.value = group; component.ngOnInit(); @@ -96,7 +86,7 @@ describe('FunctionalGroupWidgetComponent', () => { component.ngOnInit(); expect(component.groupId).toBeUndefined(); - component.field.params = {restrictWithGroup: {id: ''}}; + component.field.params = { restrictWithGroup: { id: '' } }; component.ngOnInit(); expect(component.groupId).toBe(''); }); @@ -122,7 +112,7 @@ describe('FunctionalGroupWidgetComponent', () => { await typeIntoInput('group'); const options: HTMLElement[] = Array.from(document.querySelectorAll('[id="adf-group-label-name"]')); - expect(options.map(option => option.innerText)).toEqual(['group 1', 'group 2']); + expect(options.map((option) => option.innerText)).toEqual(['group 1', 'group 2']); expect(getWorkflowGroupsSpy).toHaveBeenCalledWith('group', 'parentGroup'); }); @@ -133,7 +123,7 @@ describe('FunctionalGroupWidgetComponent', () => { await typeIntoInput('group'); let options: HTMLElement[] = Array.from(document.querySelectorAll('[id="adf-group-label-name"]')); - expect(options.map(option => option.innerText)).toEqual(['group 1', 'group 2']); + expect(options.map((option) => option.innerText)).toEqual(['group 1', 'group 2']); await typeIntoInput('unknown-group'); @@ -154,9 +144,8 @@ describe('FunctionalGroupWidgetComponent', () => { }); describe('when is required', () => { - beforeEach(() => { - component.field = new FormFieldModel(new FormModel({taskId: ''}), { + component.field = new FormFieldModel(new FormModel({ taskId: '' }), { type: FormFieldTypes.FUNCTIONAL_GROUP, required: true }); diff --git a/lib/process-services/src/lib/form/widgets/people/people.widget.spec.ts b/lib/process-services/src/lib/form/widgets/people/people.widget.spec.ts index 370a1163531..82f77ac34fc 100644 --- a/lib/process-services/src/lib/form/widgets/people/people.widget.spec.ts +++ b/lib/process-services/src/lib/form/widgets/people/people.widget.spec.ts @@ -17,20 +17,14 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; import { By } from '@angular/platform-browser'; -import { - FormFieldTypes, - FormFieldModel, - FormModel, - CoreTestingModule -} from '@alfresco/adf-core'; +import { FormFieldTypes, FormFieldModel, FormModel, CoreTestingModule } from '@alfresco/adf-core'; import { Observable, of } from 'rxjs'; import { PeopleWidgetComponent } from './people.widget'; -import { TranslateService, TranslateModule } from '@ngx-translate/core'; +import { TranslateService } from '@ngx-translate/core'; import { PeopleProcessService } from '../../../common/services/people-process.service'; import { UserProcessModel } from '../../../common/models/user-process.model'; describe('PeopleWidgetComponent', () => { - let widget: PeopleWidgetComponent; let fixture: ComponentFixture; let element: HTMLElement; @@ -39,10 +33,7 @@ describe('PeopleWidgetComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - CoreTestingModule - ] + imports: [CoreTestingModule] }); fixture = TestBed.createComponent(PeopleWidgetComponent); peopleProcessService = TestBed.inject(PeopleProcessService); @@ -70,12 +61,12 @@ describe('PeopleWidgetComponent', () => { }); it('should skip first name for display name', () => { - const model = new UserProcessModel({firstName: null, lastName: 'Doe'}); + const model = new UserProcessModel({ firstName: null, lastName: 'Doe' }); expect(widget.getDisplayName(model)).toBe('Doe'); }); it('should skip last name for display name', () => { - const model = new UserProcessModel({firstName: 'John', lastName: null}); + const model = new UserProcessModel({ firstName: 'John', lastName: null }); expect(widget.getDisplayName(model)).toBe('John'); }); @@ -127,7 +118,7 @@ describe('PeopleWidgetComponent', () => { widget.ngOnInit(); expect(widget.groupId).toBeUndefined(); - widget.field.params = {restrictWithGroup: {id: ''}}; + widget.field.params = { restrictWithGroup: { id: '' } }; widget.ngOnInit(); expect(widget.groupId).toBe(''); }); @@ -157,9 +148,8 @@ describe('PeopleWidgetComponent', () => { }); describe('when is required', () => { - beforeEach(() => { - widget.field = new FormFieldModel(new FormModel({taskId: ''}), { + widget.field = new FormFieldModel(new FormModel({ taskId: '' }), { type: FormFieldTypes.PEOPLE, required: true }); @@ -189,17 +179,19 @@ describe('PeopleWidgetComponent', () => { }); describe('when template is ready', () => { - const fakeUserResult = [ - {id: 1001, firstName: 'Test01', lastName: 'Test01', email: 'test'}, - {id: 1002, firstName: 'Test02', lastName: 'Test02', email: 'test2'}]; + { id: 1001, firstName: 'Test01', lastName: 'Test01', email: 'test' }, + { id: 1002, firstName: 'Test02', lastName: 'Test02', email: 'test2' } + ]; beforeEach(() => { - spyOn(peopleProcessService, 'getWorkflowUsers').and.returnValue(new Observable((observer) => { - observer.next(fakeUserResult); - observer.complete(); - })); - widget.field = new FormFieldModel(new FormModel({taskId: 'fake-task-id'}), { + spyOn(peopleProcessService, 'getWorkflowUsers').and.returnValue( + new Observable((observer) => { + observer.next(fakeUserResult); + observer.complete(); + }) + ); + widget.field = new FormFieldModel(new FormModel({ taskId: 'fake-task-id' }), { id: 'people-id', name: 'people-name', type: FormFieldTypes.PEOPLE, diff --git a/lib/process-services/src/lib/form/widgets/radio-buttons/radio-buttons.widget.spec.ts b/lib/process-services/src/lib/form/widgets/radio-buttons/radio-buttons.widget.spec.ts index baecc5fd9d6..0209c815845 100644 --- a/lib/process-services/src/lib/form/widgets/radio-buttons/radio-buttons.widget.spec.ts +++ b/lib/process-services/src/lib/form/widgets/radio-buttons/radio-buttons.widget.spec.ts @@ -22,7 +22,6 @@ import { RadioButtonsWidgetComponent } from './radio-buttons.widget'; import { MatIconModule } from '@angular/material/icon'; import { MatRadioModule } from '@angular/material/radio'; import { FormsModule } from '@angular/forms'; -import { TranslateModule } from '@ngx-translate/core'; import { TaskFormService } from '../../services/task-form.service'; import { ProcessDefinitionService } from '../../services/process-definition.service'; import { HarnessLoader } from '@angular/cdk/testing'; @@ -38,13 +37,13 @@ describe('RadioButtonsWidgetComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [TranslateModule.forRoot(), CoreTestingModule, MatRadioModule, FormsModule, MatIconModule] + imports: [CoreTestingModule, MatRadioModule, FormsModule, MatIconModule] }); taskFormService = TestBed.inject(TaskFormService); processDefinitionService = TestBed.inject(ProcessDefinitionService); formService = new FormService(); - widget = new RadioButtonsWidgetComponent(formService, taskFormService, processDefinitionService, null); + widget = new RadioButtonsWidgetComponent(formService, taskFormService, processDefinitionService); widget.field = new FormFieldModel(new FormModel(), { restUrl: '' }); }); diff --git a/lib/process-services/src/lib/form/widgets/radio-buttons/radio-buttons.widget.ts b/lib/process-services/src/lib/form/widgets/radio-buttons/radio-buttons.widget.ts index 253c337756d..8718a128c32 100644 --- a/lib/process-services/src/lib/form/widgets/radio-buttons/radio-buttons.widget.ts +++ b/lib/process-services/src/lib/form/widgets/radio-buttons/radio-buttons.widget.ts @@ -17,7 +17,7 @@ /* eslint-disable @angular-eslint/component-selector */ -import { LogService, FormService, WidgetComponent } from '@alfresco/adf-core'; +import { FormService, WidgetComponent } from '@alfresco/adf-core'; import { Component, OnInit, ViewEncapsulation } from '@angular/core'; import { TaskFormService } from '../../services/task-form.service'; import { ProcessDefinitionService } from '../../services/process-definition.service'; @@ -43,8 +43,7 @@ export class RadioButtonsWidgetComponent extends WidgetComponent implements OnIn constructor( public formService: FormService, private taskFormService: TaskFormService, - private processDefinitionService: ProcessDefinitionService, - private logService: LogService + private processDefinitionService: ProcessDefinitionService ) { super(formService); } @@ -60,31 +59,23 @@ export class RadioButtonsWidgetComponent extends WidgetComponent implements OnIn } getOptionsByTaskId() { - this.taskFormService.getRestFieldValues(this.field.form.taskId, this.field.id).subscribe( - (formFieldOption) => { - this.field.options = formFieldOption || []; - this.field.updateForm(); - }, - (err) => this.handleError(err) - ); + this.taskFormService.getRestFieldValues(this.field.form.taskId, this.field.id).subscribe((formFieldOption) => { + this.field.options = formFieldOption || []; + this.field.updateForm(); + }); } getOptionsByProcessDefinitionId() { - this.processDefinitionService.getRestFieldValuesByProcessId(this.field.form.processDefinitionId, this.field.id).subscribe( - (formFieldOption) => { + this.processDefinitionService + .getRestFieldValuesByProcessId(this.field.form.processDefinitionId, this.field.id) + .subscribe((formFieldOption) => { this.field.options = formFieldOption || []; this.field.updateForm(); - }, - (err) => this.handleError(err) - ); + }); } onOptionClick(optionSelected: any) { this.field.value = optionSelected; this.fieldChanged.emit(this.field); } - - handleError(error: any) { - this.logService.error(error); - } } diff --git a/lib/process-services/src/lib/form/widgets/typeahead/typeahead.widget.spec.ts b/lib/process-services/src/lib/form/widgets/typeahead/typeahead.widget.spec.ts index db083f2b9fc..8763d1529d5 100644 --- a/lib/process-services/src/lib/form/widgets/typeahead/typeahead.widget.spec.ts +++ b/lib/process-services/src/lib/form/widgets/typeahead/typeahead.widget.spec.ts @@ -16,24 +16,16 @@ */ import { ComponentFixture, TestBed } from '@angular/core/testing'; -import { Observable, of, throwError } from 'rxjs'; +import { Observable, of } from 'rxjs'; import { By } from '@angular/platform-browser'; -import { - FormService, - FormFieldOption, - FormFieldTypes, - FormFieldModel, - FormModel, - CoreTestingModule -} from '@alfresco/adf-core'; +import { FormService, FormFieldOption, FormFieldTypes, FormFieldModel, FormModel, CoreTestingModule } from '@alfresco/adf-core'; import { TypeaheadWidgetComponent } from './typeahead.widget'; -import { TranslateService, TranslateModule } from '@ngx-translate/core'; +import { TranslateService } from '@ngx-translate/core'; import { TaskFormService } from '../../services/task-form.service'; import { ProcessDefinitionService } from '../../services/process-definition.service'; describe('TypeaheadWidgetComponent', () => { - let formService: FormService; let widget: TypeaheadWidgetComponent; let translationService: TranslateService; @@ -42,10 +34,7 @@ describe('TypeaheadWidgetComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - CoreTestingModule - ] + imports: [CoreTestingModule] }); translationService = TestBed.inject(TranslateService); taskFormService = TestBed.inject(TaskFormService); @@ -54,8 +43,8 @@ describe('TypeaheadWidgetComponent', () => { spyOn(translationService, 'get').and.callFake((key) => of(key)); formService = new FormService(); - widget = new TypeaheadWidgetComponent(formService, taskFormService, processDefinitionService, null); - widget.field = new FormFieldModel(new FormModel({taskId: 'task-id'})); + widget = new TypeaheadWidgetComponent(formService, taskFormService, processDefinitionService); + widget.field = new FormFieldModel(new FormModel({ taskId: 'task-id' })); widget.field.restUrl = 'whateverURL'; }); @@ -72,10 +61,12 @@ describe('TypeaheadWidgetComponent', () => { restUrl: 'whateverURL' }); - spyOn(taskFormService, 'getRestFieldValues').and.returnValue(new Observable((observer) => { - observer.next(null); - observer.complete(); - })); + spyOn(taskFormService, 'getRestFieldValues').and.returnValue( + new Observable((observer) => { + observer.next(null); + observer.complete(); + }) + ); widget.ngOnInit(); expect(taskFormService.getRestFieldValues).toHaveBeenCalledWith(taskId, fieldId); }); @@ -97,58 +88,16 @@ describe('TypeaheadWidgetComponent', () => { expect(taskFormService.getRestFieldValues).not.toHaveBeenCalled(); }); - it('should handle error when requesting fields with task id', () => { - const taskId = ''; - const fieldId = ''; - - const form = new FormModel({ - taskId - }); - - widget.field = new FormFieldModel(form, { - id: fieldId, - restUrl: 'whateverURL' - }); - const err = 'Error'; - spyOn(taskFormService, 'getRestFieldValues').and.returnValue(throwError(err)); - spyOn(widget, 'handleError').and.stub(); - - widget.ngOnInit(); - - expect(taskFormService.getRestFieldValues).toHaveBeenCalled(); - expect(widget.handleError).toHaveBeenCalledWith(err); - }); - - it('should handle error when requesting fields with process id', () => { - const processDefinitionId = ''; - const fieldId = ''; - - const form = new FormModel({ - processDefinitionId - }); - - widget.field = new FormFieldModel(form, { - id: fieldId, - restUrl: 'whateverURL' - }); - const err = 'Error'; - spyOn(processDefinitionService, 'getRestFieldValuesByProcessId').and.returnValue(throwError(err)); - spyOn(widget, 'handleError').and.stub(); - - widget.ngOnInit(); - - expect(processDefinitionService.getRestFieldValuesByProcessId).toHaveBeenCalled(); - expect(widget.handleError).toHaveBeenCalledWith(err); - }); - it('should setup initial value', () => { - spyOn(taskFormService, 'getRestFieldValues').and.returnValue(new Observable((observer) => { - observer.next([ - {id: '1', name: 'One'}, - {id: '2', name: 'Two'} - ]); - observer.complete(); - })); + spyOn(taskFormService, 'getRestFieldValues').and.returnValue( + new Observable((observer) => { + observer.next([ + { id: '1', name: 'One' }, + { id: '2', name: 'Two' } + ]); + observer.complete(); + }) + ); widget.field.value = '2'; widget.field.restUrl = 'whateverURL'; widget.ngOnInit(); @@ -158,13 +107,15 @@ describe('TypeaheadWidgetComponent', () => { }); it('should not setup initial value due to missing option', () => { - spyOn(taskFormService, 'getRestFieldValues').and.returnValue(new Observable((observer) => { - observer.next([ - {id: '1', name: 'One'}, - {id: '2', name: 'Two'} - ]); - observer.complete(); - })); + spyOn(taskFormService, 'getRestFieldValues').and.returnValue( + new Observable((observer) => { + observer.next([ + { id: '1', name: 'One' }, + { id: '2', name: 'Two' } + ]); + observer.complete(); + }) + ); widget.field.value = '3'; widget.field.restUrl = 'whateverURL'; @@ -176,24 +127,28 @@ describe('TypeaheadWidgetComponent', () => { it('should setup field options on load', () => { const options: FormFieldOption[] = [ - {id: '1', name: 'One'}, - {id: '2', name: 'Two'} + { id: '1', name: 'One' }, + { id: '2', name: 'Two' } ]; - spyOn(taskFormService, 'getRestFieldValues').and.returnValue(new Observable((observer) => { - observer.next(options); - observer.complete(); - })); + spyOn(taskFormService, 'getRestFieldValues').and.returnValue( + new Observable((observer) => { + observer.next(options); + observer.complete(); + }) + ); widget.ngOnInit(); expect(widget.field.options).toEqual(options); }); it('should update form upon options setup', () => { - spyOn(taskFormService, 'getRestFieldValues').and.returnValue(new Observable((observer) => { - observer.next([]); - observer.complete(); - })); + spyOn(taskFormService, 'getRestFieldValues').and.returnValue( + new Observable((observer) => { + observer.next([]); + observer.complete(); + }) + ); widget.field.restUrl = 'whateverURL'; spyOn(widget.field, 'updateForm').and.callThrough(); @@ -203,8 +158,8 @@ describe('TypeaheadWidgetComponent', () => { it('should get filtered options', () => { const options: FormFieldOption[] = [ - {id: '1', name: 'Item one'}, - {id: '2', name: 'Item two'} + { id: '1', name: 'Item one' }, + { id: '2', name: 'Item two' } ]; widget.field.options = options; widget.value = 'tw'; @@ -216,8 +171,8 @@ describe('TypeaheadWidgetComponent', () => { it('should be case insensitive when filtering options', () => { const options: FormFieldOption[] = [ - {id: '1', name: 'Item one'}, - {id: '2', name: 'iTEM TWo'} + { id: '1', name: 'Item one' }, + { id: '2', name: 'iTEM TWo' } ]; widget.field.options = options; widget.value = 'tW'; @@ -232,13 +187,17 @@ describe('TypeaheadWidgetComponent', () => { let fixture: ComponentFixture; let element: HTMLElement; let stubProcessDefinitionService; - const fakeOptionList: FormFieldOption[] = [{ - id: '1', - name: 'Fake Name 1 ' - }, { - id: '2', - name: 'Fake Name 2' - }, {id: '3', name: 'Fake Name 3'}]; + const fakeOptionList: FormFieldOption[] = [ + { + id: '1', + name: 'Fake Name 1 ' + }, + { + id: '2', + name: 'Fake Name 2' + }, + { id: '3', name: 'Fake Name 3' } + ]; beforeEach(() => { fixture = TestBed.createComponent(TypeaheadWidgetComponent); @@ -252,15 +211,16 @@ describe('TypeaheadWidgetComponent', () => { }); describe('and typeahead is in readonly mode', () => { - it('should show typeahead value with input disabled', async () => { typeaheadWidgetComponent.field = new FormFieldModel( - new FormModel({processVariables: [{name: 'typeahead-id_LABEL', value: 'FakeProcessValue'}]}), { + new FormModel({ processVariables: [{ name: 'typeahead-id_LABEL', value: 'FakeProcessValue' }] }), + { id: 'typeahead-id', name: 'typeahead-name', type: 'readonly', - params: {field: {id: 'typeahead-id', name: 'typeahead-name', type: 'typeahead'}} - }); + params: { field: { id: 'typeahead-id', name: 'typeahead-name', type: 'typeahead' } } + } + ); fixture.detectChanges(); await fixture.whenStable(); @@ -274,14 +234,12 @@ describe('TypeaheadWidgetComponent', () => { afterEach(() => { fixture.destroy(); }); - }); describe('and typeahead is populated via taskId', () => { - beforeEach(() => { spyOn(taskFormService, 'getRestFieldValues').and.returnValue(of(fakeOptionList)); - typeaheadWidgetComponent.field = new FormFieldModel(new FormModel({taskId: 'fake-task-id'}), { + typeaheadWidgetComponent.field = new FormFieldModel(new FormModel({ taskId: 'fake-task-id' }), { id: 'typeahead-id', name: 'typeahead-name', type: FormFieldTypes.TYPEAHEAD, @@ -355,17 +313,16 @@ describe('TypeaheadWidgetComponent', () => { }); describe('and typeahead is populated via processDefinitionId', () => { - beforeEach(() => { stubProcessDefinitionService = fixture.debugElement.injector.get(ProcessDefinitionService); spyOn(stubProcessDefinitionService, 'getRestFieldValuesByProcessId').and.returnValue(of(fakeOptionList)); - typeaheadWidgetComponent.field = new FormFieldModel(new FormModel({processDefinitionId: 'fake-process-id'}), { + typeaheadWidgetComponent.field = new FormFieldModel(new FormModel({ processDefinitionId: 'fake-process-id' }), { id: 'typeahead-id', name: 'typeahead-name', type: FormFieldTypes.TYPEAHEAD, readOnly: 'false' }); - typeaheadWidgetComponent.field.emptyOption = {id: 'empty', name: 'Choose one...'}; + typeaheadWidgetComponent.field.emptyOption = { id: 'empty', name: 'Choose one...' }; typeaheadWidgetComponent.field.isVisible = true; fixture.detectChanges(); }); diff --git a/lib/process-services/src/lib/form/widgets/typeahead/typeahead.widget.ts b/lib/process-services/src/lib/form/widgets/typeahead/typeahead.widget.ts index 7e412a49e44..5ef82f16eeb 100644 --- a/lib/process-services/src/lib/form/widgets/typeahead/typeahead.widget.ts +++ b/lib/process-services/src/lib/form/widgets/typeahead/typeahead.widget.ts @@ -17,7 +17,7 @@ /* eslint-disable @angular-eslint/component-selector */ -import { LogService, FormService, FormFieldOption, WidgetComponent } from '@alfresco/adf-core'; +import { FormService, FormFieldOption, WidgetComponent } from '@alfresco/adf-core'; import { ENTER, ESCAPE } from '@angular/cdk/keycodes'; import { Component, OnInit, ViewEncapsulation } from '@angular/core'; import { TaskFormService } from '../../services/task-form.service'; @@ -49,8 +49,7 @@ export class TypeaheadWidgetComponent extends WidgetComponent implements OnInit constructor( public formService: FormService, private taskFormService: TaskFormService, - private processDefinitionService: ProcessDefinitionService, - private logService: LogService + private processDefinitionService: ProcessDefinitionService ) { super(formService); } @@ -67,30 +66,26 @@ export class TypeaheadWidgetComponent extends WidgetComponent implements OnInit } getValuesByTaskId() { - this.taskFormService.getRestFieldValues(this.field.form.taskId, this.field.id).subscribe( - (formFieldOption) => { - const options = formFieldOption || []; - this.field.options = options; - - const fieldValue = this.field.value; - if (fieldValue) { - const toSelect = options.find( - (item) => item.id === fieldValue || item.name.toLocaleLowerCase() === fieldValue.toLocaleLowerCase() - ); - if (toSelect) { - this.value = toSelect.name; - } + this.taskFormService.getRestFieldValues(this.field.form.taskId, this.field.id).subscribe((formFieldOption) => { + const options = formFieldOption || []; + this.field.options = options; + + const fieldValue = this.field.value; + if (fieldValue) { + const toSelect = options.find((item) => item.id === fieldValue || item.name.toLocaleLowerCase() === fieldValue.toLocaleLowerCase()); + if (toSelect) { + this.value = toSelect.name; } - this.onFieldChanged(this.field); - this.field.updateForm(); - }, - (err) => this.handleError(err) - ); + } + this.onFieldChanged(this.field); + this.field.updateForm(); + }); } getValuesByProcessDefinitionId() { - this.processDefinitionService.getRestFieldValuesByProcessId(this.field.form.processDefinitionId, this.field.id).subscribe( - (formFieldOption) => { + this.processDefinitionService + .getRestFieldValuesByProcessId(this.field.form.processDefinitionId, this.field.id) + .subscribe((formFieldOption) => { const options = formFieldOption || []; this.field.options = options; @@ -103,9 +98,7 @@ export class TypeaheadWidgetComponent extends WidgetComponent implements OnInit } this.onFieldChanged(this.field); this.field.updateForm(); - }, - (err) => this.handleError(err) - ); + }); } getOptions(): FormFieldOption[] { @@ -155,10 +148,6 @@ export class TypeaheadWidgetComponent extends WidgetComponent implements OnInit return this.value !== null && this.value !== undefined; } - handleError(error: any) { - this.logService.error(error); - } - isReadOnlyType(): boolean { return this.field.type === 'readonly'; } diff --git a/lib/process-services/src/lib/form/widgets/upload/upload.widget.spec.ts b/lib/process-services/src/lib/form/widgets/upload/upload.widget.spec.ts index cfd6da6dc4e..542c4a56ff6 100644 --- a/lib/process-services/src/lib/form/widgets/upload/upload.widget.spec.ts +++ b/lib/process-services/src/lib/form/widgets/upload/upload.widget.spec.ts @@ -19,15 +19,8 @@ import { DebugElement } from '@angular/core'; import { ComponentFixture, TestBed } from '@angular/core/testing'; import { By } from '@angular/platform-browser'; import { of } from 'rxjs'; -import { - FormService, - FormFieldTypes, - FormModel, - FormFieldModel, - CoreTestingModule -} from '@alfresco/adf-core'; +import { FormService, FormFieldTypes, FormModel, FormFieldModel, CoreTestingModule } from '@alfresco/adf-core'; import { UploadWidgetComponent } from './upload.widget'; -import { TranslateModule } from '@ngx-translate/core'; import { RelatedContentRepresentation } from '@alfresco/js-api'; import { ProcessContentService } from '../../services/process-content.service'; @@ -35,7 +28,7 @@ const fakePngAnswer = new RelatedContentRepresentation({ id: 1155, name: 'a_png_file.png', created: new Date('2017-07-25T17:17:37.099Z'), - createdBy: {id: 1001, firstName: 'Admin', lastName: 'admin', email: 'admin'}, + createdBy: { id: 1001, firstName: 'Admin', lastName: 'admin', email: 'admin' }, relatedContent: false, contentAvailable: true, link: false, @@ -49,7 +42,7 @@ const fakeJpgAnswer = new RelatedContentRepresentation({ id: 1156, name: 'a_jpg_file.jpg', created: new Date('2017-07-25T17:17:37.118Z'), - createdBy: {id: 1001, firstName: 'Admin', lastName: 'admin', email: 'admin'}, + createdBy: { id: 1001, firstName: 'Admin', lastName: 'admin', email: 'admin' }, relatedContent: false, contentAvailable: true, link: false, @@ -60,12 +53,11 @@ const fakeJpgAnswer = new RelatedContentRepresentation({ }); describe('UploadWidgetComponent', () => { - const fakeCreationFile = (name: string, id: string | number) => ({ id, name, created: '2017-07-25T17:17:37.118Z', - createdBy: {id: 1001, firstName: 'Admin', lastName: 'admin', email: 'admin'}, + createdBy: { id: 1001, firstName: 'Admin', lastName: 'admin', email: 'admin' }, relatedContent: false, contentAvailable: true, link: false, @@ -77,15 +69,12 @@ describe('UploadWidgetComponent', () => { let contentService: ProcessContentService; - const filePngFake = new File(['fakePng'], 'file-fake.png', {type: 'image/png'}); - const filJpgFake = new File(['fakeJpg'], 'file-fake.jpg', {type: 'image/jpg'}); + const filePngFake = new File(['fakePng'], 'file-fake.png', { type: 'image/png' }); + const filJpgFake = new File(['fakeJpg'], 'file-fake.jpg', { type: 'image/jpg' }); beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - CoreTestingModule - ] + imports: [CoreTestingModule] }); }); @@ -111,9 +100,7 @@ describe('UploadWidgetComponent', () => { uploadWidgetComponent.field = new FormFieldModel(null, { type: FormFieldTypes.UPLOAD, - value: [ - {name: encodedFileName} - ] + value: [{ name: encodedFileName }] }); uploadWidgetComponent.ngOnInit(); @@ -130,9 +117,7 @@ describe('UploadWidgetComponent', () => { it('should reset field value', () => { uploadWidgetComponent.field = new FormFieldModel(new FormModel(), { type: FormFieldTypes.UPLOAD, - value: [ - {name: 'filename'} - ] + value: [{ name: 'filename' }] }); uploadWidgetComponent.removeFile(uploadWidgetComponent.field.value[0]); @@ -142,7 +127,7 @@ describe('UploadWidgetComponent', () => { }); beforeEach(() => { - uploadWidgetComponent.field = new FormFieldModel(new FormModel({taskId: 'fake-upload-id'}), { + uploadWidgetComponent.field = new FormFieldModel(new FormModel({ taskId: 'fake-upload-id' }), { id: 'upload-id', name: 'upload-name', value: '', @@ -199,11 +184,10 @@ describe('UploadWidgetComponent', () => { await fixture.whenStable(); const inputDebugElement = fixture.debugElement.query(By.css('#upload-id')); - inputDebugElement.triggerEventHandler('change', {target: {files: [filJpgFake]}}); + inputDebugElement.triggerEventHandler('change', { target: { files: [filJpgFake] } }); const filesList = fixture.debugElement.query(By.css('#file-1156')); expect(filesList).toBeDefined(); - }); it('should update the form after deleted a file', async () => { @@ -217,7 +201,7 @@ describe('UploadWidgetComponent', () => { await fixture.whenStable(); const inputDebugElement = fixture.debugElement.query(By.css('#upload-id')); - inputDebugElement.triggerEventHandler('change', {target: {files: [filePngFake, filJpgFake]}}); + inputDebugElement.triggerEventHandler('change', { target: { files: [filePngFake, filJpgFake] } }); fixture.detectChanges(); await fixture.whenStable(); @@ -247,7 +231,7 @@ describe('UploadWidgetComponent', () => { await fixture.whenStable(); const inputDebugElement = fixture.debugElement.query(By.css('#upload-id')); - inputDebugElement.triggerEventHandler('change', {target: {files: [filePngFake, filJpgFake]}}); + inputDebugElement.triggerEventHandler('change', { target: { files: [filePngFake, filJpgFake] } }); fixture.detectChanges(); await fixture.whenStable(); @@ -398,7 +382,6 @@ describe('UploadWidgetComponent', () => { const fileJpegIcon = debugElement.query(By.css('#file-1156-icon')); fileJpegIcon.nativeElement.dispatchEvent(new MouseEvent('click')); }); - }); }); }); diff --git a/lib/process-services/src/lib/form/widgets/upload/upload.widget.ts b/lib/process-services/src/lib/form/widgets/upload/upload.widget.ts index 4aeedea8554..72bf0cf93b2 100644 --- a/lib/process-services/src/lib/form/widgets/upload/upload.widget.ts +++ b/lib/process-services/src/lib/form/widgets/upload/upload.widget.ts @@ -17,7 +17,7 @@ /* eslint-disable @angular-eslint/component-selector */ -import { LogService, ThumbnailService, FormService, ContentLinkModel, WidgetComponent } from '@alfresco/adf-core'; +import { ThumbnailService, FormService, ContentLinkModel, WidgetComponent } from '@alfresco/adf-core'; import { Component, ElementRef, OnInit, ViewChild, ViewEncapsulation } from '@angular/core'; import { Observable, from } from 'rxjs'; import { ProcessContentService } from '../../services/process-content.service'; @@ -49,12 +49,7 @@ export class UploadWidgetComponent extends WidgetComponent implements OnInit { @ViewChild('uploadFiles') fileInput: ElementRef; - constructor( - public formService: FormService, - private logService: LogService, - private thumbnailService: ThumbnailService, - public processContentService: ProcessContentService - ) { + constructor(public formService: FormService, private thumbnailService: ThumbnailService, public processContentService: ProcessContentService) { super(formService); } @@ -84,7 +79,7 @@ export class UploadWidgetComponent extends WidgetComponent implements OnInit { .pipe(mergeMap((file) => this.uploadRawContent(file))) .subscribe( (res) => filesSaved.push(res), - () => this.logService.error('Error uploading file. See console output for more details.'), + () => {}, () => { this.field.value = filesSaved; this.field.json.value = filesSaved; @@ -97,7 +92,6 @@ export class UploadWidgetComponent extends WidgetComponent implements OnInit { private uploadRawContent(file): Observable { return this.processContentService.createTemporaryRawRelatedContent(file).pipe( map((response: any) => { - this.logService.info(response); response.contentBlob = file; return response; }) @@ -137,14 +131,9 @@ export class UploadWidgetComponent extends WidgetComponent implements OnInit { if (file.isTypeImage() || file.isTypePdf()) { fetch = this.processContentService.getFileRawContent(file.id); } - fetch.subscribe( - (blob: Blob) => { - file.contentBlob = blob; - this.formService.formContentClicked.next(file); - }, - () => { - this.logService.error('Unable to send event for file ' + file.name); - } - ); + fetch.subscribe((blob: Blob) => { + file.contentBlob = blob; + this.formService.formContentClicked.next(file); + }); } } diff --git a/lib/process-services/src/lib/people/components/people-list/people-list.component.spec.ts b/lib/process-services/src/lib/people/components/people-list/people-list.component.spec.ts index b07b7ee4fc5..7d92fc6d9e0 100644 --- a/lib/process-services/src/lib/people/components/people-list/people-list.component.spec.ts +++ b/lib/process-services/src/lib/people/components/people-list/people-list.component.spec.ts @@ -17,7 +17,6 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; import { DataRowActionEvent, DataRowEvent, ObjectDataRow } from '@alfresco/adf-core'; -import { TranslateModule } from '@ngx-translate/core'; import { UserEventModel } from '../../../task-list/models/user-event.model'; import { PeopleListComponent } from './people-list.component'; import { ProcessTestingModule } from '../../../testing/process.testing.module'; @@ -31,16 +30,12 @@ const fakeUser: UserProcessModel = new UserProcessModel({ }); describe('PeopleListComponent', () => { - let peopleListComponent: PeopleListComponent; let fixture: ComponentFixture; beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - ProcessTestingModule - ] + imports: [ProcessTestingModule] }); fixture = TestBed.createComponent(PeopleListComponent); peopleListComponent = fixture.componentInstance; diff --git a/lib/process-services/src/lib/people/components/people-search-field/people-search-field.component.spec.ts b/lib/process-services/src/lib/people/components/people-search-field/people-search-field.component.spec.ts index 38045891835..843e18b6c4f 100644 --- a/lib/process-services/src/lib/people/components/people-search-field/people-search-field.component.spec.ts +++ b/lib/process-services/src/lib/people/components/people-search-field/people-search-field.component.spec.ts @@ -20,10 +20,8 @@ import { DebugElement } from '@angular/core'; import { PeopleSearchFieldComponent } from './people-search-field.component'; import { By } from '@angular/platform-browser'; import { ProcessTestingModule } from '../../../testing/process.testing.module'; -import { TranslateModule } from '@ngx-translate/core'; describe('PeopleSearchFieldComponent', () => { - let component: PeopleSearchFieldComponent; let fixture: ComponentFixture; let debug: DebugElement; @@ -31,10 +29,7 @@ describe('PeopleSearchFieldComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - ProcessTestingModule - ] + imports: [ProcessTestingModule] }); fixture = TestBed.createComponent(PeopleSearchFieldComponent); component = fixture.componentInstance; diff --git a/lib/process-services/src/lib/people/components/people-search/people-search.component.spec.ts b/lib/process-services/src/lib/people/components/people-search/people-search.component.spec.ts index ffa922c2c28..41d51617560 100644 --- a/lib/process-services/src/lib/people/components/people-search/people-search.component.spec.ts +++ b/lib/process-services/src/lib/people/components/people-search/people-search.component.spec.ts @@ -17,7 +17,6 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; import { of } from 'rxjs'; -import { TranslateModule } from '@ngx-translate/core'; import { PeopleSearchComponent } from './people-search.component'; import { ProcessTestingModule } from '../../../testing/process.testing.module'; import { UserProcessModel } from '../../../common/models/user-process.model'; @@ -37,7 +36,6 @@ const fakeSecondUser: UserProcessModel = new UserProcessModel({ }); describe('PeopleSearchComponent', () => { - let peopleSearchComponent: PeopleSearchComponent; let fixture: ComponentFixture; let element: HTMLElement; @@ -46,10 +44,7 @@ describe('PeopleSearchComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - ProcessTestingModule - ] + imports: [ProcessTestingModule] }); fixture = TestBed.createComponent(PeopleSearchComponent); peopleSearchComponent = fixture.componentInstance; diff --git a/lib/process-services/src/lib/people/components/people-selector/people-selector.component.spec.ts b/lib/process-services/src/lib/people/components/people-selector/people-selector.component.spec.ts index b284662d8af..c235eaa9cf9 100644 --- a/lib/process-services/src/lib/people/components/people-selector/people-selector.component.spec.ts +++ b/lib/process-services/src/lib/people/components/people-selector/people-selector.component.spec.ts @@ -16,25 +16,19 @@ */ import { ComponentFixture, TestBed } from '@angular/core/testing'; -import { LogService } from '@alfresco/adf-core'; import { PeopleSelectorComponent } from './people-selector.component'; -import { of, throwError } from 'rxjs'; +import { of } from 'rxjs'; import { By } from '@angular/platform-browser'; import { ProcessTestingModule } from '../../../testing/process.testing.module'; -import { TranslateModule } from '@ngx-translate/core'; import { PeopleProcessService } from '../../../common/services/people-process.service'; describe('PeopleSelectorComponent', () => { - let component: PeopleSelectorComponent; let fixture: ComponentFixture; beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - ProcessTestingModule - ] + imports: [ProcessTestingModule] }); fixture = TestBed.createComponent(PeopleSelectorComponent); component = fixture.componentInstance; @@ -45,7 +39,7 @@ describe('PeopleSelectorComponent', () => { expect(component.placeholder).toBe('ADF_TASK_LIST.PEOPLE.ASSIGNEE'); }); - it('should have the selected user\'s details as placeholder if one is set', () => { + it('should have the selected user details as placeholder if one is set', () => { component.selectedUser = { firstName: 'Max', lastName: 'CaulField' @@ -53,7 +47,7 @@ describe('PeopleSelectorComponent', () => { expect(component.placeholder).toBe('Max CaulField'); }); - it('should call the PeopleProcessService\'s getWorkflowUsers method on search', () => { + it('should call the PeopleProcessService getWorkflowUsers method on search', () => { const peopleProcessService = TestBed.inject(PeopleProcessService); spyOn(peopleProcessService, 'getWorkflowUsers').and.returnValue(of([])); @@ -62,27 +56,13 @@ describe('PeopleSelectorComponent', () => { expect(peopleProcessService.getWorkflowUsers).toHaveBeenCalledWith(undefined, 'Chloe Price'); }); - it('should log error on getWorkflowUsers error', () => { - const peopleProcessService = TestBed.inject(PeopleProcessService); - const logService = TestBed.inject(LogService); - spyOn(peopleProcessService, 'getWorkflowUsers').and.returnValue(throwError(new Error())); - spyOn(logService, 'error'); - - component.performSearch('Chloe Price') - .subscribe((people) => { - expect(people).toEqual([]); - expect(logService.error).toHaveBeenCalledWith('getWorkflowUsers threw error'); - }); - }); - it('should emit an event with the selected users id when userSelected method is invoked', (done) => { - component.peopleIdChange.subscribe((userId) => { expect(userId).toBe(789); done(); }); - component.userSelected({id: 789}); + component.userSelected({ id: 789 }); }); it('should emit an event with undefined when reset button is clicked', (done) => { diff --git a/lib/process-services/src/lib/people/components/people-selector/people-selector.component.ts b/lib/process-services/src/lib/people/components/people-selector/people-selector.component.ts index 039a0f8ff9a..aecfef018f8 100644 --- a/lib/process-services/src/lib/people/components/people-selector/people-selector.component.ts +++ b/lib/process-services/src/lib/people/components/people-selector/people-selector.component.ts @@ -17,7 +17,7 @@ import { Component, ViewChild, ViewEncapsulation, EventEmitter, Input, Output } from '@angular/core'; import { PerformSearchCallback } from '../../interfaces/perform-search-callback.interface'; -import { LogService, TranslationService } from '@alfresco/adf-core'; +import { TranslationService } from '@alfresco/adf-core'; import { PeopleSearchFieldComponent } from '../people-search-field/people-search-field.component'; import { getDisplayUser } from '../../helpers/get-display-user'; import { Observable, of } from 'rxjs'; @@ -49,14 +49,14 @@ export class PeopleSelectorComponent { selectedUser: UserProcessModel; defaultPlaceholder: string; - constructor(private peopleProcessService: PeopleProcessService, private logService: LogService, private translationService: TranslationService) { + constructor(private peopleProcessService: PeopleProcessService, private translationService: TranslationService) { this.peopleIdChange = new EventEmitter(); this.performSearch = this.searchUser.bind(this); this.defaultPlaceholder = this.translationService.instant(DEFAULT_ASSIGNEE_PLACEHOLDER); } searchUser(searchWord: string): Observable { - return this.peopleProcessService.getWorkflowUsers(undefined, searchWord).pipe(catchError(this.onSearchUserError.bind(this))); + return this.peopleProcessService.getWorkflowUsers(undefined, searchWord).pipe(catchError(() => of([]))); } userSelected(user: UserProcessModel): void { @@ -67,11 +67,6 @@ export class PeopleSelectorComponent { this.updateUserSelection(undefined); } - private onSearchUserError(): Observable { - this.logService.error('getWorkflowUsers threw error'); - return of([]); - } - private updateUserSelection(user: UserProcessModel): void { this.selectedUser = user; this.peopleIdChange.emit(user?.id); diff --git a/lib/process-services/src/lib/people/components/people/people.component.spec.ts b/lib/process-services/src/lib/people/components/people/people.component.spec.ts index 5376c51a7e4..9297bab5e7f 100644 --- a/lib/process-services/src/lib/people/components/people/people.component.spec.ts +++ b/lib/process-services/src/lib/people/components/people/people.component.spec.ts @@ -16,13 +16,9 @@ */ import { ComponentFixture, fakeAsync, TestBed } from '@angular/core/testing'; -import { LogService } from '@alfresco/adf-core'; import { PeopleComponent } from './people.component'; import { ProcessTestingModule } from '../../../testing/process.testing.module'; -import { TranslateModule } from '@ngx-translate/core'; -import { throwError } from 'rxjs'; import { UserProcessModel } from '../../../common/models/user-process.model'; -import { PeopleProcessService } from '../../../common/services/people-process.service'; declare let jasmine: any; @@ -41,23 +37,15 @@ const fakeSecondUser = new UserProcessModel({ }); describe('PeopleComponent', () => { - let activitiPeopleComponent: PeopleComponent; let fixture: ComponentFixture; let element: HTMLElement; const userArray = [fakeUser, fakeSecondUser]; - let logService: LogService; - let peopleProcessService: PeopleProcessService; beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - ProcessTestingModule - ] + imports: [ProcessTestingModule] }); - logService = TestBed.inject(LogService); - peopleProcessService = TestBed.inject(PeopleProcessService); fixture = TestBed.createComponent(PeopleComponent); activitiPeopleComponent = fixture.componentInstance; element = fixture.nativeElement; @@ -88,7 +76,6 @@ describe('PeopleComponent', () => { }); describe('when there are involved people', () => { - beforeEach(() => { activitiPeopleComponent.taskId = 'fake-task-id'; activitiPeopleComponent.people.push(...userArray); @@ -117,13 +104,12 @@ describe('PeopleComponent', () => { jasmine.Ajax.requests.mostRecent().respondWith({ status: 200 }); - fixture.whenStable() - .then(() => { - fixture.detectChanges(); - const gatewayElement: any = element.querySelector('#assignment-people-list .adf-datatable-body'); - expect(gatewayElement).not.toBeNull(); - expect(gatewayElement.children.length).toBe(1); - }); + fixture.whenStable().then(() => { + fixture.detectChanges(); + const gatewayElement: any = element.querySelector('#assignment-people-list .adf-datatable-body'); + expect(gatewayElement).not.toBeNull(); + expect(gatewayElement.children.length).toBe(1); + }); })); it('should involve people', fakeAsync(() => { @@ -131,13 +117,12 @@ describe('PeopleComponent', () => { jasmine.Ajax.requests.mostRecent().respondWith({ status: 200 }); - fixture.whenStable() - .then(() => { - fixture.detectChanges(); - const gatewayElement: any = element.querySelector('#assignment-people-list .adf-datatable-body'); - expect(gatewayElement).not.toBeNull(); - expect(gatewayElement.children.length).toBe(3); - }); + fixture.whenStable().then(() => { + fixture.detectChanges(); + const gatewayElement: any = element.querySelector('#assignment-people-list .adf-datatable-body'); + expect(gatewayElement).not.toBeNull(); + expect(gatewayElement.children.length).toBe(3); + }); })); it('should return an observable with user search results', (done) => { @@ -154,17 +139,20 @@ describe('PeopleComponent', () => { status: 200, contentType: 'json', responseText: { - data: [{ - id: 1, - firstName: 'fake-test-1', - lastName: 'fake-last-1', - email: 'fake-test-1@test.com' - }, { - id: 2, - firstName: 'fake-test-2', - lastName: 'fake-last-2', - email: 'fake-test-2@test.com' - }] + data: [ + { + id: 1, + firstName: 'fake-test-1', + lastName: 'fake-last-1', + email: 'fake-test-1@test.com' + }, + { + id: 2, + firstName: 'fake-test-2', + lastName: 'fake-last-2', + email: 'fake-test-2@test.com' + } + ] } }); }); @@ -184,7 +172,6 @@ describe('PeopleComponent', () => { }); describe('when there are errors on service call', () => { - beforeEach(() => { jasmine.Ajax.install(); activitiPeopleComponent.people.push(...userArray); @@ -195,16 +182,6 @@ describe('PeopleComponent', () => { jasmine.Ajax.uninstall(); }); - it('should log error message when search fails', async () => { - const logServiceErrorSpy = spyOn(logService, 'error'); - const mockThrownError = { error: 'Could not load users'}; - - spyOn(peopleProcessService, 'getWorkflowUsers').and.returnValue(throwError(mockThrownError)); - activitiPeopleComponent.searchUser('fake-search'); - - expect(logServiceErrorSpy).toHaveBeenCalledWith(mockThrownError); - }); - it('should not remove user if remove involved user fail', async () => { activitiPeopleComponent.removeInvolvedUser(fakeUser); jasmine.Ajax.requests.mostRecent().respondWith({ diff --git a/lib/process-services/src/lib/people/components/people/people.component.ts b/lib/process-services/src/lib/people/components/people/people.component.ts index 9009eecc17d..f96385be4f3 100644 --- a/lib/process-services/src/lib/people/components/people/people.component.ts +++ b/lib/process-services/src/lib/people/components/people/people.component.ts @@ -15,8 +15,7 @@ * limitations under the License. */ -import { LogService } from '@alfresco/adf-core'; -import { Component, Input, ViewChild, ViewEncapsulation } from '@angular/core'; +import { Component, EventEmitter, Input, Output, ViewChild, ViewEncapsulation } from '@angular/core'; import { Observable, Observer } from 'rxjs'; import { UserEventModel } from '../../../task-list/models/user-event.model'; import { PeopleSearchComponent } from '../people-search/people-search.component'; @@ -31,7 +30,6 @@ import { PeopleProcessService } from '../../../common/services/people-process.se encapsulation: ViewEncapsulation.None }) export class PeopleComponent { - /** The array of User objects to display. */ @Input() people: UserProcessModel[] = []; @@ -47,16 +45,16 @@ export class PeopleComponent { @ViewChild('peopleSearch') peopleSearch: PeopleSearchComponent; + @Output() + error = new EventEmitter(); + showAssignment: boolean = false; peopleSearch$: Observable; private peopleSearchObserver: Observer; - constructor(private logService: LogService, public peopleProcessService: PeopleProcessService) { - this.peopleSearch$ = new Observable((observer) => this.peopleSearchObserver = observer) - .pipe( - share() - ); + constructor(public peopleProcessService: PeopleProcessService) { + this.peopleSearch$ = new Observable((observer) => (this.peopleSearchObserver = observer)).pipe(share()); } involveUserAndCloseSearch() { @@ -72,42 +70,41 @@ export class PeopleComponent { } searchUser(searchedWord: string) { - this.peopleProcessService.getWorkflowUsers(this.taskId, searchedWord) - .subscribe((users) => { + this.peopleProcessService.getWorkflowUsers(this.taskId, searchedWord).subscribe( + (users) => { this.peopleSearchObserver.next(users); - }, (error) => this.logService.error(error)); + }, + (error) => this.error.emit(error) + ); } involveUser(user: UserProcessModel) { if (user?.id) { - this.peopleProcessService - .involveUserWithTask(this.taskId, user.id.toString()) - .subscribe( - () => this.people = [...this.people, user], - () => this.logService.error('Impossible to involve user with task') - ); + this.peopleProcessService.involveUserWithTask(this.taskId, user.id.toString()).subscribe( + () => (this.people = [...this.people, user]), + () => this.error.emit('Impossible to involve user with task') + ); } } removeInvolvedUser(user: UserProcessModel) { - this.peopleProcessService - .removeInvolvedUser(this.taskId, user.id.toString()) - .subscribe( - () => { - this.people = this.people.filter(involvedUser => involvedUser.id !== user.id); - }, - () => this.logService.error('Impossible to remove involved user from task')); + this.peopleProcessService.removeInvolvedUser(this.taskId, user.id.toString()).subscribe( + () => { + this.people = this.people.filter((involvedUser) => involvedUser.id !== user.id); + }, + () => this.error.emit('Impossible to remove involved user from task') + ); } getDisplayUser(firstName: string, lastName: string, delimiter: string = '-'): string { - firstName = (firstName !== null ? firstName : ''); - lastName = (lastName !== null ? lastName : ''); + firstName = firstName !== null ? firstName : ''; + lastName = lastName !== null ? lastName : ''; return firstName + delimiter + lastName; } getInitialUserName(firstName: string, lastName: string) { - firstName = (firstName !== null && firstName !== '' ? firstName[0] : ''); - lastName = (lastName !== null && lastName !== '' ? lastName[0] : ''); + firstName = firstName !== null && firstName !== '' ? firstName[0] : ''; + lastName = lastName !== null && lastName !== '' ? lastName[0] : ''; return this.getDisplayUser(firstName, lastName, ''); } diff --git a/lib/process-services/src/lib/pipes/process-name.pipe.spec.ts b/lib/process-services/src/lib/pipes/process-name.pipe.spec.ts index 5e7d70161ec..6309ee91501 100644 --- a/lib/process-services/src/lib/pipes/process-name.pipe.spec.ts +++ b/lib/process-services/src/lib/pipes/process-name.pipe.spec.ts @@ -17,12 +17,10 @@ import { TestBed } from '@angular/core/testing'; import { ProcessNamePipe } from './process-name.pipe'; -import { TranslateModule } from '@ngx-translate/core'; import { LocalizedDatePipe, CoreTestingModule } from '@alfresco/adf-core'; import { ProcessInstance } from '../process-list'; describe('ProcessNamePipe', () => { - let processNamePipe: ProcessNamePipe; const defaultName = 'default-name'; const datetimeIdentifier = '%{datetime}'; @@ -32,14 +30,11 @@ describe('ProcessNamePipe', () => { const nameWithProcessDefinitionIdentifier = `${defaultName} - ${processDefinitionIdentifier}`; const nameWithDatetimeIdentifier = `${defaultName} - ${datetimeIdentifier}`; const nameWithAllIdentifiers = `${defaultName} ${processDefinitionIdentifier} - ${datetimeIdentifier}`; - const fakeProcessInstanceDetails = new ProcessInstance({ processDefinitionName: 'fake-process-def-name'}); + const fakeProcessInstanceDetails = new ProcessInstance({ processDefinitionName: 'fake-process-def-name' }); beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - CoreTestingModule - ] + imports: [CoreTestingModule] }); const localizedDatePipe = TestBed.inject(LocalizedDatePipe); processNamePipe = new ProcessNamePipe(localizedDatePipe); @@ -71,5 +66,4 @@ describe('ProcessNamePipe', () => { const transformResult = processNamePipe.transform(nameWithProcessDefinitionIdentifier); expect(transformResult).toEqual(`${defaultName} - `); }); - }); diff --git a/lib/process-services/src/lib/process-comments/process-comments.component.spec.ts b/lib/process-services/src/lib/process-comments/process-comments.component.spec.ts index a22c2cd3d17..a2b7e4941c5 100644 --- a/lib/process-services/src/lib/process-comments/process-comments.component.spec.ts +++ b/lib/process-services/src/lib/process-comments/process-comments.component.spec.ts @@ -22,10 +22,8 @@ import { CommentProcessService } from './services/comment-process.service'; import { ProcessCommentsComponent } from './process-comments.component'; import { ProcessTestingModule } from '../testing/process.testing.module'; import { mockProcessInstanceComments } from '../mock/process/process-comments.mock'; -import { TranslateModule } from '@ngx-translate/core'; describe('ProcessCommentsComponent', () => { - let component: ProcessCommentsComponent; let fixture: ComponentFixture; let getCommentsSpy: jasmine.Spy; @@ -33,10 +31,7 @@ describe('ProcessCommentsComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - ProcessTestingModule - ] + imports: [ProcessTestingModule] }); fixture = TestBed.createComponent(ProcessCommentsComponent); component = fixture.componentInstance; @@ -121,7 +116,7 @@ describe('ProcessCommentsComponent', () => { expect(fixture.nativeElement.querySelector('#comment-input')).toBeNull(); }); - it('should display comments input when the process isn\'t readonly', async () => { + it('should display comments input when the process is not readonly', async () => { component.readOnly = false; fixture.detectChanges(); diff --git a/lib/process-services/src/lib/process-list/components/process-audit.directive.spec.ts b/lib/process-services/src/lib/process-list/components/process-audit.directive.spec.ts index 79a3a43f44d..893e46fa1eb 100644 --- a/lib/process-services/src/lib/process-list/components/process-audit.directive.spec.ts +++ b/lib/process-services/src/lib/process-list/components/process-audit.directive.spec.ts @@ -21,19 +21,20 @@ import { of, throwError } from 'rxjs'; import { ProcessService } from './../services/process.service'; import { DownloadService } from '@alfresco/adf-core'; import { ProcessTestingModule } from '../../testing/process.testing.module'; -import { TranslateModule } from '@ngx-translate/core'; @Component({ selector: 'adf-basic-button', - template: ` - ` }) class BasicButtonComponent { @@ -46,7 +47,6 @@ class BasicButtonComponent { } describe('ProcessAuditDirective', () => { - let fixture: ComponentFixture; let component: BasicButtonComponent; let service: ProcessService; @@ -54,32 +54,28 @@ describe('ProcessAuditDirective', () => { const createFakePdfBlob = (): Blob => { const pdfData = atob( 'JVBERi0xLjcKCjEgMCBvYmogICUgZW50cnkgcG9pbnQKPDwKICAvVHlwZSAvQ2F0YWxvZwog' + - 'IC9QYWdlcyAyIDAgUgo+PgplbmRvYmoKCjIgMCBvYmoKPDwKICAvVHlwZSAvUGFnZXMKICAv' + - 'TWVkaWFCb3ggWyAwIDAgMjAwIDIwMCBdCiAgL0NvdW50IDEKICAvS2lkcyBbIDMgMCBSIF0K' + - 'Pj4KZW5kb2JqCgozIDAgb2JqCjw8CiAgL1R5cGUgL1BhZ2UKICAvUGFyZW50IDIgMCBSCiAg' + - 'L1Jlc291cmNlcyA8PAogICAgL0ZvbnQgPDwKICAgICAgL0YxIDQgMCBSIAogICAgPj4KICA+' + - 'PgogIC9Db250ZW50cyA1IDAgUgo+PgplbmRvYmoKCjQgMCBvYmoKPDwKICAvVHlwZSAvRm9u' + - 'dAogIC9TdWJ0eXBlIC9UeXBlMQogIC9CYXNlRm9udCAvVGltZXMtUm9tYW4KPj4KZW5kb2Jq' + - 'Cgo1IDAgb2JqICAlIHBhZ2UgY29udGVudAo8PAogIC9MZW5ndGggNDQKPj4Kc3RyZWFtCkJU' + - 'CjcwIDUwIFRECi9GMSAxMiBUZgooSGVsbG8sIHdvcmxkISkgVGoKRVQKZW5kc3RyZWFtCmVu' + - 'ZG9iagoKeHJlZgowIDYKMDAwMDAwMDAwMCA2NTUzNSBmIAowMDAwMDAwMDEwIDAwMDAwIG4g' + - 'CjAwMDAwMDAwNzkgMDAwMDAgbiAKMDAwMDAwMDE3MyAwMDAwMCBuIAowMDAwMDAwMzAxIDAw' + - 'MDAwIG4gCjAwMDAwMDAzODAgMDAwMDAgbiAKdHJhaWxlcgo8PAogIC9TaXplIDYKICAvUm9v' + - 'dCAxIDAgUgo+PgpzdGFydHhyZWYKNDkyCiUlRU9G'); - return new Blob([pdfData], {type: 'application/pdf'}); + 'IC9QYWdlcyAyIDAgUgo+PgplbmRvYmoKCjIgMCBvYmoKPDwKICAvVHlwZSAvUGFnZXMKICAv' + + 'TWVkaWFCb3ggWyAwIDAgMjAwIDIwMCBdCiAgL0NvdW50IDEKICAvS2lkcyBbIDMgMCBSIF0K' + + 'Pj4KZW5kb2JqCgozIDAgb2JqCjw8CiAgL1R5cGUgL1BhZ2UKICAvUGFyZW50IDIgMCBSCiAg' + + 'L1Jlc291cmNlcyA8PAogICAgL0ZvbnQgPDwKICAgICAgL0YxIDQgMCBSIAogICAgPj4KICA+' + + 'PgogIC9Db250ZW50cyA1IDAgUgo+PgplbmRvYmoKCjQgMCBvYmoKPDwKICAvVHlwZSAvRm9u' + + 'dAogIC9TdWJ0eXBlIC9UeXBlMQogIC9CYXNlRm9udCAvVGltZXMtUm9tYW4KPj4KZW5kb2Jq' + + 'Cgo1IDAgb2JqICAlIHBhZ2UgY29udGVudAo8PAogIC9MZW5ndGggNDQKPj4Kc3RyZWFtCkJU' + + 'CjcwIDUwIFRECi9GMSAxMiBUZgooSGVsbG8sIHdvcmxkISkgVGoKRVQKZW5kc3RyZWFtCmVu' + + 'ZG9iagoKeHJlZgowIDYKMDAwMDAwMDAwMCA2NTUzNSBmIAowMDAwMDAwMDEwIDAwMDAwIG4g' + + 'CjAwMDAwMDAwNzkgMDAwMDAgbiAKMDAwMDAwMDE3MyAwMDAwMCBuIAowMDAwMDAwMzAxIDAw' + + 'MDAwIG4gCjAwMDAwMDAzODAgMDAwMDAgbiAKdHJhaWxlcgo8PAogIC9TaXplIDYKICAvUm9v' + + 'dCAxIDAgUgo+PgpzdGFydHhyZWYKNDkyCiUlRU9G' + ); + return new Blob([pdfData], { type: 'application/pdf' }); }; const blob = createFakePdfBlob(); beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - ProcessTestingModule - ], - declarations: [ - BasicButtonComponent - ] + imports: [ProcessTestingModule], + declarations: [BasicButtonComponent] }); fixture = TestBed.createComponent(BasicButtonComponent); component = fixture.componentInstance; @@ -145,22 +141,40 @@ describe('ProcessAuditDirective', () => { component.format = 'json'; component.download = true; const auditJson = { - processInstanceId: 42516, processInstanceName: 'Fake Process - August 3rd 2017', - processDefinitionName: 'Claim Approval Process', processDefinitionVersion: 1, processInstanceStartTime: 'Thu Aug 03 15:32:47 UTC 2017', processInstanceEndTime: null, + processInstanceId: 42516, + processInstanceName: 'Fake Process - August 3rd 2017', + processDefinitionName: 'Claim Approval Process', + processDefinitionVersion: 1, + processInstanceStartTime: 'Thu Aug 03 15:32:47 UTC 2017', + processInstanceEndTime: null, // eslint-disable-next-line @cspell/spellchecker processInstanceDurationInMillis: null, processInstanceInitiator: 'MyName MyLastname', - entries: [{ - index: 1, type: 'startForm', - selectedOutcome: null, formData: [{ - fieldName: 'User Name', - fieldId: 'username', value: 'dsassd' - }, - { fieldName: 'Claim Amount', fieldId: 'claimamount', value: '22' }], taskName: null, taskAssignee: null, activityId: null, - // eslint-disable-next-line @cspell/spellchecker - activityName: null, activityType: null, startTime: null, endTime: null, durationInMillis: null - } - ], decisionInfo: { calculatedValues: [], appliedRules: [] } + entries: [ + { + index: 1, + type: 'startForm', + selectedOutcome: null, + formData: [ + { + fieldName: 'User Name', + fieldId: 'username', + value: 'dsassd' + }, + { fieldName: 'Claim Amount', fieldId: 'claimamount', value: '22' } + ], + taskName: null, + taskAssignee: null, + activityId: null, + // eslint-disable-next-line @cspell/spellchecker + activityName: null, + activityType: null, + startTime: null, + endTime: null, + durationInMillis: null + } + ], + decisionInfo: { calculatedValues: [], appliedRules: [] } }; spyOn(service, 'fetchProcessAuditJsonById').and.returnValue(of(auditJson)); spyOn(component, 'onAuditClick').and.callThrough(); diff --git a/lib/process-services/src/lib/process-list/components/process-filters.component.spec.ts b/lib/process-services/src/lib/process-list/components/process-filters.component.spec.ts index 2bfb1ea54f8..8d9b80dd880 100644 --- a/lib/process-services/src/lib/process-list/components/process-filters.component.spec.ts +++ b/lib/process-services/src/lib/process-list/components/process-filters.component.spec.ts @@ -25,13 +25,11 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; import { By } from '@angular/platform-browser'; import { fakeProcessFilters } from '../../mock/process/process-filters.mock'; import { ProcessTestingModule } from '../../testing/process.testing.module'; -import { TranslateModule } from '@ngx-translate/core'; import { NavigationStart, Router } from '@angular/router'; import { RouterTestingModule } from '@angular/router/testing'; import { ProcessInstanceFilterRepresentation, UserProcessInstanceFilterRepresentation } from '@alfresco/js-api'; describe('ProcessFiltersComponent', () => { - let filterList: ProcessFiltersComponent; let fixture: ComponentFixture; let processFilterService: ProcessFilterService; @@ -40,11 +38,7 @@ describe('ProcessFiltersComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - ProcessTestingModule, - RouterTestingModule - ], + imports: [ProcessTestingModule, RouterTestingModule], schemas: [CUSTOM_ELEMENTS_SCHEMA] }); fixture = TestBed.createComponent(ProcessFiltersComponent); @@ -64,7 +58,7 @@ describe('ProcessFiltersComponent', () => { const change = new SimpleChange(null, appId, true); let lastValue: ProcessInstanceFilterRepresentation[]; - filterList.success.subscribe((res) => lastValue = res); + filterList.success.subscribe((res) => (lastValue = res)); spyOn(filterList, 'getFiltersByAppId').and.callThrough(); @@ -106,7 +100,7 @@ describe('ProcessFiltersComponent', () => { const change = new SimpleChange(null, appId, true); let lastValue: UserProcessInstanceFilterRepresentation; - filterList.filterSelected.subscribe((filter) => lastValue = filter); + filterList.filterSelected.subscribe((filter) => (lastValue = filter)); filterList.ngOnChanges({ appId: change }); fixture.detectChanges(); @@ -115,7 +109,7 @@ describe('ProcessFiltersComponent', () => { expect(lastValue.name).toEqual('FakeCompleted'); }); - it('should filterClicked emit when a filter is clicked from the UI', async () => { + it('should filterClicked emit when a filter is clicked from the UI', async () => { filterList.filters = fakeProcessFilters; spyOn(filterList.filterClicked, 'emit'); @@ -163,7 +157,7 @@ describe('ProcessFiltersComponent', () => { const change = new SimpleChange(null, appId, true); let lastValue: any; - filterList.error.subscribe((err) => lastValue = err); + filterList.error.subscribe((err) => (lastValue = err)); filterList.ngOnChanges({ appId: change }); @@ -177,7 +171,7 @@ describe('ProcessFiltersComponent', () => { const change = new SimpleChange(null, appId, true); let lastValue: any; - filterList.error.subscribe((err) => lastValue = err); + filterList.error.subscribe((err) => (lastValue = err)); filterList.ngOnChanges({ appName: change }); @@ -193,7 +187,7 @@ describe('ProcessFiltersComponent', () => { }); let lastValue: UserProcessInstanceFilterRepresentation; - filterList.filterClicked.subscribe((filter) => lastValue = filter); + filterList.filterClicked.subscribe((filter) => (lastValue = filter)); filterList.selectFilter(currentFilter); expect(lastValue).toBeDefined(); diff --git a/lib/process-services/src/lib/process-list/components/process-instance-details.component.spec.ts b/lib/process-services/src/lib/process-list/components/process-instance-details.component.spec.ts index 0ccef964b3d..6c7238e2d47 100644 --- a/lib/process-services/src/lib/process-list/components/process-instance-details.component.spec.ts +++ b/lib/process-services/src/lib/process-list/components/process-instance-details.component.spec.ts @@ -27,13 +27,11 @@ import { ProcessService } from './../services/process.service'; import { ProcessInstanceDetailsComponent } from './process-instance-details.component'; import { ProcessTestingModule } from '../../testing/process.testing.module'; import { FormModule } from '../../form'; -import { TranslateModule } from '@ngx-translate/core'; import { HarnessLoader } from '@angular/cdk/testing'; import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed'; import { MatCardHarness } from '@angular/material/card/testing'; describe('ProcessInstanceDetailsComponent', () => { - let service: ProcessService; let component: ProcessInstanceDetailsComponent; let fixture: ComponentFixture; @@ -42,12 +40,7 @@ describe('ProcessInstanceDetailsComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - ProcessTestingModule, - FormModule, - TaskListModule - ], + imports: [ProcessTestingModule, FormModule, TaskListModule], schemas: [NO_ERRORS_SCHEMA] }); fixture = TestBed.createComponent(ProcessInstanceDetailsComponent); @@ -124,7 +117,6 @@ describe('ProcessInstanceDetailsComponent', () => { }); describe('change detection', () => { - const change = new SimpleChange('123', '456', true); const nullChange = new SimpleChange('123', null, true); diff --git a/lib/process-services/src/lib/process-list/components/process-instance-details.component.ts b/lib/process-services/src/lib/process-list/components/process-instance-details.component.ts index a05be488262..fd508b1872c 100644 --- a/lib/process-services/src/lib/process-list/components/process-instance-details.component.ts +++ b/lib/process-services/src/lib/process-list/components/process-instance-details.component.ts @@ -15,7 +15,6 @@ * limitations under the License. */ -import { LogService } from '@alfresco/adf-core'; import { DatePipe } from '@angular/common'; import { Component, EventEmitter, Input, OnChanges, Output, SimpleChanges, ViewChild } from '@angular/core'; import { TaskDetailsEvent } from '../../task-list'; @@ -67,7 +66,7 @@ export class ProcessInstanceDetailsComponent implements OnChanges { processInstanceDetails: ProcessInstance; - constructor(private activitiProcess: ProcessService, private logService: LogService) {} + constructor(private activitiProcess: ProcessService) {} ngOnChanges(changes: SimpleChanges) { const processInstanceId = changes['processInstanceId']; @@ -130,8 +129,8 @@ export class ProcessInstanceDetailsComponent implements OnChanges { const datePipe = new DatePipe('en-US'); try { return datePipe.transform(value, format); - } catch (err) { - this.logService.error(`ProcessListInstanceHeader: error parsing date ${value} to format ${format}`); + } catch { + return undefined; } } diff --git a/lib/process-services/src/lib/process-list/components/process-instance-header.component.spec.ts b/lib/process-services/src/lib/process-list/components/process-instance-header.component.spec.ts index bc844747471..436b63959c1 100644 --- a/lib/process-services/src/lib/process-list/components/process-instance-header.component.spec.ts +++ b/lib/process-services/src/lib/process-list/components/process-instance-header.component.spec.ts @@ -21,20 +21,15 @@ import { ProcessInstance } from '../models/process-instance.model'; import { exampleProcess } from '../../mock'; import { ProcessInstanceHeaderComponent } from './process-instance-header.component'; import { ProcessTestingModule } from '../../testing/process.testing.module'; -import { TranslateModule } from '@ngx-translate/core'; describe('ProcessInstanceHeaderComponent', () => { - let component: ProcessInstanceHeaderComponent; let fixture: ComponentFixture; let appConfigService: AppConfigService; beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - ProcessTestingModule - ] + imports: [ProcessTestingModule] }); fixture = TestBed.createComponent(ProcessInstanceHeaderComponent); component = fixture.componentInstance; @@ -112,7 +107,7 @@ describe('ProcessInstanceHeaderComponent', () => { }); it('should display started by', async () => { - component.processInstance.startedBy = {firstName: 'Admin', lastName: 'User'}; + component.processInstance.startedBy = { firstName: 'Admin', lastName: 'User' }; component.ngOnChanges(); fixture.detectChanges(); await fixture.whenStable(); @@ -166,7 +161,6 @@ describe('ProcessInstanceHeaderComponent', () => { }); describe('Config Filtering', () => { - it('should show only the properties from the configuration file', () => { appConfigService.config['adf-process-instance-header'] = { presets: { @@ -196,5 +190,5 @@ describe('ProcessInstanceHeaderComponent', () => { expect(propertyList[0].innerText).toContain('ADF_PROCESS_LIST.PROPERTIES.STATUS'); expect(propertyList[2].innerText).toContain('ADF_PROCESS_LIST.PROPERTIES.CATEGORY'); }); - }); + }); }); diff --git a/lib/process-services/src/lib/process-list/components/process-instance-tasks.component.spec.ts b/lib/process-services/src/lib/process-list/components/process-instance-tasks.component.spec.ts index 66cf2a4203e..cbfd6c8ebd9 100644 --- a/lib/process-services/src/lib/process-list/components/process-instance-tasks.component.spec.ts +++ b/lib/process-services/src/lib/process-list/components/process-instance-tasks.component.spec.ts @@ -25,7 +25,6 @@ import { ProcessInstance } from './../models/process-instance.model'; import { ProcessService } from './../services/process.service'; import { ProcessInstanceTasksComponent } from './process-instance-tasks.component'; import { ProcessTestingModule } from '../../testing/process.testing.module'; -import { TranslateModule } from '@ngx-translate/core'; import { HarnessLoader } from '@angular/cdk/testing'; import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed'; import { MatListItemHarness } from '@angular/material/list/testing'; @@ -40,7 +39,7 @@ describe('ProcessInstanceTasksComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [TranslateModule.forRoot(), ProcessTestingModule] + imports: [ProcessTestingModule] }); fixture = TestBed.createComponent(ProcessInstanceTasksComponent); processService = TestBed.inject(ProcessService); diff --git a/lib/process-services/src/lib/process-list/components/process-instance-tasks.component.ts b/lib/process-services/src/lib/process-list/components/process-instance-tasks.component.ts index 7111122650c..5bec801fa2a 100644 --- a/lib/process-services/src/lib/process-list/components/process-instance-tasks.component.ts +++ b/lib/process-services/src/lib/process-list/components/process-instance-tasks.component.ts @@ -15,7 +15,6 @@ * limitations under the License. */ -import { LogService } from '@alfresco/adf-core'; import { DatePipe } from '@angular/common'; import { Component, EventEmitter, Input, OnChanges, OnInit, Output, SimpleChanges, ViewChild, OnDestroy } from '@angular/core'; import { MatDialog } from '@angular/material/dialog'; @@ -67,7 +66,7 @@ export class ProcessInstanceTasksComponent implements OnInit, OnChanges, OnDestr private completedTaskObserver: Observer; private onDestroy$ = new Subject(); - constructor(private activitiProcess: ProcessService, private logService: LogService, private dialog: MatDialog) { + constructor(private processService: ProcessService, private dialog: MatDialog) { this.task$ = new Observable((observer) => (this.taskObserver = observer)).pipe(share()); this.completedTask$ = new Observable((observer) => (this.completedTaskObserver = observer)).pipe(share()); } @@ -98,7 +97,7 @@ export class ProcessInstanceTasksComponent implements OnInit, OnChanges, OnDestr loadActive(processInstanceId: string) { this.activeTasks = []; if (processInstanceId) { - this.activitiProcess.getProcessTasks(processInstanceId, null).subscribe( + this.processService.getProcessTasks(processInstanceId, null).subscribe( (res) => { res.forEach((task) => { this.taskObserver.next(task); @@ -116,7 +115,7 @@ export class ProcessInstanceTasksComponent implements OnInit, OnChanges, OnDestr loadCompleted(processInstanceId: string) { this.completedTasks = []; if (processInstanceId) { - this.activitiProcess.getProcessTasks(processInstanceId, 'completed').subscribe( + this.processService.getProcessTasks(processInstanceId, 'completed').subscribe( (res) => { res.forEach((task) => { this.completedTaskObserver.next(task); @@ -146,8 +145,7 @@ export class ProcessInstanceTasksComponent implements OnInit, OnChanges, OnDestr const datePipe = new DatePipe('en-US'); try { return datePipe.transform(value, format); - } catch (err) { - this.logService.error(`ProcessListInstanceTask: error parsing date ${value} to format ${format}`); + } catch { return value; } } diff --git a/lib/process-services/src/lib/process-list/components/process-list.component.spec.ts b/lib/process-services/src/lib/process-list/components/process-list.component.spec.ts index bc960a3b9cb..c8be203e340 100644 --- a/lib/process-services/src/lib/process-list/components/process-list.component.spec.ts +++ b/lib/process-services/src/lib/process-list/components/process-list.component.spec.ts @@ -21,25 +21,24 @@ import { of, throwError, Subject } from 'rxjs'; import { By } from '@angular/platform-browser'; import { ProcessInstanceListComponent } from './process-list.component'; import { - AppConfigService, DataRow, DataColumn, - DataRowEvent, ObjectDataRow, ObjectDataTableAdapter, DataCellEvent, ObjectDataColumn + AppConfigService, + DataRow, + DataColumn, + DataRowEvent, + ObjectDataRow, + ObjectDataTableAdapter, + DataCellEvent, + ObjectDataColumn } from '@alfresco/adf-core'; -import { - fakeProcessInstance, - fakeProcessInstancesWithNoName, - fakeProcessInstancesEmpty, - fakeProcessColumnSchema -} from '../../mock'; +import { fakeProcessInstance, fakeProcessInstancesWithNoName, fakeProcessInstancesEmpty, fakeProcessColumnSchema } from '../../mock'; import { ProcessService } from '../services/process.service'; import { ProcessTestingModule } from '../../testing/process.testing.module'; -import { TranslateModule } from '@ngx-translate/core'; import { HarnessLoader } from '@angular/cdk/testing'; import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed'; import { MatProgressSpinnerHarness } from '@angular/material/progress-spinner/testing'; import { MatMenuItemHarness } from '@angular/material/menu/testing'; describe('ProcessInstanceListComponent', () => { - let fixture: ComponentFixture; let component: ProcessInstanceListComponent; let loader: HarnessLoader; @@ -57,10 +56,7 @@ describe('ProcessInstanceListComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - ProcessTestingModule - ] + imports: [ProcessTestingModule] }); fixture = TestBed.createComponent(ProcessInstanceListComponent); component = fixture.componentInstance; @@ -87,12 +83,7 @@ describe('ProcessInstanceListComponent', () => { }); it('should use the schemaColumn passed in input', () => { - component.data = new ObjectDataTableAdapter( - [], - [ - {type: 'text', key: 'fake-id', title: 'Name'} - ] - ); + component.data = new ObjectDataTableAdapter([], [{ type: 'text', key: 'fake-id', title: 'Name' }]); component.ngAfterContentInit(); expect(component.data.getColumns()).toBeDefined(); @@ -132,12 +123,7 @@ describe('ProcessInstanceListComponent', () => { })); it('should return the process instances list in original order when datalist passed non-existent columns', (done) => { - component.data = new ObjectDataTableAdapter( - [], - [ - {type: 'text', key: 'fake-id', title: 'Name'} - ] - ); + component.data = new ObjectDataTableAdapter([], [{ type: 'text', key: 'fake-id', title: 'Name' }]); component.appId = 1; component.state = 'open'; component.success.subscribe((res) => { @@ -170,11 +156,10 @@ describe('ProcessInstanceListComponent', () => { }); it('should return selected true for the selected process', () => { - component.rows = - [ - { id: '999', name: 'Fake-name' }, - { id: '888', name: 'Fake-name-888' } - ]; + component.rows = [ + { id: '999', name: 'Fake-name' }, + { id: '888', name: 'Fake-name-888' } + ]; component.selectFirst(); const dataRow = component.rows[0]; expect(dataRow).toBeDefined(); @@ -182,11 +167,10 @@ describe('ProcessInstanceListComponent', () => { }); it('should not select first row when selectFirstRow is false', () => { - component.rows = - [ - { id: '999', name: 'Fake-name' }, - { id: '888', name: 'Fake-name-888' } - ]; + component.rows = [ + { id: '999', name: 'Fake-name' }, + { id: '888', name: 'Fake-name-888' } + ]; component.selectFirstRow = false; component.selectFirst(); const dataRow = component.rows; @@ -216,14 +200,9 @@ describe('ProcessInstanceListComponent', () => { })); it('should reload processes when reload() is called', (done) => { - component.data = new ObjectDataTableAdapter( - [], - [ - {type: 'text', key: 'fake-id', title: 'Name'} - ] - ); + component.data = new ObjectDataTableAdapter([], [{ type: 'text', key: 'fake-id', title: 'Name' }]); component.state = 'open'; - component.success.subscribe( (res) => { + component.success.subscribe((res) => { expect(res).toBeDefined(); expect(component.rows).toBeDefined(); expect(component.isListEmpty()).not.toBeTruthy(); @@ -251,12 +230,14 @@ describe('ProcessInstanceListComponent', () => { it('should emit row click event on Enter', (done) => { let prevented = false; - const keyEvent = new CustomEvent('Keyboard event', { detail: { - keyboardEvent: { key: 'Enter' }, - row: new ObjectDataRow({ id: '999' }) - }}); + const keyEvent = new CustomEvent('Keyboard event', { + detail: { + keyboardEvent: { key: 'Enter' }, + row: new ObjectDataRow({ id: '999' }) + } + }); - spyOn(keyEvent, 'preventDefault').and.callFake(() => prevented = true); + spyOn(keyEvent, 'preventDefault').and.callFake(() => (prevented = true)); component.rowClick.subscribe((taskId: string) => { expect(taskId).toEqual('999'); @@ -270,12 +251,14 @@ describe('ProcessInstanceListComponent', () => { it('should NOT emit row click event on every other key', async () => { let triggered = false; - const keyEvent = new CustomEvent('Keyboard event', { detail: { - keyboardEvent: { key: 'Space' }, - row: new ObjectDataRow({ id: 999 }) - }}); + const keyEvent = new CustomEvent('Keyboard event', { + detail: { + keyboardEvent: { key: 'Space' }, + row: new ObjectDataRow({ id: 999 }) + } + }); - component.rowClick.subscribe(() => triggered = true); + component.rowClick.subscribe(() => (triggered = true)); component.onRowKeyUp(keyEvent); fixture.detectChanges(); @@ -309,14 +292,8 @@ describe('ProcessInstanceListComponent', () => { }); describe('component changes', () => { - beforeEach(() => { - component.data = new ObjectDataTableAdapter( - [], - [ - {type: 'text', key: 'fake-id', title: 'Name'} - ] - ); + component.data = new ObjectDataTableAdapter([], [{ type: 'text', key: 'fake-id', title: 'Name' }]); }); it('should NOT reload the process list when no parameters changed', () => { @@ -338,7 +315,7 @@ describe('ProcessInstanceListComponent', () => { done(); }); - component.ngOnChanges({appId: change}); + component.ngOnChanges({ appId: change }); }); it('should reload the list when the state parameter changes', (done) => { @@ -354,7 +331,7 @@ describe('ProcessInstanceListComponent', () => { done(); }); - component.ngOnChanges({state: change}); + component.ngOnChanges({ state: change }); }); it('should reload the list when the sort parameter changes', (done) => { @@ -370,7 +347,7 @@ describe('ProcessInstanceListComponent', () => { done(); }); - component.ngOnChanges({sort: change}); + component.ngOnChanges({ sort: change }); }); it('should reload the process list when the processDefinitionId parameter changes', (done) => { @@ -386,7 +363,7 @@ describe('ProcessInstanceListComponent', () => { done(); }); - component.ngOnChanges({processDefinitionId: change}); + component.ngOnChanges({ processDefinitionId: change }); }); it('should reload the process list when the processDefinitionId parameter changes to null', (done) => { @@ -402,7 +379,7 @@ describe('ProcessInstanceListComponent', () => { done(); }); - component.ngOnChanges({processDefinitionId: change}); + component.ngOnChanges({ processDefinitionId: change }); }); it('should reload the process list when the processInstanceId parameter changes', (done) => { @@ -418,7 +395,7 @@ describe('ProcessInstanceListComponent', () => { done(); }); - component.ngOnChanges({processInstanceId: change}); + component.ngOnChanges({ processInstanceId: change }); }); it('should reload the process list when the processInstanceId parameter changes to null', (done) => { @@ -434,7 +411,7 @@ describe('ProcessInstanceListComponent', () => { done(); }); - component.ngOnChanges({processInstanceId: change}); + component.ngOnChanges({ processInstanceId: change }); }); it('should update the columns when presetColumn schema changes', () => { @@ -461,22 +438,19 @@ describe('ProcessInstanceListComponent', () => { }); @Component({ - template: ` - + template: ` -
{{entry.row.obj.startedBy | fullName}}
+
{{ entry.row.obj.startedBy | fullName }}
` }) - class CustomProcessListComponent { - @ViewChild(ProcessInstanceListComponent) processList: ProcessInstanceListComponent; } @@ -487,10 +461,7 @@ describe('CustomProcessListComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - ProcessTestingModule - ], + imports: [ProcessTestingModule], declarations: [CustomProcessListComponent] }); fixture = TestBed.createComponent(CustomProcessListComponent); @@ -510,25 +481,21 @@ describe('CustomProcessListComponent', () => { @Component({ template: ` - - -

No Process Instance

-
-
- ` + + +

No Process Instance

+
+
+ ` }) -class EmptyTemplateComponent { -} +class EmptyTemplateComponent {} describe('Process List: Custom EmptyTemplateComponent', () => { let fixture: ComponentFixture; let processService: ProcessService; beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - ProcessTestingModule - ], + imports: [ProcessTestingModule], declarations: [EmptyTemplateComponent] }); fixture = TestBed.createComponent(EmptyTemplateComponent); @@ -554,18 +521,18 @@ describe('Process List: Custom EmptyTemplateComponent', () => { }); @Component({ - template: ` - + template: ` -
{{entry.row.obj.startedBy | fullName}}
+
{{ entry.row.obj.startedBy | fullName }}
@@ -587,8 +554,7 @@ class ProcessListContextMenuComponent implements OnInit { event.value.actions = [ { data: event.value.row['obj'], - model: - { + model: { key: 'processDetails', icon: 'open', title: 'View Process Details', @@ -598,8 +564,7 @@ class ProcessListContextMenuComponent implements OnInit { }, { data: event.value.row['obj'], - model: - { + model: { key: 'cancel', icon: 'open', title: 'Cancel Process', @@ -611,10 +576,9 @@ class ProcessListContextMenuComponent implements OnInit { } performContextActions() { - this.performAction$ - .subscribe((action: any) => { + this.performAction$.subscribe((action: any) => { this.contextAction.emit(action.data); - }); + }); } } @@ -627,10 +591,7 @@ describe('ProcessListContextMenuComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - ProcessTestingModule - ], + imports: [ProcessTestingModule], declarations: [ProcessListContextMenuComponent] }); fixture = TestBed.createComponent(ProcessListContextMenuComponent); @@ -648,7 +609,7 @@ describe('ProcessListContextMenuComponent', () => { }); it('Should be able to show context menu on process list', async () => { - const contextMenu = element.querySelector(`[data-automation-id="text_${fakeProcessInstance.data[0].name}"]`); + const contextMenu = element.querySelector(`[data-automation-id="text_${fakeProcessInstance.data[0].name}"]`); const contextActionSpy = spyOn(customComponent.contextAction, 'emit').and.callThrough(); contextMenu.dispatchEvent(new MouseEvent('contextmenu', { bubbles: true })); @@ -659,5 +620,5 @@ describe('ProcessListContextMenuComponent', () => { await contextActions[0].click(); expect(contextActionSpy).toHaveBeenCalled(); - }); + }); }); diff --git a/lib/process-services/src/lib/process-list/components/start-process.component.spec.ts b/lib/process-services/src/lib/process-list/components/start-process.component.spec.ts index 01ab86bfb03..58aad61c87a 100644 --- a/lib/process-services/src/lib/process-list/components/start-process.component.spec.ts +++ b/lib/process-services/src/lib/process-list/components/start-process.component.spec.ts @@ -26,7 +26,6 @@ import { ProcessService } from '../services/process.service'; import { newProcess, taskFormMock, testProcessDef, testMultipleProcessDefs, testProcessDefWithForm, testProcessDefinitions } from '../../mock'; import { StartProcessInstanceComponent } from './start-process.component'; import { ProcessTestingModule } from '../../testing/process.testing.module'; -import { TranslateModule } from '@ngx-translate/core'; import { deployedApps } from '../../mock/apps-list.mock'; import { ProcessNamePipe } from '../../pipes/process-name.pipe'; import { ProcessInstance } from '../models/process-instance.model'; @@ -52,7 +51,7 @@ describe('StartProcessComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [TranslateModule.forRoot(), ProcessTestingModule] + imports: [ProcessTestingModule] }); }); @@ -177,7 +176,9 @@ describe('StartProcessComponent', () => { component.processDefinitionInput.setValue('My Default Name'); component.processNameInput.setValue('claim'); - const inputLabels = await loader.getAllHarnesses(MatFormFieldHarness.with({ ancestor: '.adf-start-process', selector: '.adf-process-input-container' })); + const inputLabels = await loader.getAllHarnesses( + MatFormFieldHarness.with({ ancestor: '.adf-start-process', selector: '.adf-process-input-container' }) + ); expect(inputLabels.length).toBe(2); }); diff --git a/lib/process-services/src/lib/process-user-info/process-user-info.component.spec.ts b/lib/process-services/src/lib/process-user-info/process-user-info.component.spec.ts index 04b48f8284d..e60eb134f49 100644 --- a/lib/process-services/src/lib/process-user-info/process-user-info.component.spec.ts +++ b/lib/process-services/src/lib/process-user-info/process-user-info.component.spec.ts @@ -20,7 +20,6 @@ import { fakeEcmUser, fakeEcmUserNoImage } from '@alfresco/adf-content-services' import { ComponentFixture, TestBed } from '@angular/core/testing'; import { MatMenuModule } from '@angular/material/menu'; import { By } from '@angular/platform-browser'; -import { TranslateModule } from '@ngx-translate/core'; import { BpmUserModel } from '../common/models/bpm-user.model'; import { ProcessUserInfoComponent } from './process-user-info.component'; import { fakeBpmUser } from './mocks/bpm-user.service.mock'; @@ -51,11 +50,7 @@ describe('ProcessUserInfoComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - CoreTestingModule, - MatMenuModule - ] + imports: [CoreTestingModule, MatMenuModule] }); fixture = TestBed.createComponent(ProcessUserInfoComponent); component = fixture.componentInstance; @@ -82,7 +77,6 @@ describe('ProcessUserInfoComponent', () => { }); describe('when user is logged on bpm', () => { - beforeEach(async () => { component.bpmUser = fakeBpmUser; component.isLoggedIn = true; @@ -113,7 +107,7 @@ describe('ProcessUserInfoComponent', () => { }); component.bpmUser = wrongBpmUser; await whenFixtureReady(); - const fullNameElement = (element.querySelector('#adf-userinfo-bpm-name-display')); + const fullNameElement = element.querySelector('#adf-userinfo-bpm-name-display'); fixture.detectChanges(); expect(element.querySelector('#userinfo_container')).toBeDefined(); expect(element.querySelector('#adf-userinfo-bpm-name-display')).not.toBeNull(); @@ -130,7 +124,6 @@ describe('ProcessUserInfoComponent', () => { }); describe('when user is logged on bpm and ecm', () => { - beforeEach(async () => { component.bpmUser = fakeBpmUser; component.ecmUser = fakeEcmUser as any; @@ -174,7 +167,9 @@ describe('ProcessUserInfoComponent', () => { expect(ecmUsername).not.toBeNull(); expect(ecmImage).not.toBeNull(); expect(ecmImage.properties.src).toContain(profilePictureUrl); - expect(fixture.debugElement.query(By.css('#ecm-full-name')).nativeElement.textContent).toContain('fake-ecm-first-name fake-ecm-last-name'); + expect(fixture.debugElement.query(By.css('#ecm-full-name')).nativeElement.textContent).toContain( + 'fake-ecm-first-name fake-ecm-last-name' + ); expect(fixture.debugElement.query(By.css('#ecm-job-title')).nativeElement.textContent).toContain('job-ecm-test'); }); diff --git a/lib/process-services/src/lib/task-comments/services/task-comments.service.spec.ts b/lib/process-services/src/lib/task-comments/services/task-comments.service.spec.ts index 351748f49c4..fe2bea74a65 100644 --- a/lib/process-services/src/lib/task-comments/services/task-comments.service.spec.ts +++ b/lib/process-services/src/lib/task-comments/services/task-comments.service.spec.ts @@ -18,7 +18,6 @@ import { TestBed } from '@angular/core/testing'; import { CommentModel, CoreTestingModule } from '@alfresco/adf-core'; import { fakeTasksComment, fakeUser1 } from '../mocks/task-comments.mock'; -import { TranslateModule } from '@ngx-translate/core'; import { TaskCommentsService } from './task-comments.service'; declare let jasmine: any; @@ -28,10 +27,7 @@ describe('TaskCommentsService', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - CoreTestingModule - ] + imports: [CoreTestingModule] }); service = TestBed.inject(TaskCommentsService); }); @@ -45,26 +41,24 @@ describe('TaskCommentsService', () => { }); describe('Task comments', () => { - it('should add a comment task ', (done) => { - service.add('999', 'fake-comment-message').subscribe( - (res: CommentModel) => { - expect(res).toBeDefined(); - expect(res.id).not.toEqual(null); - expect(res.message).toEqual('fake-comment-message'); - expect(res.created).not.toEqual(null); - expect(res.createdBy.email).toEqual('fake-email@dom.com'); - expect(res.createdBy.firstName).toEqual('firstName'); - expect(res.createdBy.lastName).toEqual('lastName'); - done(); - } - ); + service.add('999', 'fake-comment-message').subscribe((res: CommentModel) => { + expect(res).toBeDefined(); + expect(res.id).not.toEqual(null); + expect(res.message).toEqual('fake-comment-message'); + expect(res.created).not.toEqual(null); + expect(res.createdBy.email).toEqual('fake-email@dom.com'); + expect(res.createdBy.firstName).toEqual('firstName'); + expect(res.createdBy.lastName).toEqual('lastName'); + done(); + }); jasmine.Ajax.requests.mostRecent().respondWith({ status: 200, contentType: 'application/json', responseText: JSON.stringify({ - id: '111', message: 'fake-comment-message', + id: '111', + message: 'fake-comment-message', createdBy: fakeUser1, created: '2016-07-15T11:19:17.440+0000' }) @@ -72,15 +66,13 @@ describe('TaskCommentsService', () => { }); it('should return the tasks comments ', (done) => { - service.get('999').subscribe( - (res: CommentModel[]) => { - expect(res).toBeDefined(); - expect(res.length).toEqual(2); - expect(res[0].message).toEqual('fake-message-1'); - expect(res[1].message).toEqual('fake-message-2'); - done(); - } - ); + service.get('999').subscribe((res: CommentModel[]) => { + expect(res).toBeDefined(); + expect(res.length).toEqual(2); + expect(res[0].message).toEqual('fake-message-1'); + expect(res[1].message).toEqual('fake-message-2'); + done(); + }); jasmine.Ajax.requests.mostRecent().respondWith({ status: 200, diff --git a/lib/process-services/src/lib/task-list/components/attach-form.component.spec.ts b/lib/process-services/src/lib/task-list/components/attach-form.component.spec.ts index e53e7ed2413..d9c8a21d17b 100644 --- a/lib/process-services/src/lib/task-list/components/attach-form.component.spec.ts +++ b/lib/process-services/src/lib/task-list/components/attach-form.component.spec.ts @@ -21,7 +21,6 @@ import { ProcessTestingModule } from '../../testing/process.testing.module'; import { TaskListService } from './../services/tasklist.service'; import { of } from 'rxjs'; import { By } from '@angular/platform-browser'; -import { TranslateModule } from '@ngx-translate/core'; describe('AttachFormComponent', () => { let component: AttachFormComponent; @@ -31,10 +30,7 @@ describe('AttachFormComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - ProcessTestingModule - ] + imports: [ProcessTestingModule] }); fixture = TestBed.createComponent(AttachFormComponent); component = fixture.componentInstance; @@ -160,14 +156,14 @@ describe('AttachFormComponent', () => { component.taskId = 1; component.attachFormControl.setValue(10); - spyOn(taskService, 'attachFormToATask').and.returnValue(of( - { + spyOn(taskService, 'attachFormToATask').and.returnValue( + of({ id: 91, name: 'fakeName', formKey: 1204, assignee: null - } - )); + }) + ); fixture.detectChanges(); await fixture.whenStable(); diff --git a/lib/process-services/src/lib/task-list/components/attach-form.component.ts b/lib/process-services/src/lib/task-list/components/attach-form.component.ts index fe9846d3998..7178db4fdce 100644 --- a/lib/process-services/src/lib/task-list/components/attach-form.component.ts +++ b/lib/process-services/src/lib/task-list/components/attach-form.component.ts @@ -15,7 +15,6 @@ * limitations under the License. */ -import { LogService } from '@alfresco/adf-core'; import { Component, EventEmitter, Input, OnChanges, OnInit, Output } from '@angular/core'; import { Form } from '../models/form.model'; import { TaskListService } from './../services/tasklist.service'; @@ -28,9 +27,7 @@ import { TaskFormService } from '../../form/services/task-form.service'; templateUrl: './attach-form.component.html', styleUrls: ['./attach-form.component.scss'] }) - export class AttachFormComponent implements OnInit, OnChanges { - /** Id of the task. */ @Input() taskId: any; @@ -59,14 +56,11 @@ export class AttachFormComponent implements OnInit, OnChanges { attachFormControl: UntypedFormControl; - constructor(private taskService: TaskListService, - private logService: LogService, - private modelService: ModelService, - private taskFormService: TaskFormService) { } + constructor(private taskService: TaskListService, private modelService: ModelService, private taskFormService: TaskFormService) {} ngOnInit() { this.attachFormControl = new UntypedFormControl('', Validators.required); - this.attachFormControl.valueChanges.subscribe( (currentValue) => { + this.attachFormControl.valueChanges.subscribe((currentValue) => { if (this.attachFormControl.valid) { this.disableSubmit = this.formId === currentValue; } @@ -95,8 +89,8 @@ export class AttachFormComponent implements OnInit, OnChanges { }, (err) => { this.error.emit(err); - this.logService.error('An error occurred while trying to delete the form'); - }); + } + ); } onAttachFormButtonClick(): void { @@ -104,36 +98,39 @@ export class AttachFormComponent implements OnInit, OnChanges { } private loadFormsTask(): void { - this.taskService.getFormList().subscribe((form: Form[]) => { + this.taskService.getFormList().subscribe( + (form: Form[]) => { this.forms = form; }, (err) => { this.error.emit(err); - this.logService.error('An error occurred while trying to get the forms'); - }); + } + ); } private onFormAttached() { - this.taskFormService.getTaskForm(this.taskId) - .subscribe((res) => { + this.taskFormService.getTaskForm(this.taskId).subscribe( + (res) => { this.modelService.getFormDefinitionByName(res.name).subscribe((formDef) => { this.formId = this.selectedFormId = formDef; }); - }, (err) => { + }, + (err) => { this.error.emit(err); - this.logService.error('Could not load forms'); - }); + } + ); } private attachForm(taskId: string, formId: number) { if (taskId && formId) { - this.taskService.attachFormToATask(taskId, formId) - .subscribe(() => { + this.taskService.attachFormToATask(taskId, formId).subscribe( + () => { this.success.emit(); - }, (err) => { + }, + (err) => { this.error.emit(err); - this.logService.error('Could not attach form'); - }); + } + ); } } } diff --git a/lib/process-services/src/lib/task-list/components/checklist.component.spec.ts b/lib/process-services/src/lib/task-list/components/checklist.component.spec.ts index e76d8fcc45b..984f0e6ef05 100644 --- a/lib/process-services/src/lib/task-list/components/checklist.component.spec.ts +++ b/lib/process-services/src/lib/task-list/components/checklist.component.spec.ts @@ -22,10 +22,8 @@ import { ChecklistComponent } from './checklist.component'; import { ProcessTestingModule } from '../../testing/process.testing.module'; import { TaskListService } from './../services/tasklist.service'; import { of } from 'rxjs'; -import { TranslateModule } from '@ngx-translate/core'; describe('ChecklistComponent', () => { - let checklistComponent: ChecklistComponent; let fixture: ComponentFixture; let element: HTMLElement; @@ -34,16 +32,17 @@ describe('ChecklistComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - ProcessTestingModule - ] + imports: [ProcessTestingModule] }); service = TestBed.inject(TaskListService); - spyOn(service, 'getTaskChecklist').and.returnValue(of([new TaskDetailsModel({ - id: 'fake-check-changed-id', - name: 'fake-check-changed-name' - })])); + spyOn(service, 'getTaskChecklist').and.returnValue( + of([ + new TaskDetailsModel({ + id: 'fake-check-changed-id', + name: 'fake-check-changed-name' + }) + ]) + ); fixture = TestBed.createComponent(ChecklistComponent); checklistComponent = fixture.componentInstance; @@ -63,13 +62,14 @@ describe('ChecklistComponent', () => { }); describe('when is readonly mode', () => { - beforeEach(() => { checklistComponent.taskId = 'fake-task-id'; - checklistComponent.checklist.push(new TaskDetailsModel({ - id: 'fake-check-id', - name: 'fake-check-name' - })); + checklistComponent.checklist.push( + new TaskDetailsModel({ + id: 'fake-check-id', + name: 'fake-check-name' + }) + ); checklistComponent.readOnly = true; fixture.detectChanges(); @@ -86,14 +86,15 @@ describe('ChecklistComponent', () => { }); describe('when is not in readonly mode', () => { - beforeEach(() => { checklistComponent.taskId = 'fake-task-id'; checklistComponent.readOnly = false; - checklistComponent.checklist.push(new TaskDetailsModel({ - id: 'fake-check-id', - name: 'fake-check-name' - })); + checklistComponent.checklist.push( + new TaskDetailsModel({ + id: 'fake-check-id', + name: 'fake-check-name' + }) + ); fixture.detectChanges(); showChecklistDialog = element.querySelector('#add-checklist'); @@ -109,7 +110,6 @@ describe('ChecklistComponent', () => { }); describe('when interact with checklist dialog', () => { - beforeEach(() => { checklistComponent.taskId = 'fake-task-id'; checklistComponent.checklist = []; @@ -132,7 +132,6 @@ describe('ChecklistComponent', () => { }); describe('when there are task checklist', () => { - beforeEach(() => { checklistComponent.taskId = 'fake-task-id'; checklistComponent.checklist = []; @@ -148,25 +147,31 @@ describe('ChecklistComponent', () => { }); it('should show task checklist', () => { - checklistComponent.checklist.push(new TaskDetailsModel({ - id: 'fake-check-id', - name: 'fake-check-name' - })); + checklistComponent.checklist.push( + new TaskDetailsModel({ + id: 'fake-check-id', + name: 'fake-check-name' + }) + ); fixture.detectChanges(); expect(element.querySelector('#check-fake-check-id')).not.toBeNull(); expect(element.querySelector('#check-fake-check-id').textContent).toContain('fake-check-name'); }); it('should not show delete icon when checklist task is completed', () => { - checklistComponent.checklist.push(new TaskDetailsModel({ - id: 'fake-check-id', - name: 'fake-check-name' - })); - checklistComponent.checklist.push(new TaskDetailsModel({ - id: 'fake-completed-id', - name: 'fake-completed-name', - endDate: '2018-05-23T11:25:14.552+0000' - })); + checklistComponent.checklist.push( + new TaskDetailsModel({ + id: 'fake-check-id', + name: 'fake-check-name' + }) + ); + checklistComponent.checklist.push( + new TaskDetailsModel({ + id: 'fake-completed-id', + name: 'fake-completed-name', + endDate: '2018-05-23T11:25:14.552+0000' + }) + ); fixture.detectChanges(); expect(element.querySelector('#remove-fake-check-id')).not.toBeNull(); expect(element.querySelector('#check-fake-completed-id')).not.toBeNull(); @@ -175,9 +180,14 @@ describe('ChecklistComponent', () => { }); it('should add checklist', async () => { - spyOn(service, 'addTask').and.returnValue(of(new TaskDetailsModel({ - id: 'fake-check-added-id', name: 'fake-check-added-name' - }))); + spyOn(service, 'addTask').and.returnValue( + of( + new TaskDetailsModel({ + id: 'fake-check-added-id', + name: 'fake-check-added-name' + }) + ) + ); showChecklistDialog.click(); const addButtonDialog = window.document.querySelector('#add-check'); @@ -194,10 +204,12 @@ describe('ChecklistComponent', () => { spyOn(service, 'deleteTask').and.returnValue(of(null)); checklistComponent.taskId = 'new-fake-task-id'; - checklistComponent.checklist.push(new TaskDetailsModel({ - id: 'fake-check-id', - name: 'fake-check-name' - })); + checklistComponent.checklist.push( + new TaskDetailsModel({ + id: 'fake-check-id', + name: 'fake-check-name' + }) + ); fixture.detectChanges(); await fixture.whenStable(); @@ -216,10 +228,12 @@ describe('ChecklistComponent', () => { it('should send an event when the checklist is deleted', async () => { spyOn(service, 'deleteTask').and.returnValue(of(null)); checklistComponent.taskId = 'new-fake-task-id'; - checklistComponent.checklist.push(new TaskDetailsModel({ - id: 'fake-check-id', - name: 'fake-check-name' - })); + checklistComponent.checklist.push( + new TaskDetailsModel({ + id: 'fake-check-id', + name: 'fake-check-name' + }) + ); fixture.detectChanges(); await fixture.whenStable(); @@ -235,10 +249,12 @@ describe('ChecklistComponent', () => { it('should show load task checklist on change', async () => { checklistComponent.taskId = 'new-fake-task-id'; - checklistComponent.checklist.push(new TaskDetailsModel({ - id: 'fake-check-id', - name: 'fake-check-name' - })); + checklistComponent.checklist.push( + new TaskDetailsModel({ + id: 'fake-check-id', + name: 'fake-check-name' + }) + ); fixture.detectChanges(); const change = new SimpleChange(null, 'new-fake-task-id', true); checklistComponent.ngOnChanges({ @@ -254,10 +270,12 @@ describe('ChecklistComponent', () => { it('should show empty checklist when task id is null', async () => { checklistComponent.taskId = 'new-fake-task-id'; - checklistComponent.checklist.push(new TaskDetailsModel({ - id: 'fake-check-id', - name: 'fake-check-name' - })); + checklistComponent.checklist.push( + new TaskDetailsModel({ + id: 'fake-check-id', + name: 'fake-check-name' + }) + ); fixture.detectChanges(); await fixture.whenStable(); diff --git a/lib/process-services/src/lib/task-list/components/no-task-detail-template.directive.spec.ts b/lib/process-services/src/lib/task-list/components/no-task-detail-template.directive.spec.ts index db30e33d928..01dc1f033b6 100644 --- a/lib/process-services/src/lib/task-list/components/no-task-detail-template.directive.spec.ts +++ b/lib/process-services/src/lib/task-list/components/no-task-detail-template.directive.spec.ts @@ -19,12 +19,11 @@ import { NoTaskDetailsTemplateDirective } from './no-task-detail-template.direct import { TaskDetailsComponent } from './task-details.component'; describe('NoTaskDetailsTemplateDirective', () => { - let component: NoTaskDetailsTemplateDirective; let detailsComponent: TaskDetailsComponent; beforeEach(() => { - detailsComponent = new TaskDetailsComponent(null, null, null, null, null); + detailsComponent = new TaskDetailsComponent(null, null, null, null); component = new NoTaskDetailsTemplateDirective(detailsComponent); }); diff --git a/lib/process-services/src/lib/task-list/components/start-task.component.spec.ts b/lib/process-services/src/lib/task-list/components/start-task.component.spec.ts index 9e245164871..7c4732fa464 100644 --- a/lib/process-services/src/lib/task-list/components/start-task.component.spec.ts +++ b/lib/process-services/src/lib/task-list/components/start-task.component.spec.ts @@ -16,14 +16,12 @@ */ import { ComponentFixture, TestBed } from '@angular/core/testing'; -import { LogService } from '@alfresco/adf-core'; import { of, throwError } from 'rxjs'; import { TaskListService } from '../services/tasklist.service'; import { StartTaskComponent } from './start-task.component'; import { ProcessTestingModule } from '../../testing/process.testing.module'; import { taskDetailsMock } from '../../mock/task/task-details.mock'; import { TaskDetailsModel } from '../models/task-details.model'; -import { TranslateModule } from '@ngx-translate/core'; import { HarnessLoader } from '@angular/cdk/testing'; import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed'; import { MatButtonHarness } from '@angular/material/button/testing'; @@ -33,11 +31,9 @@ describe('StartTaskComponent', () => { let fixture: ComponentFixture; let loader: HarnessLoader; let service: TaskListService; - let logService: LogService; let element: HTMLElement; let getFormListSpy: jasmine.Spy; let createNewTaskSpy: jasmine.Spy; - let logSpy: jasmine.Spy; const fakeForms$ = [ { @@ -54,7 +50,7 @@ describe('StartTaskComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [TranslateModule.forRoot(), ProcessTestingModule] + imports: [ProcessTestingModule] }); fixture = TestBed.createComponent(StartTaskComponent); component = fixture.componentInstance; @@ -62,7 +58,6 @@ describe('StartTaskComponent', () => { loader = TestbedHarnessEnvironment.loader(fixture); service = TestBed.inject(TaskListService); - logService = TestBed.inject(LogService); getFormListSpy = spyOn(service, 'getFormList').and.returnValue(of(fakeForms$)); @@ -406,14 +401,6 @@ describe('StartTaskComponent', () => { expect(name.valid).toBeTruthy(); }); - it('should call logService when task name exceeds maximum length', () => { - logSpy = spyOn(logService, 'log').and.callThrough(); - component.maxTaskNameLength = 300; - component.ngOnInit(); - fixture.detectChanges(); - expect(logSpy).toHaveBeenCalled(); - }); - it('should emit error when description have only white spaces', () => { fixture.detectChanges(); const description = component.taskForm.controls['description']; diff --git a/lib/process-services/src/lib/task-list/components/start-task.component.ts b/lib/process-services/src/lib/task-list/components/start-task.component.ts index 054b5b0ff7f..fa33dfb5ba5 100644 --- a/lib/process-services/src/lib/task-list/components/start-task.component.ts +++ b/lib/process-services/src/lib/task-list/components/start-task.component.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { LogService, FormFieldModel, FormModel, DateFnsUtils, AdfDateFnsAdapter, ADF_DATE_FORMATS } from '@alfresco/adf-core'; +import { FormFieldModel, FormModel, DateFnsUtils, AdfDateFnsAdapter, ADF_DATE_FORMATS } from '@alfresco/adf-core'; import { Component, EventEmitter, Input, OnInit, Output, ViewEncapsulation, OnDestroy } from '@angular/core'; import { DateAdapter, MAT_DATE_FORMATS } from '@angular/material/core'; import { EMPTY, Observable, Subject } from 'rxjs'; @@ -36,7 +36,8 @@ const MAX_LENGTH = 255; styleUrls: ['./start-task.component.scss'], providers: [ { provide: DateAdapter, useClass: AdfDateFnsAdapter }, - { provide: MAT_DATE_FORMATS, useValue: ADF_DATE_FORMATS }], + { provide: MAT_DATE_FORMATS, useValue: ADF_DATE_FORMATS } + ], encapsulation: ViewEncapsulation.None }) export class StartTaskComponent implements OnInit, OnDestroy { @@ -71,10 +72,7 @@ export class StartTaskComponent implements OnInit, OnDestroy { private onDestroy$ = new Subject(); - constructor(private taskService: TaskListService, - private formBuilder: UntypedFormBuilder, - private logService: LogService) { - } + constructor(private taskService: TaskListService, private formBuilder: UntypedFormBuilder) {} ngOnInit() { if (this.name) { @@ -96,20 +94,22 @@ export class StartTaskComponent implements OnInit, OnDestroy { buildForm(): void { this.taskForm = this.formBuilder.group({ - name: new UntypedFormControl(this.taskDetailsModel.name, [Validators.required, Validators.maxLength(this.maxTaskNameLength), this.whitespaceValidator]), + name: new UntypedFormControl(this.taskDetailsModel.name, [ + Validators.required, + Validators.maxLength(this.maxTaskNameLength), + this.whitespaceValidator + ]), description: new UntypedFormControl('', [this.whitespaceValidator]), formKey: new UntypedFormControl('') }); - this.taskForm.valueChanges - .pipe(takeUntil(this.onDestroy$)) - .subscribe(taskFormValues => this.setTaskDetails(taskFormValues)); + this.taskForm.valueChanges.pipe(takeUntil(this.onDestroy$)).subscribe((taskFormValues) => this.setTaskDetails(taskFormValues)); } whitespaceValidator(control: UntypedFormControl): any { if (control.value) { const isWhitespace = (control.value || '').trim().length === 0; - const isControlValid = control.value.length === 0 || !isWhitespace; + const isControlValid = control.value.length === 0 || !isWhitespace; return isControlValid ? null : { whitespace: true }; } return null; @@ -130,15 +130,14 @@ export class StartTaskComponent implements OnInit, OnDestroy { if (this.appId) { this.taskDetailsModel.category = this.appId.toString(); } - this.taskService.createNewTask(this.taskDetailsModel) + this.taskService + .createNewTask(this.taskDetailsModel) .pipe( switchMap((createRes) => this.attachForm(createRes.id, this.taskDetailsModel.formKey).pipe( defaultIfEmpty(createRes), switchMap((attachRes) => - this.assignTaskByUserId(createRes.id, this.assigneeId).pipe( - defaultIfEmpty(attachRes ? attachRes : createRes) - ) + this.assignTaskByUserId(createRes.id, this.assigneeId).pipe(defaultIfEmpty(attachRes ? attachRes : createRes)) ) ) ) @@ -151,8 +150,8 @@ export class StartTaskComponent implements OnInit, OnDestroy { (err) => { this.loading = false; this.error.emit(err); - this.logService.error('An error occurred while creating new task'); - }); + } + ); } getAssigneeId(userId: number): void { @@ -168,8 +167,8 @@ export class StartTaskComponent implements OnInit, OnDestroy { } getDisplayUser(firstName: string, lastName: string, delimiter: string = '-'): string { - firstName = (firstName !== null ? firstName : ''); - lastName = (lastName !== null ? lastName : ''); + firstName = firstName !== null ? firstName : ''; + lastName = lastName !== null ? lastName : ''; return firstName + delimiter + lastName; } @@ -199,7 +198,6 @@ export class StartTaskComponent implements OnInit, OnDestroy { private validateMaxTaskNameLength() { if (this.maxTaskNameLength > MAX_LENGTH) { this.maxTaskNameLength = MAX_LENGTH; - this.logService.log(`the task name length cannot be greater than ${MAX_LENGTH}`); } } diff --git a/lib/process-services/src/lib/task-list/components/task-audit.directive.spec.ts b/lib/process-services/src/lib/task-list/components/task-audit.directive.spec.ts index 4cc2d1c1142..17cf79cfa07 100644 --- a/lib/process-services/src/lib/task-list/components/task-audit.directive.spec.ts +++ b/lib/process-services/src/lib/task-list/components/task-audit.directive.spec.ts @@ -20,26 +20,25 @@ import { ComponentFixture, fakeAsync, TestBed } from '@angular/core/testing'; import { of } from 'rxjs'; import { TaskListService } from './../services/tasklist.service'; import { ProcessTestingModule } from '../../testing/process.testing.module'; -import { TranslateModule } from '@ngx-translate/core'; declare let jasmine: any; describe('TaskAuditDirective', () => { - @Component({ selector: 'adf-basic-button', - template: ` - ` }) class BasicButtonComponent { - download: boolean = false; fileName: string; format: string; @@ -54,27 +53,25 @@ describe('TaskAuditDirective', () => { const createFakePdfBlob = (): Blob => { const pdfData = atob( 'JVBERi0xLjcKCjEgMCBvYmogICUgZW50cnkgcG9pbnQKPDwKICAvVHlwZSAvQ2F0YWxvZwog' + - 'IC9QYWdlcyAyIDAgUgo+PgplbmRvYmoKCjIgMCBvYmoKPDwKICAvVHlwZSAvUGFnZXMKICAv' + - 'TWVkaWFCb3ggWyAwIDAgMjAwIDIwMCBdCiAgL0NvdW50IDEKICAvS2lkcyBbIDMgMCBSIF0K' + - 'Pj4KZW5kb2JqCgozIDAgb2JqCjw8CiAgL1R5cGUgL1BhZ2UKICAvUGFyZW50IDIgMCBSCiAg' + - 'L1Jlc291cmNlcyA8PAogICAgL0ZvbnQgPDwKICAgICAgL0YxIDQgMCBSIAogICAgPj4KICA+' + - 'PgogIC9Db250ZW50cyA1IDAgUgo+PgplbmRvYmoKCjQgMCBvYmoKPDwKICAvVHlwZSAvRm9u' + - 'dAogIC9TdWJ0eXBlIC9UeXBlMQogIC9CYXNlRm9udCAvVGltZXMtUm9tYW4KPj4KZW5kb2Jq' + - 'Cgo1IDAgb2JqICAlIHBhZ2UgY29udGVudAo8PAogIC9MZW5ndGggNDQKPj4Kc3RyZWFtCkJU' + - 'CjcwIDUwIFRECi9GMSAxMiBUZgooSGVsbG8sIHdvcmxkISkgVGoKRVQKZW5kc3RyZWFtCmVu' + - 'ZG9iagoKeHJlZgowIDYKMDAwMDAwMDAwMCA2NTUzNSBmIAowMDAwMDAwMDEwIDAwMDAwIG4g' + - 'CjAwMDAwMDAwNzkgMDAwMDAgbiAKMDAwMDAwMDE3MyAwMDAwMCBuIAowMDAwMDAwMzAxIDAw' + - 'MDAwIG4gCjAwMDAwMDAzODAgMDAwMDAgbiAKdHJhaWxlcgo8PAogIC9TaXplIDYKICAvUm9v' + - 'dCAxIDAgUgo+PgpzdGFydHhyZWYKNDkyCiUlRU9G'); - return new Blob([pdfData], {type: 'application/pdf'}); + 'IC9QYWdlcyAyIDAgUgo+PgplbmRvYmoKCjIgMCBvYmoKPDwKICAvVHlwZSAvUGFnZXMKICAv' + + 'TWVkaWFCb3ggWyAwIDAgMjAwIDIwMCBdCiAgL0NvdW50IDEKICAvS2lkcyBbIDMgMCBSIF0K' + + 'Pj4KZW5kb2JqCgozIDAgb2JqCjw8CiAgL1R5cGUgL1BhZ2UKICAvUGFyZW50IDIgMCBSCiAg' + + 'L1Jlc291cmNlcyA8PAogICAgL0ZvbnQgPDwKICAgICAgL0YxIDQgMCBSIAogICAgPj4KICA+' + + 'PgogIC9Db250ZW50cyA1IDAgUgo+PgplbmRvYmoKCjQgMCBvYmoKPDwKICAvVHlwZSAvRm9u' + + 'dAogIC9TdWJ0eXBlIC9UeXBlMQogIC9CYXNlRm9udCAvVGltZXMtUm9tYW4KPj4KZW5kb2Jq' + + 'Cgo1IDAgb2JqICAlIHBhZ2UgY29udGVudAo8PAogIC9MZW5ndGggNDQKPj4Kc3RyZWFtCkJU' + + 'CjcwIDUwIFRECi9GMSAxMiBUZgooSGVsbG8sIHdvcmxkISkgVGoKRVQKZW5kc3RyZWFtCmVu' + + 'ZG9iagoKeHJlZgowIDYKMDAwMDAwMDAwMCA2NTUzNSBmIAowMDAwMDAwMDEwIDAwMDAwIG4g' + + 'CjAwMDAwMDAwNzkgMDAwMDAgbiAKMDAwMDAwMDE3MyAwMDAwMCBuIAowMDAwMDAwMzAxIDAw' + + 'MDAwIG4gCjAwMDAwMDAzODAgMDAwMDAgbiAKdHJhaWxlcgo8PAogIC9TaXplIDYKICAvUm9v' + + 'dCAxIDAgUgo+PgpzdGFydHhyZWYKNDkyCiUlRU9G' + ); + return new Blob([pdfData], { type: 'application/pdf' }); }; beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - ProcessTestingModule - ], + imports: [ProcessTestingModule], declarations: [BasicButtonComponent] }); fixture = TestBed.createComponent(BasicButtonComponent); @@ -105,7 +102,6 @@ describe('TaskAuditDirective', () => { }); button.click(); - })); it('should fetch the json info when the format is json', fakeAsync(() => { @@ -113,7 +109,14 @@ describe('TaskAuditDirective', () => { component.format = 'json'; component.download = true; - const auditJson = { taskId: '77', taskName: 'Fake Task Name', assignee: 'FirstName LastName', formData: [], selectedOutcome: null, comments: [] }; + const auditJson = { + taskId: '77', + taskName: 'Fake Task Name', + assignee: 'FirstName LastName', + formData: [], + selectedOutcome: null, + comments: [] + }; spyOn(service, 'fetchTaskAuditJsonById').and.returnValue(of(auditJson)); spyOn(component, 'onAuditClick').and.callThrough(); @@ -127,7 +130,6 @@ describe('TaskAuditDirective', () => { }); button.click(); - })); it('should fetch the pdf Blob as default when the format is UNKNOWN', fakeAsync(() => { @@ -147,6 +149,5 @@ describe('TaskAuditDirective', () => { }); button.click(); - })); }); diff --git a/lib/process-services/src/lib/task-list/components/task-details.component.spec.ts b/lib/process-services/src/lib/task-list/components/task-details.component.spec.ts index b4243f30f88..e7730ca36f6 100644 --- a/lib/process-services/src/lib/task-list/components/task-details.component.spec.ts +++ b/lib/process-services/src/lib/task-list/components/task-details.component.spec.ts @@ -25,7 +25,6 @@ import { noDataMock, taskDetailsMock, taskFormMock, tasksMock, taskDetailsWithOu import { TaskListService } from './../services/tasklist.service'; import { TaskDetailsComponent } from './task-details.component'; import { ProcessTestingModule } from '../../testing/process.testing.module'; -import { TranslateModule } from '@ngx-translate/core'; import { TaskService } from '../../form/services/task.service'; import { TaskFormService } from '../../form/services/task-form.service'; import { TaskCommentsService } from '../../task-comments/services/task-comments.service'; @@ -65,7 +64,7 @@ describe('TaskDetailsComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [TranslateModule.forRoot(), ProcessTestingModule], + imports: [ProcessTestingModule], schemas: [NO_ERRORS_SCHEMA] }); peopleProcessService = TestBed.inject(PeopleProcessService); diff --git a/lib/process-services/src/lib/task-list/components/task-details.component.ts b/lib/process-services/src/lib/task-list/components/task-details.component.ts index d3b138420b4..d939bf2c47f 100644 --- a/lib/process-services/src/lib/task-list/components/task-details.component.ts +++ b/lib/process-services/src/lib/task-list/components/task-details.component.ts @@ -23,7 +23,6 @@ import { FormFieldValidator, FormModel, FormOutcomeEvent, - LogService, UpdateNotification } from '@alfresco/adf-core'; import { @@ -191,7 +190,6 @@ export class TaskDetailsComponent implements OnInit, OnChanges, OnDestroy { constructor( private taskListService: TaskListService, private peopleProcessService: PeopleProcessService, - private logService: LogService, private cardViewUpdateService: CardViewUpdateService, private dialog: MatDialog ) {} @@ -310,13 +308,10 @@ export class TaskDetailsComponent implements OnInit, OnChanges, OnDestroy { } searchUser(searchedWord: string) { - this.peopleProcessService.getWorkflowUsers(null, searchedWord).subscribe( - (users) => { - users = users.filter((user) => user.id !== this.taskDetails.assignee.id); - this.peopleSearchObserver.next(users); - }, - () => this.logService.error('Could not load users') - ); + this.peopleProcessService.getWorkflowUsers(null, searchedWord).subscribe((users) => { + users = users.filter((user) => user.id !== this.taskDetails.assignee.id); + this.peopleSearchObserver.next(users); + }); } onCloseSearch() { @@ -325,7 +320,6 @@ export class TaskDetailsComponent implements OnInit, OnChanges, OnDestroy { assignTaskToUser(selectedUser: UserProcessModel) { this.taskListService.assignTask(this.taskDetails.id, selectedUser).subscribe(() => { - this.logService.info('Task Assigned to ' + selectedUser.email); this.assignTask.emit(); }); this.showAssignee = false; diff --git a/lib/process-services/src/lib/task-list/components/task-filters.component.spec.ts b/lib/process-services/src/lib/task-list/components/task-filters.component.spec.ts index 6a468dbecaf..25f6d601d06 100644 --- a/lib/process-services/src/lib/task-list/components/task-filters.component.spec.ts +++ b/lib/process-services/src/lib/task-list/components/task-filters.component.spec.ts @@ -26,13 +26,11 @@ import { TaskFilterService } from '../services/task-filter.service'; import { TaskFiltersComponent } from './task-filters.component'; import { ProcessTestingModule } from '../../testing/process.testing.module'; import { By } from '@angular/platform-browser'; -import { TranslateModule } from '@ngx-translate/core'; import { fakeTaskFilters } from '../../mock/task/task-filters.mock'; import { NavigationStart, Router } from '@angular/router'; import { RouterTestingModule } from '@angular/router/testing'; describe('TaskFiltersComponent', () => { - let taskListService: TaskListService; let taskFilterService: TaskFilterService; let appsProcessService: AppsProcessService; @@ -42,11 +40,7 @@ describe('TaskFiltersComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - ProcessTestingModule, - RouterTestingModule - ] + imports: [ProcessTestingModule, RouterTestingModule] }); const appConfig: AppConfigService = TestBed.inject(AppConfigService); appConfig.config.bpmHost = 'http://localhost:9876/bpm'; @@ -67,11 +61,11 @@ describe('TaskFiltersComponent', () => { const change = new SimpleChange(null, appId, true); let lastError: any; - component.error.subscribe((err) => lastError = err); + component.error.subscribe((err) => (lastError = err)); component.ngOnChanges({ appId: change }); expect(lastError).toBeDefined(); - }); + }); it('should return the filter task list', () => { spyOn(taskFilterService, 'getTaskListFilters').and.returnValue(of(fakeTaskFilters)); @@ -79,7 +73,7 @@ describe('TaskFiltersComponent', () => { const change = new SimpleChange(null, appId, true); let lastValue: any; - component.success.subscribe((res) => lastValue = res); + component.success.subscribe((res) => (lastValue = res)); component.ngOnChanges({ appId: change }); @@ -93,7 +87,7 @@ describe('TaskFiltersComponent', () => { it('Should call the API to create the default task filters when no task filters exist', async () => { spyOn(taskFilterService, 'getTaskListFilters').and.returnValue(of([])); - const filtersMock: any[] = [{ name: 'default-task-filter-1'}, { name: 'default-task-filter-2'}]; + const filtersMock: any[] = [{ name: 'default-task-filter-1' }, { name: 'default-task-filter-2' }]; const createDefaultFiltersSpy = spyOn(taskFilterService, 'createDefaultFilters').and.returnValue(of(filtersMock)); const appId = '2'; const change = new SimpleChange(null, appId, true); @@ -110,7 +104,7 @@ describe('TaskFiltersComponent', () => { const change = new SimpleChange(null, 'test', true); let lastValue: any; - component.success.subscribe((res) => lastValue = res); + component.success.subscribe((res) => (lastValue = res)); component.ngOnChanges({ appName: change }); @@ -123,7 +117,7 @@ describe('TaskFiltersComponent', () => { component.filterParam = new FilterParamsModel({ name: 'FakeMyTasks1' }); let lastValue: any; - component.success.subscribe((res) => lastValue = res); + component.success.subscribe((res) => (lastValue = res)); const appId = '1'; const change = new SimpleChange(null, appId, true); @@ -132,14 +126,14 @@ describe('TaskFiltersComponent', () => { expect(lastValue).toBeDefined(); expect(component.currentFilter).toBeDefined(); expect(component.currentFilter.name).toEqual('FakeMyTasks1'); - }); + }); it('should select the task filter based on the input by index param', () => { spyOn(taskFilterService, 'getTaskListFilters').and.returnValue(of(fakeTaskFilters)); component.filterParam = new FilterParamsModel({ index: 2 }); let lastValue: any; - component.success.subscribe((res) => lastValue = res); + component.success.subscribe((res) => (lastValue = res)); const appId = '1'; const change = new SimpleChange(null, appId, true); @@ -148,7 +142,7 @@ describe('TaskFiltersComponent', () => { expect(lastValue).toBeDefined(); expect(component.currentFilter).toBeDefined(); expect(component.currentFilter.name).toEqual('FakeMyTasks2'); - }); + }); it('should select the task filter based on the input by id param', () => { spyOn(taskFilterService, 'getTaskListFilters').and.returnValue(of(fakeTaskFilters)); @@ -159,14 +153,14 @@ describe('TaskFiltersComponent', () => { const change = new SimpleChange(null, appId, true); let lastValue: any; - component.success.subscribe((res) => lastValue = res); + component.success.subscribe((res) => (lastValue = res)); component.ngOnChanges({ appId: change }); expect(lastValue).toBeDefined(); expect(component.currentFilter).toBeDefined(); expect(component.currentFilter.name).toEqual('FakeInvolvedTasks'); - }); + }); it('should emit the selected filter based on the filterParam input', () => { spyOn(component.filterSelected, 'emit'); @@ -181,7 +175,7 @@ describe('TaskFiltersComponent', () => { expect(component.filterSelected.emit).toHaveBeenCalledWith(fakeTaskFilters[0]); }); - it('should filterClicked emit when a filter is clicked from the UI', async () => { + it('should filterClicked emit when a filter is clicked from the UI', async () => { component.filters = fakeTaskFilters; spyOn(component.filterClicked, 'emit'); @@ -306,7 +300,7 @@ describe('TaskFiltersComponent', () => { it('should reset selection when filterParam is a filter that does not exist', async () => { spyOn(taskFilterService, 'getTaskListFilters').and.returnValue(of(fakeTaskFilters)); component.currentFilter = fakeTaskFilters[0]; - component.filterParam = new FilterRepresentationModel( {name: 'non-existing-filter'}); + component.filterParam = new FilterRepresentationModel({ name: 'non-existing-filter' }); const appId = '1'; const change = new SimpleChange(null, appId, true); @@ -319,8 +313,7 @@ describe('TaskFiltersComponent', () => { }); describe('Display Task Filters', () => { - - it('Should be able to display default task filters', async () => { + it('Should be able to display default task filters', async () => { spyOn(taskFilterService, 'getTaskListFilters').and.returnValue(of([])); const defaultTaskFiltersMock: any = [ { name: 'default-my-filter' }, @@ -349,7 +342,7 @@ describe('TaskFiltersComponent', () => { spyOn(router.events, 'pipe').and.returnValue(of(navigationStartEvent)); fixture.detectChanges(); expect(component.isTaskActive).toBe(true); - }); + }); it('should set isTaskActive to false when activeRoute does not include "tasks"', () => { const navigationStartEvent = new NavigationStart(1, 'other-route'); diff --git a/lib/process-services/src/lib/task-list/components/task-form/claim-task.directive.ts b/lib/process-services/src/lib/task-list/components/task-form/claim-task.directive.ts index c83f059b802..c66cbafb308 100644 --- a/lib/process-services/src/lib/task-list/components/task-form/claim-task.directive.ts +++ b/lib/process-services/src/lib/task-list/components/task-form/claim-task.directive.ts @@ -15,19 +15,11 @@ * limitations under the License. */ -import { - Directive, - Input, - Output, - EventEmitter, - HostListener, - OnInit -} from '@angular/core'; +import { Directive, Input, Output, EventEmitter, HostListener, OnInit } from '@angular/core'; import { TaskListService } from '../../services/tasklist.service'; -import { LogService } from '@alfresco/adf-core'; @Directive({ - // eslint-disable-next-line @angular-eslint/directive-selector + // eslint-disable-next-line @angular-eslint/directive-selector selector: '[adf-claim-task]' }) export class ClaimTaskDirective implements OnInit { @@ -45,9 +37,7 @@ export class ClaimTaskDirective implements OnInit { invalidParams: string[] = []; - constructor( - private taskListService: TaskListService, - private logService: LogService) {} + constructor(private taskListService: TaskListService) {} @HostListener('click') onClick() { @@ -68,9 +58,7 @@ export class ClaimTaskDirective implements OnInit { } if (this.invalidParams.length) { - throw new Error( - `Attribute ${this.invalidParams.join(', ')} is required` - ); + throw new Error(`Attribute ${this.invalidParams.join(', ')} is required`); } } @@ -81,10 +69,9 @@ export class ClaimTaskDirective implements OnInit { private claimTask() { this.taskListService.claimTask(this.taskId).subscribe( () => { - this.logService.info('Task claimed'); this.success.emit(this.taskId); }, - error => this.error.emit(error) + (error) => this.error.emit(error) ); } } diff --git a/lib/process-services/src/lib/task-list/components/task-form/task-form.component.spec.ts b/lib/process-services/src/lib/task-list/components/task-form/task-form.component.spec.ts index 867c6d5541a..211d1eb3b93 100644 --- a/lib/process-services/src/lib/task-list/components/task-form/task-form.component.spec.ts +++ b/lib/process-services/src/lib/task-list/components/task-form/task-form.component.spec.ts @@ -43,7 +43,6 @@ import { } from '../../../mock/task/task-details.mock'; import { TaskDetailsModel } from '../../models/task-details.model'; import { ProcessTestingModule } from '../../../testing/process.testing.module'; -import { TranslateModule } from '@ngx-translate/core'; import { By } from '@angular/platform-browser'; import { TaskFormService } from '../../../form/services/task-form.service'; import { TaskService } from '../../../form/services/task.service'; @@ -63,7 +62,7 @@ describe('TaskFormComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [TranslateModule.forRoot(), ProcessTestingModule], + imports: [ProcessTestingModule], schemas: [NO_ERRORS_SCHEMA] }); fixture = TestBed.createComponent(TaskFormComponent); diff --git a/lib/process-services/src/lib/task-list/components/task-form/unclaim-task.directive.ts b/lib/process-services/src/lib/task-list/components/task-form/unclaim-task.directive.ts index b5c572396c6..08710e7ba01 100644 --- a/lib/process-services/src/lib/task-list/components/task-form/unclaim-task.directive.ts +++ b/lib/process-services/src/lib/task-list/components/task-form/unclaim-task.directive.ts @@ -15,16 +15,8 @@ * limitations under the License. */ -import { - Directive, - HostListener, - Input, - Output, - EventEmitter, - OnInit -} from '@angular/core'; +import { Directive, HostListener, Input, Output, EventEmitter, OnInit } from '@angular/core'; import { TaskListService } from '../../services/tasklist.service'; -import { LogService } from '@alfresco/adf-core'; @Directive({ // eslint-disable-next-line @angular-eslint/directive-selector @@ -45,9 +37,7 @@ export class UnclaimTaskDirective implements OnInit { invalidParams: string[] = []; - constructor( - private taskListService: TaskListService, - private logService: LogService) {} + constructor(private taskListService: TaskListService) {} @HostListener('click') onClick() { @@ -67,9 +57,7 @@ export class UnclaimTaskDirective implements OnInit { this.invalidParams.push('taskId'); } if (this.invalidParams.length) { - throw new Error( - `Attribute ${this.invalidParams.join(', ')} is required` - ); + throw new Error(`Attribute ${this.invalidParams.join(', ')} is required`); } } @@ -80,10 +68,9 @@ export class UnclaimTaskDirective implements OnInit { private unclaimTask() { this.taskListService.unclaimTask(this.taskId).subscribe( () => { - this.logService.info('Task unclaimed'); this.success.emit(this.taskId); }, - error => this.error.emit(error) + (error) => this.error.emit(error) ); } } diff --git a/lib/process-services/src/lib/task-list/components/task-header.component.spec.ts b/lib/process-services/src/lib/task-list/components/task-header.component.spec.ts index b88f9f73966..32b490df739 100644 --- a/lib/process-services/src/lib/task-list/components/task-header.component.spec.ts +++ b/lib/process-services/src/lib/task-list/components/task-header.component.spec.ts @@ -32,7 +32,6 @@ import { TaskDetailsModel } from '../models/task-details.model'; import { TaskListService } from './../services/tasklist.service'; import { TaskHeaderComponent } from './task-header.component'; import { ProcessTestingModule } from '../../testing/process.testing.module'; -import { TranslateModule } from '@ngx-translate/core'; import { PeopleProcessService } from '../../common/services/people-process.service'; import { BpmUserModel } from '../../common/models/bpm-user.model'; @@ -59,7 +58,7 @@ describe('TaskHeaderComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [TranslateModule.forRoot(), ProcessTestingModule] + imports: [ProcessTestingModule] }); fixture = TestBed.createComponent(TaskHeaderComponent); component = fixture.componentInstance; diff --git a/lib/process-services/src/lib/task-list/components/task-list.component.spec.ts b/lib/process-services/src/lib/task-list/components/task-list.component.spec.ts index 850b9aa19cf..14db1b32c0e 100644 --- a/lib/process-services/src/lib/task-list/components/task-list.component.spec.ts +++ b/lib/process-services/src/lib/task-list/components/task-list.component.spec.ts @@ -23,7 +23,7 @@ import { TaskListService } from '../services/tasklist.service'; import { TaskListComponent } from './task-list.component'; import { ProcessTestingModule } from '../../testing/process.testing.module'; import { fakeGlobalTask, fakeEmptyTask, paginatedTask, fakeColumnSchema, fakeCustomSchema } from '../../mock'; -import { TranslateService, TranslateModule } from '@ngx-translate/core'; +import { TranslateService } from '@ngx-translate/core'; import { of, Subject } from 'rxjs'; import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed'; import { HarnessLoader } from '@angular/cdk/testing'; @@ -93,7 +93,7 @@ describe('TaskListComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [TranslateModule.forRoot(), ProcessTestingModule] + imports: [ProcessTestingModule] }); appConfig = TestBed.inject(AppConfigService); appConfig.config.bpmHost = 'http://localhost:9876/bpm'; @@ -651,7 +651,7 @@ describe('CustomTaskListComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [TranslateModule.forRoot(), ProcessTestingModule], + imports: [ProcessTestingModule], declarations: [CustomTaskListComponent] }); fixture = TestBed.createComponent(CustomTaskListComponent); @@ -691,7 +691,7 @@ describe('Task List: Custom EmptyTemplateComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [TranslateModule.forRoot(), ProcessTestingModule], + imports: [ProcessTestingModule], declarations: [EmptyTemplateComponent] }); translateService = TestBed.inject(TranslateService); @@ -779,7 +779,7 @@ describe('TaskListContextMenuComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [TranslateModule.forRoot(), ProcessTestingModule], + imports: [ProcessTestingModule], declarations: [TaskListContextMenuComponent] }); fixture = TestBed.createComponent(TaskListContextMenuComponent); diff --git a/lib/process-services/src/lib/task-list/components/task-standalone.component.spec.ts b/lib/process-services/src/lib/task-list/components/task-standalone.component.spec.ts index 94097bcf8f5..4055b0c8489 100644 --- a/lib/process-services/src/lib/task-list/components/task-standalone.component.spec.ts +++ b/lib/process-services/src/lib/task-list/components/task-standalone.component.spec.ts @@ -18,7 +18,6 @@ import { TaskStandaloneComponent } from './task-standalone.component'; import { ComponentFixture, TestBed } from '@angular/core/testing'; import { ProcessTestingModule } from '../../testing/process.testing.module'; -import { TranslateModule } from '@ngx-translate/core'; describe('TaskStandaloneComponent', () => { let component: TaskStandaloneComponent; @@ -27,10 +26,7 @@ describe('TaskStandaloneComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - ProcessTestingModule - ] + imports: [ProcessTestingModule] }); fixture = TestBed.createComponent(TaskStandaloneComponent); component = fixture.componentInstance;