|
| 1 | +import { TestBed } from '@angular/core/testing'; |
| 2 | +import { RouterTestingModule } from '@angular/router/testing'; |
| 3 | +import {Router, Routes} from '@angular/router'; |
| 4 | + |
| 5 | +import { SidebarNavHelper } from './app-sidebar-nav.service'; |
| 6 | + |
| 7 | +describe('SidebarNavHelper', () => { |
| 8 | + let service: SidebarNavHelper; |
| 9 | + let router: RouterTestingModule; |
| 10 | + const routes: Routes = [ |
| 11 | + {path: 'dashboard', redirectTo: 'home', pathMatch: 'full'}, |
| 12 | + {path: '', redirectTo: 'dashboard', pathMatch: 'full'} |
| 13 | + ]; |
| 14 | + |
| 15 | + beforeEach(() => { |
| 16 | + TestBed.configureTestingModule({ |
| 17 | + imports: [RouterTestingModule.withRoutes(routes)], |
| 18 | + providers: [SidebarNavHelper], |
| 19 | + }); |
| 20 | + |
| 21 | + router = TestBed.inject(Router); |
| 22 | + service = TestBed.inject(SidebarNavHelper); |
| 23 | + }); |
| 24 | + |
| 25 | + it('should be created', () => { |
| 26 | + expect(service).toBeTruthy(); |
| 27 | + }); |
| 28 | + it('should return itemType', () => { |
| 29 | + expect(service.itemType({divider: true})).toEqual('divider'); |
| 30 | + expect(service.itemType({title: true})).toEqual('title'); |
| 31 | + expect(service.itemType({children: []})).toEqual('dropdown'); |
| 32 | + expect(service.itemType({label: true})).toEqual('label'); |
| 33 | + expect(service.itemType({})).toEqual('empty'); |
| 34 | + expect(service.itemType({ |
| 35 | + name: 'Disabled', |
| 36 | + url: '/dashboard', |
| 37 | + icon: 'icon-ban', |
| 38 | + attributes: { disabled: true }, |
| 39 | + } |
| 40 | + )).toEqual('link'); |
| 41 | + }); |
| 42 | + |
| 43 | + it('should be active', () => { |
| 44 | + expect(service.isActive(router, {url: ''})).toBeTrue(); |
| 45 | + expect(service.isActive(router, {url: 'dashboard'})).toBeFalse(); |
| 46 | + }); |
| 47 | + |
| 48 | + it('item hasBadge', () => { |
| 49 | + expect(service.hasBadge({badge: {}})).toBeTruthy(); |
| 50 | + expect(service.hasBadge({})).toBeFalsy(); |
| 51 | + }); |
| 52 | + it('item hasIcon', () => { |
| 53 | + expect(service.hasIcon({icon: 'icon-ban'})).toBeTruthy(); |
| 54 | + expect(service.hasIcon({})).toBeFalsy(); |
| 55 | + }); |
| 56 | + |
| 57 | + it('should return icon class object', () => { |
| 58 | + expect(service.getIconClass({icon: 'icon-ban'})).toEqual(jasmine.objectContaining({ 'nav-icon': true, 'icon-ban': true})); |
| 59 | + expect(service.getIconClass({icon: 'icon-ban'})).toEqual(jasmine.objectContaining({ 'nav-icon': true })); |
| 60 | + expect(service.getIconClass({icon: ''})).toEqual(jasmine.objectContaining({ 'nav-icon': true })); |
| 61 | + }); |
| 62 | +}); |
0 commit comments