From 6be5d6818a62a60b838955f71dd7e74c974d54a2 Mon Sep 17 00:00:00 2001 From: Tacho Date: Mon, 14 Jan 2019 12:37:16 +0200 Subject: [PATCH] test(navbar): add test for vertically-centered actionIcon content #3584 --- .../src/lib/navbar/navbar.component.spec.ts | 49 +++++++++++++++++-- src/app/navbar/navbar.sample.html | 2 +- 2 files changed, 45 insertions(+), 6 deletions(-) diff --git a/projects/igniteui-angular/src/lib/navbar/navbar.component.spec.ts b/projects/igniteui-angular/src/lib/navbar/navbar.component.spec.ts index 98b6a825061..f2c4d4e3d0a 100644 --- a/projects/igniteui-angular/src/lib/navbar/navbar.component.spec.ts +++ b/projects/igniteui-angular/src/lib/navbar/navbar.component.spec.ts @@ -2,8 +2,10 @@ import { Component, ViewChild } from '@angular/core'; import { async, TestBed } from '@angular/core/testing'; import { By } from '@angular/platform-browser'; import { IgxNavbarComponent, IgxNavbarModule } from './navbar.component'; +import { IgxIconModule } from '../icon/index'; import { configureTestSuite } from '../test-utils/configure-suite'; +import { wait } from '../test-utils/ui-interactions.spec'; const LEFT_AREA_CSS_CLAS = '.igx-navbar__left'; @@ -13,10 +15,12 @@ describe('IgxNavbar', () => { TestBed.configureTestingModule({ declarations: [ NavbarIntializeTestComponent, - NavbarCustomActionIconTestComponent + NavbarCustomActionIconTestComponent, + NavbarCustomIgxIconTestComponent ], imports: [ - IgxNavbarModule + IgxNavbarModule, + IgxIconModule ] }).compileComponents(); })); @@ -95,12 +99,10 @@ describe('IgxNavbar', () => { }); describe('Custom Action Icon', () => { - beforeEach(() => { + it('should have custom action icon/content when user has provided one', () => { fixture = TestBed.createComponent(NavbarCustomActionIconTestComponent); fixture.detectChanges(); - }); - it('should have custom action icon/content when user has provided one', () => { const leftArea = fixture.debugElement.query(By.css(LEFT_AREA_CSS_CLAS)); // Verify there is no default icon on the left. @@ -114,6 +116,28 @@ describe('IgxNavbar', () => { const customContentLeft = (customContent.nativeElement).getBoundingClientRect().left; expect(leftAreaLeft).toBe(customContentLeft, 'Custom action icon content is not first on the left.'); }); + + it('should have vertically-centered custom action icon content', (async() => { + fixture = TestBed.createComponent(NavbarCustomIgxIconTestComponent); + fixture.detectChanges(); + + await wait(100); + + const domNavbar = fixture.debugElement.query(By.css('igx-navbar')); + const customActionIcon = domNavbar.query(By.css('igx-action-icon')); + const customIcon = customActionIcon.query(By.css('igx-icon')); + + // Verify custom igxIcon is vertically-centered within the igx-action-icon. + const navbarTop = (domNavbar.nativeElement).getBoundingClientRect().top; + const customIconTop = (customIcon.nativeElement).getBoundingClientRect().top; + const topOffset = customIconTop - navbarTop; + + const navbarBottom = (domNavbar.nativeElement).getBoundingClientRect().bottom; + const customIconBottom = (customIcon.nativeElement).getBoundingClientRect().bottom; + const bottomOffset = navbarBottom - customIconBottom; + + expect(topOffset).toBe(bottomOffset, 'Custom icon is not vertically-centered.'); + })); }); }); @Component({ @@ -145,3 +169,18 @@ class NavbarIntializeTestComponent { class NavbarCustomActionIconTestComponent { @ViewChild(IgxNavbarComponent) public navbar: IgxNavbarComponent; } + +@Component({ + selector: 'igx-navbar-custom-igxicon-component', + template: ` + + arrow_back + + ` +}) +class NavbarCustomIgxIconTestComponent { + @ViewChild(IgxNavbarComponent) public navbar: IgxNavbarComponent; +} \ No newline at end of file diff --git a/src/app/navbar/navbar.sample.html b/src/app/navbar/navbar.sample.html index dace1529e2e..3251e8ec0de 100644 --- a/src/app/navbar/navbar.sample.html +++ b/src/app/navbar/navbar.sample.html @@ -39,7 +39,7 @@

With custom nav icon and action icons

more_vert - arrow_back + arrow_back