]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-ci.git/blob
444a6d11568894fc5c4c545a02edd7cb068b9ae6
[ceph-ci.git] /
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';
5
6 describe('NotificationHeaderComponent', () => {
7   let component: NotificationHeaderComponent;
8   let fixture: ComponentFixture<NotificationHeaderComponent>;
9   let notificationService: NotificationService;
10   let muteStateSubject: BehaviorSubject<boolean>;
11
12   beforeEach(async () => {
13     muteStateSubject = new BehaviorSubject<boolean>(false);
14     await TestBed.configureTestingModule({
15       declarations: [NotificationHeaderComponent],
16       providers: [
17         {
18           provide: NotificationService,
19           useValue: {
20             muteState$: muteStateSubject.asObservable(),
21             removeAll: jasmine.createSpy('removeAll'),
22             suspendToasties: jasmine.createSpy('suspendToasties')
23           }
24         }
25       ]
26     }).compileComponents();
27
28     fixture = TestBed.createComponent(NotificationHeaderComponent);
29     component = fixture.componentInstance;
30     notificationService = TestBed.inject(NotificationService);
31     fixture.detectChanges();
32   });
33
34   it('should create', () => {
35     expect(component).toBeTruthy();
36   });
37
38   it('should initialize with default mute state', () => {
39     expect(component.isMuted).toBe(false);
40   });
41
42   it('should update mute state when subscription emits', () => {
43     muteStateSubject.next(true);
44     fixture.detectChanges();
45     expect(component.isMuted).toBe(true);
46   });
47
48   it('should emit dismissAll event and call removeAll on dismiss', () => {
49     spyOn(component.dismissAll, 'emit');
50
51     component.onDismissAll();
52
53     expect(component.dismissAll.emit).toHaveBeenCalled();
54     expect(notificationService.removeAll).toHaveBeenCalled();
55   });
56
57   it('should toggle mute state', () => {
58     component.isMuted = false;
59     component.onToggleMute();
60     expect(notificationService.suspendToasties).toHaveBeenCalledWith(true);
61
62     component.isMuted = true;
63     component.onToggleMute();
64     expect(notificationService.suspendToasties).toHaveBeenCalledWith(false);
65   });
66
67   it('should unsubscribe on destroy', () => {
68     spyOn(component['subs'], 'unsubscribe');
69     component.ngOnDestroy();
70     expect(component['subs'].unsubscribe).toHaveBeenCalled();
71   });
72 });