Skip to content
Merged
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
23 changes: 23 additions & 0 deletions client/e2e/notifications.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,26 @@ for (const [name, width, height] of [
await main.getByRole("tab", { name: /Settings/ }).click();
await expect(main.getByText("7 days")).toBeVisible();
});

test("Clear all in the bell panel empties the list the Notifications screen shows", async ({ page }) => {
await page.setViewportSize({ width: 1280, height: 800 });
await seed(page);
await page.goto("/", { waitUntil: "domcontentloaded" });

const bell = page.getByRole("button", { name: "Open notifications" }).locator("visible=true");
await expect(bell).toHaveCount(1, { timeout: 30_000 });
await bell.click();
const panel = page.getByTestId("notifications-panel").locator("visible=true");
await expect(panel.getByRole("listitem")).toHaveCount(8);

// All twelve go, not only the eight the panel shows; with nothing left the button goes too.
await panel.getByRole("button", { name: "Clear all" }).click();
await expect(panel.getByRole("listitem")).toHaveCount(0);
await expect(panel.getByText(/No notifications yet/)).toBeVisible();
await expect(panel.getByRole("button", { name: "Clear all" })).toHaveCount(0);
await expect(bell.getByTestId("notifications-badge")).toHaveCount(0);

await panel.getByRole("button", { name: "See all" }).click();
await expect(page).toHaveURL(/\/notifications$/);
await expect(page.getByRole("main").getByTestId("notifications-app-list").getByRole("listitem")).toHaveCount(0);
});
40 changes: 27 additions & 13 deletions client/src/layout/NotificationInbox.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useEffect, useRef, useState } from "react";
import { useNavigate } from "react-router";
import { ArrowRight, Bell, Tv, X } from "lucide-react";
import { ArrowRight, Bell, Trash2, Tv, X } from "lucide-react";

import { useNotificationsStore } from "../state/notifications";
import { useTr } from "../state/lang";
Expand Down Expand Up @@ -75,6 +75,7 @@ export default function NotificationInbox({
const entries = useNotificationsStore((s) => s.entries);
const markRead = useNotificationsStore((s) => s.markRead);
const remove = useNotificationsStore((s) => s.remove);
const clear = useNotificationsStore((s) => s.clear);
const [open, setOpen] = useState(false);
const wrapperRef = useRef<HTMLDivElement>(null);
const triggerRef = useRef<HTMLButtonElement>(null);
Expand Down Expand Up @@ -160,18 +161,31 @@ export default function NotificationInbox({
{tr("notif_tab_app", undefined, "This app")}
</span>
</h3>
<button
type="button"
onClick={() => {
setOpen(false);
triggerRef.current?.focus();
}}
aria-label={tr("close", undefined, "Close")}
title={tr("close", undefined, "Close")}
className="rounded-full p-1.5 text-[var(--color-muted)] hover:bg-[var(--color-surface-2)] hover:text-[var(--color-text)] max-md:p-2.5"
>
<X size={14} />
</button>
<div className="flex shrink-0 items-center gap-1">
{/* Every notice, as the screen's Clear all: update notices pile up between visits. */}
{entries.length > 0 && (
<button
type="button"
onClick={clear}
className="inline-flex min-h-8 items-center gap-1 rounded-full px-2 text-xs text-[var(--color-muted)] hover:bg-[var(--color-surface-2)] hover:text-[var(--color-text)] max-md:min-h-11"
>
<Trash2 size={12} aria-hidden />
{tr("notifications_clear", undefined, "Clear all")}
</button>
)}
<button
type="button"
onClick={() => {
setOpen(false);
triggerRef.current?.focus();
}}
aria-label={tr("close", undefined, "Close")}
title={tr("close", undefined, "Close")}
className="rounded-full p-1.5 text-[var(--color-muted)] hover:bg-[var(--color-surface-2)] hover:text-[var(--color-text)] max-md:p-2.5"
>
<X size={14} />
</button>
</div>
</header>
<div className="min-h-0 flex-1 overflow-y-auto overscroll-contain md:max-h-96">
{peek.length === 0 ? (
Expand Down
Loading