mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-06-30 18:15:11 +00:00
[AAE-8740 Add a confirmation message in ADW (#7660)
* [AAE-8740 Add a confirmation message in ADW * update tests * use MatDialogHarness for tests * Cleaning tests Co-authored-by: Bartosz Sekula <Bartosz.Sekula@hyland.com>
This commit is contained in:
parent
7c13a99ed7
commit
aeb5bff264
@ -35,6 +35,10 @@ import { FormValidationService } from '../../../services/form-validation-service
|
|||||||
import { ProcessFormModel } from './process-form-model.interface';
|
import { ProcessFormModel } from './process-form-model.interface';
|
||||||
import { WidgetTypeEnum, WidgetVisibilityModel } from '../../../models/widget-visibility.model';
|
import { WidgetTypeEnum, WidgetVisibilityModel } from '../../../models/widget-visibility.model';
|
||||||
|
|
||||||
|
export interface ConfirmMessage {
|
||||||
|
show: boolean;
|
||||||
|
message: string;
|
||||||
|
}
|
||||||
export interface FormRepresentationModel {
|
export interface FormRepresentationModel {
|
||||||
[key: string]: any;
|
[key: string]: any;
|
||||||
|
|
||||||
@ -55,7 +59,6 @@ export interface FormRepresentationModel {
|
|||||||
fields?: any[];
|
fields?: any[];
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export class FormModel implements ProcessFormModel {
|
export class FormModel implements ProcessFormModel {
|
||||||
|
|
||||||
static UNSET_TASK_NAME: string = 'Nameless task';
|
static UNSET_TASK_NAME: string = 'Nameless task';
|
||||||
@ -66,6 +69,7 @@ export class FormModel implements ProcessFormModel {
|
|||||||
readonly id: string | number;
|
readonly id: string | number;
|
||||||
readonly name: string;
|
readonly name: string;
|
||||||
readonly taskId: string;
|
readonly taskId: string;
|
||||||
|
readonly confirmMessage: ConfirmMessage;
|
||||||
readonly taskName = FormModel.UNSET_TASK_NAME;
|
readonly taskName = FormModel.UNSET_TASK_NAME;
|
||||||
readonly processDefinitionId: string;
|
readonly processDefinitionId: string;
|
||||||
readonly selectedOutcome: string;
|
readonly selectedOutcome: string;
|
||||||
@ -102,6 +106,7 @@ export class FormModel implements ProcessFormModel {
|
|||||||
this.variables = json.variables || [];
|
this.variables = json.variables || [];
|
||||||
this.processVariables = json.processVariables || [];
|
this.processVariables = json.processVariables || [];
|
||||||
this.enableFixedSpace = enableFixedSpace ? true : false;
|
this.enableFixedSpace = enableFixedSpace ? true : false;
|
||||||
|
this.confirmMessage = json.confirmMessage || {};
|
||||||
|
|
||||||
const tabCache: FormWidgetModelCache<TabModel> = {};
|
const tabCache: FormWidgetModelCache<TabModel> = {};
|
||||||
|
|
||||||
|
@ -55,6 +55,10 @@ import { NoopAnimationsModule } from '@angular/platform-browser/animations';
|
|||||||
import { CloudFormRenderingService } from './cloud-form-rendering.service';
|
import { CloudFormRenderingService } from './cloud-form-rendering.service';
|
||||||
import { Node } from '@alfresco/js-api';
|
import { Node } from '@alfresco/js-api';
|
||||||
import { ESCAPE } from '@angular/cdk/keycodes';
|
import { ESCAPE } from '@angular/cdk/keycodes';
|
||||||
|
import { MatDialog } from '@angular/material/dialog';
|
||||||
|
import { HarnessLoader } from '@angular/cdk/testing';
|
||||||
|
import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed';
|
||||||
|
import { MatDialogHarness } from '@angular/material/dialog/testing';
|
||||||
|
|
||||||
const mockOauth2Auth: any = {
|
const mockOauth2Auth: any = {
|
||||||
oauth2Auth: {
|
oauth2Auth: {
|
||||||
@ -68,9 +72,11 @@ describe('FormCloudComponent', () => {
|
|||||||
let formCloudService: FormCloudService;
|
let formCloudService: FormCloudService;
|
||||||
let fixture: ComponentFixture<FormCloudComponent>;
|
let fixture: ComponentFixture<FormCloudComponent>;
|
||||||
let formComponent: FormCloudComponent;
|
let formComponent: FormCloudComponent;
|
||||||
|
let matDialog: MatDialog;
|
||||||
let visibilityService: WidgetVisibilityService;
|
let visibilityService: WidgetVisibilityService;
|
||||||
let formRenderingService: CloudFormRenderingService;
|
let formRenderingService: CloudFormRenderingService;
|
||||||
let translateService: TranslateService;
|
let translateService: TranslateService;
|
||||||
|
let documentRootLoader: HarnessLoader;
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'adf-cloud-custom-widget',
|
selector: 'adf-cloud-custom-widget',
|
||||||
@ -130,12 +136,14 @@ describe('FormCloudComponent', () => {
|
|||||||
formCloudService = TestBed.inject(FormCloudService);
|
formCloudService = TestBed.inject(FormCloudService);
|
||||||
|
|
||||||
translateService = TestBed.inject(TranslateService);
|
translateService = TestBed.inject(TranslateService);
|
||||||
|
matDialog = TestBed.inject(MatDialog);
|
||||||
|
|
||||||
visibilityService = TestBed.inject(WidgetVisibilityService);
|
visibilityService = TestBed.inject(WidgetVisibilityService);
|
||||||
spyOn(visibilityService, 'refreshVisibility').and.callThrough();
|
spyOn(visibilityService, 'refreshVisibility').and.callThrough();
|
||||||
|
|
||||||
fixture = TestBed.createComponent(FormCloudComponent);
|
fixture = TestBed.createComponent(FormCloudComponent);
|
||||||
formComponent = fixture.componentInstance;
|
formComponent = fixture.componentInstance;
|
||||||
|
documentRootLoader = TestbedHarnessEnvironment.documentRootLoader(fixture);
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -737,6 +745,63 @@ describe('FormCloudComponent', () => {
|
|||||||
expect(completed).toBeTruthy();
|
expect(completed).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should open confirmation dialog on complete task', async () => {
|
||||||
|
formComponent.form = new FormModel({
|
||||||
|
confirmMessage: {
|
||||||
|
show: true,
|
||||||
|
message: 'Are you sure you want to submit the form?'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
formComponent.completeTaskForm();
|
||||||
|
let dialogs = await documentRootLoader.getAllHarnesses(MatDialogHarness);
|
||||||
|
expect(dialogs.length).toBe(1);
|
||||||
|
|
||||||
|
await dialogs[0].close();
|
||||||
|
dialogs = await documentRootLoader.getAllHarnesses(MatDialogHarness);
|
||||||
|
expect(dialogs.length).toBe(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should submit form when user confirms', () => {
|
||||||
|
spyOn(matDialog, 'open').and.returnValue({ afterClosed: () => of(true) });
|
||||||
|
fixture.detectChanges();
|
||||||
|
|
||||||
|
const formModel = new FormModel({
|
||||||
|
confirmMessage: {
|
||||||
|
show: true,
|
||||||
|
message: 'Are you sure you want to submit the form?'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
formComponent.form = formModel;
|
||||||
|
formComponent.taskId = 'id';
|
||||||
|
formComponent.appName = 'appName';
|
||||||
|
|
||||||
|
spyOn(formComponent['formCloudService'], 'completeTaskForm').and.returnValue(of(formModel));
|
||||||
|
formComponent.completeTaskForm('complete');
|
||||||
|
|
||||||
|
expect(formComponent['formCloudService'].completeTaskForm).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not confirm form if user rejects', () => {
|
||||||
|
const outcome = 'complete';
|
||||||
|
spyOn(matDialog, 'open').and.returnValue({ afterClosed: () => of(false) });
|
||||||
|
|
||||||
|
const formModel = new FormModel({
|
||||||
|
confirmMessage: {
|
||||||
|
show: true,
|
||||||
|
message: 'Are you sure you want to submit the form?'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
formComponent.form = formModel;
|
||||||
|
spyOn(formComponent['formCloudService'], 'completeTaskForm');
|
||||||
|
|
||||||
|
formComponent.completeTaskForm(outcome);
|
||||||
|
|
||||||
|
expect(matDialog.open).toHaveBeenCalled();
|
||||||
|
expect(formComponent['formCloudService'].completeTaskForm).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
it('should require json to parse form', () => {
|
it('should require json to parse form', () => {
|
||||||
expect(formComponent.parseForm(null)).toBeNull();
|
expect(formComponent.parseForm(null)).toBeNull();
|
||||||
});
|
});
|
||||||
|
@ -38,6 +38,10 @@ import {
|
|||||||
import { FormCloudService } from '../services/form-cloud.service';
|
import { FormCloudService } from '../services/form-cloud.service';
|
||||||
import { TaskVariableCloud } from '../models/task-variable-cloud.model';
|
import { TaskVariableCloud } from '../models/task-variable-cloud.model';
|
||||||
import { TaskDetailsCloudModel } from '../../task/start-task/models/task-details-cloud.model';
|
import { TaskDetailsCloudModel } from '../../task/start-task/models/task-details-cloud.model';
|
||||||
|
import { MatDialog } from '@angular/material/dialog';
|
||||||
|
import {
|
||||||
|
ConfirmDialogComponent
|
||||||
|
} from '@alfresco/adf-content-services';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'adf-cloud-form',
|
selector: 'adf-cloud-form',
|
||||||
@ -105,6 +109,7 @@ export class FormCloudComponent extends FormBaseComponent implements OnChanges,
|
|||||||
|
|
||||||
constructor(protected formCloudService: FormCloudService,
|
constructor(protected formCloudService: FormCloudService,
|
||||||
protected formService: FormService,
|
protected formService: FormService,
|
||||||
|
private dialog: MatDialog,
|
||||||
protected visibilityService: WidgetVisibilityService) {
|
protected visibilityService: WidgetVisibilityService) {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
@ -266,6 +271,27 @@ export class FormCloudComponent extends FormBaseComponent implements OnChanges,
|
|||||||
}
|
}
|
||||||
|
|
||||||
completeTaskForm(outcome?: string) {
|
completeTaskForm(outcome?: string) {
|
||||||
|
if (this.form?.confirmMessage?.show === true) {
|
||||||
|
const dialogRef = this.dialog.open(ConfirmDialogComponent, {
|
||||||
|
data: {
|
||||||
|
message: this.form.confirmMessage.message
|
||||||
|
},
|
||||||
|
minWidth: '450px'
|
||||||
|
});
|
||||||
|
|
||||||
|
dialogRef.afterClosed()
|
||||||
|
.subscribe(
|
||||||
|
(result) => {
|
||||||
|
if (result === true) {
|
||||||
|
this.completeForm(outcome);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
this.completeForm(outcome);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private completeForm(outcome?: string) {
|
||||||
if (this.form && this.appName && this.taskId) {
|
if (this.form && this.appName && this.taskId) {
|
||||||
this.formCloudService
|
this.formCloudService
|
||||||
.completeTaskForm(this.appName, this.taskId, this.processInstanceId, `${this.form.id}`, this.form.values, outcome, this.appVersion)
|
.completeTaskForm(this.appName, this.taskId, this.processInstanceId, `${this.form.id}`, this.form.values, outcome, this.appVersion)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user