@umituz/web-dashboard 7.9.0 → 7.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # @umituz/web-dashboard
2
2
 
3
3
  Installable app skeleton for SaaS dashboards: layouts, analytics, a content
4
- calendar, a product onboarding flow, a permissions/module registry, and an
5
- organization/membership module. Every
4
+ calendar, a product onboarding flow, a permissions/module registry, an
5
+ organization/membership module, and a notifications module. Every
6
6
  domain is an independent entry point — import only what your app uses. UI
7
7
  atoms and design tokens come from [@umituz/web-design-system](https://github.com/umituz/web-design-system);
8
8
  translations from [@umituz/web-localization](https://github.com/umituz/web-localization).
@@ -46,6 +46,7 @@ hosts set dark values on the DS variables under `[data-theme="dark"]` /
46
46
  @umituz/web-dashboard/styles.css # component stylesheet (udb-* BEM, incl. udb-onb-*)
47
47
  @umituz/web-dashboard/permissions # PermissionMatrix, hasPermission, guards
48
48
  @umituz/web-dashboard/organization # OrganizationProvider, members + invitations, seats, switcher
49
+ @umituz/web-dashboard/notifications # NotificationsProvider, bell + center, page skeleton
49
50
  @umituz/web-dashboard/modules # DashboardModule, buildRoutes, buildNav
50
51
  @umituz/web-dashboard/layouts # DashboardLayout, DashboardSidebar, DashboardHeader
51
52
  @umituz/web-dashboard/settings # SettingsLayout, admin skeletons (users, matrix, audit)
@@ -148,6 +149,30 @@ const service = new CalendarService(new MyDatabase());
148
149
  const demo = new CalendarService(createInMemoryCalendarDatabase());
149
150
  ```
150
151
 
152
+ ### Notifications
153
+
154
+ Feed state is provider-owned; the host owns persistence. Records carry
155
+ `{ id, type, title?, body?, read?, at | createdAt, severity?, link? }` —
156
+ either timestamp column is accepted and `critical` severity normalizes to
157
+ `danger`. Reads and dismisses apply optimistically while the callbacks persist.
158
+
159
+ ```tsx
160
+ import { NotificationsProvider } from "@umituz/web-dashboard/notifications";
161
+ import { NotificationCenter, NotificationsPage } from "@umituz/web-dashboard/notifications/components";
162
+
163
+ <NotificationsProvider
164
+ notifications={feed} // fresh array re-seeds the copy
165
+ loaded={!loading}
166
+ onMarkAllRead={() => api.post("/api/notifications/mark-read")}
167
+ onMarkRead={(id) => api.post(`/api/notifications/${id}/read`)}
168
+ >
169
+ <NotificationCenter viewAllTo="/notifications" /> {/* bell + badge, popover or drawer */}
170
+ </NotificationsProvider>
171
+
172
+ // Route body — segments derive from typeMeta counts; "Unread (n)" is built in:
173
+ <NotificationsPage typeMeta={TYPE_META} attentionLabel="Needs attention" />
174
+ ```
175
+
151
176
  ### Analytics
152
177
 
153
178
  `AnalyticsChart` consumes `ChartConfig` for line/area/bar/pie/donut. Tooltips
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umituz/web-dashboard",
3
- "version": "7.9.0",
3
+ "version": "7.10.0",
4
4
  "description": "Installable app skeleton for the fleet — layouts, analytics (dependency-free SVG charts), calendar, onboarding flow permissions/module registry; udb-* stylesheet on design-system tokens",
5
5
  "type": "module",
6
6
  "main": "./src/index.ts",
@@ -31,6 +31,8 @@
31
31
  "./layouts/types": "./src/domains/layouts/types/index.ts",
32
32
  "./layouts/utils": "./src/domains/layouts/utils/index.ts",
33
33
  "./modules": "./src/domains/modules/index.ts",
34
+ "./notifications": "./src/domains/notifications/index.ts",
35
+ "./notifications/components": "./src/domains/notifications/components/index.ts",
34
36
  "./onboarding": "./src/domains/onboarding/index.ts",
35
37
  "./organization": "./src/domains/organization/index.ts",
36
38
  "./organization/components": "./src/domains/organization/components/index.ts",
@@ -0,0 +1,90 @@
1
+ import { describe, expect, it, vi } from "vitest";
2
+ import { act, render } from "@testing-library/react";
3
+ import { NotificationsProvider, useNotifications } from "./NotificationsContext";
4
+ import type { NotificationRecord } from "./types";
5
+
6
+ const FEED: NotificationRecord[] = [
7
+ { id: "n1", type: "order", title: "Order shipped", body: "Out for delivery", read: false, at: "2026-10-23T10:00:00Z" },
8
+ { id: "n2", type: "system", title: "Welcome", read: true, createdAt: "2026-10-22T10:00:00Z" },
9
+ ];
10
+
11
+ interface ProbeValue {
12
+ notifications: NotificationRecord[];
13
+ unreadCount: number;
14
+ loaded: boolean;
15
+ canDismiss: boolean;
16
+ }
17
+
18
+ function Probe({ into }: { into: ProbeValue[] }) {
19
+ const { notifications, unreadCount, loaded, canDismiss } = useNotifications();
20
+ into.push({ notifications: [...notifications], unreadCount, loaded, canDismiss });
21
+ return null;
22
+ }
23
+
24
+ describe("NotificationsProvider", () => {
25
+ it("counts unread and passes loaded through", () => {
26
+ const seen: ProbeValue[] = [];
27
+ render(
28
+ <NotificationsProvider notifications={FEED} loaded={false}>
29
+ <Probe into={seen} />
30
+ </NotificationsProvider>,
31
+ );
32
+ expect(seen.at(-1)?.unreadCount).toBe(1);
33
+ expect(seen.at(-1)?.loaded).toBe(false);
34
+ expect(seen.at(-1)?.canDismiss).toBe(false);
35
+ });
36
+
37
+ it("marks all read optimistically and notifies the host", () => {
38
+ const onMarkAllRead = vi.fn();
39
+ const seen: ProbeValue[] = [];
40
+ let api: ReturnType<typeof useNotifications> | null = null;
41
+ function Caller() {
42
+ api = useNotifications();
43
+ return <Probe into={seen} />;
44
+ }
45
+ render(
46
+ <NotificationsProvider notifications={FEED} onMarkAllRead={onMarkAllRead}>
47
+ <Caller />
48
+ </NotificationsProvider>,
49
+ );
50
+ act(() => api!.markAllAsRead());
51
+ expect(seen.at(-1)?.unreadCount).toBe(0);
52
+ expect(onMarkAllRead).toHaveBeenCalledTimes(1);
53
+ });
54
+
55
+ it("marks one read once and dismisses through the host callback", () => {
56
+ const onMarkRead = vi.fn();
57
+ const onDismiss = vi.fn();
58
+ let api: ReturnType<typeof useNotifications> | null = null;
59
+ function Caller() {
60
+ api = useNotifications();
61
+ return null;
62
+ }
63
+ render(
64
+ <NotificationsProvider notifications={FEED} onMarkRead={onMarkRead} onDismiss={onDismiss}>
65
+ <Caller />
66
+ </NotificationsProvider>,
67
+ );
68
+ act(() => api!.markRead("n1"));
69
+ act(() => api!.markRead("n1"));
70
+ expect(onMarkRead).toHaveBeenCalledTimes(2);
71
+ act(() => api!.dismiss("n2"));
72
+ expect(onDismiss).toHaveBeenCalledWith("n2");
73
+ expect(api!.notifications.map((n) => n.id)).toEqual(["n1"]);
74
+ });
75
+
76
+ it("re-seeds when the host passes a fresh array reference", () => {
77
+ const seen: ProbeValue[] = [];
78
+ const { rerender } = render(
79
+ <NotificationsProvider notifications={FEED}>
80
+ <Probe into={seen} />
81
+ </NotificationsProvider>,
82
+ );
83
+ rerender(
84
+ <NotificationsProvider notifications={[{ id: "n9", type: "x", title: "From host" }]}>
85
+ <Probe into={seen} />
86
+ </NotificationsProvider>,
87
+ );
88
+ expect(seen.at(-1)?.notifications.map((n) => n.id)).toEqual(["n9"]);
89
+ });
90
+ });
@@ -0,0 +1,92 @@
1
+ import { createContext, useCallback, useContext, useEffect, useMemo, useState } from "react";
2
+ import type { ReactNode } from "react";
3
+ import type { NotificationRecord } from "./types";
4
+
5
+ export interface NotificationsContextValue {
6
+ notifications: NotificationRecord[];
7
+ unreadCount: number;
8
+ loaded: boolean;
9
+ markAllAsRead: () => void;
10
+ markRead: (id: string) => void;
11
+ dismiss: (id: string) => void;
12
+ canDismiss: boolean;
13
+ }
14
+
15
+ export interface NotificationsProviderProps {
16
+ /** The host's current feed — a new array reference re-seeds the local copy. */
17
+ notifications: readonly NotificationRecord[];
18
+ /** False while the host is still fetching; pages can render their own loading row. */
19
+ loaded?: boolean;
20
+ onMarkAllRead?: () => void;
21
+ onMarkRead?: (id: string) => void;
22
+ onDismiss?: (id: string) => void;
23
+ children: ReactNode;
24
+ }
25
+
26
+ const NotificationsContext = createContext<NotificationsContextValue | null>(null);
27
+
28
+ /** Shared feed state so the header bell and the page stay in sync. */
29
+ export function NotificationsProvider({
30
+ notifications,
31
+ loaded = true,
32
+ onMarkAllRead,
33
+ onMarkRead,
34
+ onDismiss,
35
+ children,
36
+ }: NotificationsProviderProps) {
37
+ // Optimistic local copy: reads/dismisses land instantly while the host
38
+ // persists through the callbacks; a fresh array from the host re-seeds it.
39
+ const [items, setItems] = useState<NotificationRecord[]>(() => [...notifications]);
40
+
41
+ useEffect(() => {
42
+ setItems([...notifications]);
43
+ }, [notifications]);
44
+
45
+ const markAllAsRead = useCallback(() => {
46
+ setItems((prev) => prev.map((n) => (n.read ? n : { ...n, read: true })));
47
+ onMarkAllRead?.();
48
+ }, [onMarkAllRead]);
49
+
50
+ const markRead = useCallback(
51
+ (id: string) => {
52
+ setItems((prev) => {
53
+ const target = prev.find((n) => n.id === id);
54
+ if (!target || target.read) return prev;
55
+ return prev.map((n) => (n.id === id ? { ...n, read: true } : n));
56
+ });
57
+ onMarkRead?.(id);
58
+ },
59
+ [onMarkRead],
60
+ );
61
+
62
+ const dismiss = useCallback(
63
+ (id: string) => {
64
+ setItems((prev) => prev.filter((n) => n.id !== id));
65
+ onDismiss?.(id);
66
+ },
67
+ [onDismiss],
68
+ );
69
+
70
+ const unreadCount = useMemo(() => items.filter((n) => !n.read).length, [items]);
71
+
72
+ const value = useMemo<NotificationsContextValue>(
73
+ () => ({
74
+ notifications: items,
75
+ unreadCount,
76
+ loaded,
77
+ markAllAsRead,
78
+ markRead,
79
+ dismiss,
80
+ canDismiss: Boolean(onDismiss),
81
+ }),
82
+ [items, unreadCount, loaded, markAllAsRead, markRead, dismiss, onDismiss],
83
+ );
84
+
85
+ return <NotificationsContext.Provider value={value}>{children}</NotificationsContext.Provider>;
86
+ }
87
+
88
+ export function useNotifications(): NotificationsContextValue {
89
+ const ctx = useContext(NotificationsContext);
90
+ if (!ctx) throw new Error("useNotifications must be used within NotificationsProvider");
91
+ return ctx;
92
+ }
@@ -0,0 +1,81 @@
1
+ import { describe, expect, it, vi } from "vitest";
2
+ import { fireEvent, render, screen } from "@testing-library/react";
3
+ import { MemoryRouter } from "react-router";
4
+ import { NotificationCenter } from "./NotificationCenter";
5
+ import { NotificationsProvider } from "../NotificationsContext";
6
+ import type { NotificationRecord } from "../types";
7
+
8
+ const FEED: NotificationRecord[] = Array.from({ length: 10 }, (_, i) => ({
9
+ id: `n${i}`,
10
+ type: "order",
11
+ title: `Alert ${i}`,
12
+ read: i < 8,
13
+ at: "2026-10-23T10:00:00Z",
14
+ }));
15
+
16
+ const mount = (feed: readonly NotificationRecord[] = FEED, props: Record<string, unknown> = {}) =>
17
+ render(
18
+ <MemoryRouter>
19
+ <NotificationsProvider notifications={feed}>
20
+ <NotificationCenter timeFormatter={() => "T"} {...props} />
21
+ </NotificationsProvider>
22
+ </MemoryRouter>,
23
+ );
24
+
25
+ describe("NotificationCenter", () => {
26
+ it("shows the unread badge count on the bell", () => {
27
+ mount();
28
+ expect(screen.getByRole("button", { name: "Notifications, 2 unread" })).not.toBeNull();
29
+ expect(screen.getByText("2")).not.toBeNull();
30
+ });
31
+
32
+ it("opens the popover with the truncated list and the more hint", () => {
33
+ mount();
34
+ fireEvent.click(screen.getByRole("button", { name: /Notifications/ }));
35
+ expect(screen.getByRole("dialog", { name: "Notifications" })).not.toBeNull();
36
+ expect(screen.getByText("Alert 0")).not.toBeNull();
37
+ expect(screen.getByText("+2 more")).not.toBeNull();
38
+ });
39
+
40
+ it("closes on Escape", () => {
41
+ mount();
42
+ fireEvent.click(screen.getByRole("button", { name: /Notifications/ }));
43
+ fireEvent.keyDown(document, { key: "Escape" });
44
+ expect(screen.queryByRole("dialog")).toBeNull();
45
+ });
46
+
47
+ it("marks all read from the panel header", () => {
48
+ const onMarkAllRead = vi.fn();
49
+ render(
50
+ <MemoryRouter>
51
+ <NotificationsProvider notifications={FEED} onMarkAllRead={onMarkAllRead}>
52
+ <NotificationCenter timeFormatter={() => "T"} />
53
+ </NotificationsProvider>
54
+ </MemoryRouter>,
55
+ );
56
+ fireEvent.click(screen.getByRole("button", { name: /Notifications/ }));
57
+ fireEvent.click(screen.getByText("Mark all read"));
58
+ expect(onMarkAllRead).toHaveBeenCalledTimes(1);
59
+ expect(screen.queryByText("Mark all read")).toBeNull();
60
+ });
61
+
62
+ it("renders the caught-up empty state instead of rows", () => {
63
+ mount([], { itemLimit: 8 });
64
+ fireEvent.click(screen.getByRole("button", { name: "Notifications" }));
65
+ expect(screen.getByText("You're all caught up")).not.toBeNull();
66
+ });
67
+
68
+ it("links to the notifications page from the footer", () => {
69
+ mount(FEED, { viewAllTo: "/notifications" });
70
+ fireEvent.click(screen.getByRole("button", { name: /Notifications/ }));
71
+ expect(screen.getByRole("link", { name: "View all" }).getAttribute("href")).toBe(
72
+ "/notifications",
73
+ );
74
+ });
75
+
76
+ it("drawer variant opens the design-system drawer", () => {
77
+ mount(FEED, { variant: "drawer" });
78
+ fireEvent.click(screen.getByRole("button", { name: /Notifications/ }));
79
+ expect(screen.getByText("Alert 0")).not.toBeNull();
80
+ });
81
+ });
@@ -0,0 +1,154 @@
1
+ import { useEffect, useRef, useState } from "react";
2
+ import { Link } from "react-router";
3
+ import { Bell, CheckCheck } from "lucide-react";
4
+ import { Button } from "@umituz/web-design-system/atoms";
5
+ import { Drawer } from "@umituz/web-design-system/organisms";
6
+ import { useNotifications } from "../NotificationsContext";
7
+ import type {
8
+ NotificationListLabels,
9
+ NotificationTypeMeta,
10
+ } from "../types";
11
+ import { NotificationList } from "./NotificationList";
12
+
13
+ export interface NotificationCenterLabels extends NotificationListLabels {
14
+ title: string;
15
+ markAllLabel: string;
16
+ viewAllLabel: string;
17
+ /** "{n} more" hint under a truncated popover list. */
18
+ morePattern: string;
19
+ /** "{n} unread" — the bell's accessible name when the badge has a count. */
20
+ bellPattern: string;
21
+ }
22
+
23
+ const DEFAULT_LABELS: NotificationCenterLabels = {
24
+ title: "Notifications",
25
+ markAllLabel: "Mark all read",
26
+ viewAllLabel: "View all",
27
+ morePattern: "+{n} more",
28
+ bellPattern: "Notifications, {n} unread",
29
+ markReadLabel: "Mark read",
30
+ dismissLabel: "Dismiss",
31
+ viewLabel: "View",
32
+ unreadLabel: "Unread",
33
+ emptyTitle: "You're all caught up",
34
+ emptyDescription: "New alerts will land here.",
35
+ };
36
+
37
+ export interface NotificationCenterProps {
38
+ /** `popover` anchors under the bell; `drawer` opens the design-system Drawer. */
39
+ variant?: "popover" | "drawer";
40
+ /** Rows shown before the popover truncates into the "more" hint. */
41
+ itemLimit?: number;
42
+ /** Page path for the "View all" link; omit to hide the footer link. */
43
+ viewAllTo?: string;
44
+ typeMeta?: NotificationTypeMeta;
45
+ timeFormatter?: (iso: string) => string;
46
+ labels?: Partial<NotificationCenterLabels>;
47
+ }
48
+
49
+ /** Header bell + unread badge + feed surface; reads the NotificationsProvider. */
50
+ export const NotificationCenter = ({
51
+ variant = "popover",
52
+ itemLimit = 8,
53
+ viewAllTo,
54
+ typeMeta,
55
+ timeFormatter,
56
+ labels,
57
+ }: NotificationCenterProps) => {
58
+ const text = { ...DEFAULT_LABELS, ...labels };
59
+ const { notifications, unreadCount, markAllAsRead, markRead, dismiss, canDismiss } =
60
+ useNotifications();
61
+ const [open, setOpen] = useState(false);
62
+ const wrapRef = useRef<HTMLDivElement>(null);
63
+
64
+ useEffect(() => {
65
+ if (!open) return;
66
+ const onPointerDown = (event: MouseEvent) => {
67
+ if (!wrapRef.current?.contains(event.target as Node)) setOpen(false);
68
+ };
69
+ const onKeyDown = (event: KeyboardEvent) => {
70
+ if (event.key === "Escape") setOpen(false);
71
+ };
72
+ document.addEventListener("mousedown", onPointerDown);
73
+ document.addEventListener("keydown", onKeyDown);
74
+ return () => {
75
+ document.removeEventListener("mousedown", onPointerDown);
76
+ document.removeEventListener("keydown", onKeyDown);
77
+ };
78
+ }, [open]);
79
+
80
+ const shown = itemLimit > 0 ? notifications.slice(0, itemLimit) : notifications;
81
+ const hidden = notifications.length - shown.length;
82
+ const list = (
83
+ <>
84
+ <NotificationList
85
+ notifications={shown}
86
+ typeMeta={typeMeta}
87
+ onMarkRead={markRead}
88
+ onDismiss={canDismiss ? dismiss : undefined}
89
+ timeFormatter={timeFormatter}
90
+ labels={text}
91
+ />
92
+ {hidden > 0 && (
93
+ <p className="udb-notif-center__more">{text.morePattern.replace("{n}", String(hidden))}</p>
94
+ )}
95
+ </>
96
+ );
97
+
98
+ const markAllButton = unreadCount > 0 && (
99
+ <Button variant="ghost" size="sm" icon={<CheckCheck size={14} />} onClick={markAllAsRead}>
100
+ {text.markAllLabel}
101
+ </Button>
102
+ );
103
+
104
+ const bellLabel = unreadCount > 0 ? text.bellPattern.replace("{n}", String(unreadCount)) : text.title;
105
+
106
+ const bell = (
107
+ <button
108
+ type="button"
109
+ className="udb-notif-bell"
110
+ aria-label={bellLabel}
111
+ aria-expanded={open}
112
+ aria-haspopup="dialog"
113
+ onClick={() => setOpen((value) => !value)}
114
+ >
115
+ <Bell size={17} aria-hidden="true" />
116
+ {unreadCount > 0 && (
117
+ <span className="udb-notif-bell__badge">{unreadCount > 99 ? "99+" : unreadCount}</span>
118
+ )}
119
+ </button>
120
+ );
121
+
122
+ if (variant === "drawer") {
123
+ return (
124
+ <div ref={wrapRef}>
125
+ {bell}
126
+ <Drawer open={open} onClose={() => setOpen(false)} title={text.title} footer={markAllButton}>
127
+ {list}
128
+ </Drawer>
129
+ </div>
130
+ );
131
+ }
132
+
133
+ return (
134
+ <div className="udb-notif-center" ref={wrapRef}>
135
+ {bell}
136
+ {open && (
137
+ <div className="udb-notif-center__panel" role="dialog" aria-label={text.title}>
138
+ <header className="udb-notif-center__head">
139
+ <h3 className="udb-notif-center__title">{text.title}</h3>
140
+ {markAllButton}
141
+ </header>
142
+ <div className="udb-notif-center__list">{list}</div>
143
+ {viewAllTo && (
144
+ <footer className="udb-notif-center__foot">
145
+ <Link to={viewAllTo} onClick={() => setOpen(false)}>
146
+ {text.viewAllLabel}
147
+ </Link>
148
+ </footer>
149
+ )}
150
+ </div>
151
+ )}
152
+ </div>
153
+ );
154
+ };
@@ -0,0 +1,108 @@
1
+ import { describe, expect, it, vi } from "vitest";
2
+ import { fireEvent, render, screen } from "@testing-library/react";
3
+ import { MemoryRouter } from "react-router";
4
+ import { NotificationItem } from "./NotificationItem";
5
+ import type { NotificationRecord } from "../types";
6
+
7
+ const UNREAD: NotificationRecord = {
8
+ id: "n1",
9
+ type: "order",
10
+ title: "Order shipped",
11
+ body: "Out for delivery",
12
+ read: false,
13
+ at: "2026-10-23T10:00:00Z",
14
+ };
15
+
16
+ const fixedTime = () => "T-10m";
17
+
18
+ describe("NotificationItem", () => {
19
+ it("renders title, body, time and the unread dot", () => {
20
+ render(
21
+ <MemoryRouter>
22
+ <NotificationItem notification={UNREAD} timeFormatter={fixedTime} />
23
+ </MemoryRouter>,
24
+ );
25
+ expect(screen.getByText("Order shipped")).not.toBeNull();
26
+ expect(screen.getByText("Out for delivery")).not.toBeNull();
27
+ expect(screen.getByText("T-10m")).not.toBeNull();
28
+ expect(screen.getByRole("img", { name: "Unread" })).not.toBeNull();
29
+ });
30
+
31
+ it("marks read through the host handler and hides both affordances once read", () => {
32
+ const onMarkRead = vi.fn();
33
+ const { rerender } = render(
34
+ <MemoryRouter>
35
+ <NotificationItem
36
+ notification={UNREAD}
37
+ onMarkRead={onMarkRead}
38
+ timeFormatter={fixedTime}
39
+ />
40
+ </MemoryRouter>,
41
+ );
42
+ fireEvent.click(screen.getByText("Mark read"));
43
+ expect(onMarkRead).toHaveBeenCalledWith("n1");
44
+
45
+ rerender(
46
+ <MemoryRouter>
47
+ <NotificationItem
48
+ notification={{ ...UNREAD, read: true }}
49
+ onMarkRead={onMarkRead}
50
+ timeFormatter={fixedTime}
51
+ />
52
+ </MemoryRouter>,
53
+ );
54
+ expect(screen.queryByRole("img", { name: "Unread" })).toBeNull();
55
+ expect(screen.queryByText("Mark read")).toBeNull();
56
+ });
57
+
58
+ it("omits the mark-read button without a handler", () => {
59
+ render(
60
+ <MemoryRouter>
61
+ <NotificationItem notification={UNREAD} timeFormatter={fixedTime} />
62
+ </MemoryRouter>,
63
+ );
64
+ expect(screen.queryByText("Mark read")).toBeNull();
65
+ });
66
+
67
+ it("dismisses through the host handler", () => {
68
+ const onDismiss = vi.fn();
69
+ render(
70
+ <MemoryRouter>
71
+ <NotificationItem notification={UNREAD} onDismiss={onDismiss} timeFormatter={fixedTime} />
72
+ </MemoryRouter>,
73
+ );
74
+ fireEvent.click(screen.getByLabelText("Dismiss"));
75
+ expect(onDismiss).toHaveBeenCalledWith("n1");
76
+ });
77
+
78
+ it("navigates via the record link and marks read on the way", () => {
79
+ const onMarkRead = vi.fn();
80
+ render(
81
+ <MemoryRouter>
82
+ <NotificationItem
83
+ notification={{ ...UNREAD, link: "/orders" }}
84
+ onMarkRead={onMarkRead}
85
+ timeFormatter={fixedTime}
86
+ />
87
+ </MemoryRouter>,
88
+ );
89
+ const anchor = screen.getByRole("link", { name: /Order shipped/ });
90
+ expect(anchor.getAttribute("href")).toBe("/orders");
91
+ fireEvent.click(anchor);
92
+ expect(onMarkRead).toHaveBeenCalledWith("n1");
93
+ });
94
+
95
+ it("falls back to the typeMeta label when the record has no title", () => {
96
+ render(
97
+ <MemoryRouter>
98
+ <NotificationItem
99
+ notification={{ id: "n2", type: "expiry", body: "Milk expires tomorrow", read: true }}
100
+ typeMeta={{ expiry: { label: "Expiry warning" } }}
101
+ timeFormatter={fixedTime}
102
+ />
103
+ </MemoryRouter>,
104
+ );
105
+ expect(screen.getByText("Expiry warning")).not.toBeNull();
106
+ expect(screen.getByText("Milk expires tomorrow")).not.toBeNull();
107
+ });
108
+ });