Skip to content

Commit

Permalink
AAE-23358: Fix allowing to bypass required form on start event by cli… (
Browse files Browse the repository at this point in the history
#9977)

* AAE-23358: Fix allowing to bypass required form on start event by clicking the start button before form is loaded

* AAE-23358 change submit button disabled condition to make solution more in sync with original one

* Use specific version and regenerate the lock

---------

Co-authored-by: mauriziovitale <[email protected]>
Co-authored-by: Eugenio Romano <[email protected]>
  • Loading branch information
3 people committed Jul 31, 2024
1 parent 72ea94e commit fcd9d64
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 88 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<mat-card appearance="outlined" class="adf-start-process" *ngIf="(loading$ | async) === false; else spinner">
<mat-card appearance="outlined" class="adf-start-process" *ngIf="processDefinitionLoaded; else spinner">

<mat-card-content>

<mat-card-title
*ngIf="showTitle"
class="adf-title">
Expand All @@ -12,7 +11,7 @@
{{ errorMessageId | translate }}
</mat-card-subtitle>

<div *ngIf="!isProcessDefinitionsEmpty(); else emptyProcessDefinitionsList">
<div *ngIf="!isProcessDefinitionsEmpty; else emptyProcessDefinitionsList">
<form [formGroup]="processForm" class="adf-select-process-form">
<mat-form-field
class="adf-process-input-container"
Expand Down Expand Up @@ -72,7 +71,7 @@
</adf-inplace-form-input>
</form>

<ng-container *ngIf="hasForm() else taskFormCloudButtons">
<ng-container *ngIf="hasForm else taskFormCloudButtons">
<adf-cloud-form
[appName]="appName"
[appVersion]="processDefinitionCurrent.appVersion"
Expand Down Expand Up @@ -111,7 +110,7 @@
<button
color="primary"
mat-raised-button
[disabled]="disableStartButton() || !isProcessFormValid()"
[disabled]="disableStartButton || !isProcessFormValid"
(click)="startProcess()"
data-automation-id="btn-start"
id="button-start"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ describe('StartProcessCloudComponent', () => {

fixture.detectChanges();
const startBtn = fixture.nativeElement.querySelector('#button-start');
expect(component.isProcessFormValid()).toBe(true);
expect(component.isProcessFormValid).toBe(true);
expect(startBtn.disabled).toBe(false);
}));

Expand All @@ -154,7 +154,7 @@ describe('StartProcessCloudComponent', () => {

expect(component.processDefinitionCurrent.name).toBe(JSON.parse(JSON.stringify(fakeProcessDefinitions[1])).name);
const startBtn = fixture.nativeElement.querySelector('#button-start');
expect(component.isProcessFormValid()).toBe(true);
expect(component.isProcessFormValid).toBe(true);
expect(startBtn.disabled).toBe(false);
});

Expand All @@ -167,7 +167,7 @@ describe('StartProcessCloudComponent', () => {

const startBtn = fixture.nativeElement.querySelector('#button-start');
expect(startBtn.disabled).toBe(true);
expect(component.isProcessFormValid()).toBe(false);
expect(component.isProcessFormValid).toBe(false);
});

