[AAE-8740] Add a confirmation message in ADW

This commit is contained in:
Ketevani Kvirikashvili
2022-05-31 15:58:39 +02:00
parent 4c70a84568
commit 0ecb7298b9
4 changed files with 119 additions and 62 deletions

View File

@@ -161,6 +161,7 @@ export abstract class FormBaseComponent {
* @param outcome Form outcome model
*/
onOutcomeClicked(outcome: FormOutcomeModel): boolean {
debugger
if (!this.readOnly && outcome && this.form) {
if (!this.onExecuteOutcome(outcome)) {

View File

@@ -65,6 +65,7 @@ export class FormModel implements ProcessFormModel {
readonly id: string | number;
readonly name: string;
readonly confirmMessage: {show: boolean, message: string};
readonly taskId: string;
readonly taskName = FormModel.UNSET_TASK_NAME;
readonly processDefinitionId: string;
@@ -93,6 +94,7 @@ export class FormModel implements ProcessFormModel {
if (json) {
this.id = json.id;
this.name = json.name;
this.confirmMessage = json.confirmMessage || {};
this.taskId = json.taskId;
this.taskName = json.taskName || json.name || FormModel.UNSET_TASK_NAME;
this.processDefinitionId = json.processDefinitionId;

View File

@@ -689,6 +689,7 @@ fdescribe('FormCloudComponent', () => {
});
it('should require form with appName and taskId to complete', () => {
debugger;
spyOn(formCloudService, 'completeTaskForm').and.stub();
formComponent.form = null;
@@ -744,60 +745,73 @@ fdescribe('FormCloudComponent', () => {
expect(formComponent.parseForm(null)).toBeNull();
});
fit('should open confirmation dialog on complete task', () => {
spyOn(matDialog, 'open').and.returnValue({
afterClosed: () => of(false)
} as any);
it('should open confirmation dialog on complete task', () => {
// spyOn(matDialog, 'open').and.returnValue({ beforeClosed: () => of() } as any);
spyOn(matDialog, 'open').and.returnValue({ afterClosed: () => of(false) } as any);
formComponent.form = new FormModel({
confirmMessage: {
show: true,
message: 'Are you sure you want to submit the form?'
}
});
formComponent.completeTaskForm();
expect(matDialog.open).toHaveBeenCalled();
});
// fit('should submit form when user confirms', () => {
// fixture.detectChanges();
// spyOn(matDialog, 'open').and.returnValue({
// afterClosed: () => of(true)
// } as any);
it('should submit form when user confirms', () => {
fixture.detectChanges();
const afterClose = of(true);
// spyOn(formComponent['formCloudService'], 'completeTaskForm').and.returnValue(Promise.resolve(false));
spyOn(matDialog, 'open').and.returnValue({
afterClosed: () => afterClose
} as any);
// const taskId = '123-223';
// const appVersion = 1;
// const appName = 'test-app';
// const processInstanceId = '333-444';
spyOn(formComponent['formCloudService'], 'completeTaskForm').and.returnValue(Promise.resolve(false));
const outcome = 'complete';
// const formModel = new FormModel({
// id: '23',
// taskId,
// fields: [
// { id: 'field1' },
// { id: 'field2' }
// ]
// });
const taskId = '123-223';
const appVersion = 1;
const appName = 'test-app';
const processInstanceId = '333-444';
// formComponent.appVersion = appVersion;
// formComponent.form = formModel;
// formComponent.taskId = taskId;
// formComponent.appName = appName;
// formComponent.processInstanceId = processInstanceId;
// formComponent.completeTaskForm('outcome');
// expect(matDialog.open).toHaveBeenCalled();
// expect(formComponent['formCloudService'].completeTaskForm).toHaveBeenCalledWith(appName, formModel.taskId, processInstanceId, formModel.id, formModel.values, 'outcome', appVersion);
// });
const formModel = new FormModel({
id: '23',
taskId,
fields: [
{ id: 'field1' },
{ id: 'field2' }
],
confirmMessage: {
show: true,
message: 'Are you sure you want to submit the form?'
}
});
// fit('should not confirm form if user rejects', () => {
// spyOn(matDialog, 'open').and.returnValue({
// afterClosed: () => of(false)
// } as any);
formComponent.appVersion = appVersion;
formComponent.form = formModel;
formComponent.taskId = taskId;
formComponent.appName = appName;
formComponent.processInstanceId = processInstanceId;
formComponent.completeTaskForm(outcome);
expect(matDialog.open).toHaveBeenCalled();
// spyOn(formComponent['formCloudService'], 'completeTaskForm').and.returnValue(Promise.resolve(false));
// formComponent.completeTaskForm();
expect(formComponent['formCloudService'].completeTaskForm).toHaveBeenCalledWith(appName, formModel.taskId, processInstanceId, formModel.id, formModel.values, outcome, appVersion);
});
// expect(formCloudService.completeTaskForm).not.toHaveBeenCalled();
it('should not confirm form if user rejects', () => {
const outcome = 'complete';
// formComponent.completeTaskForm('outcome');
// expect(formComponent['formCloudService'].completeTaskForm).not.toHaveBeenCalled();
// });
spyOn(matDialog, 'open').and.returnValue({
afterClosed: () => of(false)
} as any);
spyOn(formComponent['formCloudService'], 'completeTaskForm').and.returnValue(Promise.resolve(false));
formComponent.completeTaskForm(outcome);
expect(formComponent['formCloudService'].completeTaskForm).not.toHaveBeenCalled();
});
it('should parse form from json', () => {
const form = formComponent.parseForm({

View File

@@ -272,30 +272,70 @@ export class FormCloudComponent extends FormBaseComponent implements OnChanges,
completeTaskForm(outcome?: string) {
debugger;
// this.form.values.confirmMessage
const dialogRef = this.dialog.open(ConfirmDialogComponent, {
data: {
title: 'Save the form',
message: 'Do you want to save the form?'
},
minWidth: '250px'
});
dialogRef.afterClosed().subscribe((result) => {
if (result === true) {
if (this.form && this.appName && this.taskId) {
this.formCloudService
.completeTaskForm(this.appName, this.taskId, this.processInstanceId, `${this.form.id}`, this.form.values, outcome, this.appVersion)
.pipe(takeUntil(this.onDestroy$))
.subscribe(
() => {
this.onTaskCompleted(this.form);
},
(error) => this.onTaskCompletedError(error)
);
// const confirmMessage = this.form.json.confirmMessage.message;
if (this.form?.confirmMessage?.show === true) {
const dialogRef = this.dialog.open(ConfirmDialogComponent, {
data: {
title: 'Save the form',
message: this.form.confirmMessage.message
},
minWidth: '450px'
});
dialogRef.afterClosed().subscribe((result) => {
if (result === true) {
if (this.form && this.appName && this.taskId) {
this.formCloudService
.completeTaskForm(this.appName, this.taskId, this.processInstanceId, `${this.form.id}`, this.form.values, outcome, this.appVersion)
.pipe(takeUntil(this.onDestroy$))
.subscribe(
() => {
this.onTaskCompleted(this.form);
},
(error) => this.onTaskCompletedError(error)
);
}
}
});
} else {
if (this.form && this.appName && this.taskId) {
this.formCloudService
.completeTaskForm(this.appName, this.taskId, this.processInstanceId, `${this.form.id}`, this.form.values, outcome, this.appVersion)
.pipe(takeUntil(this.onDestroy$))
.subscribe(
() => {
this.onTaskCompleted(this.form);
},
(error) => this.onTaskCompletedError(error)
);
}
});
}
// const dialogRef = this.dialog.open(ConfirmDialogComponent, {
// data: {
// title: 'Save the form',
// message: this.form.confirmMessage.message
// },
// minWidth: '450px'
// });
// dialogRef.afterClosed().subscribe((result) => {
// if (result === true) {
// if (this.form && this.appName && this.taskId) {
// this.formCloudService
// .completeTaskForm(this.appName, this.taskId, this.processInstanceId, `${this.form.id}`, this.form.values, outcome, this.appVersion)
// .pipe(takeUntil(this.onDestroy$))
// .subscribe(
// () => {
// this.onTaskCompleted(this.form);
// },
// (error) => this.onTaskCompletedError(error)
// );
// }
// }
// });
}
parseForm(formCloudRepresentationJSON: any): FormModel {