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')
|
reply: jasmine.createSpy('reply')
|
||||||
};
|
};
|
||||||
|
|
||||||
fdescribe('FormCloudComponent', () => {
|
describe('FormCloudComponent', () => {
|
||||||
let formCloudService: FormCloudService;
|
let formCloudService: FormCloudService;
|
||||||
let fixture: ComponentFixture<FormCloudComponent>;
|
let fixture: ComponentFixture<FormCloudComponent>;
|
||||||
let formComponent: FormCloudComponent;
|
let formComponent: FormCloudComponent;
|
||||||
@@ -689,7 +689,6 @@ fdescribe('FormCloudComponent', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should require form with appName and taskId to complete', () => {
|
it('should require form with appName and taskId to complete', () => {
|
||||||
debugger;
|
|
||||||
spyOn(formCloudService, 'completeTaskForm').and.stub();
|
spyOn(formCloudService, 'completeTaskForm').and.stub();
|
||||||
|
|
||||||
formComponent.form = null;
|
formComponent.form = null;
|
||||||
@@ -746,8 +745,6 @@ fdescribe('FormCloudComponent', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should open confirmation dialog on complete task', () => {
|
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);
|
spyOn(matDialog, 'open').and.returnValue({ afterClosed: () => of(false) } as any);
|
||||||
formComponent.form = new FormModel({
|
formComponent.form = new FormModel({
|
||||||
confirmMessage: {
|
confirmMessage: {
|
||||||
@@ -755,49 +752,31 @@ fdescribe('FormCloudComponent', () => {
|
|||||||
message: 'Are you sure you want to submit the form?'
|
message: 'Are you sure you want to submit the form?'
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
formComponent.completeTaskForm();
|
formComponent.completeTaskForm();
|
||||||
expect(matDialog.open).toHaveBeenCalled();
|
expect(matDialog.open).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should submit form when user confirms', () => {
|
it('should submit form when user confirms', () => {
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
const afterClose = of(true);
|
const formModel = new FormModel({
|
||||||
|
|
||||||
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' }
|
|
||||||
],
|
|
||||||
confirmMessage: {
|
confirmMessage: {
|
||||||
show: true,
|
show: true,
|
||||||
message: 'Are you sure you want to submit the form?'
|
message: 'Are you sure you want to submit the form?'
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
formComponent.appVersion = appVersion;
|
|
||||||
formComponent.form = formModel;
|
formComponent.form = formModel;
|
||||||
formComponent.taskId = taskId;
|
spyOn(matDialog, 'open').and.returnValue({
|
||||||
formComponent.appName = appName;
|
afterClosed: () => of(true)
|
||||||
formComponent.processInstanceId = processInstanceId;
|
} as any);
|
||||||
formComponent.completeTaskForm(outcome);
|
|
||||||
expect(matDialog.open).toHaveBeenCalled();
|
|
||||||
|
|
||||||
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', () => {
|
it('should not confirm form if user rejects', () => {
|
||||||
@@ -807,9 +786,19 @@ fdescribe('FormCloudComponent', () => {
|
|||||||
afterClosed: () => of(false)
|
afterClosed: () => of(false)
|
||||||
} as any);
|
} 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);
|
formComponent.completeTaskForm(outcome);
|
||||||
|
|
||||||
|
expect(matDialog.open).toHaveBeenCalled();
|
||||||
expect(formComponent['formCloudService'].completeTaskForm).not.toHaveBeenCalled();
|
expect(formComponent['formCloudService'].completeTaskForm).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@@ -271,10 +271,6 @@ export class FormCloudComponent extends FormBaseComponent implements OnChanges,
|
|||||||
}
|
}
|
||||||
|
|
||||||
completeTaskForm(outcome?: string) {
|
completeTaskForm(outcome?: string) {
|
||||||
debugger;
|
|
||||||
|
|
||||||
// const confirmMessage = this.form.json.confirmMessage.message;
|
|
||||||
|
|
||||||
if (this.form?.confirmMessage?.show === true) {
|
if (this.form?.confirmMessage?.show === true) {
|
||||||
const dialogRef = this.dialog.open(ConfirmDialogComponent, {
|
const dialogRef = this.dialog.open(ConfirmDialogComponent, {
|
||||||
data: {
|
data: {
|
||||||
@@ -286,56 +282,26 @@ export class FormCloudComponent extends FormBaseComponent implements OnChanges,
|
|||||||
|
|
||||||
dialogRef.afterClosed().subscribe((result) => {
|
dialogRef.afterClosed().subscribe((result) => {
|
||||||
if (result === true) {
|
if (result === true) {
|
||||||
if (this.form && this.appName && this.taskId) {
|
this.completeTaskFormWithConfirmMessage(outcome);
|
||||||
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 {
|
} else {
|
||||||
if (this.form && this.appName && this.taskId) {
|
this.completeTaskFormWithConfirmMessage(outcome);
|
||||||
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) => {
|
completeTaskFormWithConfirmMessage(outcome?: string) {
|
||||||
// if (result === true) {
|
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)
|
.pipe(takeUntil(this.onDestroy$))
|
||||||
// .pipe(takeUntil(this.onDestroy$))
|
.subscribe(
|
||||||
// .subscribe(
|
() => {
|
||||||
// () => {
|
this.onTaskCompleted(this.form);
|
||||||
// this.onTaskCompleted(this.form);
|
},
|
||||||
// },
|
(error) => this.onTaskCompletedError(error)
|
||||||
// (error) => this.onTaskCompletedError(error)
|
);
|
||||||
// );
|
}
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
parseForm(formCloudRepresentationJSON: any): FormModel {
|
parseForm(formCloudRepresentationJSON: any): FormModel {
|
||||||
|
Reference in New Issue
Block a user