Skip to content

Commit

Permalink
AAE-11739 removed unnecessary api call when cancelling not started pr… (
Browse files Browse the repository at this point in the history
#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
  • Loading branch information
tomaszhanaj authored Dec 13, 2022
1 parent 0cb1c50 commit ef278bd
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import { ProcessNameCloudPipe } from '../../../pipes/process-name-cloud.pipe';
import { ProcessInstanceCloud } from '../models/process-instance-cloud.model';
import { ESCAPE } from '@angular/cdk/keycodes';
import { ProcessDefinitionCloud, TaskVariableCloud } from '@alfresco/adf-process-services-cloud';
import { first } from 'rxjs/operators';

describe('StartProcessCloudComponent', () => {

Expand Down Expand Up @@ -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'));
const change = new SimpleChange(null, 'MyApp', false);
fixture.detectChanges();
Expand Down Expand Up @@ -207,14 +208,14 @@ describe('StartProcessCloudComponent', () => {

it('should include the static input mappings in the resolved values', fakeAsync(() => {
const values: TaskVariableCloud[] = [
new TaskVariableCloud({name: 'value1', value: 'value'}),
new TaskVariableCloud({name: 'value2', value: 1}),
new TaskVariableCloud({name: 'value3', value: false})
new TaskVariableCloud({ name: 'value1', value: 'value' }),
new TaskVariableCloud({ name: 'value2', value: 1 }),
new TaskVariableCloud({ name: 'value3', value: false })
];
const staticInputs: TaskVariableCloud[] = [
new TaskVariableCloud({name: 'static1', value: 'static value'}),
new TaskVariableCloud({name: 'static2', value: 0}),
new TaskVariableCloud({name: 'static3', value: true})
new TaskVariableCloud({ name: 'static1', value: 'static value' }),
new TaskVariableCloud({ name: 'static2', value: 0 }),
new TaskVariableCloud({ name: 'static3', value: true })
];
component.name = 'My new process';
component.processDefinitionName = 'processwithoutform2';
Expand Down Expand Up @@ -831,7 +832,7 @@ describe('StartProcessCloudComponent', () => {
it('should set the process name using the processName cloud pipe when a process definition gets selected', () => {
const processNameCloudPipe = TestBed.inject(ProcessNameCloudPipe);
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));

component.appName = 'myApp';
Expand All @@ -846,7 +847,7 @@ describe('StartProcessCloudComponent', () => {
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[] = [{
appName: 'app',
appVersion: 1,
Expand Down Expand Up @@ -939,4 +940,34 @@ describe('StartProcessCloudComponent', () => {
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();
});

});
});
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ export class StartProcessCloudComponent implements OnChanges, OnInit, OnDestroy
loading$ = new BehaviorSubject<boolean>(!this.processDefinitionLoaded);

constructor(private startProcessCloudService: StartProcessCloudService,
private formBuilder: UntypedFormBuilder,
private processNameCloudPipe: ProcessNameCloudPipe) {
private formBuilder: UntypedFormBuilder,
private processNameCloudPipe: ProcessNameCloudPipe) {
}

ngOnInit() {
Expand Down Expand Up @@ -260,20 +260,20 @@ export class StartProcessCloudComponent implements OnChanges, OnInit, OnDestroy
}),
takeUntil(this.onDestroy$))
.subscribe((processDefinitionRepresentations: ProcessDefinitionCloud[]) => {
this.processDefinitionList = processDefinitionRepresentations;
if (processDefinitionRepresentations.length === 1) {
this.selectDefaultProcessDefinition();
} else if (this.processDefinitionName) {
this.processDefinition.setValue(this.processDefinitionName);

const processDefinition = this.processDefinitionList.find(process => process.name === this.processDefinitionName);
if (processDefinition) {
this.filteredProcesses = this.getProcessDefinitionListByNameOrKey(processDefinition.name);
this.setProcessDefinitionOnForm(processDefinition.name);
this.processDefinitionSelectionChanged(processDefinition);
}
this.processDefinitionList = processDefinitionRepresentations;
if (processDefinitionRepresentations.length === 1) {
this.selectDefaultProcessDefinition();
} else if (this.processDefinitionName) {
this.processDefinition.setValue(this.processDefinitionName);

const processDefinition = this.processDefinitionList.find(process => process.name === this.processDefinitionName);
if (processDefinition) {
this.filteredProcesses = this.getProcessDefinitionListByNameOrKey(processDefinition.name);
this.setProcessDefinitionOnForm(processDefinition.name);
this.processDefinitionSelectionChanged(processDefinition);
}
},
}
},
() => {
this.errorMessageId = 'ADF_CLOUD_PROCESS_LIST.ADF_CLOUD_START_PROCESS.ERROR.LOAD_PROCESS_DEFS';
});
Expand Down Expand Up @@ -334,11 +334,7 @@ export class StartProcessCloudComponent implements OnChanges, OnInit, OnDestroy
);
}

async cancelStartProcess() {
if (this.currentCreatedProcess) {
await this.startProcessCloudService.deleteProcess(this.appName, this.currentCreatedProcess.id);
}

cancelStartProcess() {
this.currentCreatedProcess = null;
this.cancel.emit();
}
Expand Down

0 comments on commit ef278bd

Please sign in to comment.