Skip to content

Commit df5babd

Browse files
committed
test(tabs/bottomNav): extracting routing tests in separate describes #4297
1 parent 5738d17 commit df5babd

File tree

2 files changed

+127
-117
lines changed

2 files changed

+127
-117
lines changed

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

Lines changed: 63 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -162,66 +162,71 @@ describe('TabBar', () => {
162162
tabbar.tabs.forEach((tab) => expect(tab.relatedPanel.customTabTemplate).toBeDefined());
163163
});
164164

165-
it('should navigate to the correct URL when clicking on tab buttons', fakeAsync(() => {
166-
const router = TestBed.get(Router);
167-
const location = TestBed.get(Location);
168-
const fixture = TestBed.createComponent(TabBarRoutingTestComponent);
169-
const bottomNav = fixture.componentInstance.bottomNavComp;
170-
fixture.detectChanges();
171-
172-
fixture.ngZone.run(() => { router.initialNavigation(); });
173-
tick();
174-
expect(location.path()).toBe('/');
175-
176-
const theTabs = bottomNav.contentTabs.toArray();
177-
178-
fixture.ngZone.run(() => { theTabs[2].elementRef().nativeElement.dispatchEvent(new Event('click')); });
179-
tick();
180-
expect(location.path()).toBe('/view3');
181-
182-
fixture.ngZone.run(() => { theTabs[1].elementRef().nativeElement.dispatchEvent(new Event('click')); });
183-
tick();
184-
expect(location.path()).toBe('/view2');
185-
186-
fixture.ngZone.run(() => { theTabs[0].elementRef().nativeElement.dispatchEvent(new Event('click')); });
187-
tick();
188-
expect(location.path()).toBe('/view1');
189-
}));
190-
191-
it('should select the correct tab button/panel when navigating an URL', fakeAsync(() => {
192-
const router = TestBed.get(Router);
193-
const location = TestBed.get(Location);
194-
const fixture = TestBed.createComponent(TabBarRoutingTestComponent);
195-
const bottomNav = fixture.componentInstance.bottomNavComp;
196-
fixture.detectChanges();
165+
describe('Routing Navigation Tests', () => {
166+
configureTestSuite();
167+
168+
let router;
169+
let location;
170+
let fixture;
171+
let bottomNav;
172+
let theTabs;
173+
174+
beforeEach(async(() => {
175+
router = TestBed.get(Router);
176+
location = TestBed.get(Location);
177+
fixture = TestBed.createComponent(TabBarRoutingTestComponent);
178+
bottomNav = fixture.componentInstance.bottomNavComp;
179+
fixture.detectChanges();
180+
theTabs = bottomNav.contentTabs.toArray();
181+
}));
182+
183+
it('should navigate to the correct URL when clicking on tab buttons', fakeAsync(() => {
184+
fixture.ngZone.run(() => { router.initialNavigation(); });
185+
tick();
186+
expect(location.path()).toBe('/');
187+
188+
fixture.ngZone.run(() => { theTabs[2].elementRef().nativeElement.dispatchEvent(new Event('click')); });
189+
tick();
190+
expect(location.path()).toBe('/view3');
191+
192+
fixture.ngZone.run(() => { theTabs[1].elementRef().nativeElement.dispatchEvent(new Event('click')); });
193+
tick();
194+
expect(location.path()).toBe('/view2');
195+
196+
fixture.ngZone.run(() => { theTabs[0].elementRef().nativeElement.dispatchEvent(new Event('click')); });
197+
tick();
198+
expect(location.path()).toBe('/view1');
199+
}));
200+
201+
it('should select the correct tab button/panel when navigating an URL', fakeAsync(() => {
202+
fixture.ngZone.run(() => { router.initialNavigation(); });
203+
tick();
204+
expect(location.path()).toBe('/');
205+
206+
fixture.ngZone.run(() => { router.navigate(['/view3']); });
207+
tick();
208+
expect(location.path()).toBe('/view3');
209+
fixture.detectChanges();
210+
expect(bottomNav.selectedIndex).toBe(2);
211+
expect(theTabs[2].isSelected).toBe(true);
212+
213+
fixture.ngZone.run(() => { router.navigate(['/view2']); });
214+
tick();
215+
expect(location.path()).toBe('/view2');
216+
fixture.detectChanges();
217+
expect(bottomNav.selectedIndex).toBe(1);
218+
expect(theTabs[1].isSelected).toBe(true);
219+
220+
fixture.ngZone.run(() => { router.navigate(['/view1']); });
221+
tick();
222+
expect(location.path()).toBe('/view1');
223+
fixture.detectChanges();
224+
expect(bottomNav.selectedIndex).toBe(0);
225+
expect(theTabs[0].isSelected).toBe(true);
226+
}));
197227

198-
fixture.ngZone.run(() => { router.initialNavigation(); });
199-
tick();
200-
expect(location.path()).toBe('/');
201-
202-
const theTabs = bottomNav.contentTabs.toArray();
203-
204-
fixture.ngZone.run(() => { router.navigate(['/view3']); });
205-
tick();
206-
expect(location.path()).toBe('/view3');
207-
fixture.detectChanges();
208-
expect(bottomNav.selectedIndex).toBe(2);
209-
expect(theTabs[2].isSelected).toBe(true);
210-
211-
fixture.ngZone.run(() => { router.navigate(['/view2']); });
212-
tick();
213-
expect(location.path()).toBe('/view2');
214-
fixture.detectChanges();
215-
expect(bottomNav.selectedIndex).toBe(1);
216-
expect(theTabs[1].isSelected).toBe(true);
228+
});
217229

218-
fixture.ngZone.run(() => { router.navigate(['/view1']); });
219-
tick();
220-
expect(location.path()).toBe('/view1');
221-
fixture.detectChanges();
222-
expect(bottomNav.selectedIndex).toBe(0);
223-
expect(theTabs[0].isSelected).toBe(true);
224-
}));
225230
});
226231