it('should have start button disabled when name not filled out', async () => {
Expand All @@ -179,7 +179,7 @@ describe('StartProcessCloudComponent', () => {

const startBtn = fixture.nativeElement.querySelector('#button-start');
expect(startBtn.disabled).toBe(true);
expect(component.isProcessFormValid()).toBe(false);
expect(component.isProcessFormValid).toBe(false);
});

it('should include the static input mappings in the resolved values', fakeAsync(() => {
Expand Down Expand Up @@ -334,7 +334,7 @@ describe('StartProcessCloudComponent', () => {

const startBtn = fixture.nativeElement.querySelector('#button-start');
expect(startBtn.disabled).toBe(false);
expect(component.isProcessFormValid()).toBe(true);
expect(component.isProcessFormValid).toBe(true);
});

it('should have start button enabled when default values are set', async () => {
Expand Down Expand Up @@ -444,7 +444,7 @@ describe('StartProcessCloudComponent', () => {
await fixture.whenStable();

const processForm = fixture.nativeElement.querySelector('adf-cloud-form');
expect(component.hasForm()).toBeTruthy();
expect(component.hasForm).toBeTruthy();
expect(processForm).not.toBeNull();
});

Expand Down Expand Up @@ -713,7 +713,7 @@ describe('StartProcessCloudComponent', () => {
await fixture.whenStable();

const processForm = fixture.nativeElement.querySelector('adf-cloud-form');
expect(component.hasForm()).toBeTruthy();
expect(component.hasForm).toBeTruthy();
expect(processForm).not.toBeNull();

const payload: ProcessPayloadCloud = new ProcessPayloadCloud({
Expand Down Expand Up @@ -896,7 +896,6 @@ describe('StartProcessCloudComponent', () => {
});

it('should hide title', () => {
component.loading$.next(false);
component.showTitle = false;
fixture.detectChanges();

Expand All @@ -906,7 +905,7 @@ describe('StartProcessCloudComponent', () => {
});

it('should show title', () => {
component.loading$.next(false);
component.processDefinitionLoaded = true;
fixture.detectChanges();

const title = fixture.debugElement.query(By.css('.adf-title'));
Expand All @@ -915,7 +914,7 @@ describe('StartProcessCloudComponent', () => {
});

it('should show process definition dropdown', () => {
component.loading$.next(false);
component.processDefinitionLoaded = true;
component.processDefinitionList = fakeProcessDefinitions;
fixture.detectChanges();

Expand All @@ -925,7 +924,7 @@ describe('StartProcessCloudComponent', () => {
});

it('should hide process definition dropdown', () => {
component.loading$.next(false);
component.processDefinitionLoaded = true;
component.processDefinitionList = fakeProcessDefinitions;
component.showSelectProcessDropdown = false;
fixture.detectChanges();
Expand All @@ -936,7 +935,7 @@ describe('StartProcessCloudComponent', () => {
});

it('should show the loading spinner before process definitions loaded', () => {
component.loading$.next(true);
component.processDefinitionLoaded = false;
fixture.detectChanges();

const spinner = fixture.debugElement.query(By.css('.adf-loading'));
Expand All @@ -945,7 +944,7 @@ describe('StartProcessCloudComponent', () => {
});

it('should show the process card after process definitions loaded', () => {
component.loading$.next(false);
component.processDefinitionLoaded = true;
fixture.detectChanges();

const card = fixture.debugElement.query(By.css('.adf-start-process'));
Expand All @@ -964,31 +963,45 @@ describe('StartProcessCloudComponent', () => {
component.processDefinitionName = fakeProcessDefinitions[0].name;
});

it('start process button should be enabled when isLoading is false', async () => {
it('start process button should be enabled when isProcessStarting is false', async () => {
fixture.detectChanges();
component.processForm.controls['processInstanceName'].setValue(fakeProcessDefinitions[0].id);
component.appName = 'test app name';
component.isLoading = false;
component.isProcessStarting = false;
fixture.detectChanges();
await fixture.whenStable();

const startButton = fixture.debugElement.query(By.css('#button-start'));
expect(startButton).not.toBeNull();
expect(component.disableStartButton()).toBeFalse();
expect(component.disableStartButton).toBeFalse();
expect((startButton.nativeElement as HTMLButtonElement).disabled).toBeFalse();
});

it('start process button should be disabled when isFormCloudLoading is true', async () => {
fixture.detectChanges();
component.processForm.controls['processInstanceName'].setValue(fakeProcessDefinitions[0].id);
component.appName = 'test app name';
component.isFormCloudLoading = true;
fixture.detectChanges();
await fixture.whenStable();

const startButton = fixture.debugElement.query(By.css('#button-start'));
expect(startButton).not.toBeNull();
expect(component.disableStartButton).toBeTrue();
expect((startButton.nativeElement as HTMLButtonElement).disabled).toBeTrue();
});

it('start process button should be disabled when isLoading is true', async () => {
fixture.detectChanges();
component.processForm.controls['processInstanceName'].setValue(fakeProcessDefinitions[0].id);
component.appName = 'test app name';
component.isLoading = true;
component.isProcessStarting = true;
fixture.detectChanges();
await fixture.whenStable();

const startButton = fixture.debugElement.query(By.css('#button-start'));
expect(startButton).not.toBeNull();
expect(component.disableStartButton()).toBeTrue();
expect(component.disableStartButton).toBeTrue();
expect((startButton.nativeElement as HTMLButtonElement).disabled).toBeTrue();
});
});
Expand Down
Loading

0 comments on commit fcd9d64

Please sign in to comment.