Berichten: badge met aantal nieuwe berichten bij het menu-item (lichte unread-count-endpoint, 60 s verversing en bij focus, direct bijgewerkt bij openen)
Continuous Integration / config-sls (pull_request) Successful in 7s
Continuous Integration / changes (pull_request) Successful in 10s
Continuous Integration / config-asf (pull_request) Successful in 19s
Continuous Integration / backend-build (pull_request) Successful in 1m19s
Continuous Integration / frontend-prepare (pull_request) Successful in 32s
Continuous Integration / compile-sites (pull_request) Successful in 1m1s
Continuous Integration / vulnerability-scan (pull_request) Successful in 1m20s
Continuous Integration / frontend-build (pull_request) Successful in 35s
Continuous Integration / backend-test (pull_request) Successful in 2m20s
Continuous Integration / frontend-lint (pull_request) Successful in 36s
Continuous Integration / frontend-test (pull_request) Successful in 1m16s
Continuous Integration / publish-sls-test (pull_request) Skipped
Continuous Integration / publish-sls-production (pull_request) Skipped
Continuous Integration / deploy-sls-test (pull_request) Skipped
Continuous Integration / deploy-sls-production (pull_request) Skipped
Continuous Integration / publish-asf-test (pull_request) Skipped
Continuous Integration / deploy-asf-test (pull_request) Skipped
Continuous Integration / smoke-sls-test (pull_request) Skipped
Continuous Integration / smoke-asf-test (pull_request) Skipped

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-17 08:51:07 +01:00
co-authored by Claude Sonnet 5.5
parent 0824bfa888
commit 8aaae89f4c
12 changed files with 153 additions and 5 deletions
@@ -140,6 +140,7 @@ export const contactHandlers = [
unreadCount: messages.filter((m) => m.status === 'new').length,
});
}),
http.get(`${BASE}/unread-count`, () => HttpResponse.json({ unreadCount: messages.filter((m) => m.status === 'new').length })),
http.get(`${BASE}/:id`, ({ params }) => {
const m = messages.find((x) => x.id === params.id);
return m ? HttpResponse.json(m) : new HttpResponse(null, { status: 404 });
@@ -13,6 +13,7 @@ import {
resetMockContact,
} from '@/features/contact/mocks/handlers';
import { _resetSetupStatusCache } from '@/router';
import { UNREAD_REFRESH_MS } from '@/features/contact/services/useContactMessages';
const LONG = { timeout: 10000 };
@@ -43,6 +44,50 @@ async function openSettings() {
await screen.findByTestId('contact-panel-settings');
}
describe('Unread badge on the Berichten menu item', () => {
it('shows the number of new messages, with an accessible name, and not by colour alone', async () => {
capabilities(WITH_CONTACT);
renderApp('/dashboard');
const badge = await screen.findByTestId('nav-messages-badge', {}, LONG);
expect(badge).toHaveTextContent('1');
expect(badge).toHaveAttribute('aria-hidden', 'true');
expect(screen.getByTestId('nav-messages')).toHaveAccessibleName(/Berichten.*1 nieuw bericht|Messages.*1 new message/);
});
it('is hidden at zero and shows 99+ above 99', async () => {
capabilities(WITH_CONTACT);
server.use(http.get(`${API_BASE}/api/v1/contact-messages/unread-count`, () => HttpResponse.json({ unreadCount: 0 })));
renderApp('/dashboard');
await screen.findByTestId('nav-messages', {}, LONG);
await new Promise((r) => setTimeout(r, 300));
expect(screen.queryByTestId('nav-messages-badge')).not.toBeInTheDocument();
});
it('shows 99+ for a hundred or more', async () => {
capabilities(WITH_CONTACT);
server.use(http.get(`${API_BASE}/api/v1/contact-messages/unread-count`, () => HttpResponse.json({ unreadCount: 250 })));
renderApp('/dashboard');
expect(await screen.findByTestId('nav-messages-badge', {}, LONG)).toHaveTextContent('99+');
expect(screen.getByTestId('nav-messages-badge-text')).toHaveTextContent(/250/);
});
it('follows at once when a message is opened (and so marked as read)', async () => {
capabilities(WITH_CONTACT);
renderApp('/messages');
expect(await screen.findByTestId('nav-messages-badge', {}, LONG)).toHaveTextContent('1');
await userEvent.click(await screen.findByTestId(`contact-row-${MSG_NEW}`, {}, LONG));
await waitFor(() => expect(screen.queryByTestId('nav-messages-badge')).not.toBeInTheDocument(), LONG);
});
it('asks the light endpoint every minute and when the window gets focus', () => {
expect(UNREAD_REFRESH_MS).toBe(60_000);
});
});
describe('Berichten navigation', () => {
it('shows the sidebar entry when the module is loaded and the API answers', async () => {
capabilities(WITH_CONTACT);
@@ -22,13 +22,20 @@ export function useContactMessages(filter: ContactFilter, page: number) {
});
}
/** Only the unread counter, for the dashboard tile (one item is enough: the counter is part of every list answer). */
/**
* Only the unread counter, for the menu badge and the dashboard tile (a light endpoint). It is refreshed every minute and
* when the window gets focus again; React Query stops the interval while the tab is hidden. Opening or marking a message
* invalidates it (the key lives under ['contact', 'messages']), so the badge follows at once.
*/
export const UNREAD_REFRESH_MS = 60_000;
export function useUnreadContactCount(enabled: boolean) {
return useQuery<number, Error>({
queryKey: ['contact', 'messages', 'unreadCount'],
enabled,
queryFn: async () =>
(await api.get<ContactMessageList>(`${BASE}?page=1&pageSize=1`)).unreadCount,
refetchInterval: UNREAD_REFRESH_MS,
refetchOnWindowFocus: true,
queryFn: async () => (await api.get<{ unreadCount: number }>(`${BASE}/unread-count`)).unreadCount,
});
}