Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AAE-32255 Start Process button in start event is showing and failing for form with custom outcomes #10697

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/core/src/lib/form/components/form-base.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ export abstract class FormBaseComponent {
*/
formStyle: string = '';

get hasVisibleOutcomes(): boolean {
return this.form?.outcomes?.some((outcome) => this.isOutcomeButtonVisible(outcome, this.form.readOnly));
}

get form(): FormModel {
return this._form;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@

<ng-container *ngIf="hasForm else taskFormCloudButtons">
<adf-cloud-form
#startForm
[appName]="appName"
[appVersion]="processDefinitionCurrent.appVersion"
[data]="resolvedValues"
Expand Down Expand Up @@ -108,7 +109,7 @@
{{ cancelButtonLabel }}
</button>
<button
*ngIf="showStartProcessButton"
*ngIf="shouldShowStartProcessButton()"
color="primary"
mat-raised-button
[disabled]="disableStartButton || !isProcessFormValid"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ import {
fakeNoNameProcessDefinitions,
fakeSingleProcessDefinition,
fakeSingleProcessDefinitionWithoutForm,
fakeFormModelJson
fakeFormModelJson,
fakeStartFormWithOutcomes
} from '../mock/start-process.component.mock';
import { By } from '@angular/platform-browser';
import { ProcessPayloadCloud } from '../models/process-payload-cloud.model';
Expand Down Expand Up @@ -69,6 +70,8 @@ describe('StartProcessCloudComponent', () => {

const panel = await loader.getHarness(MatAutocompleteHarness);
await panel.selectOption({ text: name });
fixture.detectChanges();
await fixture.whenStable();
};

const typeValueInto = (selector: any, value: string) => {
Expand Down Expand Up @@ -185,8 +188,6 @@ describe('StartProcessCloudComponent', () => {
component.name = 'My new process';
component.processDefinitionName = 'process';
await selectOptionByName('processwithoutform2');
fixture.detectChanges();
await fixture.whenStable();

expect(component.processDefinitionCurrent.name).toBe(JSON.parse(JSON.stringify(fakeProcessDefinitions[1])).name);
const startBtn = fixture.nativeElement.querySelector('#button-start');
Expand Down Expand Up @@ -537,8 +538,6 @@ describe('StartProcessCloudComponent', () => {
await fixture.whenStable();

await selectOptionByName('processwithform');
fixture.detectChanges();
await fixture.whenStable();

component.processDefinitionName = fakeProcessDefinitions[2].name;
component.setProcessDefinitionOnForm(fakeProcessDefinitions[2].name);
Expand Down Expand Up @@ -570,9 +569,6 @@ describe('StartProcessCloudComponent', () => {
component.ngOnChanges({});
await selectOptionByName('process');

fixture.detectChanges();
await fixture.whenStable();

expect(component.processDefinitionCurrent.name).toBe(JSON.parse(JSON.stringify(fakeProcessDefinitions[3])).name);
expect(component.processDefinitionCurrent.key).toBe(JSON.parse(JSON.stringify(fakeProcessDefinitions[3])).key);
});
Expand Down Expand Up @@ -701,16 +697,38 @@ describe('StartProcessCloudComponent', () => {
fixture.detectChanges();
});

it('should see start button', async () => {
it('should show start button', () => {
component.ngOnChanges({ appName: firstChange });
fixture.detectChanges();
await fixture.whenStable();

const startButton = fixture.debugElement.query(By.css('#button-start'));
expect(startButton).toBeDefined();
expect(startButton).not.toBeNull();
});

it('should show start button when start process has form without outcomes', async () => {
formDefinitionSpy.and.returnValue(of(fakeStartForm));
component.ngOnChanges({ appName: firstChange });
fixture.detectChanges();

await selectOptionByName('processwithform');

const startButton = fixture.debugElement.query(By.css('#button-start'));
expect(startButton).toBeDefined();
expect(startButton).not.toBeNull();
});

it('should NOT see start button when start process has form with outcomes', async () => {
formDefinitionSpy.and.returnValue(of(fakeStartFormWithOutcomes));
component.ngOnChanges({ appName: firstChange });
fixture.detectChanges();

await selectOptionByName('processwithform');

const startButton = fixture.debugElement.query(By.css('#button-start'));
expect(startButton).toBeNull();
});

it('should call service with the correct parameters when button is clicked and variables are defined and formCloud is undefined', async () => {
component.ngOnChanges({ appName: firstChange });
component.processForm.controls['processInstanceName'].setValue('My Process 1');
Expand Down Expand Up @@ -820,8 +838,6 @@ describe('StartProcessCloudComponent', () => {
await fixture.whenStable();

await selectOptionByName('processwithform');
fixture.detectChanges();
await fixture.whenStable();

component.processDefinitionName = fakeProcessDefinitions[2].name;
component.setProcessDefinitionOnForm(fakeProcessDefinitions[2].name);
Expand Down Expand Up @@ -941,8 +957,6 @@ describe('StartProcessCloudComponent', () => {
await fixture.whenStable();
component.processDefinitionName = 'processwithoutform1';
await selectOptionByName(fakeProcessDefinitions[0].name);
fixture.detectChanges();
await fixture.whenStable();
expect(emitSpy).toHaveBeenCalledOnceWith(fakeProcessDefinitions[0]);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ export class StartProcessCloudComponent implements OnChanges, OnInit {
@ViewChild(MatAutocompleteTrigger)
inputAutocomplete: MatAutocompleteTrigger;

@ViewChild('startForm') startForm: FormCloudComponent;

/** (required) Name of the app. */
@Input()
appName: string = '';
Expand Down Expand Up @@ -163,7 +165,7 @@ export class StartProcessCloudComponent implements OnChanges, OnInit {
isFormCloudLoading = false;
processDefinitionLoaded = false;

showStartProcessButton = true;
startEnabledConstant: string;
startProcessButtonLabel: string;
cancelButtonLabel: string;

Expand Down Expand Up @@ -294,7 +296,7 @@ export class StartProcessCloudComponent implements OnChanges, OnInit {
const cancelLabel = constants?.find((constant) => constant.name === 'cancelLabel');

if (displayStart) {
this.showStartProcessButton = displayStart?.value === 'true';
this.startEnabledConstant = displayStart?.value;
}
if (startLabel) {
this.startProcessButtonLabel = startLabel?.value?.trim()?.length > 0 ? startLabel.value.trim() : this.defaultStartProcessButtonLabel;
Expand Down Expand Up @@ -530,4 +532,10 @@ export class StartProcessCloudComponent implements OnChanges, OnInit {
}
return processName;
}

shouldShowStartProcessButton(): boolean {
if (this.startEnabledConstant) return this.startEnabledConstant === 'true';

return !this.startForm?.hasVisibleOutcomes;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,26 @@ export const fakeStartForm = {
}
};

export const fakeStartFormWithOutcomes = {
formRepresentation: {
...fakeStartForm.formRepresentation,
formDefinition: {
...fakeStartForm.formRepresentation.formDefinition,
outcomes: [
{
id: 'c5676ca7-8ad4-421c-9538-aaf8560bd5fc',
name: 'Option 1',
visibilityCondition: null
},
{
id: '48e9c1f8-50b9-4d2f-998c-7836c132986f',
name: 'Option 2',
visibilityCondition: null
}
]
}
}
};
export const fakeStartFormNotValid = {
formRepresentation: {
id: 'form-a5d50817-5183-4850-802d-17af54b2632f',
Expand Down
Loading