|
| 1 | +import { ActivatedRoute } from '@angular/router'; |
| 2 | +import { IconType } from '@hypertrace/assets-library'; |
| 3 | +import { NavigationService } from '@hypertrace/common'; |
| 4 | +import { createServiceFactory, mockProvider, SpectatorService } from '@ngneat/spectator/jest'; |
| 5 | +import { NavigationListService } from './navigation-list.service'; |
| 6 | +import { NavItemType } from './navigation.config'; |
| 7 | + |
| 8 | +describe('Navigation List Service', () => { |
| 9 | + let spectator: SpectatorService<NavigationListService>; |
| 10 | + |
| 11 | + const buildService = createServiceFactory({ |
| 12 | + service: NavigationListService, |
| 13 | + providers: [ |
| 14 | + mockProvider(ActivatedRoute), |
| 15 | + mockProvider(NavigationService, { |
| 16 | + getRouteConfig: jest.fn().mockReturnValue({ |
| 17 | + path: 'root', |
| 18 | + data: { features: ['test-feature'] }, |
| 19 | + children: [] |
| 20 | + }) |
| 21 | + }) |
| 22 | + ] |
| 23 | + }); |
| 24 | + |
| 25 | + beforeEach(() => { |
| 26 | + spectator = buildService(); |
| 27 | + }); |
| 28 | + |
| 29 | + test('decorating navItem with features work as expected', () => { |
| 30 | + expect( |
| 31 | + spectator.service.decorateNavItem( |
| 32 | + { |
| 33 | + type: NavItemType.Header, |
| 34 | + label: 'Label' |
| 35 | + }, |
| 36 | + spectator.inject(ActivatedRoute) |
| 37 | + ) |
| 38 | + ).toEqual({ type: NavItemType.Header, label: 'Label' }); |
| 39 | + |
| 40 | + expect( |
| 41 | + spectator.service.decorateNavItem( |
| 42 | + { |
| 43 | + type: NavItemType.Link, |
| 44 | + label: 'Label', |
| 45 | + icon: IconType.None, |
| 46 | + matchPaths: ['root'] |
| 47 | + }, |
| 48 | + spectator.inject(ActivatedRoute) |
| 49 | + ) |
| 50 | + ).toEqual({ |
| 51 | + type: NavItemType.Link, |
| 52 | + label: 'Label', |
| 53 | + icon: IconType.None, |
| 54 | + matchPaths: ['root'], |
| 55 | + features: ['test-feature'] |
| 56 | + }); |
| 57 | + }); |
| 58 | +}); |
0 commit comments