diff --git a/aio/src/app/layout/top-menu/top-menu.component.spec.ts b/aio/src/app/layout/top-menu/top-menu.component.spec.ts index fbc6efde79..083aed170d 100644 --- a/aio/src/app/layout/top-menu/top-menu.component.spec.ts +++ b/aio/src/app/layout/top-menu/top-menu.component.spec.ts @@ -1,42 +1,41 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; - -import { BehaviorSubject } from 'rxjs'; - import { TopMenuComponent } from './top-menu.component'; -import { NavigationService, NavigationViews } from 'app/navigation/navigation.service'; describe('TopMenuComponent', () => { let component: TopMenuComponent; let fixture: ComponentFixture; - beforeEach(() => { - TestBed.configureTestingModule({ - declarations: [ TopMenuComponent ], - providers: [ - { provide: NavigationService, useClass: TestNavigationService } - ] - }); - }); + // Helpers + const getListItems = () => { + const list: HTMLUListElement = fixture.debugElement.nativeElement.querySelector('ul'); + return Array.from(list.querySelectorAll('li')); + }; beforeEach(() => { + TestBed.configureTestingModule({ + declarations: [ + TopMenuComponent, + ], + }); + fixture = TestBed.createComponent(TopMenuComponent); component = fixture.componentInstance; + + component.nodes = [ + {url: 'api', title: 'API', tooltip: 'API docs'}, + {url: 'features', title: 'Features', tooltip: 'Angular features overview'}, + ]; fixture.detectChanges(); }); - it('should create', () => { - expect(component).toBeTruthy(); + it('should create an item for each navigation node', () => { + const items = getListItems(); + const links = items.map(item => item.querySelector('a')) + .filter((link): link is NonNullable => link !== null); + + expect(links.length).toBe(2); + expect(links.map(link => link.pathname)).toEqual(['/api', '/features']); + expect(links.map(link => link.textContent)).toEqual(['API', 'Features']); + expect(links.map(link => link.title)).toEqual(['API docs', 'Angular features overview']); }); }); - -//// Test Helpers //// -class TestNavigationService { - navJson = { - TopBar: [ - {url: 'api', title: 'API' }, - {url: 'features', title: 'Features' } - ], - }; - - navigationViews = new BehaviorSubject(this.navJson); -} diff --git a/aio/src/app/layout/top-menu/top-menu.component.ts b/aio/src/app/layout/top-menu/top-menu.component.ts index 3eff5116fd..685413eb40 100644 --- a/aio/src/app/layout/top-menu/top-menu.component.ts +++ b/aio/src/app/layout/top-menu/top-menu.component.ts @@ -6,7 +6,7 @@ import { NavigationNode } from 'app/navigation/navigation.service'; template: `