From fadb166488eb56a7d3498d6efe71350686c3e760 Mon Sep 17 00:00:00 2001 From: Sander Muller Date: Sun, 18 Oct 2026 20:08:42 +0200 Subject: [PATCH 1/3] fix: poll notifications with the filter on screen Co-Authored-By: Claude Opus 5.5 --- resources/js/pages/notification/index.tsx | 8 +- tests/Unit/NotificationPoll.test.tsx | 109 ++++++++++++++++++++++ tests/draft-images.config.ts | 1 + tests/tsconfig.json | 1 + 4 files changed, 118 insertions(+), 1 deletion(-) create mode 100644 tests/Unit/NotificationPoll.test.tsx diff --git a/resources/js/pages/notification/index.tsx b/resources/js/pages/notification/index.tsx index eb2a90e3f4..26d7040e51 100644 --- a/resources/js/pages/notification/index.tsx +++ b/resources/js/pages/notification/index.tsx @@ -158,9 +158,14 @@ export default function Index({ const { start, stop } = usePoll( 30_000, () => ({ - only: ['notifications', 'auth.unreadNotificationsCount'], + only: [ + 'notifications', + 'auth.unreadNotificationsCount', + 'auth.unreadMessagesCount', + ], reset: ['notifications'], data: { + type: filters.type, cursor: '', through: notifications.data.at(-1)?.created_at, }, @@ -364,6 +369,7 @@ export default function Index({ <> +import assert from 'node:assert/strict'; +import type { ReactNode } from 'react'; +import { renderToString } from 'react-dom/server'; +import { test, vi } from 'vite-plus/test'; +import type { NotificationGroup, User } from '../../resources/js/types'; + +let poll: () => { only?: string[]; data?: Record }; +let scrollParams: { data?: Record } | undefined; + +vi.doMock('@inertiajs/react', async () => ({ + ...(await vi.importActual('@inertiajs/react')), + usePoll: (_interval: number, options: typeof poll) => { + poll = options; + + return { start: () => {}, stop: () => {} }; + }, + InfiniteScroll: ({ + params, + children, + }: { + params?: typeof scrollParams; + children: ReactNode; + }) => { + scrollParams = params; + + return children; + }, +})); + +const { createInertiaApp } = await import('@inertiajs/react'); +const { default: Index } = + await import('../../resources/js/pages/notification/index'); + +const timestamp = '2026-10-16T12:00:00Z'; +const actor: User = { + id: 'actor', + username: 'follower', + name: 'Follower', + avatar_url: null, + bio: null, + location: null, + website: null, + company: null, + has_sponsors_listing: false, + timezone: null, + has_github_account: true, + lane: 0, + created_at: timestamp, + updated_at: timestamp, +}; +const follow: NotificationGroup = { + id: 'notice', + recipient_id: 'recipient', + actor_id: actor.id, + commit_id: null, + subject_id: null, + reason: null, + read_at: timestamp, + group_id: 'notice', + type: 'followed', + actor: { ...actor, is_followed: false }, + actors: [actor], + actors_count: 1, + event_count: 1, + unread_count: 0, + created_at: timestamp, + updated_at: timestamp, + commit: null, +}; + +await createInertiaApp({ + page: { + component: 'notification/index', + props: { + auth: { user: { id: 'recipient', username: 'recipient' }, log: {} }, + errors: {}, + }, + url: '/notifications', + version: null, + clearHistory: false, + encryptHistory: false, + rescuedProps: [], + rememberedState: {}, + flash: {}, + }, + resolve: () => () => ( + + ), + render: renderToString, + setup: ({ App, props }) => , +}); + +test('polls and loads more for the filter on screen, not the remembered one', () => { + assert.equal(poll().data?.type, 'follows'); + assert.equal(scrollParams?.data?.type, 'follows'); +}); + +test('keeps the messages badge current while the layout poller is off', () => { + assert.ok(poll().only?.includes('auth.unreadMessagesCount')); +}); diff --git a/tests/draft-images.config.ts b/tests/draft-images.config.ts index 4170077549..5085a5264b 100644 --- a/tests/draft-images.config.ts +++ b/tests/draft-images.config.ts @@ -23,6 +23,7 @@ export default defineConfig({ 'tests/Unit/SearchDialogComposition.test.tsx', 'tests/Unit/ReportResolution.test.tsx', 'tests/Unit/LinkifiedText.test.tsx', + 'tests/Unit/NotificationPoll.test.tsx', ], }, }); diff --git a/tests/tsconfig.json b/tests/tsconfig.json index 5390d6411f..d18cae9301 100644 --- a/tests/tsconfig.json +++ b/tests/tsconfig.json @@ -11,6 +11,7 @@ "Unit/SearchDialogComposition.test.tsx", "Unit/DraftImageReads.test.tsx", "Unit/ImageAttachments.test.tsx", + "Unit/NotificationPoll.test.tsx", "../resources/js/types/*.d.ts", "draft-images.config.ts" ] From 02496601b3be1e1506e00fedb62f005db2306925 Mon Sep 17 00:00:00 2001 From: Sander Muller Date: Sun, 18 Oct 2026 20:15:13 +0200 Subject: [PATCH 2/3] test: name the notification poll test for what it checks Co-Authored-By: Claude Opus 5.5 --- tests/Unit/NotificationPoll.test.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Unit/NotificationPoll.test.tsx b/tests/Unit/NotificationPoll.test.tsx index efc17813d4..7990b36bf3 100644 --- a/tests/Unit/NotificationPoll.test.tsx +++ b/tests/Unit/NotificationPoll.test.tsx @@ -99,7 +99,7 @@ await createInertiaApp({ setup: ({ App, props }) => , }); -test('polls and loads more for the filter on screen, not the remembered one', () => { +test('polls and loads more with the filter on screen', () => { assert.equal(poll().data?.type, 'follows'); assert.equal(scrollParams?.data?.type, 'follows'); }); From 5749b20aa2b883677fe53adfd71ab809ac49b360 Mon Sep 17 00:00:00 2001 From: Sander Muller Date: Mon, 19 Oct 2026 20:16:58 +0200 Subject: [PATCH 3/3] test: render the notification poll test inside a tooltip provider Co-Authored-By: Claude Opus 5.5 --- tests/Unit/NotificationPoll.test.tsx | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/Unit/NotificationPoll.test.tsx b/tests/Unit/NotificationPoll.test.tsx index 7990b36bf3..6fc14c70f3 100644 --- a/tests/Unit/NotificationPoll.test.tsx +++ b/tests/Unit/NotificationPoll.test.tsx @@ -3,6 +3,7 @@ import assert from 'node:assert/strict'; import type { ReactNode } from 'react'; import { renderToString } from 'react-dom/server'; import { test, vi } from 'vite-plus/test'; +import { TooltipProvider } from '../../resources/js/components/ui/tooltip'; import type { NotificationGroup, User } from '../../resources/js/types'; let poll: () => { only?: string[]; data?: Record }; @@ -96,7 +97,11 @@ await createInertiaApp({ /> ), render: renderToString, - setup: ({ App, props }) => , + setup: ({ App, props }) => ( + + + + ), }); test('polls and loads more with the filter on screen', () => {