1 import { ComponentFixture, TestBed } from '@angular/core/testing';
2 import { NotificationHeaderComponent } from './notification-header.component';
3 import { NotificationService } from '../../../../shared/services/notification.service';
4 import { BehaviorSubject } from 'rxjs';
6 describe('NotificationHeaderComponent', () => {
7 let component: NotificationHeaderComponent;
8 let fixture: ComponentFixture<NotificationHeaderComponent>;
9 let notificationService: NotificationService;
10 let muteStateSubject: BehaviorSubject<boolean>;
12 beforeEach(async () => {
13 muteStateSubject = new BehaviorSubject<boolean>(false);
14 await TestBed.configureTestingModule({
15 declarations: [NotificationHeaderComponent],
18 provide: NotificationService,
20 muteState$: muteStateSubject.asObservable(),
21 removeAll: jasmine.createSpy('removeAll'),
22 suspendToasties: jasmine.createSpy('suspendToasties')
26 }).compileComponents();
28 fixture = TestBed.createComponent(NotificationHeaderComponent);
29 component = fixture.componentInstance;
30 notificationService = TestBed.inject(NotificationService);
31 fixture.detectChanges();
34 it('should create', () => {
35 expect(component).toBeTruthy();
38 it('should initialize with default mute state', () => {
39 expect(component.isMuted).toBe(false);
42 it('should update mute state when subscription emits', () => {
43 muteStateSubject.next(true);
44 fixture.detectChanges();
45 expect(component.isMuted).toBe(true);
48 it('should emit dismissAll event and call removeAll on dismiss', () => {
49 spyOn(component.dismissAll, 'emit');
51 component.onDismissAll();
53 expect(component.dismissAll.emit).toHaveBeenCalled();
54 expect(notificationService.removeAll).toHaveBeenCalled();
57 it('should toggle mute state', () => {
58 component.isMuted = false;
59 component.onToggleMute();
60 expect(notificationService.suspendToasties).toHaveBeenCalledWith(true);
62 component.isMuted = true;
63 component.onToggleMute();
64 expect(notificationService.suspendToasties).toHaveBeenCalledWith(false);
67 it('should unsubscribe on destroy', () => {
68 spyOn(component['subs'], 'unsubscribe');
69 component.ngOnDestroy();
70 expect(component['subs'].unsubscribe).toHaveBeenCalled();