[ADF-4250] Improve Error Content component (#4555)

* [ADF-4250] Improve Error Content component

* [ADF-4250] Fix unit test
This commit is contained in:
davidcanonieto
2019-04-06 11:09:36 +01:00
committed by Eugenio Romano
parent 4339af9f42
commit a42d58af49
3 changed files with 40 additions and 3 deletions

View File

@@ -141,7 +141,7 @@ describe('ErrorContentComponent', () => {
});
it('should navigate to an error given by the route params', async(() => {
spyOn(translateService, 'get').and.returnValue(of('404'));
spyOn(translateService, 'instant').and.returnValue(of('404'));
fixture.detectChanges();
fixture.whenStable().then(() => {
expect(errorContentComponent.errorCode).toBe('404');

View File

@@ -36,6 +36,8 @@ import { TranslationService } from '../../services/translation.service';
})
export class ErrorContentComponent implements OnInit, AfterContentChecked {
static UNKNOWN_ERROR = 'UNKNOWN';
/** Target URL for the secondary button. */
@Input()
secondaryButtonUrl: string = 'report-issue';
@@ -46,7 +48,7 @@ export class ErrorContentComponent implements OnInit, AfterContentChecked {
/** Error code associated with this error. */
@Input()
errorCode: string = 'UNKNOWN';
errorCode: string = ErrorContentComponent.UNKNOWN_ERROR;
hasSecondButton: boolean;
@@ -59,12 +61,17 @@ export class ErrorContentComponent implements OnInit, AfterContentChecked {
if (this.route) {
this.route.params.forEach((params: Params) => {
if (params['id']) {
this.errorCode = params['id'];
this.errorCode = this.checkErrorExists(params['id']) ? params['id'] : ErrorContentComponent.UNKNOWN_ERROR;
}
});
}
}
checkErrorExists(errorCode: string ) {
const errorMessage = this.translateService.instant('ERROR_CONTENT.' + errorCode);
return errorMessage !== ('ERROR_CONTENT.' + errorCode);
}
getTranslations() {
this.hasSecondButton = this.translateService.instant(
'ERROR_CONTENT.' + this.errorCode + '.SECONDARY_BUTTON.TEXT') ? true : false;