[ADF-4867] adf-error-component refactor (#5056)

* Refactor the adf-error-component
Move the custom buttons on demoshell
Fix unit test
Remove usefull e2e

* Add basic example
This commit is contained in:
Maurizio Vitale
2019-09-07 10:29:19 +01:00
committed by Eugenio Romano
parent 4d7c07ef93
commit 4de00fd6ca
12 changed files with 98 additions and 97 deletions

View File

@@ -9,14 +9,5 @@
<p class="adf-error-content-description">
{{ 'ERROR_CONTENT.' + errorCode + '.DESCRIPTION' | translate }}
</p>
<div class="adf-error-content-buttons">
<a a id="adf-secondary-button" mat-raised-button color="primary"
*ngIf="hasSecondButton" (click)="onSecondButton()"
class="adf-error-content-description-link">
{{ 'ERROR_CONTENT.' + errorCode + '.SECONDARY_BUTTON.TEXT' | translate | uppercase }}
</a>
<a id="adf-return-button" mat-raised-button color="primary" (click)="onReturnButton()">
{{ 'ERROR_CONTENT.' + this.errorCode + '.RETURN_BUTTON.TEXT' | translate | uppercase }}
</a>
</div>
<ng-content select="[adf-error-content-actions]"></ng-content>
</div>

View File

@@ -40,12 +40,6 @@
margin-bottom: 60px;
line-height: 30px;
}
&-buttons {
display: flex;
width: 100%;
justify-content: space-evenly;
}
}
@media screen and ($mat-small) {

View File

@@ -99,27 +99,6 @@ describe('ErrorContentComponent', () => {
});
}));
it('should render secondary button with its value from the translate file', async(() => {
spyOn(translateService, 'instant').and.callFake(() => {
return 'Secondary Button';
});
fixture.detectChanges();
fixture.whenStable().then(() => {
const errorContentElement = element.querySelector('#adf-secondary-button');
expect(errorContentElement).not.toBeNull();
expect(errorContentElement).toBeDefined();
expect(errorContentElement.textContent).toContain('ERROR_CONTENT.UNKNOWN.SECONDARY_BUTTON.TEXT');
});
}));
it('should the default value of return button be /', async(() => {
fixture.detectChanges();
fixture.whenStable().then(() => {
expect(errorContentComponent.returnButtonUrl).toBe('/');
});
}));
it('should navigate to the default error UNKNOWN if it does not find the error', async(() => {
fixture.detectChanges();
fixture.whenStable().then(() => {

View File

@@ -20,10 +20,9 @@ import {
ChangeDetectionStrategy,
Input,
ViewEncapsulation,
OnInit,
AfterContentChecked
OnInit
} from '@angular/core';
import { Params, ActivatedRoute, Router } from '@angular/router';
import { Params, ActivatedRoute } from '@angular/router';
import { TranslationService } from '../../services/translation.service';
@Component({
@@ -34,26 +33,15 @@ import { TranslationService } from '../../services/translation.service';
encapsulation: ViewEncapsulation.None,
host: { class: 'adf-error-content' }
})
export class ErrorContentComponent implements OnInit, AfterContentChecked {
export class ErrorContentComponent implements OnInit {
static UNKNOWN_ERROR = 'UNKNOWN';
/** Target URL for the secondary button. */
@Input()
secondaryButtonUrl: string = 'report-issue';
/** Target URL for the return button. */
@Input()
returnButtonUrl: string = '/';
/** Error code associated with this error. */
@Input()
errorCode: string = ErrorContentComponent.UNKNOWN_ERROR;
hasSecondButton: boolean;
constructor(private route: ActivatedRoute,
private router: Router,
private translateService: TranslationService) {
}
@@ -72,20 +60,4 @@ export class ErrorContentComponent implements OnInit, AfterContentChecked {
return errorMessage !== ('ERROR_CONTENT.' + errorCode);
}
getTranslations() {
this.hasSecondButton = this.translateService.instant(
'ERROR_CONTENT.' + this.errorCode + '.SECONDARY_BUTTON.TEXT') ? true : false;
}
ngAfterContentChecked() {
this.getTranslations();
}
onSecondButton() {
this.router.navigate(['/' + this.secondaryButtonUrl]);
}
onReturnButton() {
this.router.navigate(['/' + this.returnButtonUrl]);
}
}