From f68200a633c9c175ad1796002d41a75c75dc58a8 Mon Sep 17 00:00:00 2001 From: Cilibiu Bogdan Date: Mon, 17 Dec 2018 08:54:53 +0200 Subject: [PATCH] [ACA-2067] Side navigation - highlight element with children only when not expanded (#880) * highlight parent element condition * update test * e2e --- e2e/suites/navigation/sidebar.test.ts | 6 +-- .../components/sidenav/sidenav.component.html | 16 +++++--- .../sidenav/sidenav.component.spec.ts | 40 +++++++++++++++---- .../sidenav/sidenav.component.theme.scss | 4 ++ 4 files changed, 49 insertions(+), 17 deletions(-) diff --git a/e2e/suites/navigation/sidebar.test.ts b/e2e/suites/navigation/sidebar.test.ts index 0c9700206c..ed61a3dffc 100755 --- a/e2e/suites/navigation/sidebar.test.ts +++ b/e2e/suites/navigation/sidebar.test.ts @@ -53,21 +53,21 @@ describe('Sidebar', () => { it('My Libraries is automatically selected on expanding File Libraries - [C289900]', async () => { await page.clickFileLibraries(); expect(await browser.getCurrentUrl()).toContain(APP_ROUTES.MY_LIBRARIES); - expect(await sidenav.isActive(SIDEBAR_LABELS.FILE_LIBRARIES)).toBe(true, 'File Libraries link not active'); + expect(await sidenav.isActive(SIDEBAR_LABELS.FILE_LIBRARIES)).toBe(false, 'File Libraries link is active'); expect(await sidenav.childIsActive(SIDEBAR_LABELS.MY_LIBRARIES)).toBe(true, 'My Libraries link not active'); }); it('navigate to Favorite Libraries - [C289902]', async () => { await page.goToFavoriteLibraries(); expect(await browser.getCurrentUrl()).toContain(APP_ROUTES.FAVORITE_LIBRARIES); - expect(await sidenav.isActive(SIDEBAR_LABELS.FILE_LIBRARIES)).toBe(true, 'File Libraries link not active'); + expect(await sidenav.isActive(SIDEBAR_LABELS.FILE_LIBRARIES)).toBe(false, 'File Libraries link is active'); expect(await sidenav.childIsActive(SIDEBAR_LABELS.FAVORITE_LIBRARIES)).toBe(true, 'Favorite Libraries link not active'); }); it('navigate to My Libraries - [C289901]', async () => { await page.goToMyLibraries(); expect(await browser.getCurrentUrl()).toContain(APP_ROUTES.MY_LIBRARIES); - expect(await sidenav.isActive(SIDEBAR_LABELS.FILE_LIBRARIES)).toBe(true, 'File Libraries link not active'); + expect(await sidenav.isActive(SIDEBAR_LABELS.FILE_LIBRARIES)).toBe(false, 'File Libraries link is active'); expect(await sidenav.childIsActive(SIDEBAR_LABELS.MY_LIBRARIES)).toBe(true, 'My Libraries link not active'); }); diff --git a/src/app/components/sidenav/sidenav.component.html b/src/app/components/sidenav/sidenav.component.html index b0b9bef5c0..6315e13890 100644 --- a/src/app/components/sidenav/sidenav.component.html +++ b/src/app/components/sidenav/sidenav.component.html @@ -40,18 +40,22 @@ - {{ item.icon }} - + {{ item.icon }} + + - {{ item.title | translate }} + 'item--default': !routerLink.isActive && expansionPanel.expanded, + 'item--active': routerLink.isActive && !expansionPanel.expanded + }" + >{{ item.title | translate }} diff --git a/src/app/components/sidenav/sidenav.component.spec.ts b/src/app/components/sidenav/sidenav.component.spec.ts index 78a09728aa..16b374b4e0 100644 --- a/src/app/components/sidenav/sidenav.component.spec.ts +++ b/src/app/components/sidenav/sidenav.component.spec.ts @@ -26,29 +26,53 @@ import { NO_ERRORS_SCHEMA } from '@angular/core'; import { TestBed, async, ComponentFixture } from '@angular/core/testing'; import { SidenavComponent } from './sidenav.component'; -import { EffectsModule } from '@ngrx/effects'; -import { NodeEffects } from '../../store/effects/node.effects'; import { AppTestingModule } from '../../testing/app-testing.module'; -import { ExperimentalDirective } from '../../directives/experimental.directive'; +import { MatExpansionModule } from '@angular/material/expansion'; +import { AppExtensionService } from '../../extensions/extension.service'; describe('SidenavComponent', () => { let fixture: ComponentFixture; let component: SidenavComponent; + let extensionService: AppExtensionService; + const navbarMock = [ + { + items: [ + { + route: 'route' + } + ] + } + ]; beforeEach(async(() => { TestBed.configureTestingModule({ - imports: [AppTestingModule, EffectsModule.forRoot([NodeEffects])], - declarations: [SidenavComponent, ExperimentalDirective], + imports: [MatExpansionModule, AppTestingModule], + providers: [AppExtensionService], + declarations: [SidenavComponent], schemas: [NO_ERRORS_SCHEMA] }) .compileComponents() .then(() => { fixture = TestBed.createComponent(SidenavComponent); component = fixture.componentInstance; + extensionService = TestBed.get(AppExtensionService); + + extensionService.navbar = navbarMock; + + fixture.detectChanges(); }); })); - it('should be created', () => { - expect(component).toBeTruthy(); - }); + it('should set the sidenav data', async(() => { + expect(component.groups).toEqual([ + { + items: [ + { + route: 'route', + url: '/route' + } + ] + } + ]); + })); }); diff --git a/src/app/components/sidenav/sidenav.component.theme.scss b/src/app/components/sidenav/sidenav.component.theme.scss index 85ff9c878d..65e3c86fe6 100644 --- a/src/app/components/sidenav/sidenav.component.theme.scss +++ b/src/app/components/sidenav/sidenav.component.theme.scss @@ -41,6 +41,10 @@ color: mat-color($foreground, text); } + .item--label { + color: mat-color($primary, 0.87); + } + .item--active { color: mat-color($accent); }