]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-ci.git/blob
67bc2924686cabaeef26765e07af91a28d198ad6
[ceph-ci.git] /
1 import { ComponentFixture, TestBed } from '@angular/core/testing';
2 import { NotificationPanelComponent } from './notification-panel.component';
3 import { NotificationService } from '~/app/shared/services/notification.service';
4
5 describe('NotificationPanelComponent', () => {
6   let component: NotificationPanelComponent;
7   let fixture: ComponentFixture<NotificationPanelComponent>;
8   let notificationService: NotificationService;
9
10   beforeEach(async () => {
11     await TestBed.configureTestingModule({
12       declarations: [NotificationPanelComponent],
13       providers: [
14         {
15           provide: NotificationService,
16           useValue: {
17             toggleSidebar: jasmine.createSpy('toggleSidebar')
18           }
19         }
20       ]
21     }).compileComponents();
22   });
23
24   beforeEach(() => {
25     fixture = TestBed.createComponent(NotificationPanelComponent);
26     component = fixture.componentInstance;
27     notificationService = TestBed.inject(NotificationService);
28     fixture.detectChanges();
29   });
30
31   it('should create', () => {
32     expect(component).toBeTruthy();
33   });
34
35   describe('handleClickOutside', () => {
36     it('should close sidebar when clicking outside', () => {
37       // Create a click event outside the component
38       const outsideClickEvent = new MouseEvent('click', {
39         bubbles: true,
40         cancelable: true
41       });
42       document.dispatchEvent(outsideClickEvent);
43
44       expect(notificationService.toggleSidebar).toHaveBeenCalledWith(false, true);
45     });
46
47     it('should not close sidebar when clicking inside', () => {
48       // Create a click event inside the component
49       const insideClickEvent = new MouseEvent('click', {
50         bubbles: true,
51         cancelable: true
52       });
53
54       const componentElement = fixture.nativeElement;
55       componentElement.dispatchEvent(insideClickEvent);
56
57       expect(notificationService.toggleSidebar).not.toHaveBeenCalled();
58     });
59   });
60 });