From 24b573b08f3a072327efefc0196bd949cbca3766 Mon Sep 17 00:00:00 2001
From: davidcanonieto
Date: Tue, 5 Jun 2018 18:13:52 +0100
Subject: [PATCH] [ADF-2753] Fixed routing and second button showing up (#3421)
* [ADF-1938] Overflowing text in reports section fidex
* [ADF-1938] Long names in report section now fit
* [ADF-1938] Reverted changes in container widget
* [ADF-2753] New error component created
* [ADF-2753] Unit test for Error Content Component
* Deleting unused files
* Deleting unused files
* Deleting unused files
* [ADF-2753] Documentation added
* [ADF-2753] Removed unnecessary files and updated trnaslation file
* []
* [ADF-2753] Fixed routing and second button showing up
* [ADF-2753] Fixed typo
* [ADF-2753] Fixed view loading before variables
* [ADF-2753] Missing whitespace
* [ADF-2753] Added test for route params
* [ADF-2753] Changed getData function name to getTranslations
---
.../error-content.component.html | 4 +--
.../error-content.component.spec.ts | 30 +++++++++++++++----
.../error-content/error-content.component.ts | 19 ++++++++----
3 files changed, 41 insertions(+), 12 deletions(-)
diff --git a/lib/core/templates/error-content/error-content.component.html b/lib/core/templates/error-content/error-content.component.html
index 55ab5c899d..cf113b19f7 100644
--- a/lib/core/templates/error-content/error-content.component.html
+++ b/lib/core/templates/error-content/error-content.component.html
@@ -10,12 +10,12 @@
{{ 'ERROR_CONTENT.' + errorCode + '.DESCRIPTION' | translate }}
diff --git a/lib/core/templates/error-content/error-content.component.spec.ts b/lib/core/templates/error-content/error-content.component.spec.ts
index 16708f88d6..a0aca798c1 100644
--- a/lib/core/templates/error-content/error-content.component.spec.ts
+++ b/lib/core/templates/error-content/error-content.component.spec.ts
@@ -21,6 +21,8 @@ import { ErrorContentComponent } from './error-content.component';
import { TranslationService } from '../../services/translation.service';
import { TranslationMock } from '../../mock/translation.service.mock';
import { setupTestBed } from '../../testing/setupTestBed';
+import { ActivatedRoute } from '@angular/router';
+import { Observable } from 'rxjs/Observable';
describe('ErrorContentComponent', () => {
@@ -30,9 +32,12 @@ describe('ErrorContentComponent', () => {
let translateService: TranslationService;
setupTestBed({
- imports: [CoreTestingModule],
+ imports: [
+ CoreTestingModule
+ ],
providers: [
- { provide: TranslationService, useClass: TranslationMock }
+ { provide: TranslationService, useClass: TranslationMock },
+ { provide: ActivatedRoute, useValue: { params: Observable.of({id: '404'})}}
]
});
@@ -84,7 +89,7 @@ describe('ErrorContentComponent', () => {
it('should hide secondary button if this one has no value', async(() => {
spyOn(translateService, 'instant').and.callFake((inputString) => {
return '';
- } );
+ });
fixture.detectChanges();
fixture.whenStable().then(() => {
const errorContentElement = element.querySelector('.adf-error-content-description-link');
@@ -95,7 +100,7 @@ describe('ErrorContentComponent', () => {
it('should render secondary button with its value from the translate file', async(() => {
spyOn(translateService, 'instant').and.callFake((inputString) => {
return 'Secondary Button';
- } );
+ });
fixture.detectChanges();
fixture.whenStable().then(() => {
expect(errorContentComponent.secondaryButtonText).toBe('Secondary Button');
@@ -108,11 +113,26 @@ describe('ErrorContentComponent', () => {
it('should render return button with its value from the translate file', async(() => {
spyOn(translateService, 'instant').and.callFake((inputString) => {
return 'Home';
- } );
+ });
fixture.detectChanges();
fixture.whenStable().then(() => {
expect(errorContentComponent.returnButtonUrl).toBe('Home');
});
}));
+ it('should navigate to an error given by the route params', async(() => {
+ spyOn(translateService, 'get').and.returnValue(Observable.of('404'));
+ fixture.detectChanges();
+ fixture.whenStable().then(() => {
+ expect(errorContentComponent.errorCode).toBe('404');
+ });
+ }));
+
+ it('should navigate to the default error UNKNOWN if it does not find the error', async(() => {
+ fixture.detectChanges();
+ fixture.whenStable().then(() => {
+ expect(errorContentComponent.errorCode).toBe('UNKNOWN');
+ });
+ }));
+
});
diff --git a/lib/core/templates/error-content/error-content.component.ts b/lib/core/templates/error-content/error-content.component.ts
index 88a097f5b6..4278a2e5da 100644
--- a/lib/core/templates/error-content/error-content.component.ts
+++ b/lib/core/templates/error-content/error-content.component.ts
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-import { Component, ChangeDetectionStrategy, ViewEncapsulation, OnInit } from '@angular/core';
+import { Component, ChangeDetectionStrategy, ViewEncapsulation, OnInit, AfterContentChecked } from '@angular/core';
import { Params, ActivatedRoute, Router } from '@angular/router';
import { TranslationService } from '../../services/translation.service';
@@ -27,7 +27,7 @@ import { TranslationService } from '../../services/translation.service';
encapsulation: ViewEncapsulation.None,
host: { class: 'adf-error-content' }
})
-export class ErrorContentComponent implements OnInit {
+export class ErrorContentComponent implements OnInit, AfterContentChecked {
errorCode: string;
secondaryButtonText: string;
@@ -44,14 +44,23 @@ export class ErrorContentComponent implements OnInit {
this.route.params.forEach((params: Params) => {
if (params['id']) {
this.errorCode = params['id'];
+ let unknown = '';
+ this.translateService.get('ERROR_CONTENT.' + this.errorCode + '.TITLE').subscribe((errorTranslation: string) => {
+ unknown = errorTranslation;
+ });
+ if (unknown === 'ERROR_CONTENT.' + this.errorCode + '.TITLE') {
+ this.errorCode = 'UNKNOWN';
+ }
}
});
}
-
- this.getData();
}
- getData() {
+ ngAfterContentChecked() {
+ this.getTranslations();
+ }
+
+ getTranslations() {
this.returnButtonUrl = this.translateService.instant(
'ERROR_CONTENT.' + this.errorCode + '.RETURN_BUTTON.ROUTE');