[ACA-2956] Add event emitter when processDefinition selection changes (for both APS and CLOUD) (#5579)

This commit is contained in:
arditdomi
2020-03-31 09:50:51 +01:00
committed by GitHub
parent f4f46d0c60
commit 6564ef256e
8 changed files with 55 additions and 3 deletions

View File

@@ -29,7 +29,8 @@
#auto="matAutocomplete"
id="processDefinitionOptions"
[displayWith]="displayFn">
<mat-option *ngFor="let processDef of filteredProcesses | async" [value]="processDef.name">
<mat-option *ngFor="let processDef of filteredProcesses | async" [value]="processDef.name"
(click)="processDefinitionSelectionChanged(processDef)">
{{ processDef.name }}
</mat-option>
</mat-autocomplete>

View File

@@ -15,7 +15,7 @@
* limitations under the License.
*/
import { SimpleChange } from '@angular/core';
import { DebugElement, SimpleChange } from '@angular/core';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ActivitiContentService, AppConfigService, FormService, setupTestBed } from '@alfresco/adf-core';
import { of, throwError } from 'rxjs';
@@ -32,6 +32,7 @@ import {
} from '../../mock';
import { StartProcessInstanceComponent } from './start-process.component';
import { ProcessTestingModule } from '../../testing/process.testing.module';
import { By } from '@angular/platform-browser';
describe('StartFormComponent', () => {
@@ -52,6 +53,19 @@ describe('StartFormComponent', () => {
]
});
const selectOptionByName = (name: string) => {
const selectElement = fixture.nativeElement.querySelector('button#adf-select-process-dropdown');
selectElement.click();
fixture.detectChanges();
const options: any = fixture.debugElement.queryAll(By.css('.mat-option-text'));
const currentOption = options.find( (option: DebugElement) => option.nativeElement.innerHTML.trim() === name );
if (currentOption) {
currentOption.nativeElement.click();
}
};
beforeEach(() => {
appConfig = TestBed.get(AppConfigService);
activitiContentService = TestBed.get(ActivitiContentService);
@@ -490,6 +504,15 @@ describe('StartFormComponent', () => {
fixture.detectChanges();
});
it('should emit processDefinitionSelection event when a process definition is selected', (done) => {
component.processDefinitionSelection.subscribe((processDefinition) => {
expect(processDefinition).toEqual(testProcessDef);
done();
});
fixture.detectChanges();
selectOptionByName(testProcessDef.name);
});
it('should not emit start event when start the process without select a process and name', () => {
component.name = null;
component.selectedProcessDef = null;

View File

@@ -91,6 +91,10 @@ export class StartProcessInstanceComponent implements OnChanges, OnInit, OnDestr
@Output()
error: EventEmitter<ProcessInstance> = new EventEmitter<ProcessInstance>();
/** Emitted when process definition selection changes. */
@Output()
processDefinitionSelection: EventEmitter<ProcessDefinitionRepresentation> = new EventEmitter<ProcessDefinitionRepresentation>();
@ViewChild('startForm')
startForm: StartFormComponent;
@@ -320,4 +324,8 @@ export class StartProcessInstanceComponent implements OnChanges, OnInit, OnDestr
get nameController(): AbstractControl {
return this.processNameInput;
}
processDefinitionSelectionChanged(processDefinition) {
this.processDefinitionSelection.emit(processDefinition);
}
}