|
|
@ -9,8 +9,12 @@ import { ThemeSharedModule } from '../theme-shared.module'; |
|
|
import { MessageService } from 'primeng/components/common/messageservice'; |
|
|
import { MessageService } from 'primeng/components/common/messageservice'; |
|
|
import { RouterError, RouterDataResolved } from '@ngxs/router-plugin'; |
|
|
import { RouterError, RouterDataResolved } from '@ngxs/router-plugin'; |
|
|
import { NavigationError, ResolveEnd } from '@angular/router'; |
|
|
import { NavigationError, ResolveEnd } from '@angular/router'; |
|
|
|
|
|
import { OAuthModule, OAuthService } from 'angular-oauth2-oidc'; |
|
|
|
|
|
|
|
|
@Component({ selector: 'abp-dummy', template: 'dummy works! <abp-confirmation></abp-confirmation>' }) |
|
|
@Component({ |
|
|
|
|
|
selector: 'abp-dummy', |
|
|
|
|
|
template: 'dummy works! <abp-confirmation></abp-confirmation>', |
|
|
|
|
|
}) |
|
|
class DummyComponent { |
|
|
class DummyComponent { |
|
|
constructor(public errorHandler: ErrorHandler) {} |
|
|
constructor(public errorHandler: ErrorHandler) {} |
|
|
} |
|
|
} |
|
|
@ -21,6 +25,7 @@ describe('ErrorHandler', () => { |
|
|
const createComponent = createRoutingFactory({ |
|
|
const createComponent = createRoutingFactory({ |
|
|
component: DummyComponent, |
|
|
component: DummyComponent, |
|
|
imports: [CoreModule, ThemeSharedModule.forRoot(), NgxsModule.forRoot([])], |
|
|
imports: [CoreModule, ThemeSharedModule.forRoot(), NgxsModule.forRoot([])], |
|
|
|
|
|
mocks: [OAuthService], |
|
|
stubsEnabled: false, |
|
|
stubsEnabled: false, |
|
|
routes: [ |
|
|
routes: [ |
|
|
{ path: '', component: DummyComponent }, |
|
|
{ path: '', component: DummyComponent }, |
|
|
@ -38,33 +43,53 @@ describe('ErrorHandler', () => { |
|
|
|
|
|
|
|
|
it('should display the error component when server error occurs', () => { |
|
|
it('should display the error component when server error occurs', () => { |
|
|
store.dispatch(new RestOccurError(new HttpErrorResponse({ status: 500 }))); |
|
|
store.dispatch(new RestOccurError(new HttpErrorResponse({ status: 500 }))); |
|
|
expect(document.querySelector('.error-template')).toHaveText(DEFAULT_ERROR_MESSAGES.defaultError500.title); |
|
|
expect(document.querySelector('.error-template')).toHaveText( |
|
|
expect(document.querySelector('.error-details')).toHaveText(DEFAULT_ERROR_MESSAGES.defaultError500.details); |
|
|
DEFAULT_ERROR_MESSAGES.defaultError500.title, |
|
|
|
|
|
); |
|
|
|
|
|
expect(document.querySelector('.error-details')).toHaveText( |
|
|
|
|
|
DEFAULT_ERROR_MESSAGES.defaultError500.details, |
|
|
|
|
|
); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
it('should display the error component when authorize error occurs', () => { |
|
|
it('should display the error component when authorize error occurs', () => { |
|
|
store.dispatch(new RestOccurError(new HttpErrorResponse({ status: 403 }))); |
|
|
store.dispatch(new RestOccurError(new HttpErrorResponse({ status: 403 }))); |
|
|
expect(document.querySelector('.error-template')).toHaveText(DEFAULT_ERROR_MESSAGES.defaultError403.title); |
|
|
expect(document.querySelector('.error-template')).toHaveText( |
|
|
expect(document.querySelector('.error-details')).toHaveText(DEFAULT_ERROR_MESSAGES.defaultError403.details); |
|
|
DEFAULT_ERROR_MESSAGES.defaultError403.title, |
|
|
|
|
|
); |
|
|
|
|
|
expect(document.querySelector('.error-details')).toHaveText( |
|
|
|
|
|
DEFAULT_ERROR_MESSAGES.defaultError403.details, |
|
|
|
|
|
); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
it('should display the error component when unknown error occurs', () => { |
|
|
it('should display the error component when unknown error occurs', () => { |
|
|
store.dispatch(new RestOccurError(new HttpErrorResponse({ status: 0, statusText: 'Unknown Error' }))); |
|
|
store.dispatch( |
|
|
expect(document.querySelector('.error-template')).toHaveText(DEFAULT_ERROR_MESSAGES.defaultError.title); |
|
|
new RestOccurError(new HttpErrorResponse({ status: 0, statusText: 'Unknown Error' })), |
|
|
|
|
|
); |
|
|
|
|
|
expect(document.querySelector('.error-template')).toHaveText( |
|
|
|
|
|
DEFAULT_ERROR_MESSAGES.defaultError.title, |
|
|
|
|
|
); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
it('should display the confirmation when not found error occurs', () => { |
|
|
it('should display the confirmation when not found error occurs', () => { |
|
|
store.dispatch(new RestOccurError(new HttpErrorResponse({ status: 404 }))); |
|
|
store.dispatch(new RestOccurError(new HttpErrorResponse({ status: 404 }))); |
|
|
spectator.detectChanges(); |
|
|
spectator.detectChanges(); |
|
|
expect(spectator.query('.abp-confirm-summary')).toHaveText(DEFAULT_ERROR_MESSAGES.defaultError404.title); |
|
|
expect(spectator.query('.abp-confirm-summary')).toHaveText( |
|
|
expect(spectator.query('.abp-confirm-body')).toHaveText(DEFAULT_ERROR_MESSAGES.defaultError404.details); |
|
|
DEFAULT_ERROR_MESSAGES.defaultError404.title, |
|
|
|
|
|
); |
|
|
|
|
|
expect(spectator.query('.abp-confirm-body')).toHaveText( |
|
|
|
|
|
DEFAULT_ERROR_MESSAGES.defaultError404.details, |
|
|
|
|
|
); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
it('should display the confirmation when default error occurs', () => { |
|
|
it('should display the confirmation when default error occurs', () => { |
|
|
store.dispatch(new RestOccurError(new HttpErrorResponse({ status: 412 }))); |
|
|
store.dispatch(new RestOccurError(new HttpErrorResponse({ status: 412 }))); |
|
|
spectator.detectChanges(); |
|
|
spectator.detectChanges(); |
|
|
expect(spectator.query('.abp-confirm-summary')).toHaveText(DEFAULT_ERROR_MESSAGES.defaultError.title); |
|
|
expect(spectator.query('.abp-confirm-summary')).toHaveText( |
|
|
expect(spectator.query('.abp-confirm-body')).toHaveText(DEFAULT_ERROR_MESSAGES.defaultError.details); |
|
|
DEFAULT_ERROR_MESSAGES.defaultError.title, |
|
|
|
|
|
); |
|
|
|
|
|
expect(spectator.query('.abp-confirm-body')).toHaveText( |
|
|
|
|
|
DEFAULT_ERROR_MESSAGES.defaultError.details, |
|
|
|
|
|
); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
it('should display the confirmation when authenticated error occurs', async () => { |
|
|
it('should display the confirmation when authenticated error occurs', async () => { |
|
|
@ -110,7 +135,8 @@ describe('ErrorHandler', () => { |
|
|
|
|
|
|
|
|
@Component({ |
|
|
@Component({ |
|
|
selector: 'abp-dummy-error', |
|
|
selector: 'abp-dummy-error', |
|
|
template: '<p>{{errorStatus}}</p><button id="close-dummy" (click)="destroy$.next()">Close</button>', |
|
|
template: |
|
|
|
|
|
'<p>{{errorStatus}}</p><button id="close-dummy" (click)="destroy$.next()">Close</button>', |
|
|
}) |
|
|
}) |
|
|
class DummyErrorComponent { |
|
|
class DummyErrorComponent { |
|
|
errorStatus; |
|
|
errorStatus; |
|
|
@ -130,12 +156,16 @@ describe('ErrorHandler with custom error component', () => { |
|
|
imports: [ |
|
|
imports: [ |
|
|
CoreModule, |
|
|
CoreModule, |
|
|
ThemeSharedModule.forRoot({ |
|
|
ThemeSharedModule.forRoot({ |
|
|
httpErrorConfig: { errorScreen: { component: DummyErrorComponent, forWhichErrors: [401, 403, 404, 500] } }, |
|
|
httpErrorConfig: { |
|
|
|
|
|
errorScreen: { component: DummyErrorComponent, forWhichErrors: [401, 403, 404, 500] }, |
|
|
|
|
|
}, |
|
|
}), |
|
|
}), |
|
|
NgxsModule.forRoot([]), |
|
|
NgxsModule.forRoot([]), |
|
|
ErrorModule, |
|
|
ErrorModule, |
|
|
], |
|
|
], |
|
|
|
|
|
mocks: [OAuthService], |
|
|
stubsEnabled: false, |
|
|
stubsEnabled: false, |
|
|
|
|
|
|
|
|
routes: [ |
|
|
routes: [ |
|
|
{ path: '', component: DummyComponent }, |
|
|
{ path: '', component: DummyComponent }, |
|
|
{ path: 'account/login', component: RouterOutletComponent }, |
|
|
{ path: 'account/login', component: RouterOutletComponent }, |
|
|
|