[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
This commit is contained in:
davidcanonieto
2018-06-05 18:13:52 +01:00
committed by Eugenio Romano
parent 6d6045aba4
commit 24b573b08f
3 changed files with 41 additions and 12 deletions

View File

@@ -10,12 +10,12 @@
{{ 'ERROR_CONTENT.' + errorCode + '.DESCRIPTION' | translate }} {{ 'ERROR_CONTENT.' + errorCode + '.DESCRIPTION' | translate }}
</p> </p>
<div class="adf-error-content-buttons"> <div class="adf-error-content-buttons">
<a href="/" mat-raised-button color="primary" <a mat-raised-button color="primary"
*ngIf="secondaryButtonText" (click)="onSecondButton()" *ngIf="secondaryButtonText" (click)="onSecondButton()"
class="adf-error-content-description-link"> class="adf-error-content-description-link">
{{ 'ERROR_CONTENT.' + errorCode + '.SECONDARY_BUTTON.TEXT' | translate | uppercase }} {{ 'ERROR_CONTENT.' + errorCode + '.SECONDARY_BUTTON.TEXT' | translate | uppercase }}
</a> </a>
<a href="/" mat-raised-button color="primary" (click)="onReturnButton()"> <a mat-raised-button color="primary" (click)="onReturnButton()">
{{ 'ERROR_CONTENT.' + this.errorCode + '.RETURN_BUTTON.TEXT' | translate | uppercase }} {{ 'ERROR_CONTENT.' + this.errorCode + '.RETURN_BUTTON.TEXT' | translate | uppercase }}
</a> </a>
</div> </div>

View File

@@ -21,6 +21,8 @@ import { ErrorContentComponent } from './error-content.component';
import { TranslationService } from '../../services/translation.service'; import { TranslationService } from '../../services/translation.service';
import { TranslationMock } from '../../mock/translation.service.mock'; import { TranslationMock } from '../../mock/translation.service.mock';
import { setupTestBed } from '../../testing/setupTestBed'; import { setupTestBed } from '../../testing/setupTestBed';
import { ActivatedRoute } from '@angular/router';
import { Observable } from 'rxjs/Observable';
describe('ErrorContentComponent', () => { describe('ErrorContentComponent', () => {
@@ -30,9 +32,12 @@ describe('ErrorContentComponent', () => {
let translateService: TranslationService; let translateService: TranslationService;
setupTestBed({ setupTestBed({
imports: [CoreTestingModule], imports: [
CoreTestingModule
],
providers: [ providers: [
{ provide: TranslationService, useClass: TranslationMock } { provide: TranslationService, useClass: TranslationMock },
{ provide: ActivatedRoute, useValue: { params: Observable.of({id: '404'})}}
] ]
}); });
@@ -115,4 +120,19 @@ describe('ErrorContentComponent', () => {
}); });
})); }));
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');
});
}));
}); });

View File

@@ -15,7 +15,7 @@
* limitations under the License. * 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 { Params, ActivatedRoute, Router } from '@angular/router';
import { TranslationService } from '../../services/translation.service'; import { TranslationService } from '../../services/translation.service';
@@ -27,7 +27,7 @@ import { TranslationService } from '../../services/translation.service';
encapsulation: ViewEncapsulation.None, encapsulation: ViewEncapsulation.None,
host: { class: 'adf-error-content' } host: { class: 'adf-error-content' }
}) })
export class ErrorContentComponent implements OnInit { export class ErrorContentComponent implements OnInit, AfterContentChecked {
errorCode: string; errorCode: string;
secondaryButtonText: string; secondaryButtonText: string;
@@ -44,14 +44,23 @@ export class ErrorContentComponent implements OnInit {
this.route.params.forEach((params: Params) => { this.route.params.forEach((params: Params) => {
if (params['id']) { if (params['id']) {
this.errorCode = 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( this.returnButtonUrl = this.translateService.instant(
'ERROR_CONTENT.' + this.errorCode + '.RETURN_BUTTON.ROUTE'); 'ERROR_CONTENT.' + this.errorCode + '.RETURN_BUTTON.ROUTE');