notification-click.test.ts 878 B

123456789101112131415161718192021222324252627
  1. import { afterEach, describe, expect, test } from "bun:test"
  2. import { handleNotificationClick, setNavigate } from "./notification-click"
  3. describe("notification click", () => {
  4. afterEach(() => {
  5. setNavigate(undefined as any)
  6. })
  7. test("navigates via registered navigate function", () => {
  8. const calls: string[] = []
  9. setNavigate((href) => calls.push(href))
  10. handleNotificationClick("/abc/session/123")
  11. expect(calls).toEqual(["/abc/session/123"])
  12. })
  13. test("does not navigate when href is missing", () => {
  14. const calls: string[] = []
  15. setNavigate((href) => calls.push(href))
  16. handleNotificationClick(undefined)
  17. expect(calls).toEqual([])
  18. })
  19. test("falls back to location.assign without registered navigate", () => {
  20. handleNotificationClick("/abc/session/123")
  21. // falls back to window.location.assign — no error thrown
  22. })
  23. })