AAE-11739 removed unnecessary api call when cancelling not started pr… (#8041)

* AAE-11739 removed unnecessary api call when cancelling not started process

* AAE-11739 added unit tests for cancelling process

* AAE-11739 fixed erroneous test

* AAE-11739 fix for test related error thrown in afterAll

* AAE-11739 added proper way to test wheter button exist
This commit is contained in:
tomasz hanaj 2022-12-13 11:39:31 +01:00 committed by GitHub
parent 0cb1c502c0
commit ef278bde79
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 55 additions and 28 deletions

View File

@ -45,6 +45,7 @@ import { ProcessNameCloudPipe } from '../../../pipes/process-name-cloud.pipe';
import { ProcessInstanceCloud } from '../models/process-instance-cloud.model'; import { ProcessInstanceCloud } from '../models/process-instance-cloud.model';
import { ESCAPE } from '@angular/cdk/keycodes'; import { ESCAPE } from '@angular/cdk/keycodes';
import { ProcessDefinitionCloud, TaskVariableCloud } from '@alfresco/adf-process-services-cloud'; import { ProcessDefinitionCloud, TaskVariableCloud } from '@alfresco/adf-process-services-cloud';
import { first } from 'rxjs/operators';
describe('StartProcessCloudComponent', () => { describe('StartProcessCloudComponent', () => {
@ -159,7 +160,7 @@ describe('StartProcessCloudComponent', () => {
}); });
})); }));
it('should have start button disabled if create operation failed', fakeAsync(() => { it('should have start button disabled if create operation failed', fakeAsync(() => {
createProcessSpy.and.returnValue(throwError('fake error')); createProcessSpy.and.returnValue(throwError('fake error'));
const change = new SimpleChange(null, 'MyApp', false); const change = new SimpleChange(null, 'MyApp', false);
fixture.detectChanges(); fixture.detectChanges();
@ -207,14 +208,14 @@ describe('StartProcessCloudComponent', () => {
it('should include the static input mappings in the resolved values', fakeAsync(() => { it('should include the static input mappings in the resolved values', fakeAsync(() => {
const values: TaskVariableCloud[] = [ const values: TaskVariableCloud[] = [
new TaskVariableCloud({name: 'value1', value: 'value'}), new TaskVariableCloud({ name: 'value1', value: 'value' }),
new TaskVariableCloud({name: 'value2', value: 1}), new TaskVariableCloud({ name: 'value2', value: 1 }),
new TaskVariableCloud({name: 'value3', value: false}) new TaskVariableCloud({ name: 'value3', value: false })
]; ];
const staticInputs: TaskVariableCloud[] = [ const staticInputs: TaskVariableCloud[] = [
new TaskVariableCloud({name: 'static1', value: 'static value'}), new TaskVariableCloud({ name: 'static1', value: 'static value' }),
new TaskVariableCloud({name: 'static2', value: 0}), new TaskVariableCloud({ name: 'static2', value: 0 }),
new TaskVariableCloud({name: 'static3', value: true}) new TaskVariableCloud({ name: 'static3', value: true })
]; ];
component.name = 'My new process'; component.name = 'My new process';
component.processDefinitionName = 'processwithoutform2'; component.processDefinitionName = 'processwithoutform2';
@ -831,7 +832,7 @@ describe('StartProcessCloudComponent', () => {
it('should set the process name using the processName cloud pipe when a process definition gets selected', () => { it('should set the process name using the processName cloud pipe when a process definition gets selected', () => {
const processNameCloudPipe = TestBed.inject(ProcessNameCloudPipe); const processNameCloudPipe = TestBed.inject(ProcessNameCloudPipe);
const processNamePipeTransformSpy = spyOn(processNameCloudPipe, 'transform').and.returnValue('fake-transformed-name'); const processNamePipeTransformSpy = spyOn(processNameCloudPipe, 'transform').and.returnValue('fake-transformed-name');
const expectedProcessInstanceDetails: ProcessInstanceCloud = { processDefinitionName: fakeProcessDefinitions[0].name}; const expectedProcessInstanceDetails: ProcessInstanceCloud = { processDefinitionName: fakeProcessDefinitions[0].name };
getDefinitionsSpy = getDefinitionsSpy.and.returnValue(of(fakeProcessDefinitions)); getDefinitionsSpy = getDefinitionsSpy.and.returnValue(of(fakeProcessDefinitions));
component.appName = 'myApp'; component.appName = 'myApp';
@ -846,7 +847,7 @@ describe('StartProcessCloudComponent', () => {
expect(component.processInstanceName.value).toEqual('fake-transformed-name'); expect(component.processInstanceName.value).toEqual('fake-transformed-name');
}); });
it('should set the process name on when a process definition name is present', (done) => { it('should set the process name on when a process definition name is present', (done) => {
const definitions: ProcessDefinitionCloud[] = [{ const definitions: ProcessDefinitionCloud[] = [{
appName: 'app', appName: 'app',
appVersion: 1, appVersion: 1,
@ -939,4 +940,34 @@ describe('StartProcessCloudComponent', () => {
expect(card).toBeTruthy(); expect(card).toBeTruthy();
}); });
}); });
describe('cancel process', () => {
beforeEach(() => {
fixture.detectChanges();
component.name = 'NewProcess 1';
component.appName = 'myApp';
component.ngOnChanges({});
});
it('user should see cancel button', () => {
fixture.whenStable().then(() => {
fixture.detectChanges();
const cancelBtn = fixture.debugElement.query(By.css('#cancel_process'));
expect(cancelBtn.nativeElement).toBeDefined();
});
});
it('currentCreatedProcess should be null when cancel button clicked', () => {
component.cancelStartProcess();
expect(component.currentCreatedProcess).toBeNull();
});
it('undefined should be emitted when cancel button clicked', () => {
component.cancel.pipe(first()).subscribe((data: any) => {
expect(data).toBe(undefined);
});
component.cancelStartProcess();
});
});
}); });

View File

@ -117,8 +117,8 @@ export class StartProcessCloudComponent implements OnChanges, OnInit, OnDestroy
loading$ = new BehaviorSubject<boolean>(!this.processDefinitionLoaded); loading$ = new BehaviorSubject<boolean>(!this.processDefinitionLoaded);
constructor(private startProcessCloudService: StartProcessCloudService, constructor(private startProcessCloudService: StartProcessCloudService,
private formBuilder: UntypedFormBuilder, private formBuilder: UntypedFormBuilder,
private processNameCloudPipe: ProcessNameCloudPipe) { private processNameCloudPipe: ProcessNameCloudPipe) {
} }
ngOnInit() { ngOnInit() {
@ -260,20 +260,20 @@ export class StartProcessCloudComponent implements OnChanges, OnInit, OnDestroy
}), }),
takeUntil(this.onDestroy$)) takeUntil(this.onDestroy$))
.subscribe((processDefinitionRepresentations: ProcessDefinitionCloud[]) => { .subscribe((processDefinitionRepresentations: ProcessDefinitionCloud[]) => {
this.processDefinitionList = processDefinitionRepresentations; this.processDefinitionList = processDefinitionRepresentations;
if (processDefinitionRepresentations.length === 1) { if (processDefinitionRepresentations.length === 1) {
this.selectDefaultProcessDefinition(); this.selectDefaultProcessDefinition();
} else if (this.processDefinitionName) { } else if (this.processDefinitionName) {
this.processDefinition.setValue(this.processDefinitionName); this.processDefinition.setValue(this.processDefinitionName);
const processDefinition = this.processDefinitionList.find(process => process.name === this.processDefinitionName); const processDefinition = this.processDefinitionList.find(process => process.name === this.processDefinitionName);
if (processDefinition) { if (processDefinition) {
this.filteredProcesses = this.getProcessDefinitionListByNameOrKey(processDefinition.name); this.filteredProcesses = this.getProcessDefinitionListByNameOrKey(processDefinition.name);
this.setProcessDefinitionOnForm(processDefinition.name); this.setProcessDefinitionOnForm(processDefinition.name);
this.processDefinitionSelectionChanged(processDefinition); this.processDefinitionSelectionChanged(processDefinition);
}
} }
}, }
},
() => { () => {
this.errorMessageId = 'ADF_CLOUD_PROCESS_LIST.ADF_CLOUD_START_PROCESS.ERROR.LOAD_PROCESS_DEFS'; this.errorMessageId = 'ADF_CLOUD_PROCESS_LIST.ADF_CLOUD_START_PROCESS.ERROR.LOAD_PROCESS_DEFS';
}); });
@ -334,11 +334,7 @@ export class StartProcessCloudComponent implements OnChanges, OnInit, OnDestroy
); );
} }
async cancelStartProcess() { cancelStartProcess() {
if (this.currentCreatedProcess) {
await this.startProcessCloudService.deleteProcess(this.appName, this.currentCreatedProcess.id);
}
this.currentCreatedProcess = null; this.currentCreatedProcess = null;
this.cancel.emit(); this.cancel.emit();
} }