|
|
@ -1,63 +1,68 @@ |
|
|
import { LocalizationPipe } from '@abp/ng.core'; |
|
|
import { ABP, LocalizationPipe, RouterOutletComponent, RoutesService } from '@abp/ng.core'; |
|
|
import { Directive } from '@angular/core'; |
|
|
import { RouterModule } from '@angular/router'; |
|
|
import { Router } from '@angular/router'; |
|
|
import { createRoutingFactory, SpectatorRouting, SpyObject } from '@ngneat/spectator/jest'; |
|
|
import { createComponentFactory, Spectator, SpyObject } from '@ngneat/spectator/jest'; |
|
|
|
|
|
import { Store } from '@ngxs/store'; |
|
|
import { Store } from '@ngxs/store'; |
|
|
import { BreadcrumbComponent } from '../components/breadcrumb/breadcrumb.component'; |
|
|
import { BreadcrumbComponent } from '../components/breadcrumb/breadcrumb.component'; |
|
|
|
|
|
|
|
|
@Directive({ |
|
|
const mockRoutes: ABP.Route[] = [ |
|
|
// tslint:disable-next-line: directive-selector
|
|
|
{ name: 'Identity', path: '/identity' }, |
|
|
selector: '[routerLink], [routerLinkActive]', |
|
|
{ name: 'Users', path: '/identity/users', parentName: 'Identity' }, |
|
|
}) |
|
|
]; |
|
|
class DummyRouterLinkDirective {} |
|
|
|
|
|
|
|
|
|
|
|
describe('BreadcrumbComponent', () => { |
|
|
describe('BreadcrumbComponent', () => { |
|
|
let spectator: Spectator<BreadcrumbComponent>; |
|
|
let spectator: SpectatorRouting<RouterOutletComponent>; |
|
|
|
|
|
let routes: RoutesService; |
|
|
let store: SpyObject<Store>; |
|
|
let store: SpyObject<Store>; |
|
|
const createComponent = createComponentFactory({ |
|
|
|
|
|
component: BreadcrumbComponent, |
|
|
const createRouting = createRoutingFactory({ |
|
|
mocks: [Store, Router], |
|
|
component: RouterOutletComponent, |
|
|
imports: [], |
|
|
stubsEnabled: false, |
|
|
declarations: [LocalizationPipe, DummyRouterLinkDirective], |
|
|
|
|
|
detectChanges: false, |
|
|
detectChanges: false, |
|
|
|
|
|
mocks: [Store], |
|
|
|
|
|
declarations: [LocalizationPipe, BreadcrumbComponent], |
|
|
|
|
|
imports: [RouterModule], |
|
|
|
|
|
routes: [ |
|
|
|
|
|
{ |
|
|
|
|
|
path: '', |
|
|
|
|
|
children: [ |
|
|
|
|
|
{ |
|
|
|
|
|
path: 'identity', |
|
|
|
|
|
children: [ |
|
|
|
|
|
{ |
|
|
|
|
|
path: 'users', |
|
|
|
|
|
component: BreadcrumbComponent, |
|
|
|
|
|
}, |
|
|
|
|
|
], |
|
|
|
|
|
}, |
|
|
|
|
|
], |
|
|
|
|
|
}, |
|
|
|
|
|
], |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
beforeEach(() => { |
|
|
beforeEach(() => { |
|
|
spectator = createComponent(); |
|
|
spectator = createRouting(); |
|
|
|
|
|
routes = spectator.get(RoutesService); |
|
|
store = spectator.get(Store); |
|
|
store = spectator.get(Store); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
it('should display the breadcrumb', () => { |
|
|
it('should display the breadcrumb', async () => { |
|
|
const router = spectator.get(Router); |
|
|
routes.add(mockRoutes); |
|
|
(router as any).url = '/identity/users'; |
|
|
await spectator.router.navigateByUrl('/identity/users'); |
|
|
store.selectSnapshot.mockReturnValueOnce({ LeptonLayoutState: {} }); |
|
|
|
|
|
store.selectSnapshot.mockReturnValueOnce({ |
|
|
|
|
|
name: 'Identity', |
|
|
|
|
|
children: [{ name: 'Users', path: 'users' }], |
|
|
|
|
|
}); |
|
|
|
|
|
// for abpLocalization
|
|
|
// for abpLocalization
|
|
|
store.selectSnapshot.mockReturnValueOnce('Identity'); |
|
|
store.selectSnapshot.mockReturnValueOnce('Identity'); |
|
|
store.selectSnapshot.mockReturnValueOnce('Users'); |
|
|
store.selectSnapshot.mockReturnValueOnce('Users'); |
|
|
spectator.detectChanges(); |
|
|
spectator.detectChanges(); |
|
|
|
|
|
|
|
|
expect(spectator.component.segments).toEqual(['Identity', 'Users']); |
|
|
|
|
|
const elements = spectator.queryAll('li'); |
|
|
const elements = spectator.queryAll('li'); |
|
|
expect(elements).toHaveLength(3); |
|
|
expect(elements).toHaveLength(3); |
|
|
expect(elements[1]).toHaveText('Identity'); |
|
|
expect(elements[1]).toHaveText('Identity'); |
|
|
expect(elements[2]).toHaveText('Users'); |
|
|
expect(elements[2]).toHaveText('Users'); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
it('should not display the breadcrumb', () => { |
|
|
it('should not display the breadcrumb when empty', async () => { |
|
|
const router = spectator.get(Router); |
|
|
routes.add([]); |
|
|
(router as any).url = '/identity/users'; |
|
|
await spectator.router.navigateByUrl('/identity/users'); |
|
|
spectator.detectChanges(); |
|
|
|
|
|
expect(spectator.query('ol.breadcrumb')).toBeFalsy(); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('should not display the breadcrumb when abp route not found', () => { |
|
|
|
|
|
const router = spectator.get(Router); |
|
|
|
|
|
(router as any).url = '/identity/users'; |
|
|
|
|
|
store.selectSnapshot.mockReturnValueOnce({ LeptonLayoutState: {} }); |
|
|
|
|
|
spectator.detectChanges(); |
|
|
spectator.detectChanges(); |
|
|
expect(spectator.query('ol.breadcrumb')).toBeFalsy(); |
|
|
expect(spectator.query('ol.breadcrumb')).toBeFalsy(); |
|
|
}); |
|
|
}); |
|
|
|