[ADF-2188] Start Process - Change processDefinition property and fix bug (#2884)

* Change processDefinition property and fix bug

* Fix unit test

* Fix async

* Fix id
This commit is contained in:
Maurizio Vitale
2018-01-25 17:52:05 +01:00
committed by Eugenio Romano
parent abca6e481d
commit 657c28491a
7 changed files with 43 additions and 32 deletions

View File

@@ -12,7 +12,7 @@
<div *ngIf="showSelectProcessDropdown">
<mat-form-field>
<mat-select [(value)]="selectedProcessDef" placeholder="{{'ADF_PROCESS_LIST.START_PROCESS.FORM.LABEL.TYPE'|translate}}" required>
<mat-option>{{'ADF_PROCESS_LIST.START_PROCESS.FORM.TYPE_PLACEHOLDER' | translate}}</mat-option>
<mat-option *ngIf="!hasSingleProcessDefinition()">{{'ADF_PROCESS_LIST.START_PROCESS.FORM.TYPE_PLACEHOLDER' | translate}}</mat-option>
<mat-option *ngFor="let processDef of processDefinitions" [value]="processDef">
{{ processDef.name }}
</mat-option>

View File

@@ -274,7 +274,7 @@ describe('StartFormComponent', () => {
it('should select processDefinition based on processDefinition input', async(() => {
getDefinitionsSpy = getDefinitionsSpy.and.returnValue(Observable.of(testMultipleProcessDefs));
component.appId = 123;
component.processDefinition = 'My Process 2';
component.processDefinitionName = 'My Process 2';
component.ngOnChanges({});
fixture.detectChanges();
fixture.whenStable().then(() => {
@@ -292,16 +292,6 @@ describe('StartFormComponent', () => {
});
}));
it('should select automatically the first processDefinition if the app contain multiple process and there is no processDefinition in input', async(() => {
getDefinitionsSpy = getDefinitionsSpy.and.returnValue(Observable.of(testMultipleProcessDefs));
component.appId = 123;
component.ngOnChanges({});
fixture.detectChanges();
fixture.whenStable().then(() => {
expect(component.selectedProcessDef.name).toBe(JSON.parse(JSON.stringify(testMultipleProcessDefs[0])).name);
});
}));
describe('dropdown', () => {
it('should hide the process dropdown if showSelectProcessDropdown is false', async(() => {
@@ -319,7 +309,7 @@ describe('StartFormComponent', () => {
it('should show the process dropdown if showSelectProcessDropdown is false', async(() => {
getDefinitionsSpy = getDefinitionsSpy.and.returnValue(Observable.of(testMultipleProcessDefs));
component.appId = 123;
component.processDefinition = 'My Process 2';
component.processDefinitionName = 'My Process 2';
component.showSelectProcessDropdown = true;
component.ngOnChanges({});
fixture.detectChanges();
@@ -332,7 +322,7 @@ describe('StartFormComponent', () => {
it('should show the process dropdown by default', async(() => {
getDefinitionsSpy = getDefinitionsSpy.and.returnValue(Observable.of(testMultipleProcessDefs));
component.appId = 123;
component.processDefinition = 'My Process 2';
component.processDefinitionName = 'My Process 2';
component.ngOnChanges({});
fixture.detectChanges();
fixture.whenStable().then(() => {
@@ -454,14 +444,18 @@ describe('StartFormComponent', () => {
});
}));
it('should emit start event when start select a process and add a name', () => {
it('should emit start event when start select a process and add a name', async(() => {
let startSpy: jasmine.Spy = spyOn(component.start, 'emit');
component.selectedProcessDef.id = '1001';
component.selectedProcessDef = testProcessDefRepr;
component.name = 'my:Process';
component.startProcess();
fixture.detectChanges();
expect(startSpy).toHaveBeenCalled();
});
fixture.whenStable().then(() => {
let startButton = fixture.nativeElement.querySelector('#button-start');
startButton.click();
expect(startSpy).toHaveBeenCalled();
});
}));
it('should not emit start event when start the process without select a process and name', () => {
component.name = null;

View File

@@ -50,7 +50,7 @@ export class StartProcessInstanceComponent implements OnChanges {
appId: number;
@Input()
processDefinition: string;
processDefinitionName: string;
@Input()
variables: ProcessInstanceVariable[];
@@ -106,16 +106,12 @@ export class StartProcessInstanceComponent implements OnChanges {
(processDefinitionRepresentations: ProcessDefinitionRepresentation[]) => {
this.processDefinitions = processDefinitionRepresentations;
if (this.processDefinitions.length === 1 || !this.processDefinition) {
if (this.hasSingleProcessDefinition()) {
this.selectedProcessDef = this.processDefinitions[0];
} else {
this.selectedProcessDef = this.processDefinitions.find((currentProcessDefinition) => {
return currentProcessDefinition.name === this.processDefinition;
return currentProcessDefinition.name === this.processDefinitionName;
});
if (!this.selectedProcessDef) {
this.selectedProcessDef = this.processDefinitions[0];
}
}
},
() => {
@@ -124,6 +120,10 @@ export class StartProcessInstanceComponent implements OnChanges {
}
hasSingleProcessDefinition(): boolean {
return this.processDefinitions.length === 1;
}
getAlfrescoRepositoryName(): string {
let alfrescoRepositoryName = this.appConfig.get<string>('alfrescoRepositoryName');
if (!alfrescoRepositoryName) {