1 import { ComponentFixture, TestBed } from '@angular/core/testing';
2 import { NotificationPanelComponent } from './notification-panel.component';
3 import { NotificationService } from '~/app/shared/services/notification.service';
5 describe('NotificationPanelComponent', () => {
6 let component: NotificationPanelComponent;
7 let fixture: ComponentFixture<NotificationPanelComponent>;
8 let notificationService: NotificationService;
10 beforeEach(async () => {
11 await TestBed.configureTestingModule({
12 declarations: [NotificationPanelComponent],
15 provide: NotificationService,
17 toggleSidebar: jasmine.createSpy('toggleSidebar')
21 }).compileComponents();
25 fixture = TestBed.createComponent(NotificationPanelComponent);
26 component = fixture.componentInstance;
27 notificationService = TestBed.inject(NotificationService);
28 fixture.detectChanges();
31 it('should create', () => {
32 expect(component).toBeTruthy();
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', {
42 document.dispatchEvent(outsideClickEvent);
44 expect(notificationService.toggleSidebar).toHaveBeenCalledWith(false, true);
47 it('should not close sidebar when clicking inside', () => {
48 // Create a click event inside the component
49 const insideClickEvent = new MouseEvent('click', {
54 const componentElement = fixture.nativeElement;
55 componentElement.dispatchEvent(insideClickEvent);
57 expect(notificationService.toggleSidebar).not.toHaveBeenCalled();