diff --git a/aio/src/app/app.component.html b/aio/src/app/app.component.html index beac0b6bb8..457662ed19 100644 --- a/aio/src/app/app.component.html +++ b/aio/src/app/app.component.html @@ -22,7 +22,7 @@ Home Home - +
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 083aed170d..579e58adc1 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 @@ -10,6 +10,8 @@ describe('TopMenuComponent', () => { const list: HTMLUListElement = fixture.debugElement.nativeElement.querySelector('ul'); return Array.from(list.querySelectorAll('li')); }; + const getSelected = (items: HTMLLIElement[]) => + items.filter(item => item.classList.contains('selected')); beforeEach(() => { TestBed.configureTestingModule({ @@ -38,4 +40,47 @@ describe('TopMenuComponent', () => { expect(links.map(link => link.textContent)).toEqual(['API', 'Features']); expect(links.map(link => link.title)).toEqual(['API docs', 'Angular features overview']); }); + + it('should mark the currently selected node with `.selected`', () => { + const items = getListItems(); + expect(getSelected(items)).toEqual([]); + + component.currentNode = {url: 'api', view: 'foo', nodes: []}; + fixture.detectChanges(); + expect(getSelected(items)).toEqual([items[0]]); + + component.currentNode = {url: 'features', view: 'foo', nodes: []}; + fixture.detectChanges(); + expect(getSelected(items)).toEqual([items[1]]); + + component.currentNode = {url: 'something/else', view: 'foo', nodes: []}; + fixture.detectChanges(); + expect(getSelected(items)).toEqual([]); + }); + + it('should not mark any node with `.selected` if the current URL is undefined', () => { + component.nodes = [ + {url: '', title: 'API', tooltip: 'API docs'}, + {url: undefined, title: 'Features', tooltip: 'Angular features overview'}, + ]; + fixture.detectChanges(); + const items = getListItems(); + + component.currentNode = undefined; + fixture.detectChanges(); + expect(getSelected(items)).toEqual([]); + }); + + it('should correctly mark a node with `.selected` even if its URL is empty', () => { + component.nodes = [ + {url: '', title: 'API', tooltip: 'API docs'}, + {url: undefined, title: 'Features', tooltip: 'Angular features overview'}, + ]; + fixture.detectChanges(); + const items = getListItems(); + + component.currentNode = {url: '', view: 'Empty url', nodes: []}; + fixture.detectChanges(); + expect(getSelected(items)).toEqual([items[0]]); + }); }); 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 685413eb40..2ef09554ec 100644 --- a/aio/src/app/layout/top-menu/top-menu.component.ts +++ b/aio/src/app/layout/top-menu/top-menu.component.ts @@ -1,11 +1,11 @@ import { Component, Input } from '@angular/core'; -import { NavigationNode } from 'app/navigation/navigation.service'; +import { CurrentNode, NavigationNode } from 'app/navigation/navigation.service'; @Component({ selector: 'aio-top-menu', template: `