The bell pushed the user menu off a 360 px screen; the right-hand controls now use smaller gaps and a capped company picker on phones. Mark all read on the page now tells the bell to recount at once instead of on its next poll. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EFUzfiCVCgCVJZq4NDEqZs
62 lines
2.6 KiB
TypeScript
62 lines
2.6 KiB
TypeScript
import { render, screen, waitFor } from "@testing-library/react";
|
|
import userEvent from "@testing-library/user-event";
|
|
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
|
|
const svc = vi.hoisted(() => ({ listNotifications: vi.fn(), markAllRead: vi.fn() }));
|
|
vi.mock("@/app/lib/services/notifications", async (orig) => ({
|
|
...(await orig<typeof import("@/app/lib/services/notifications")>()),
|
|
...svc,
|
|
}));
|
|
|
|
import NotificationsPage from "./page";
|
|
|
|
const row = (id: number, seen: boolean) => ({
|
|
id, title: "NoticeFollowUpDue", type: "FOLLOW_UP_DUE", link: "/leads", seen, createDateTime: "2026-12-02T08:00:00",
|
|
message: '{"code":"NoticeFollowUpBody","params":{"due":2,"overdue":1}}',
|
|
});
|
|
|
|
beforeEach(() => {
|
|
vi.clearAllMocks();
|
|
svc.listNotifications.mockResolvedValue({ items: [row(1, false), row(2, true)], total: 2 });
|
|
svc.markAllRead.mockResolvedValue(undefined);
|
|
});
|
|
|
|
// add-lead-notifications: the full list of the signed-in user's notifications.
|
|
describe("/notifications", () => {
|
|
it("lists the user's notifications with links and marks unread ones", async () => {
|
|
render(<NotificationsPage />);
|
|
const links = await screen.findAllByRole("link", { name: /Follow-ups due/ });
|
|
expect(links).toHaveLength(2);
|
|
expect(links[0]).toHaveAttribute("href", "/leads");
|
|
expect(screen.getAllByText("2 due today, 1 overdue")).toHaveLength(2);
|
|
expect(screen.getAllByText("Unread")).toHaveLength(1);
|
|
expect(svc.listNotifications).toHaveBeenCalledWith(0, 20);
|
|
});
|
|
|
|
it("Mark all read marks them and reloads", async () => {
|
|
const changed = vi.fn();
|
|
window.addEventListener("notifications:changed", changed);
|
|
render(<NotificationsPage />);
|
|
await screen.findAllByRole("link", { name: /Follow-ups due/ });
|
|
svc.listNotifications.mockResolvedValue({ items: [row(1, true), row(2, true)], total: 2 });
|
|
|
|
await userEvent.click(screen.getByRole("button", { name: "Mark all read" }));
|
|
|
|
expect(svc.markAllRead).toHaveBeenCalled();
|
|
await waitFor(() => expect(screen.queryByText("Unread")).not.toBeInTheDocument());
|
|
expect(changed).toHaveBeenCalled(); // the header bell recounts at once
|
|
window.removeEventListener("notifications:changed", changed);
|
|
});
|
|
|
|
it("shows an empty state and a load error", async () => {
|
|
svc.listNotifications.mockResolvedValue({ items: [], total: 0 });
|
|
const { unmount } = render(<NotificationsPage />);
|
|
expect(await screen.findByText("No notifications yet.")).toBeInTheDocument();
|
|
unmount();
|
|
|
|
svc.listNotifications.mockRejectedValue(new Error("down"));
|
|
render(<NotificationsPage />);
|
|
expect(await screen.findByText("Couldn't load notifications.")).toBeInTheDocument();
|
|
});
|
|
});
|