mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-09-17 14:21:29 +00:00
refactor method
This commit is contained in:
@@ -65,7 +65,7 @@ const mockOauth2Auth: any = {
|
||||
reply: jasmine.createSpy('reply')
|
||||
};
|
||||
|
||||
fdescribe('FormCloudComponent', () => {
|
||||
describe('FormCloudComponent', () => {
|
||||
let formCloudService: FormCloudService;
|
||||
let fixture: ComponentFixture<FormCloudComponent>;
|
||||
let formComponent: FormCloudComponent;
|
||||
@@ -689,7 +689,6 @@ fdescribe('FormCloudComponent', () => {
|
||||
});
|
||||
|
||||
it('should require form with appName and taskId to complete', () => {
|
||||
debugger;
|
||||
spyOn(formCloudService, 'completeTaskForm').and.stub();
|
||||
|
||||
formComponent.form = null;
|
||||
@@ -746,8 +745,6 @@ fdescribe('FormCloudComponent', () => {
|
||||
});
|
||||
|
||||
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: {
|
||||
@@ -762,42 +759,24 @@ fdescribe('FormCloudComponent', () => {
|
||||
|
||||
it('should submit form when user confirms', () => {
|
||||
fixture.detectChanges();
|
||||
const afterClose = of(true);
|
||||
|
||||
spyOn(matDialog, 'open').and.returnValue({
|
||||
afterClosed: () => afterClose
|
||||
} as any);
|
||||
|
||||
spyOn(formComponent['formCloudService'], 'completeTaskForm').and.returnValue(Promise.resolve(false));
|
||||
const outcome = 'complete';
|
||||
|
||||
const taskId = '123-223';
|
||||
const appVersion = 1;
|
||||
const appName = 'test-app';
|
||||
const processInstanceId = '333-444';
|
||||
|
||||
const formModel = new FormModel({
|
||||
id: '23',
|
||||
taskId,
|
||||
fields: [
|
||||
{ id: 'field1' },
|
||||
{ id: 'field2' }
|
||||
],
|
||||
const formModel = new FormModel({
|
||||
confirmMessage: {
|
||||
show: true,
|
||||
message: 'Are you sure you want to submit the form?'
|
||||
}
|
||||
});
|
||||
|
||||
formComponent.appVersion = appVersion;
|
||||
formComponent.form = formModel;
|
||||
formComponent.taskId = taskId;
|
||||
formComponent.appName = appName;
|
||||
formComponent.processInstanceId = processInstanceId;
|
||||
formComponent.completeTaskForm(outcome);
|
||||
expect(matDialog.open).toHaveBeenCalled();
|
||||
spyOn(matDialog, 'open').and.returnValue({
|
||||
afterClosed: () => of(true)
|
||||
} as any);
|
||||
|
||||
expect(formComponent['formCloudService'].completeTaskForm).toHaveBeenCalledWith(appName, formModel.taskId, processInstanceId, formModel.id, formModel.values, outcome, appVersion);
|
||||
spyOn(formComponent['formCloudService'], 'completeTaskForm').and.returnValue(Promise.resolve(true));
|
||||
|
||||
formComponent.completeTaskForm('complete');
|
||||
|
||||
expect(matDialog.open).toHaveBeenCalled();
|
||||
expect(formComponent['formCloudService'].completeTaskForm).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should not confirm form if user rejects', () => {
|
||||
@@ -807,9 +786,19 @@ fdescribe('FormCloudComponent', () => {
|
||||
afterClosed: () => of(false)
|
||||
} as any);
|
||||
|
||||
spyOn(formComponent['formCloudService'], 'completeTaskForm').and.returnValue(Promise.resolve(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').and.returnValue(Promise.resolve(true));
|
||||
|
||||
formComponent.completeTaskForm(outcome);
|
||||
|
||||
expect(matDialog.open).toHaveBeenCalled();
|
||||
expect(formComponent['formCloudService'].completeTaskForm).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
|
@@ -271,10 +271,6 @@ export class FormCloudComponent extends FormBaseComponent implements OnChanges,
|
||||
}
|
||||
|
||||
completeTaskForm(outcome?: string) {
|
||||
debugger;
|
||||
|
||||
// const confirmMessage = this.form.json.confirmMessage.message;
|
||||
|
||||
if (this.form?.confirmMessage?.show === true) {
|
||||
const dialogRef = this.dialog.open(ConfirmDialogComponent, {
|
||||
data: {
|
||||
@@ -286,56 +282,26 @@ export class FormCloudComponent extends FormBaseComponent implements OnChanges,
|
||||
|
||||
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)
|
||||
);
|
||||
}
|
||||
this.completeTaskFormWithConfirmMessage(outcome);
|
||||
}
|
||||
});
|
||||
} 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)
|
||||
);
|
||||
}
|
||||
this.completeTaskFormWithConfirmMessage(outcome);
|
||||
}
|
||||
}
|
||||
|
||||
// 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)
|
||||
// );
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
completeTaskFormWithConfirmMessage(outcome?: string) {
|
||||
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 {
|
||||
|
Reference in New Issue
Block a user