ACS-7579 Remove unused process audit directive (#11474)

This commit is contained in:
Denys Vuika
2025-12-19 12:07:20 +00:00
committed by GitHub
parent 744bb671f1
commit fcb15868f8
8 changed files with 4 additions and 376 deletions
@@ -18,11 +18,10 @@
import { ADF_COMMENTS_SERVICE, CommentsComponent } from '@alfresco/adf-core';
import { CommentProcessService } from './services/comment-process.service';
import { Component, Input, ViewEncapsulation } from '@angular/core';
import { CommonModule } from '@angular/common';
@Component({
selector: 'adf-process-instance-comments',
imports: [CommonModule, CommentsComponent],
imports: [CommentsComponent],
providers: [
{
provide: ADF_COMMENTS_SERVICE,
@@ -1,216 +0,0 @@
/*!
* @license
* Copyright © 2005-2025 Hyland Software, Inc. and its affiliates. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { Component } from '@angular/core';
import { ComponentFixture, fakeAsync, TestBed } from '@angular/core/testing';
import { of, throwError } from 'rxjs';
import { ProcessService } from '../../services/process.service';
import { DownloadService } from '@alfresco/adf-core';
import { ProcessInstanceAuditInfoRepresentation } from '@alfresco/js-api';
import { ProcessAuditDirective } from './process-audit.directive';
@Component({
selector: 'adf-basic-button',
imports: [ProcessAuditDirective],
template: ` <button
id="auditButton"
adf-process-audit
[process-id]="'1234'"
[download]="download"
[fileName]="fileName"
[format]="format"
(error)="onAuditError($event)"
(clicked)="onAuditClick($event)"
>
My button
</button>`
})
class BasicButtonComponent {
download: boolean = false;
fileName: string;
format: string;
onAuditClick(_event: any) {
/* do nothing */
}
onAuditError(_event: any) {
/* do nothing */
}
}
describe('ProcessAuditDirective', () => {
let fixture: ComponentFixture<BasicButtonComponent>;
let component: BasicButtonComponent;
let service: ProcessService;
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' });
};
const blob = createFakePdfBlob();
beforeEach(() => {
TestBed.configureTestingModule({
imports: [BasicButtonComponent]
});
fixture = TestBed.createComponent(BasicButtonComponent);
component = fixture.componentInstance;
service = TestBed.inject(ProcessService);
});
afterEach(() => fixture.destroy());
it('should fetch the pdf Blob when the format is pdf', fakeAsync(() => {
component.fileName = 'FakeAuditName';
component.format = 'pdf';
spyOn(service, 'fetchProcessAuditPdfById').and.returnValue(of(blob));
spyOn(component, 'onAuditClick').and.callThrough();
fixture.detectChanges();
const button = fixture.nativeElement.querySelector('#auditButton');
fixture.whenStable().then(() => {
fixture.detectChanges();
expect(component.onAuditClick).toHaveBeenCalledWith({ format: 'pdf', value: blob, fileName: 'FakeAuditName' });
});
button.click();
}));
it('should download the audit in PDF format (default mode)', fakeAsync(() => {
component.fileName = 'FakeAuditName';
component.download = true;
const downloadService = TestBed.inject(DownloadService);
spyOn(service, 'fetchProcessAuditPdfById').and.returnValue(of(blob));
spyOn(downloadService, 'downloadBlob').and.stub();
fixture.detectChanges();
const button = fixture.nativeElement.querySelector('#auditButton');
fixture.whenStable().then(() => {
fixture.detectChanges();
expect(downloadService.downloadBlob).toHaveBeenCalledWith(blob, 'FakeAuditName.pdf');
});
button.click();
}));
it('should throw error if download audit failed', fakeAsync(() => {
const expectedError = 'Failed to get audit';
spyOn(service, 'fetchProcessAuditPdfById').and.returnValue(throwError(expectedError));
spyOn(component, 'onAuditError').and.stub();
fixture.detectChanges();
const button = fixture.nativeElement.querySelector('#auditButton');
fixture.whenStable().then(() => {
fixture.detectChanges();
expect(component.onAuditError).toHaveBeenCalledWith(expectedError);
});
button.click();
}));
it('should fetch the json info when the format is json', fakeAsync(() => {
component.fileName = 'FakeAuditName';
component.format = 'json';
component.download = true;
const auditJson: ProcessInstanceAuditInfoRepresentation = {
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: [] }
};
spyOn(service, 'fetchProcessAuditJsonById').and.returnValue(of(auditJson));
spyOn(component, 'onAuditClick').and.callThrough();
fixture.detectChanges();
const button = fixture.nativeElement.querySelector('#auditButton');
fixture.whenStable().then(() => {
fixture.detectChanges();
expect(component.onAuditClick).toHaveBeenCalledWith({ format: 'json', value: auditJson, fileName: 'FakeAuditName' });
});
button.click();
}));
it('should fetch the pdf Blob as default when the format is UNKNOW', fakeAsync(() => {
component.fileName = 'FakeAuditName';
component.format = 'fakeFormat';
spyOn(service, 'fetchProcessAuditPdfById').and.returnValue(of(blob));
spyOn(component, 'onAuditClick').and.callThrough();
fixture.detectChanges();
const button = fixture.nativeElement.querySelector('#auditButton');
fixture.whenStable().then(() => {
fixture.detectChanges();
expect(component.onAuditClick).toHaveBeenCalledWith({ format: 'pdf', value: blob, fileName: 'FakeAuditName' });
});
button.click();
}));
});
@@ -1,109 +0,0 @@
/*!
* @license
* Copyright © 2005-2025 Hyland Software, Inc. and its affiliates. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* eslint-disable @angular-eslint/no-input-rename */
import { DownloadService } from '@alfresco/adf-core';
import { Directive, EventEmitter, Input, OnChanges, Output } from '@angular/core';
import { ProcessService } from '../../services/process.service';
const JSON_FORMAT: string = 'json';
const PDF_FORMAT: string = 'pdf';
@Directive({
// eslint-disable-next-line @angular-eslint/directive-selector
selector: 'button[adf-process-audit]',
host: {
role: 'button',
'(click)': 'onClickAudit()'
}
})
export class ProcessAuditDirective implements OnChanges {
/** ID of the process. */
@Input('process-id')
processId: string;
/** Name of the file to download (for PDF downloads). */
@Input()
fileName: string = 'Audit';
/** Format for the audit information (can be "pdf" or "json"). */
@Input()
format: string = 'pdf';
/** Enables downloading of the audit file on clicking. */
@Input()
download: boolean = true;
/** Emitted when the decorated element is clicked. */
@Output()
clicked: EventEmitter<any> = new EventEmitter<any>();
/** Emitted when an error occurs. */
@Output()
error: EventEmitter<any> = new EventEmitter<any>();
constructor(private downloadService: DownloadService, private processListService: ProcessService) {}
ngOnChanges(): void {
if (!this.isValidType()) {
this.setDefaultFormatType();
}
}
isValidType() {
return this.format && (this.isJsonFormat() || this.isPdfFormat());
}
setDefaultFormatType(): void {
this.format = PDF_FORMAT;
}
/**
* fetch the audit information in the requested format
*/
fetchAuditInfo(): void {
if (this.isPdfFormat()) {
this.processListService.fetchProcessAuditPdfById(this.processId).subscribe(
(blob: Blob) => {
if (this.download) {
this.downloadService.downloadBlob(blob, this.fileName + '.pdf');
}
this.clicked.emit({ format: this.format, value: blob, fileName: this.fileName });
},
(err) => this.error.emit(err)
);
} else {
this.processListService.fetchProcessAuditJsonById(this.processId).subscribe(
(res) => this.clicked.emit({ format: this.format, value: res, fileName: this.fileName }),
(err) => this.error.emit(err)
);
}
}
onClickAudit() {
this.fetchAuditInfo();
}
isJsonFormat() {
return this.format === JSON_FORMAT;
}
isPdfFormat() {
return this.format === PDF_FORMAT;
}
}
@@ -15,29 +15,25 @@
* limitations under the License.
*/
// component
import { ProcessInstanceListComponent } from './components/process-list/process-list.component';
import { ProcessFiltersComponent } from './components/process-filters/process-filters.component';
import { ProcessInstanceDetailsComponent } from './components/process-instance-details/process-instance-details.component';
import { ProcessInstanceHeaderComponent } from './components/process-instance-header/process-instance-header.component';
import { ProcessInstanceTasksComponent } from './components/process-instance-tasks/process-instance-tasks.component';
import { StartProcessInstanceComponent } from './components/start-process/start-process.component';
import { ProcessAuditDirective } from './components/process-audit/process-audit.directive';
export * from './components/process-filters/process-filters.component';
export * from './components/process-instance-details/process-instance-details.component';
export * from './components/process-audit/process-audit.directive';
export * from './components/process-instance-header/process-instance-header.component';
export * from './components/process-instance-tasks/process-instance-tasks.component';
export * from './components/process-list/process-list.component';
export * from './components/start-process/start-process.component';
// services
export * from './services/process.service';
export * from './services/process-filter.service';
/* @deprecated use individual exports */
export const PROCESS_LIST_DIRECTIVES = [
ProcessAuditDirective,
ProcessInstanceListComponent,
ProcessFiltersComponent,
ProcessInstanceDetailsComponent,
@@ -106,6 +106,7 @@ export class ProcessService {
}
/**
* @deprecated This api is no longer used and will be removed in future releases.
* Fetches the Process Audit information as a PDF.
*
* @param processId ID of the target process
@@ -116,6 +117,7 @@ export class ProcessService {
}
/**
* @deprecated This api is no longer used and will be removed in future releases.
* Fetches the Process Audit information in a JSON format.
*
* @param processId ID of the target process