Skip to content

Commit fd95608

Browse files
committed
test(navbar): Adding tests for custom title #7377
1 parent 6079f6b commit fd95608

File tree

1 file changed

+113
-11
lines changed

1 file changed

+113
-11
lines changed

projects/igniteui-angular/src/lib/navbar/navbar.component.spec.ts

Lines changed: 113 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Component, ViewChild } from '@angular/core';
22
import { async, TestBed } from '@angular/core/testing';
33
import { By } from '@angular/platform-browser';
4-
import { IgxNavbarComponent, IgxNavbarModule } from './navbar.component';
4+
import { IgxNavbarComponent, IgxNavbarModule, IgxNavbarTitleDirective, IgxNavbarActionDirective } from './navbar.component';
55
import { IgxIconModule } from '../icon/public_api';
66

77
import { configureTestSuite } from '../test-utils/configure-suite';
@@ -16,7 +16,10 @@ describe('IgxNavbar', () => {
1616
declarations: [
1717
NavbarIntializeTestComponent,
1818
NavbarCustomActionIconTestComponent,
19-
NavbarCustomIgxIconTestComponent
19+
NavbarCustomIgxIconTestComponent,
20+
NavbarCustomTitleTestComponent,
21+
NavbarCustomTitleDirectiveTestComponent,
22+
NavbarCustomIgxIconDirectiveTestComponent
2023
],
2124
imports: [
2225
IgxNavbarModule,
@@ -86,7 +89,7 @@ describe('IgxNavbar', () => {
8689
const leftArea = fixture.debugElement.query(By.css(LEFT_AREA_CSS_CLAS));
8790

8891
// Verify there is no custom content on the left
89-
const customContent = leftArea.query(By.css('igx-action-icon'));
92+
const customContent = leftArea.query(By.css('igx-navbar-action'));
9093
expect(customContent).toBeNull('Custom action icon content is found on the left.');
9194

9295
// Verify there is a default icon on the left.
@@ -110,24 +113,24 @@ describe('IgxNavbar', () => {
110113
expect(defaultIcon).toBeNull('Default icon is found on the left.');
111114

112115
// Verify there is a custom content on the left.
113-
const customContent = leftArea.query(By.css('igx-action-icon'));
116+
const customContent = leftArea.query(By.css('igx-navbar-action'));
114117
expect(customContent).not.toBeNull('Custom action icon content is not found on the left.');
115118
const leftAreaLeft = (<HTMLElement>leftArea.nativeElement).getBoundingClientRect().left;
116119
const customContentLeft = (<HTMLElement>customContent.nativeElement).getBoundingClientRect().left;
117120
expect(leftAreaLeft).toBe(customContentLeft, 'Custom action icon content is not first on the left.');
118121
});
119122

120-
it('should have vertically-centered custom action icon content', (async() => {
123+
it('should have vertically-centered custom action icon content', (async () => {
121124
fixture = TestBed.createComponent(NavbarCustomIgxIconTestComponent);
122125
fixture.detectChanges();
123126

124127
await wait(100);
125128

126129
domNavbar = fixture.debugElement.query(By.css('igx-navbar'));
127-
const customActionIcon = domNavbar.query(By.css('igx-action-icon'));
130+
const customActionIcon = domNavbar.query(By.css('igx-navbar-action'));
128131
const customIcon = customActionIcon.query(By.css('igx-icon'));
129132

130-
// Verify custom igxIcon is vertically-centered within the igx-action-icon.
133+
// Verify custom igxIcon is vertically-centered within the igx-navbar-action.
131134
const navbarTop = (<HTMLElement>domNavbar.nativeElement).getBoundingClientRect().top;
132135
const customIconTop = (<HTMLElement>customIcon.nativeElement).getBoundingClientRect().top;
133136
const topOffset = customIconTop - navbarTop;
@@ -138,6 +141,57 @@ describe('IgxNavbar', () => {
138141

139142
expect(topOffset).toBe(bottomOffset, 'Custom icon is not vertically-centered.');
140143
}));
144+
145+
it('action icon via directive', (async () => {
146+
fixture = TestBed.createComponent(NavbarCustomIgxIconDirectiveTestComponent);
147+
fixture.detectChanges();
148+
149+
const leftArea = fixture.debugElement.query(By.css(LEFT_AREA_CSS_CLAS));
150+
const customContent = leftArea.query(By.directive(IgxNavbarActionDirective));
151+
expect(customContent).not.toBeNull('Custom action icon content is not found on the left.');
152+
const leftAreaLeft = (<HTMLElement>leftArea.nativeElement).getBoundingClientRect().left;
153+
const customContentLeft = (<HTMLElement>customContent.nativeElement).getBoundingClientRect().left;
154+
expect(leftAreaLeft).toBe(customContentLeft, 'Custom action icon content is not first on the left.');
155+
156+
}));
157+
});
158+
159+
describe('Custom title content', () => {
160+
beforeEach(() => {
161+
fixture = TestBed.createComponent(NavbarIntializeTestComponent);
162+
fixture.detectChanges();
163+
component = fixture.componentInstance;
164+
domNavbar = fixture.debugElement.query(By.css('igx-navbar')).nativeElement;
165+
});
166+
167+
it('Custom content should override the title property value', () => {
168+
fixture = TestBed.createComponent(NavbarCustomTitleTestComponent);
169+
fixture.detectChanges();
170+
171+
const leftArea = fixture.debugElement.query(By.css(LEFT_AREA_CSS_CLAS));
172+
173+
// Verify there is no default icon on the left.
174+
const customTitle = leftArea.query(By.css('igx-navbar-title'));
175+
expect(customTitle.nativeElement.textContent).toBe('Custom Title', 'Custom title is missing');
176+
177+
const defaultTitle = leftArea.query(By.css('igx-navbar__title'));
178+
expect(defaultTitle).toBeNull('Default title should not be present');
179+
});
180+
181+
it('Custom content should override the default title property', () => {
182+
fixture = TestBed.createComponent(NavbarCustomTitleDirectiveTestComponent);
183+
fixture.detectChanges();
184+
185+
const leftArea = fixture.debugElement.query(By.css(LEFT_AREA_CSS_CLAS));
186+
187+
// Verify there is no default icon on the left.
188+
const customTitle = leftArea.query(By.directive(IgxNavbarTitleDirective));
189+
expect(customTitle.nativeElement.children[0].textContent).toBe('Custom', 'Custom title is missing');
190+
expect(customTitle.nativeElement.children[1].textContent).toBe('Title', 'Custom title is missing');
191+
192+
const defaultTitle = leftArea.query(By.css('igx-navbar__title'));
193+
expect(defaultTitle).toBeNull('Default title should not be present');
194+
});
141195
});
142196
});
143197
@Component({
@@ -161,9 +215,9 @@ class NavbarIntializeTestComponent {
161215
title="Test Title"
162216
actionButtonIcon="home"
163217
isActionButtonVisible="true">
164-
<igx-action-icon>
218+
<igx-navbar-action>
165219
<button>custom action</button>
166-
</igx-action-icon>
220+
</igx-navbar-action>
167221
</igx-navbar>`
168222
})
169223
class NavbarCustomActionIconTestComponent {
@@ -176,11 +230,59 @@ class NavbarCustomActionIconTestComponent {
176230
title="Test Title"
177231
actionButtonIcon="home"
178232
isActionButtonVisible="true">
179-
<igx-action-icon>
233+
<igx-navbar-action>
180234
<igx-icon fontSet="material">arrow_back</igx-icon>
181-
</igx-action-icon>
235+
</igx-navbar-action>
182236
</igx-navbar>`
183237
})
184238
class NavbarCustomIgxIconTestComponent {
185239
@ViewChild(IgxNavbarComponent, { static: true }) public navbar: IgxNavbarComponent;
186240
}
241+
242+
@Component({
243+
selector: 'igx-navbar-custom-igxicon-component',
244+
template: `<igx-navbar #navbar
245+
title="Test Title"
246+
actionButtonIcon="home"
247+
isActionButtonVisible="true">
248+
<igx-icon igxNavbarAction fontSet="material">arrow_back</igx-icon>
249+
</igx-navbar>`
250+
})
251+
class NavbarCustomIgxIconDirectiveTestComponent {
252+
@ViewChild(IgxNavbarComponent, { static: true }) public navbar: IgxNavbarComponent;
253+
}
254+
255+
@Component({
256+
selector: 'igx-navbar-custom-title',
257+
template: `<igx-navbar #navbar
258+
title="Test Title"
259+
actionButtonIcon="home"
260+
isActionButtonVisible="true">
261+
<igx-navbar-action>
262+
<igx-icon fontSet="material">arrow_back</igx-icon>
263+
</igx-navbar-action>
264+
<igx-navbar-title>Custom Title</igx-navbar-title>
265+
</igx-navbar>`
266+
})
267+
class NavbarCustomTitleTestComponent {
268+
@ViewChild(IgxNavbarComponent, { static: true }) public navbar: IgxNavbarComponent;
269+
}
270+
271+
@Component({
272+
selector: 'igx-navbar-custom-title',
273+
template: `<igx-navbar #navbar
274+
title="Test Title"
275+
actionButtonIcon="home"
276+
isActionButtonVisible="true">
277+
<igx-navbar-action>
278+
<igx-icon fontSet="material">arrow_back</igx-icon>
279+
</igx-navbar-action>
280+
<div igxNavbarTitle>
281+
<div>Custom</div>
282+
<span>Title</span>
283+
</div>
284+
</igx-navbar>`
285+
})
286+
class NavbarCustomTitleDirectiveTestComponent {
287+
@ViewChild(IgxNavbarComponent, { static: true }) public navbar: IgxNavbarComponent;
288+
}

0 commit comments

Comments
 (0)