refactor(frontend): utility dedup, component splits, dead code removal (#193–#200) #241

Merged
marcel merged 19 commits from refactor/issues-193-200 into main 2026-04-15 15:23:16 +02:00
Showing only changes of commit 8739511058 - Show all commits

View File

@@ -6,6 +6,7 @@ let lastEventSource: {
close: ReturnType<typeof vi.fn>;
onopen: (() => void) | null;
onerror: (() => void) | null;
simulate: (type: string, data: string) => void;
} | null = null;
class MockEventSource {
@@ -23,6 +24,13 @@ class MockEventSource {
if (!this.listeners[type]) this.listeners[type] = [];
this.listeners[type].push(fn);
}
simulate(type: string, data: string) {
const event = new MessageEvent(type, { data });
for (const fn of this.listeners[type] ?? []) {
fn(event);
}
}
}
vi.stubGlobal('EventSource', MockEventSource);
@@ -106,4 +114,29 @@ describe('createNotificationStream', () => {
stream.destroy();
expect(lastEventSource!.close).toHaveBeenCalled();
});
it('SSE notification event prepends notification and increments unreadCount', async () => {
mockFetch.mockResolvedValue(new Response(JSON.stringify({ count: 0 }), { status: 200 }));
const stream = createNotificationStream();
stream.init();
const notification = makeNotification({ id: 'sse-1', read: false });
lastEventSource!.simulate('notification', JSON.stringify(notification));
expect(stream.notifications).toHaveLength(1);
expect(stream.notifications[0].id).toBe('sse-1');
expect(stream.unreadCount).toBe(1);
});
it('SSE notification event with read:true does not increment unreadCount', async () => {
mockFetch.mockResolvedValue(new Response(JSON.stringify({ count: 0 }), { status: 200 }));
const stream = createNotificationStream();
stream.init();
const notification = makeNotification({ id: 'sse-2', read: true });
lastEventSource!.simulate('notification', JSON.stringify(notification));
expect(stream.notifications).toHaveLength(1);
expect(stream.unreadCount).toBe(0);
});
});