Skip to content

Commit 9941929

Browse files
CopilotLipata
andcommitted
Remove RouterLink dependency and update tests to expect events on routing tabs
Co-authored-by: Lipata <[email protected]>
1 parent 3673b83 commit 9941929

File tree

3 files changed

+12
-39
lines changed

3 files changed

+12
-39
lines changed

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

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ describe('IgxBottomNav', () => {
388388
indexChangingSpy = spyOn(bottomNav.selectedIndexChanging, 'emit');
389389
}));
390390

391-
it('Validate the events are not fired on clicking tab headers before pressing enter/space key.', fakeAsync(() => {
391+
it('Validate the events are fired on clicking tab headers for routing tabs.', fakeAsync(() => {
392392
fixture.ngZone.run(() => router.initialNavigation());
393393
tick();
394394
expect(location.path()).toBe('/');
@@ -398,28 +398,20 @@ describe('IgxBottomNav', () => {
398398
});
399399
tick();
400400
expect(location.path()).toBe('/view2');
401-
expect(bottomNav.selectedIndex).toBe(-1);
402-
403-
expect(indexChangingSpy).not.toHaveBeenCalled();
404-
expect(indexChangeSpy).not.toHaveBeenCalled();
405-
expect(itemChangeSpy).not.toHaveBeenCalled();
406-
407-
headers[1].dispatchEvent(KEY_ENTER_EVENT);
408-
tick(200);
409-
fixture.detectChanges();
401+
expect(bottomNav.selectedIndex).toBe(1);
410402

411-
expect(itemChangeSpy).toHaveBeenCalledWith({
412-
owner: bottomNav,
413-
oldItem: undefined,
414-
newItem: tabItems[1]
415-
});
416403
expect(indexChangingSpy).toHaveBeenCalledWith({
417404
owner: bottomNav,
418405
cancel: false,
419406
oldIndex: -1,
420407
newIndex: 1
421408
});
422409
expect(indexChangeSpy).toHaveBeenCalledWith(1);
410+
expect(itemChangeSpy).toHaveBeenCalledWith({
411+
owner: bottomNav,
412+
oldItem: undefined,
413+
newItem: tabItems[1]
414+
});
423415
}));
424416
});
425417
});

projects/igniteui-angular/src/lib/tabs/tab-header.directive.ts

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11

2-
import { Directive, ElementRef, HostBinding, HostListener, Optional, inject } from '@angular/core';
3-
import { RouterLink } from '@angular/router';
2+
import { Directive, ElementRef, HostBinding, HostListener } from '@angular/core';
43
import { PlatformUtil } from '../core/utils';
54
import { IgxTabItemDirective } from './tab-item.directive';
65
import { IgxTabHeaderBase, IgxTabsBase } from './tabs.base';
@@ -18,13 +17,7 @@ export abstract class IgxTabHeaderDirective implements IgxTabHeaderBase {
1817
public tab: IgxTabItemDirective,
1918
private elementRef: ElementRef<HTMLElement>,
2019
protected platform: PlatformUtil
21-
) {
22-
// Inject RouterLink directive if present
23-
this.routerLink = inject(RouterLink, { optional: true });
24-
}
25-
26-
/** @hidden */
27-
private routerLink?: RouterLink;
20+
) { }
2821

2922
/** @hidden */
3023
@HostBinding('attr.tabindex')
@@ -47,11 +40,7 @@ export abstract class IgxTabHeaderDirective implements IgxTabHeaderBase {
4740
/** @hidden */
4841
@HostListener('click')
4942
public onClick() {
50-
// For routing tabs, let the RouterLink handle navigation and don't select the tab immediately
51-
// For other tabs (content tabs or action tabs), allow immediate selection
52-
if (!this.routerLink) {
53-
this.tabs.selectTab(this.tab, true);
54-
}
43+
this.tabs.selectTab(this.tab, true);
5544
}
5645

5746
/** @hidden */

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

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1089,7 +1089,7 @@ describe('IgxTabs', () => {
10891089
indexChangingSpy = spyOn(tabs.selectedIndexChanging, 'emit');
10901090
}));
10911091

1092-
it('Validate the events are not fired on clicking tab headers before pressing enter/space key.', fakeAsync(() => {
1092+
it('Validate the events are fired on clicking tab headers for routing tabs.', fakeAsync(() => {
10931093
fixture.ngZone.run(() => router.initialNavigation());
10941094
tick();
10951095
expect(location.path()).toBe('/');
@@ -1099,15 +1099,7 @@ describe('IgxTabs', () => {
10991099
});
11001100
tick();
11011101
expect(location.path()).toBe('/view2');
1102-
expect(tabs.selectedIndex).toBe(-1);
1103-
1104-
expect(indexChangingSpy).not.toHaveBeenCalled();
1105-
expect(indexChangeSpy).not.toHaveBeenCalled();
1106-
expect(itemChangeSpy).not.toHaveBeenCalled();
1107-
1108-
headers[1].dispatchEvent(KEY_ENTER_EVENT);
1109-
tick(200);
1110-
fixture.detectChanges();
1102+
expect(tabs.selectedIndex).toBe(1);
11111103

11121104
expect(indexChangingSpy).toHaveBeenCalledWith({
11131105
owner: tabs,

0 commit comments

Comments
 (0)