From c9719dff7223aa1fc19540f3cd627c7f40e4bf36 Mon Sep 17 00:00:00 2001 From: Adam <2363879+adamdotdevin@users.noreply.github.com> Date: Thu, 12 Feb 2026 20:04:19 -0600 Subject: fix(app): notification should navigate to session --- packages/app/src/utils/notification-click.test.ts | 26 +++++++++++++++++++++++ packages/app/src/utils/notification-click.ts | 12 +++++++++++ 2 files changed, 38 insertions(+) create mode 100644 packages/app/src/utils/notification-click.test.ts create mode 100644 packages/app/src/utils/notification-click.ts (limited to 'packages/app/src/utils') diff --git a/packages/app/src/utils/notification-click.test.ts b/packages/app/src/utils/notification-click.test.ts new file mode 100644 index 000000000..76535f83a --- /dev/null +++ b/packages/app/src/utils/notification-click.test.ts @@ -0,0 +1,26 @@ +import { describe, expect, test } from "bun:test" +import { handleNotificationClick } from "./notification-click" + +describe("notification click", () => { + test("focuses and navigates when href exists", () => { + const calls: string[] = [] + handleNotificationClick("/abc/session/123", { + focus: () => calls.push("focus"), + location: { + assign: (href) => calls.push(href), + }, + }) + expect(calls).toEqual(["focus", "/abc/session/123"]) + }) + + test("only focuses when href is missing", () => { + const calls: string[] = [] + handleNotificationClick(undefined, { + focus: () => calls.push("focus"), + location: { + assign: (href) => calls.push(href), + }, + }) + expect(calls).toEqual(["focus"]) + }) +}) diff --git a/packages/app/src/utils/notification-click.ts b/packages/app/src/utils/notification-click.ts new file mode 100644 index 000000000..1234cd1d6 --- /dev/null +++ b/packages/app/src/utils/notification-click.ts @@ -0,0 +1,12 @@ +type WindowTarget = { + focus: () => void + location: { + assign: (href: string) => void + } +} + +export const handleNotificationClick = (href?: string, target: WindowTarget = window) => { + target.focus() + if (!href) return + target.location.assign(href) +} -- cgit v1.2.3