Add new tests for dealing with errors

Refs #1066
This commit is contained in:
Will Abson
2016-11-18 13:58:54 +00:00
committed by Mario Romano
parent f4c8dd314b
commit 6c0cfee617
5 changed files with 64 additions and 3 deletions

View File

@@ -20,6 +20,17 @@
top: 4px;
}
.mdl-card {
width: 100%;
min-height: initial;
margin-bottom: 20px;
}
.mdl-card .mdl-dialog__content {
width: 100%;
padding: 20px;
}
.mdl-dialog {
width: -moz-fit-content;
width: -webkit-fit-content;

View File

@@ -3,6 +3,9 @@
<dialog class="mdl-dialog" #dialog>
<h4 class="mdl-dialog__title">{{'START_PROCESS.DIALOG.TITLE'|translate}}</h4>
<div class="mdl-dialog__content">
<div class="mdl-card mdl-shadow--2dp error-message" *ngIf="errorMessageId">
<div class="mdl-card__supporting-text">{{errorMessageId|translate}}</div>
</div>
<div class="mdl-textfield mdl-js-textfield alf-mdl-selectfield">
<select name="processDefinition" [(ngModel)]="currentProcessDef.id" (ngModelChange)="onProcessDefChange($event)" id="processDefinition" required>
<option value="" selected="selected">{{'START_PROCESS.DIALOG.TYPE_PLACEHOLDER'|translate}}</option>

View File

@@ -102,6 +102,16 @@ describe('ActivitiStartProcessButton', () => {
});
});
it('should indicate an error to the user if process defs cannot be loaded', async(() => {
getDefinitionsSpy = getDefinitionsSpy.and.returnValue(Observable.throw({}));
fixture.detectChanges();
fixture.whenStable().then(() => {
let errorEl: DebugElement = debugElement.query(By.css('.error-message'));
expect(errorEl).not.toBeNull('Expected error message to be present');
expect(errorEl.nativeElement.innerText).toBe('START_PROCESS.ERROR.LOAD_PROCESS_DEFS');
});
}));
});
describe('input changes', () => {
@@ -176,6 +186,29 @@ describe('ActivitiStartProcessButton', () => {
});
}));
it('should throw start event error when process cannot be started', async(() => {
let errorSpy = spyOn(component.start, 'error');
let error = { message: 'My error' };
startProcessSpy = startProcessSpy.and.returnValue(Observable.throw(error));
component.onProcessDefChange('my:process1');
component.startProcess();
fixture.whenStable().then(() => {
expect(errorSpy).toHaveBeenCalledWith(error);
});
}));
it('should indicate an error to the user if process cannot be started', async(() => {
startProcessSpy = startProcessSpy.and.returnValue(Observable.throw({}));
component.onProcessDefChange('my:process1');
component.startProcess();
fixture.whenStable().then(() => {
fixture.detectChanges();
let errorEl: DebugElement = debugElement.query(By.css('.error-message'));
expect(errorEl).not.toBeNull();
expect(errorEl.nativeElement.innerText).toBe('START_PROCESS.ERROR.START');
});
}));
});
describe('start forms', () => {

View File

@@ -51,6 +51,8 @@ export class ActivitiStartProcessButton implements OnInit, OnChanges {
currentProcessDef: ProcessDefinitionRepresentation = new ProcessDefinitionRepresentation();
errorMessageId: string = '';
constructor(private translate: AlfrescoTranslationService,
private activitiProcess: ActivitiProcessService) {
@@ -73,12 +75,13 @@ export class ActivitiStartProcessButton implements OnInit, OnChanges {
public load(appId: string) {
this.resetSelectedProcessDefinition();
this.resetErrorMessage();
this.activitiProcess.getProcessDefinitions(appId).subscribe(
(res) => {
this.processDefinitions = res;
},
(err) => {
console.log(err);
() => {
this.errorMessageId = 'START_PROCESS.ERROR.LOAD_PROCESS_DEFS';
}
);
}
@@ -92,6 +95,7 @@ export class ActivitiStartProcessButton implements OnInit, OnChanges {
public startProcess() {
if (this.currentProcessDef.id && this.name) {
this.resetErrorMessage();
let formValues = this.startForm ? this.startForm.form.values : undefined;
this.activitiProcess.startProcess(this.currentProcessDef.id, this.name, formValues).subscribe(
(res) => {
@@ -100,7 +104,8 @@ export class ActivitiStartProcessButton implements OnInit, OnChanges {
this.cancel();
},
(err) => {
console.log(err);
this.errorMessageId = 'START_PROCESS.ERROR.START';
this.start.error(err);
}
);
}
@@ -135,11 +140,16 @@ export class ActivitiStartProcessButton implements OnInit, OnChanges {
this.currentProcessDef = new ProcessDefinitionRepresentation();
}
private resetErrorMessage(): void {
this.errorMessageId = '';
}
private reset() {
this.resetSelectedProcessDefinition();
this.name = '';
if (this.startForm) {
this.startForm.data = {};
}
this.resetErrorMessage();
}
}

View File

@@ -52,6 +52,10 @@
"START": "Start",
"CANCEL": "Cancel"
}
},
"ERROR": {
"LOAD_PROCESS_DEFS": "Could not load process definitions, please check you have access.",
"START": "Could start new process instance, please check you have permission."
}
}
}