mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[ADF-4905] StartProcessCloud - fix starting different process than se… (#5091)
* [ADF-4905] StartProcessCloud - fix starting different process than selected in dropdown * fix process e2e test * revert e2e changes
This commit is contained in:
committed by
Eugenio Romano
parent
4709cda51e
commit
c49e2dca7e
@@ -32,7 +32,7 @@
|
||||
[matAutocomplete]="auto"
|
||||
id="processDefinitionName">
|
||||
<div class="adf-process-input-autocomplete">
|
||||
<mat-autocomplete #auto="matAutocomplete" id="processDefinitionOptions" [displayWith]="displayProcessNameOnDropdown">
|
||||
<mat-autocomplete #auto="matAutocomplete" id="processDefinitionOptions" [displayWith]="displayProcessNameOnDropdown" (optionSelected)="setProcessDefinitionOnForm($event.option.value)">
|
||||
<mat-option *ngFor="let processDef of filteredProcesses" [value]="getProcessDefinitionValue(processDef)">
|
||||
{{ getProcessDefinitionValue(processDef) }}
|
||||
</mat-option>
|
||||
|
@@ -15,7 +15,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { SimpleChange } from '@angular/core';
|
||||
import { SimpleChange, DebugElement } from '@angular/core';
|
||||
import { async, ComponentFixture, TestBed, fakeAsync, tick } from '@angular/core/testing';
|
||||
import { setupTestBed } from '@alfresco/adf-core';
|
||||
import { of, throwError } from 'rxjs';
|
||||
@@ -27,6 +27,7 @@ import { ProcessServiceCloudTestingModule } from '../../../testing/process-servi
|
||||
import { ProcessCloudModule } from '../../process-cloud.module';
|
||||
import { fakeProcessDefinitions, fakeStartForm, fakeStartFormNotValid,
|
||||
fakeProcessInstance, fakeProcessPayload, fakeNoNameProcessDefinitions } from '../mock/start-process.component.mock';
|
||||
import { By } from '@angular/platform-browser';
|
||||
|
||||
describe('StartProcessCloudComponent', () => {
|
||||
|
||||
@@ -37,6 +38,19 @@ describe('StartProcessCloudComponent', () => {
|
||||
let getDefinitionsSpy: jasmine.Spy;
|
||||
let startProcessSpy: jasmine.Spy;
|
||||
|
||||
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();
|
||||
}
|
||||
};
|
||||
|
||||
setupTestBed({
|
||||
imports: [
|
||||
ProcessServiceCloudTestingModule,
|
||||
@@ -315,6 +329,18 @@ describe('StartProcessCloudComponent', () => {
|
||||
});
|
||||
}));
|
||||
|
||||
it('should select the right process when the processKey begins with the name', async(() => {
|
||||
getDefinitionsSpy = getDefinitionsSpy.and.returnValue(of(fakeProcessDefinitions));
|
||||
component.name = 'My new process';
|
||||
component.processDefinitionName = 'process';
|
||||
selectOptionByName('process');
|
||||
|
||||
fixture.whenStable().then(() => {
|
||||
expect(component.processDefinitionCurrent.name).toBe(JSON.parse(JSON.stringify(fakeProcessDefinitions[3])).name);
|
||||
expect(component.processDefinitionCurrent.key).toBe(JSON.parse(JSON.stringify(fakeProcessDefinitions[3])).key);
|
||||
});
|
||||
}));
|
||||
|
||||
describe('dropdown', () => {
|
||||
|
||||
it('should hide the process dropdown button if showSelectProcessDropdown is false', async(() => {
|
||||
@@ -396,7 +422,7 @@ describe('StartProcessCloudComponent', () => {
|
||||
component.processForm.controls['processDefinition'].setValue('process');
|
||||
fixture.detectChanges();
|
||||
tick(3000);
|
||||
expect(component.filteredProcesses.length).toEqual(3);
|
||||
expect(component.filteredProcesses.length).toEqual(4);
|
||||
|
||||
component.processForm.controls['processDefinition'].setValue('processwithfo');
|
||||
fixture.detectChanges();
|
||||
|
@@ -109,12 +109,7 @@ export class StartProcessCloudComponent implements OnChanges, OnInit, OnDestroy
|
||||
.pipe(debounceTime(300))
|
||||
.pipe(takeUntil(this.onDestroy$))
|
||||
.subscribe((processDefinitionName) => {
|
||||
this.processPayloadCloud.processDefinitionKey = null;
|
||||
if (this.processDefinition.valid) {
|
||||
this.setProcessDefinitionOnForm(processDefinitionName);
|
||||
} else {
|
||||
this.filteredProcesses = this.getProcessDefinitionList(processDefinitionName);
|
||||
}
|
||||
this.filteredProcesses = this.getProcessDefinitionList(processDefinitionName);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -139,12 +134,12 @@ export class StartProcessCloudComponent implements OnChanges, OnInit, OnDestroy
|
||||
StartProcessCloudComponent.MAX_NAME_LENGTH : this.maxNameLength;
|
||||
}
|
||||
|
||||
setProcessDefinitionOnForm(processDefinition: string) {
|
||||
this.filteredProcesses = this.getProcessDefinitionList(processDefinition);
|
||||
const selectedProcess = this.getProcessIfExists(processDefinition);
|
||||
this.processDefinitionCurrent = selectedProcess;
|
||||
setProcessDefinitionOnForm(selectedProcessDefinitionName: string) {
|
||||
this.processDefinitionCurrent = this.filteredProcesses.find( (process: ProcessDefinitionCloud) =>
|
||||
process.name === selectedProcessDefinitionName || process.key === selectedProcessDefinitionName );
|
||||
|
||||
this.isFormCloudLoaded = false;
|
||||
this.processPayloadCloud.processDefinitionKey = selectedProcess.key;
|
||||
this.processPayloadCloud.processDefinitionKey = this.processDefinitionCurrent.key;
|
||||
}
|
||||
|
||||
private getProcessDefinitionList(processDefinition: string): ProcessDefinitionCloud[] {
|
||||
|
@@ -54,6 +54,13 @@ export let fakeProcessDefinitions: ProcessDefinitionCloud[] = [
|
||||
id: 'd00c0237-8772-11e9-859a-428f83d5904f',
|
||||
key: 'process-5151ad1d-f992-4ee6-9742-3a04617469fe',
|
||||
name: 'processwithform'
|
||||
}),
|
||||
new ProcessDefinitionCloud({
|
||||
appName: 'startformwithoutupload',
|
||||
formKey: 'form-a5d50817-5183-4850-802d-17af54b2632f',
|
||||
id: 'd00c0237-8772-11e9-859a-428f83d5904f',
|
||||
key: 'process-51251ad1d-f992-4ee6-9742-3a04617469f1',
|
||||
name: 'process'
|
||||
})
|
||||
];
|
||||
|
||||
|
Reference in New Issue
Block a user