summaryrefslogtreecommitdiffhomepage
path: root/packages/app/src/utils
diff options
context:
space:
mode:
authorFrank <[email protected]>2026-03-04 11:13:14 -0500
committerFrank <[email protected]>2026-03-04 11:13:14 -0500
commite9de2505f65b65a581a90dbd3b29f21dac6568de (patch)
treeb4f982f67f5e1fd78debf192ad237806db2cd62d /packages/app/src/utils
parent22fcde926fd8a071a213a54d624584372e73822d (diff)
parent715b844c2a88810b6178d7a2467c7d36ea8fb764 (diff)
downloadopencode-e9de2505f65b65a581a90dbd3b29f21dac6568de.tar.gz
opencode-e9de2505f65b65a581a90dbd3b29f21dac6568de.zip
Merge branch 'dev' into go-page
Diffstat (limited to 'packages/app/src/utils')
-rw-r--r--packages/app/src/utils/notification-click.test.ts37
-rw-r--r--packages/app/src/utils/notification-click.ts16
2 files changed, 27 insertions, 26 deletions
diff --git a/packages/app/src/utils/notification-click.test.ts b/packages/app/src/utils/notification-click.test.ts
index 76535f83a..fa81b0e02 100644
--- a/packages/app/src/utils/notification-click.test.ts
+++ b/packages/app/src/utils/notification-click.test.ts
@@ -1,26 +1,27 @@
-import { describe, expect, test } from "bun:test"
-import { handleNotificationClick } from "./notification-click"
+import { afterEach, describe, expect, test } from "bun:test"
+import { handleNotificationClick, setNavigate } from "./notification-click"
describe("notification click", () => {
- test("focuses and navigates when href exists", () => {
+ afterEach(() => {
+ setNavigate(undefined as any)
+ })
+
+ test("navigates via registered navigate function", () => {
const calls: string[] = []
- handleNotificationClick("/abc/session/123", {
- focus: () => calls.push("focus"),
- location: {
- assign: (href) => calls.push(href),
- },
- })
- expect(calls).toEqual(["focus", "/abc/session/123"])
+ setNavigate((href) => calls.push(href))
+ handleNotificationClick("/abc/session/123")
+ expect(calls).toEqual(["/abc/session/123"])
})
- test("only focuses when href is missing", () => {
+ test("does not navigate when href is missing", () => {
const calls: string[] = []
- handleNotificationClick(undefined, {
- focus: () => calls.push("focus"),
- location: {
- assign: (href) => calls.push(href),
- },
- })
- expect(calls).toEqual(["focus"])
+ setNavigate((href) => calls.push(href))
+ handleNotificationClick(undefined)
+ expect(calls).toEqual([])
+ })
+
+ test("falls back to location.assign without registered navigate", () => {
+ handleNotificationClick("/abc/session/123")
+ // falls back to window.location.assign — no error thrown
})
})
diff --git a/packages/app/src/utils/notification-click.ts b/packages/app/src/utils/notification-click.ts
index 1234cd1d6..94086c595 100644
--- a/packages/app/src/utils/notification-click.ts
+++ b/packages/app/src/utils/notification-click.ts
@@ -1,12 +1,12 @@
-type WindowTarget = {
- focus: () => void
- location: {
- assign: (href: string) => void
- }
+let nav: ((href: string) => void) | undefined
+
+export const setNavigate = (fn: (href: string) => void) => {
+ nav = fn
}
-export const handleNotificationClick = (href?: string, target: WindowTarget = window) => {
- target.focus()
+export const handleNotificationClick = (href?: string) => {
+ window.focus()
if (!href) return
- target.location.assign(href)
+ if (nav) nav(href)
+ else window.location.assign(href)
}