[ADF-2753] Error Component throwing default error fixed (#3364)

* [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] Error Component throwing default error fixed

* [ADF-2753] White space removed

* [ADF-2753] Removed unnecessary files and updated trnaslation file

* [ADF-2753] Changed link for button in error component

* [ADF-2753] Updated doc file

* [ADF-2753] Removed fdescribe

* [ADF-2753] Improved code coverage
This commit is contained in:
davidcanonieto
2018-05-30 12:51:04 +01:00
committed by Eugenio Romano
parent 39f76a11c4
commit fa2613f096
8 changed files with 127 additions and 79 deletions

View File

@@ -1,9 +1,22 @@
<div class="adf-error-content">
<p class="adf-error-content-code">{{ errorCode }}</p>
<p class="adf-error-content-code">
{{ errorCode }}
</p>
<div class="adf-error-content-shadow"></div>
<p class="adf-error-content-title">{{ errorTitle | translate }}</p>
<p class="adf-error-content-description">{{ errorDescription | translate }}
<a href="{{errorLinkUrl}}" *ngIf="errorLinkText"
class="adf-error-content-description-link" > {{ errorLinkText | translate }}</a></p>
<a href="" mat-raised-button color="primary" routerLink="/home">{{ homeButton | translate}}</a>
<p class="adf-error-content-title">
{{ 'ERROR_CONTENT.' + errorCode + '.TITLE' | translate }}
</p>
<p class="adf-error-content-description">
{{ 'ERROR_CONTENT.' + errorCode + '.DESCRIPTION' | translate }}
</p>
<div class="adf-error-content-buttons">
<a href="/" mat-raised-button color="primary"
*ngIf="secondaryButtonText" (click)="onSecondButton()"
class="adf-error-content-description-link">
{{ 'ERROR_CONTENT.' + errorCode + '.SECONDARY_BUTTON.TEXT' | translate | uppercase }}
</a>
<a href="/" mat-raised-button color="primary" (click)="onReturnButton()">
{{ 'ERROR_CONTENT.' + this.errorCode + '.RETURN_BUTTON.TEXT' | translate | uppercase }}
</a>
</div>
</div>

View File

@@ -39,11 +39,12 @@
min-width: 250px;
margin-bottom: 60px;
line-height: 30px;
}
&-link{
color: mat-color($primary);
text-decoration: none;
}
&-buttons {
display: flex;
width: 100%;
justify-content: space-evenly;
}
}

View File

@@ -15,8 +15,6 @@
* limitations under the License.
*/
/*tslint:disable:ban*/
import { TestBed, async } from '@angular/core/testing';
import { CoreTestingModule } from '../../testing/core.testing.module';
import { ErrorContentComponent } from './error-content.component';
@@ -76,17 +74,14 @@ describe('ErrorContentComponent', () => {
expect(errorContentElement).toBeDefined();
}));
it('should render report issue links', async(() => {
errorContentComponent.errorLinkUrl = '403 Link';
it('should render error description', async(() => {
fixture.detectChanges();
fixture.whenStable().then(() => {
const errorContentElement = element.querySelector('.adf-error-content-description-link');
expect(errorContentElement).not.toBeNull();
expect(errorContentElement).toBeDefined();
});
const errorContentElement = element.querySelector('.adf-error-content-description');
expect(errorContentElement).not.toBeNull();
expect(errorContentElement).toBeDefined();
}));
it('should hide link if this one is empty', async(() => {
it('should hide secondary button if this one has no value', async(() => {
spyOn(translateService, 'instant').and.callFake((inputString) => {
return '';
} );
@@ -97,4 +92,27 @@ 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');
const errorContentElement = element.querySelector('.adf-error-content-description-link');
expect(errorContentElement).not.toBeNull();
expect(errorContentElement).toBeDefined();
});
}));
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');
});
}));
});

View File

@@ -16,7 +16,7 @@
*/
import { Component, ChangeDetectionStrategy, ViewEncapsulation, OnInit } from '@angular/core';
import { Params, ActivatedRoute } from '@angular/router';
import { Params, ActivatedRoute, Router } from '@angular/router';
import { TranslationService } from '../../services/translation.service';
@Component({
@@ -30,15 +30,12 @@ import { TranslationService } from '../../services/translation.service';
export class ErrorContentComponent implements OnInit {
errorCode: string;
errorTitle: string;
errorDescription: string;
errorLinkText: string;
errorLinkUrl: string;
homeButton: string;
secondaryButtonText: string;
secondaryButtonUrl: string;
returnButtonUrl: string;
constructor(private route: ActivatedRoute,
private router: Router,
private translateService: TranslationService) {
}
@@ -52,28 +49,26 @@ export class ErrorContentComponent implements OnInit {
}
this.getData();
}
getData() {
this.errorTitle = this.translateService.instant(
'ERROR_CONTENT.' + this.errorCode + '.TITLE');
this.returnButtonUrl = this.translateService.instant(
'ERROR_CONTENT.' + this.errorCode + '.RETURN_BUTTON.ROUTE');
if (this.errorTitle === 'ERROR_CONTENT.' + this.errorCode + '.TITLE') {
this.errorCode = 'UNKNOWN';
this.errorTitle = this.translateService.instant(
'ERROR_CONTENT.' + this.errorCode + '.TITLE');
this.secondaryButtonText = this.translateService.instant(
'ERROR_CONTENT.' + this.errorCode + '.SECONDARY_BUTTON.TEXT');
if (this.secondaryButtonText) {
this.secondaryButtonUrl = this.translateService.instant(
'ERROR_CONTENT.' + this.errorCode + '.SECONDARY_BUTTON.URL');
}
}
this.errorDescription = this.translateService.instant(
'ERROR_CONTENT.' + this.errorCode + '.DESCRIPTION');
this.errorLinkText = this.translateService.instant(
'ERROR_CONTENT.' + this.errorCode + '.LINK.TEXT');
this.errorLinkUrl = this.translateService.instant(
'ERROR_CONTENT.' + this.errorCode + '.LINK.URL');
this.homeButton = this.translateService.instant(
'ERROR_CONTENT.HOME_BUTTON').toUpperCase();
onSecondButton() {
this.router.navigate(['/' + this.secondaryButtonUrl]);
}
onReturnButton() {
this.router.navigate(['/' + this.returnButtonUrl]);
}
}

View File

@@ -37,4 +37,4 @@ import { EmptyContentComponent } from './empty-content/empty-content.component';
EmptyContentComponent
]
})
export class TemplatetModule {}
export class TemplateModule {}