|
|
@ -1,9 +1,9 @@ |
|
|
import { CoreModule, RestOccurError, RouterOutletComponent } from '@abp/ng.core'; |
|
|
import { ConfigState, CoreModule, RestOccurError, RouterOutletComponent } from '@abp/ng.core'; |
|
|
import { Location } from '@angular/common'; |
|
|
import { Location } from '@angular/common'; |
|
|
import { HttpErrorResponse, HttpHeaders } from '@angular/common/http'; |
|
|
import { HttpErrorResponse, HttpHeaders } from '@angular/common/http'; |
|
|
import { Component } from '@angular/core'; |
|
|
import { Component } from '@angular/core'; |
|
|
import { RouterModule } from '@angular/router'; |
|
|
import { RouterModule } from '@angular/router'; |
|
|
import { createHostFactory, SpectatorHost } from '@ngneat/spectator'; |
|
|
import { createRoutingFactory, SpectatorRouting } from '@ngneat/spectator'; |
|
|
import { RouterState } from '@ngxs/router-plugin'; |
|
|
import { RouterState } from '@ngxs/router-plugin'; |
|
|
import { NgxsModule, Store } from '@ngxs/store'; |
|
|
import { NgxsModule, Store } from '@ngxs/store'; |
|
|
import { NgxsResetPluginModule, StateOverwrite } from 'ngxs-reset-plugin'; |
|
|
import { NgxsResetPluginModule, StateOverwrite } from 'ngxs-reset-plugin'; |
|
|
@ -16,87 +16,84 @@ class DummyComponent { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
describe('With Custom Host Component', function() { |
|
|
describe('With Custom Host Component', function() { |
|
|
let host: SpectatorHost<DummyComponent>; |
|
|
let component: SpectatorRouting<DummyComponent>; |
|
|
const createHost = createHostFactory({ |
|
|
const createComponent = createRoutingFactory({ |
|
|
component: DummyComponent, |
|
|
component: DummyComponent, |
|
|
imports: [ |
|
|
imports: [CoreModule, ThemeSharedModule.forRoot(), NgxsModule.forRoot([]), NgxsResetPluginModule.forRoot()], |
|
|
CoreModule, |
|
|
stubsEnabled: false, |
|
|
ThemeSharedModule.forRoot(), |
|
|
routes: [{ path: '', component: DummyComponent }, { path: 'account/login', component: RouterOutletComponent }], |
|
|
NgxsModule.forRoot([]), |
|
|
|
|
|
NgxsResetPluginModule.forRoot(), |
|
|
|
|
|
RouterModule.forRoot([{ path: 'account/login', component: RouterOutletComponent }]), |
|
|
|
|
|
], |
|
|
|
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
beforeEach(() => { |
|
|
beforeEach(() => { |
|
|
host = createHost(`<dummy></dummy>`); |
|
|
component = createComponent(); |
|
|
const abpError = document.querySelector('abp-error'); |
|
|
const abpError = document.querySelector('abp-error'); |
|
|
if (abpError) document.body.removeChild(abpError); |
|
|
if (abpError) document.body.removeChild(abpError); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
it('should display the error component when server error occurs', () => { |
|
|
it('should display the error component when server error occurs', () => { |
|
|
host.component.store.dispatch(new RestOccurError(new HttpErrorResponse({ status: 500 }))); |
|
|
component.component.store.dispatch(new RestOccurError(new HttpErrorResponse({ status: 500 }))); |
|
|
host.detectChanges(); |
|
|
component.detectChanges(); |
|
|
expect(document.querySelector('.error-template')).toHaveText(DEFAULT_ERROR_MESSAGES.defaultError500.title); |
|
|
expect(document.querySelector('.error-template')).toHaveText(DEFAULT_ERROR_MESSAGES.defaultError500.title); |
|
|
expect(document.querySelector('.error-details')).toHaveText(DEFAULT_ERROR_MESSAGES.defaultError500.details); |
|
|
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', () => { |
|
|
host.component.store.dispatch(new RestOccurError(new HttpErrorResponse({ status: 403 }))); |
|
|
component.component.store.dispatch(new RestOccurError(new HttpErrorResponse({ status: 403 }))); |
|
|
host.detectChanges(); |
|
|
component.detectChanges(); |
|
|
expect(document.querySelector('.error-template')).toHaveText(DEFAULT_ERROR_MESSAGES.defaultError403.title); |
|
|
expect(document.querySelector('.error-template')).toHaveText(DEFAULT_ERROR_MESSAGES.defaultError403.title); |
|
|
expect(document.querySelector('.error-details')).toHaveText(DEFAULT_ERROR_MESSAGES.defaultError403.details); |
|
|
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', () => { |
|
|
host.component.store.dispatch( |
|
|
component.component.store.dispatch( |
|
|
new RestOccurError(new HttpErrorResponse({ status: 0, statusText: 'Unknown Error' })), |
|
|
new RestOccurError(new HttpErrorResponse({ status: 0, statusText: 'Unknown Error' })), |
|
|
); |
|
|
); |
|
|
host.detectChanges(); |
|
|
component.detectChanges(); |
|
|
expect(document.querySelector('.error-template')).toHaveText(DEFAULT_ERROR_MESSAGES.defaultErrorUnknown.title); |
|
|
expect(document.querySelector('.error-template')).toHaveText(DEFAULT_ERROR_MESSAGES.defaultErrorUnknown.title); |
|
|
expect(document.querySelector('.error-details')).toHaveText(DEFAULT_ERROR_MESSAGES.defaultErrorUnknown.details); |
|
|
expect(document.querySelector('.error-details')).toHaveText(DEFAULT_ERROR_MESSAGES.defaultErrorUnknown.details); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
it('should display the confirmation when not found error occurs', () => { |
|
|
it('should display the confirmation when not found error occurs', () => { |
|
|
host.component.store.dispatch(new RestOccurError(new HttpErrorResponse({ status: 404 }))); |
|
|
component.component.store.dispatch(new RestOccurError(new HttpErrorResponse({ status: 404 }))); |
|
|
host.detectChanges(); |
|
|
component.detectChanges(); |
|
|
expect(host.query('.abp-confirm-summary')).toHaveText(DEFAULT_ERROR_MESSAGES.defaultError404.title); |
|
|
expect(component.query('.abp-confirm-summary')).toHaveText(DEFAULT_ERROR_MESSAGES.defaultError404.title); |
|
|
expect(host.query('.abp-confirm-body')).toHaveText(DEFAULT_ERROR_MESSAGES.defaultError404.details); |
|
|
expect(component.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', () => { |
|
|
host.component.store.dispatch(new RestOccurError(new HttpErrorResponse({ status: 412 }))); |
|
|
component.component.store.dispatch(new RestOccurError(new HttpErrorResponse({ status: 412 }))); |
|
|
host.detectChanges(); |
|
|
component.detectChanges(); |
|
|
expect(host.query('.abp-confirm-summary')).toHaveText(DEFAULT_ERROR_MESSAGES.defaultError.title); |
|
|
expect(component.query('.abp-confirm-summary')).toHaveText(DEFAULT_ERROR_MESSAGES.defaultError.title); |
|
|
expect(host.query('.abp-confirm-body')).toHaveText(DEFAULT_ERROR_MESSAGES.defaultError.details); |
|
|
expect(component.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 () => { |
|
|
host.component.store.dispatch(new RestOccurError(new HttpErrorResponse({ status: 401 }))); |
|
|
component.component.store.dispatch(new RestOccurError(new HttpErrorResponse({ status: 401 }))); |
|
|
host.detectChanges(); |
|
|
component.detectChanges(); |
|
|
host.component.store.dispatch(new StateOverwrite([RouterState, { state: { url: '/' } }])); |
|
|
|
|
|
host.click('#confirm'); |
|
|
component.component.store.dispatch(new StateOverwrite([RouterState, { state: { url: '/' } }])); |
|
|
await host.fixture.whenStable(); |
|
|
component.click('#confirm'); |
|
|
expect(host.get(Location).path()).toBe('/account/login'); |
|
|
await component.fixture.whenStable(); |
|
|
|
|
|
expect(component.get(Location).path()).toBe('/account/login'); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
it('should display the confirmation when authenticated error occurs with _AbpErrorFormat header', async () => { |
|
|
it('should display the confirmation when authenticated error occurs with _AbpErrorFormat header', async () => { |
|
|
let headers: HttpHeaders = new HttpHeaders(); |
|
|
let headers: HttpHeaders = new HttpHeaders(); |
|
|
headers = headers.append('_AbpErrorFormat', '_AbpErrorFormat'); |
|
|
headers = headers.append('_AbpErrorFormat', '_AbpErrorFormat'); |
|
|
|
|
|
|
|
|
host.component.store.dispatch(new RestOccurError(new HttpErrorResponse({ status: 401, headers }))); |
|
|
component.component.store.dispatch(new RestOccurError(new HttpErrorResponse({ status: 401, headers }))); |
|
|
host.detectChanges(); |
|
|
component.detectChanges(); |
|
|
host.component.store.dispatch(new StateOverwrite([RouterState, { state: { url: '/' } }])); |
|
|
component.component.store.dispatch(new StateOverwrite([RouterState, { state: { url: '/' } }])); |
|
|
host.click('#confirm'); |
|
|
component.click('#confirm'); |
|
|
await host.fixture.whenStable(); |
|
|
await component.fixture.whenStable(); |
|
|
expect(host.get(Location).path()).toBe('/account/login'); |
|
|
expect(component.get(Location).path()).toBe('/account/login'); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
it('should display the confirmation when error occurs with _AbpErrorFormat header', () => { |
|
|
it('should display the confirmation when error occurs with _AbpErrorFormat header', () => { |
|
|
let headers: HttpHeaders = new HttpHeaders(); |
|
|
let headers: HttpHeaders = new HttpHeaders(); |
|
|
headers = headers.append('_AbpErrorFormat', '_AbpErrorFormat'); |
|
|
headers = headers.append('_AbpErrorFormat', '_AbpErrorFormat'); |
|
|
|
|
|
|
|
|
host.component.store.dispatch( |
|
|
component.component.store.dispatch( |
|
|
new RestOccurError( |
|
|
new RestOccurError( |
|
|
new HttpErrorResponse({ |
|
|
new HttpErrorResponse({ |
|
|
error: { error: { message: 'test message', details: 'test detail' } }, |
|
|
error: { error: { message: 'test message', details: 'test detail' } }, |
|
|
@ -105,9 +102,9 @@ describe('With Custom Host Component', function() { |
|
|
}), |
|
|
}), |
|
|
), |
|
|
), |
|
|
); |
|
|
); |
|
|
host.detectChanges(); |
|
|
component.detectChanges(); |
|
|
|
|
|
|
|
|
expect(host.query('.abp-confirm-summary')).toHaveText('test message'); |
|
|
expect(component.query('.abp-confirm-summary')).toHaveText('test message'); |
|
|
expect(host.query('.abp-confirm-body')).toHaveText('test detail'); |
|
|
expect(component.query('.abp-confirm-body')).toHaveText('test detail'); |
|
|
}); |
|
|
}); |
|
|
}); |
|
|
}); |
|
|
|