Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion resources/js/pages/notification/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down Expand Up @@ -364,6 +369,7 @@ export default function Index({
<>
<InfiniteScroll
data="notifications"
params={{ data: { type: filters.type } }}
onlyNext
preserveUrl
loading={
Expand Down
114 changes: 114 additions & 0 deletions tests/Unit/NotificationPoll.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
/// <reference types="node" />
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<string, unknown> };
let scrollParams: { data?: Record<string, unknown> } | 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: () => () => (
<Index
notifications={{
data: [follow],
next_cursor: 'next',
prev_cursor: null,
}}
filters={{ type: 'follows' }}
readAt={timestamp}
/>
),
render: renderToString,
setup: ({ App, props }) => (
<TooltipProvider>
<App {...props} />
</TooltipProvider>
),
});

test('polls and loads more with the filter on screen', () => {
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'));
});
1 change: 1 addition & 0 deletions tests/draft-images.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
],
},
});
1 change: 1 addition & 0 deletions tests/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
Expand Down
Loading