feat: opening the notifications inbox marks what it shows as read (#6275)
release / govulncheck (push) Successful in 22s
release / web (push) Successful in 1m23s
release / go (push) Successful in 1m39s
release / android (push) Failing after 4m25s
release / integration (push) Successful in 5m8s
release / Build signed APK (releases and dev) (push) Successful in 5m33s
release / Attach APK to the Release (tag releases only) (push) Skipped
release / Build + push container image (push) Skipped
release / Verify release artifacts (tag releases only) (push) Skipped
release / govulncheck (push) Successful in 22s
release / web (push) Successful in 1m23s
release / go (push) Successful in 1m39s
release / android (push) Failing after 4m25s
release / integration (push) Successful in 5m8s
release / Build signed APK (releases and dev) (push) Successful in 5m33s
release / Attach APK to the Release (tag releases only) (push) Skipped
release / Build + push container image (push) Skipped
release / Verify release artifacts (tag releases only) (push) Skipped
The web panel and the Android Notifications screen now mark every unread notice they show as read the moment they appear, so the badge clears on a look instead of a dismissal. Rows that were unread keep looking new until the inbox closes. The read goes through read-all with a cutoff of the newest notice shown plus 1 ms, so one that arrived unseen stays unread. 'Mark all read' is gone; opening the inbox does its job. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
import { beforeEach, describe, expect, test, vi } from 'vitest';
|
||||
import { render, screen, fireEvent, waitFor } from '@testing-library/svelte';
|
||||
import { tick } from 'svelte';
|
||||
import { writable } from 'svelte/store';
|
||||
import { mockQuery } from '../../test-utils/query';
|
||||
|
||||
const invalidateMock = vi.fn();
|
||||
@@ -12,6 +14,7 @@ vi.mock('#lib/api/notifications.js', async (orig) => {
|
||||
const actual = (await orig()) as Record<string, unknown>;
|
||||
return {
|
||||
badgeLabel: actual.badgeLabel,
|
||||
readAllCutoff: actual.readAllCutoff,
|
||||
createUnreadCountQuery: vi.fn(),
|
||||
createNotificationsQuery: vi.fn(),
|
||||
markNotificationRead: vi.fn().mockResolvedValue(undefined),
|
||||
@@ -19,8 +22,6 @@ vi.mock('#lib/api/notifications.js', async (orig) => {
|
||||
};
|
||||
});
|
||||
|
||||
vi.mock('#lib/stores/toast.svelte.js', () => ({ pushToast: vi.fn() }));
|
||||
|
||||
import NotificationBell from './NotificationBell.svelte';
|
||||
import { goto } from '$app/navigation';
|
||||
import {
|
||||
@@ -29,6 +30,7 @@ import {
|
||||
createUnreadCountQuery,
|
||||
markAllNotificationsRead,
|
||||
markNotificationRead,
|
||||
readAllCutoff,
|
||||
type NotificationItem
|
||||
} from '#lib/api/notifications.js';
|
||||
|
||||
@@ -137,21 +139,74 @@ describe('NotificationBell', () => {
|
||||
expect(markNotificationRead).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
test('mark all read clears everything and refreshes', async () => {
|
||||
setInbox([item(), item({ id: 'n2' })]);
|
||||
test('opening the panel marks what it shows read, up to the newest notice', async () => {
|
||||
setInbox([
|
||||
item({ id: 'new', created_at: '2026-10-23T12:00:00.123456Z' }),
|
||||
item({ id: 'older', created_at: '2026-10-23T11:00:00Z' })
|
||||
]);
|
||||
render(NotificationBell);
|
||||
await openPanel();
|
||||
await fireEvent.click(screen.getByRole('button', { name: 'Mark all read' }));
|
||||
expect(markAllNotificationsRead).not.toHaveBeenCalled();
|
||||
|
||||
await waitFor(() => expect(markAllNotificationsRead).toHaveBeenCalled());
|
||||
await openPanel();
|
||||
|
||||
await waitFor(() =>
|
||||
expect(markAllNotificationsRead).toHaveBeenCalledWith('2026-10-23T12:00:00.124Z')
|
||||
);
|
||||
expect(markAllNotificationsRead).toHaveBeenCalledTimes(1);
|
||||
expect(invalidateMock).toHaveBeenCalledWith({ queryKey: ['notifications'] });
|
||||
});
|
||||
|
||||
test('an empty inbox says so and offers no mark all', async () => {
|
||||
test('a notice read on opening still looks new until the panel closes', async () => {
|
||||
const page = (items: NotificationItem[]) => ({
|
||||
data: { items, unread_count: 0 },
|
||||
isPending: false,
|
||||
isError: false,
|
||||
refetch: () => {}
|
||||
});
|
||||
const list = writable(page([item({ id: 'n1' })]));
|
||||
(createUnreadCountQuery as ReturnType<typeof vi.fn>).mockReturnValue(mockQuery({ data: 1 }));
|
||||
(createNotificationsQuery as ReturnType<typeof vi.fn>).mockReturnValue(list);
|
||||
render(NotificationBell);
|
||||
await openPanel();
|
||||
await waitFor(() => expect(markAllNotificationsRead).toHaveBeenCalled());
|
||||
|
||||
// The refetch after marking brings the row back read.
|
||||
list.set(page([item({ id: 'n1', read_at: new Date().toISOString() })]));
|
||||
await tick();
|
||||
expect(screen.getByTestId('notification-item')).toHaveAttribute('data-unread', 'true');
|
||||
|
||||
await openPanel(); // closes
|
||||
await openPanel(); // opens again
|
||||
expect(screen.getByTestId('notification-item')).not.toHaveAttribute('data-unread');
|
||||
});
|
||||
|
||||
test('opening an inbox with nothing unread marks nothing', async () => {
|
||||
setInbox([item({ read_at: new Date().toISOString() })]);
|
||||
render(NotificationBell);
|
||||
await openPanel();
|
||||
expect(markAllNotificationsRead).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
test('an empty inbox says so', async () => {
|
||||
setInbox([]);
|
||||
render(NotificationBell);
|
||||
await openPanel();
|
||||
expect(screen.getByText('Nothing waiting for you.')).toBeInTheDocument();
|
||||
expect(screen.queryByRole('button', { name: 'Mark all read' })).toBeNull();
|
||||
expect(markAllNotificationsRead).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('readAllCutoff', () => {
|
||||
test('is a millisecond past the newest notice, so its microseconds are covered', () => {
|
||||
expect(
|
||||
readAllCutoff([
|
||||
item({ created_at: '2026-10-23T11:00:00Z' }),
|
||||
item({ created_at: '2026-10-23T12:00:00.123456Z' })
|
||||
])
|
||||
).toBe('2026-10-23T12:00:00.124Z');
|
||||
});
|
||||
|
||||
test('is undefined with nothing to mark', () => {
|
||||
expect(readAllCutoff([])).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user