227232
@Component({

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

Lines changed: 64 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -413,66 +413,71 @@ describe('IgxTabs', () => {
413413
expect(indicator.nativeElement.style.width).toBe('90px');
414414
}));
415415

416-
it('should navigate to the correct URL when clicking on tab buttons', fakeAsync(() => {
417-
const router = TestBed.get(Router);
418-
const location = TestBed.get(Location);
419-
const fixture = TestBed.createComponent(TabsRoutingTestComponent);
420-
const tabsComp = fixture.componentInstance.tabs;
421-
fixture.detectChanges();
422-
423-
fixture.ngZone.run(() => { router.initialNavigation(); });
424-
tick();
425-
expect(location.path()).toBe('/');
426-
427-
const theTabs = tabsComp.contentTabs.toArray();
428-
429-
fixture.ngZone.run(() => { theTabs[2].nativeTabItem.nativeElement.dispatchEvent(new Event('click')); });
430-
tick();
431-
expect(location.path()).toBe('/view3');
432-
433-
fixture.ngZone.run(() => { theTabs[1].nativeTabItem.nativeElement.dispatchEvent(new Event('click')); });
434-
tick();
435-
expect(location.path()).toBe('/view2');
436-
437-
fixture.ngZone.run(() => { theTabs[0].nativeTabItem.nativeElement.dispatchEvent(new Event('click')); });
438-
tick();
439-
expect(location.path()).toBe('/view1');
440-
}));
441-
442-
it('should select the correct tab button/panel when navigating an URL', fakeAsync(() => {
443-
const router = TestBed.get(Router);
444-
const location = TestBed.get(Location);
445-
const fixture = TestBed.createComponent(TabsRoutingTestComponent);
446-
const tabsComp = fixture.componentInstance.tabs;
447-
fixture.detectChanges();
416+
describe('Routing Navigation Tests', () => {
417+
configureTestSuite();
418+
419+
let router;
420+
let location;
421+
let fixture;
422+
let tabsComp;
423+
let theTabs;
424+
425+
beforeEach(async(() => {
426+
router = TestBed.get(Router);
427+
location = TestBed.get(Location);
428+
fixture = TestBed.createComponent(TabsRoutingTestComponent);
429+
tabsComp = fixture.componentInstance.tabs;
430+
fixture.detectChanges();
431+
theTabs = tabsComp.contentTabs.toArray();
432+
}));
433+
434+
it('should navigate to the correct URL when clicking on tab buttons', fakeAsync(() => {
435+
fixture.ngZone.run(() => { router.initialNavigation(); });
436+
tick();
437+
expect(location.path()).toBe('/');
438+
439+
fixture.ngZone.run(() => { theTabs[2].nativeTabItem.nativeElement.dispatchEvent(new Event('click')); });
440+
tick();
441+
expect(location.path()).toBe('/view3');
442+
443+
fixture.ngZone.run(() => { theTabs[1].nativeTabItem.nativeElement.dispatchEvent(new Event('click')); });
444+
tick();
445+
expect(location.path()).toBe('/view2');
446+
447+
fixture.ngZone.run(() => { theTabs[0].nativeTabItem.nativeElement.dispatchEvent(new Event('click')); });
448+
tick();
449+
expect(location.path()).toBe('/view1');
450+
}));
451+
452+
it('should select the correct tab button/panel when navigating an URL', fakeAsync(() => {
453+
fixture.ngZone.run(() => { router.initialNavigation(); });
454+
tick();
455+
expect(location.path()).toBe('/');
456+
457+
fixture.ngZone.run(() => { router.navigate(['/view3']); });
458+
tick();
459+
expect(location.path()).toBe('/view3');
460+
fixture.detectChanges();
461+
expect(tabsComp.selectedIndex).toBe(2);
462+
expect(theTabs[2].isSelected).toBe(true);
463+
464+
fixture.ngZone.run(() => { router.navigate(['/view2']); });
465+
tick();
466+
expect(location.path()).toBe('/view2');
467+
fixture.detectChanges();
468+
expect(tabsComp.selectedIndex).toBe(1);
469+
expect(theTabs[1].isSelected).toBe(true);
470+
471+
fixture.ngZone.run(() => { router.navigate(['/view1']); });
472+
tick();
473+
expect(location.path()).toBe('/view1');
474+
fixture.detectChanges();
475+
expect(tabsComp.selectedIndex).toBe(0);
476+
expect(theTabs[0].isSelected).toBe(true);
477+
}));
478+
479+
});
448480

449-
fixture.ngZone.run(() => { router.initialNavigation(); });
450-
tick();
451-
expect(location.path()).toBe('/');
452-
453-
const theTabs = tabsComp.contentTabs.toArray();
454-
455-
fixture.ngZone.run(() => { router.navigate(['/view3']); });
456-
tick();
457-
expect(location.path()).toBe('/view3');
458-
fixture.detectChanges();
459-
expect(tabsComp.selectedIndex).toBe(2);
460-
expect(theTabs[2].isSelected).toBe(true);
461-
462-
fixture.ngZone.run(() => { router.navigate(['/view2']); });
463-
tick();
464-
expect(location.path()).toBe('/view2');
465-
fixture.detectChanges();
466-
expect(tabsComp.selectedIndex).toBe(1);
467-
expect(theTabs[1].isSelected).toBe(true);
468-
469-
fixture.ngZone.run(() => { router.navigate(['/view1']); });
470-
tick();
471-
expect(location.path()).toBe('/view1');
472-
fixture.detectChanges();
473-
expect(tabsComp.selectedIndex).toBe(0);
474-
expect(theTabs[0].isSelected).toBe(true);
475-
}));
476481
});
477482

478483
@Component({

0 commit comments

Comments
 (0)