[AAE-2505] [PS cloud] Should not allow to start the process if is not created (#5659)

* * fixed bug

* * cherry pick
This commit is contained in:
dhrn
2020-05-01 14:10:40 +05:30
committed by GitHub
parent 1430314815
commit 7d2af84a58
6 changed files with 77 additions and 31 deletions

View File

@@ -78,7 +78,7 @@
<button mat-button (click)="cancelStartProcess()" id="cancel_process">
{{ 'ADF_CLOUD_PROCESS_LIST.ADF_CLOUD_START_PROCESS.FORM.ACTION.CANCEL' | translate | uppercase}}
</button>
<button color="primary" mat-button [disabled]="!isProcessFormValid()" (click)="startProcess()"
<button color="primary" mat-button [disabled]="!currentCreatedProcess || !isProcessFormValid()" (click)="startProcess()"
data-automation-id="btn-start" id="button-start" class="btn-start">
{{'ADF_CLOUD_PROCESS_LIST.ADF_CLOUD_START_PROCESS.FORM.ACTION.START' | translate | uppercase}}
</button>

View File

@@ -27,7 +27,7 @@ import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { TranslateModule, TranslateStore } from '@ngx-translate/core';
import { MatCardModule, MatOptionModule, MatAutocompleteModule, MatIconModule, MatButtonModule, MatFormFieldModule, MatInputModule, MatRippleModule, MatCommonModule } from '@angular/material';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { FormCloudModule } from 'process-services-cloud/src/lib/form/form-cloud.module';
import { FormCloudModule } from '../../../form/form-cloud.module';
import { fakeProcessDefinitions, fakeStartForm, fakeStartFormNotValid,
fakeProcessInstance, fakeNoNameProcessDefinitions,
@@ -124,16 +124,18 @@ describe('StartProcessCloudComponent', () => {
typeValueInto('#processName', 'OLE');
typeValueInto('#processDefinitionName', 'processwithoutform2');
fixture.detectChanges();
fixture.whenStable();
tick(450);
const startBtn = fixture.nativeElement.querySelector('#button-start');
expect(startBtn.disabled).toBe(false);
expect(component.isProcessFormValid()).toBe(true);
expect(createProcessSpy).toHaveBeenCalledWith('MyApp', new ProcessPayloadCloud({name: 'OLE',
processDefinitionKey: fakeProcessDefinitions[1].key}));
expect(component.currentCreatedProcess.status).toBe('CREATED');
expect(component.currentCreatedProcess.startDate).toBeNull();
fixture.whenStable().then(() => {
fixture.detectChanges();
const startBtn = fixture.nativeElement.querySelector('#button-start');
expect(startBtn.disabled).toBe(false);
expect(component.isProcessFormValid()).toBe(true);
expect(createProcessSpy).toHaveBeenCalledWith('MyApp', new ProcessPayloadCloud({name: 'OLE',
processDefinitionKey: fakeProcessDefinitions[1].key}));
expect(component.currentCreatedProcess.status).toBe('CREATED');
expect(component.currentCreatedProcess.startDate).toBeNull();
});
}));
it('should be able to start a process with a valid process name and process definition', async(() => {
@@ -152,6 +154,28 @@ describe('StartProcessCloudComponent', () => {
});
}));
it('should have start button disabled if create operation failed', fakeAsync(() => {
createProcessSpy.and.returnValue(throwError('fake error'));
const change = new SimpleChange(null, 'MyApp', true);
fixture.detectChanges();
component.ngOnChanges({ 'appName': change });
fixture.detectChanges();
tick();
typeValueInto('#processName', 'OLE');
typeValueInto('#processDefinitionName', 'processwithoutform2');
fixture.detectChanges();
tick(450);
fixture.whenStable().then(() => {
fixture.detectChanges();
const startBtn = fixture.nativeElement.querySelector('#button-start');
expect(startBtn.disabled).toBe(true);
expect(component.isProcessFormValid()).toBe(false);
expect(createProcessSpy).toHaveBeenCalledWith('MyApp', component.processPayloadCloud);
});
}));
it('should have start button disabled when no process is selected', async(() => {
component.name = '';
component.processDefinitionName = '';
@@ -191,7 +215,7 @@ describe('StartProcessCloudComponent', () => {
component.name = 'My new process with form';
});
it('should be able to start a process with a valid form', async(() => {
it('should be able to start a process with a valid form', fakeAsync(() => {
component.processDefinitionName = 'processwithform';
getDefinitionsSpy.and.returnValue(of(fakeSingleProcessDefinition(component.processDefinitionName)));
fixture.detectChanges();
@@ -200,8 +224,14 @@ describe('StartProcessCloudComponent', () => {
const change = new SimpleChange(null, 'MyApp', true);
component.ngOnChanges({ 'appName': change });
fixture.detectChanges();
tick();
typeValueInto('#processName', 'My new process with form');
typeValueInto('#processDefinitionName', 'processwithform');
fixture.detectChanges();
tick(450);
fixture.whenStable().then(() => {
fixture.detectChanges();
const firstNameEl = fixture.nativeElement.querySelector('#firstName');
expect(firstNameEl).toBeDefined();
const lastNameEl = fixture.nativeElement.querySelector('#lastName');
@@ -212,8 +242,7 @@ describe('StartProcessCloudComponent', () => {
});
}));
it('should NOT be able to start a process with a form NOT valid', async(() => {
component.processDefinitionName = 'processwithform';
it('should NOT be able to start a process with a form NOT valid', fakeAsync(() => {
getDefinitionsSpy.and.returnValue(of(fakeSingleProcessDefinition(component.processDefinitionName)));
fixture.detectChanges();
formDefinitionSpy = spyOn(formCloudService, 'getForm').and.returnValue(of(fakeStartFormNotValid));
@@ -222,7 +251,14 @@ describe('StartProcessCloudComponent', () => {
component.ngOnChanges({ 'appName': change });
fixture.detectChanges();
tick();
typeValueInto('#processName', 'My new process with form');
typeValueInto('#processDefinitionName', 'processwithform');
fixture.detectChanges();
tick(450);
fixture.whenStable().then(() => {
fixture.detectChanges();
const firstNameEl = fixture.nativeElement.querySelector('#firstName');
expect(firstNameEl).toBeDefined();
const lastNameEl = fixture.nativeElement.querySelector('#lastName');
@@ -233,7 +269,7 @@ describe('StartProcessCloudComponent', () => {
});
}));
it('should be able to start a process with a prefilled valid form', async(() => {
it('should be able to start a process with a prefilled valid form', fakeAsync(() => {
component.processDefinitionName = 'processwithform';
getDefinitionsSpy.and.returnValue(of(fakeSingleProcessDefinition(component.processDefinitionName)));
component.values = [{'name': 'firstName', 'value': 'FakeName'}, {'name': 'lastName', 'value': 'FakeLastName'}];
@@ -244,7 +280,14 @@ describe('StartProcessCloudComponent', () => {
component.ngOnChanges({ 'appName': change });
fixture.detectChanges();
tick();
typeValueInto('#processName', 'My new process with form');
typeValueInto('#processDefinitionName', 'processwithform');
fixture.detectChanges();
tick(450);
fixture.whenStable().then(() => {
fixture.detectChanges();
const firstNameEl = fixture.nativeElement.querySelector('#firstName');
expect(firstNameEl).toBeDefined();
expect(firstNameEl.value).toEqual('FakeName');
@@ -293,17 +336,19 @@ describe('StartProcessCloudComponent', () => {
const change = new SimpleChange(null, 'MyApp', true);
component.ngOnChanges({ 'appName': change });
fixture.detectChanges();
fixture.whenStable();
tick(450);
const startBtn = fixture.nativeElement.querySelector('#button-start');
expect(startBtn.disabled).toBe(false);
expect(component.formCloud.isValid).toBe(true);
expect(component.isProcessFormValid()).toBe(true);
expect(createProcessSpy).toHaveBeenCalledWith('MyApp', new ProcessPayloadCloud({name: 'testFormWithProcess',
processDefinitionKey: fakeProcessDefinitions[1].key}));
expect(component.currentCreatedProcess.status).toBe('CREATED');
expect(component.currentCreatedProcess.startDate).toBeNull();
fixture.whenStable().then(() => {
fixture.detectChanges();
const startBtn = fixture.nativeElement.querySelector('#button-start');
expect(startBtn.disabled).toBe(false);
expect(component.formCloud.isValid).toBe(true);
expect(component.isProcessFormValid()).toBe(true);
expect(createProcessSpy).toHaveBeenCalledWith('MyApp', new ProcessPayloadCloud({name: 'testFormWithProcess',
processDefinitionKey: fakeProcessDefinitions[1].key}));
expect(component.currentCreatedProcess.status).toBe('CREATED');
expect(component.currentCreatedProcess.startDate).toBeNull();
});
}));
});

View File

@@ -26,7 +26,7 @@ import { FormControl, Validators, FormGroup, AbstractControl, FormBuilder, Valid
import { FormModel, ContentLinkModel } from '@alfresco/adf-core';
import { MatAutocompleteTrigger } from '@angular/material';
import { ProcessPayloadCloud } from '../models/process-payload-cloud.model';
import { debounceTime, takeUntil, switchMap, filter, distinctUntilChanged } from 'rxjs/operators';
import { debounceTime, takeUntil, switchMap, filter, distinctUntilChanged, tap } from 'rxjs/operators';
import { ProcessDefinitionCloud } from '../models/process-definition-cloud.model';
import { Subject, Observable, concat } from 'rxjs';
import { TaskVariableCloud } from '../../../form/models/task-variable-cloud.model';
@@ -122,6 +122,7 @@ export class StartProcessCloudComponent implements OnChanges, OnInit, OnDestroy
this.processForm.valueChanges
.pipe(
tap(() => this.currentCreatedProcess = undefined),
debounceTime(400),
distinctUntilChanged(),
filter(() => this.isProcessSelectionValid()),