|
|
|
@ -1,9 +1,15 @@ |
|
|
|
import { LocalizationPipe, ABP } from '@abp/ng.core'; |
|
|
|
import { RouterTestingModule } from '@angular/router/testing'; |
|
|
|
import { LocalizationPipe } from '@abp/ng.core'; |
|
|
|
import { Directive } from '@angular/core'; |
|
|
|
import { Router } from '@angular/router'; |
|
|
|
import { createComponentFactory, Spectator, SpyObject } from '@ngneat/spectator/jest'; |
|
|
|
import { Store } from '@ngxs/store'; |
|
|
|
import { BreadcrumbComponent } from '../components/breadcrumb/breadcrumb.component'; |
|
|
|
import { Router } from '@angular/router'; |
|
|
|
|
|
|
|
@Directive({ |
|
|
|
// tslint:disable-next-line: directive-selector
|
|
|
|
selector: '[routerLink], [routerLinkActive]', |
|
|
|
}) |
|
|
|
class DummyRouterLinkDirective {} |
|
|
|
|
|
|
|
describe('BreadcrumbComponent', () => { |
|
|
|
let spectator: Spectator<BreadcrumbComponent>; |
|
|
|
@ -11,8 +17,8 @@ describe('BreadcrumbComponent', () => { |
|
|
|
const createComponent = createComponentFactory({ |
|
|
|
component: BreadcrumbComponent, |
|
|
|
mocks: [Store, Router], |
|
|
|
imports: [RouterTestingModule], |
|
|
|
declarations: [LocalizationPipe], |
|
|
|
imports: [], |
|
|
|
declarations: [LocalizationPipe, DummyRouterLinkDirective], |
|
|
|
detectChanges: false, |
|
|
|
}); |
|
|
|
|
|
|
|
@ -24,14 +30,20 @@ describe('BreadcrumbComponent', () => { |
|
|
|
it('should display the breadcrumb', () => { |
|
|
|
const router = spectator.get(Router); |
|
|
|
(router as any).url = '/identity/users'; |
|
|
|
store.selectSnapshot.andReturn({ |
|
|
|
store.selectSnapshot.mockReturnValueOnce({ LeptonLayoutState: {} }); |
|
|
|
store.selectSnapshot.mockReturnValueOnce({ |
|
|
|
name: 'Identity', |
|
|
|
children: [{ name: 'Users', path: 'users' }], |
|
|
|
}); |
|
|
|
spectator.component.show = true; |
|
|
|
// for abpLocalization
|
|
|
|
store.selectSnapshot.mockReturnValueOnce('Identity'); |
|
|
|
store.selectSnapshot.mockReturnValueOnce('Users'); |
|
|
|
spectator.detectChanges(); |
|
|
|
spectator.detectComponentChanges(); |
|
|
|
|
|
|
|
expect(spectator.component.segments).toEqual(['Identity', 'Users']); |
|
|
|
// expect(spectator.queryAll('li')).toHaveLength(3);
|
|
|
|
const elements = spectator.queryAll('li'); |
|
|
|
expect(elements).toHaveLength(3); |
|
|
|
expect(elements[1]).toHaveText('Identity'); |
|
|
|
expect(elements[2]).toHaveText('Users'); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|