This commit is contained in:
Bastian Wagner
2026-07-16 15:23:53 +02:00
parent 543e8273a7
commit c03b2e17f5
114 changed files with 7631 additions and 506 deletions

View File

@@ -0,0 +1,79 @@
import { TestBed } from '@angular/core/testing';
import { provideRouter } from '@angular/router';
import { signal } from '@angular/core';
import type { NotificationDto } from '@boilerplate/api-client';
import { NotificationStore } from '../core/notification.store';
import { NotificationPanelComponent } from './notification-panel';
const notification: NotificationDto = {
id: 'n1',
type: 'system',
title: 'Titel',
message: 'Nachricht',
link: '/',
metadata: null,
read: false,
readAt: null,
createdAt: '2026-07-16T08:00:00.000Z',
};
describe('NotificationPanelComponent', () => {
it('shows unread notifications and emits close', async () => {
const closed = vi.fn();
await TestBed.configureTestingModule({
imports: [NotificationPanelComponent],
providers: [
provideRouter([]),
{
provide: NotificationStore,
useValue: {
notifications: signal([notification]),
loading: signal(false),
error: signal(null),
markAllAsRead: vi.fn(),
markAsRead: vi.fn(),
markAsUnread: vi.fn(),
delete: vi.fn(),
isInternalLink: () => true,
},
},
],
}).compileComponents();
const fixture = TestBed.createComponent(NotificationPanelComponent);
fixture.componentInstance.closed.subscribe(closed);
fixture.detectChanges();
const element = fixture.nativeElement as HTMLElement;
expect(element.querySelector('article.unread')).not.toBeNull();
element.querySelector<HTMLButtonElement>('header button')?.click();
expect(closed).toHaveBeenCalledOnce();
});
it('renders empty and error states', async () => {
await TestBed.configureTestingModule({
imports: [NotificationPanelComponent],
providers: [
provideRouter([]),
{
provide: NotificationStore,
useValue: {
notifications: signal([]),
loading: signal(false),
error: signal({
message: 'Fehler',
requestId: 'req-1',
status: 500,
code: 'INTERNAL_ERROR',
}),
markAllAsRead: vi.fn(),
isInternalLink: () => false,
},
},
],
}).compileComponents();
const fixture = TestBed.createComponent(NotificationPanelComponent);
fixture.detectChanges();
expect((fixture.nativeElement as HTMLElement).textContent).toContain('req-1');
});
});