Skip to content
File

Blob: tests/client/lib/shared-inbox-navigation.test.ts

typescript25 lines
1import { describe, expect, it } from "vitest";
2import { getSharedInboxReturnTo, withSharedInboxReturnTo } from "@/client/lib/shared-inbox-navigation";
3 
4describe("shared inbox navigation helpers", () => {
5 it("reads a valid in-app return target from history state", () => {
6 expect(getSharedInboxReturnTo({ blandSharedInboxReturnTo: "/workspace/page?x=1#hash" })).toBe(
7 "/workspace/page?x=1#hash",
8 );
9 });
10 
11 it("rejects missing or unsafe return targets", () => {
12 expect(getSharedInboxReturnTo(null)).toBeNull();
13 expect(getSharedInboxReturnTo({ blandSharedInboxReturnTo: "https://example.com" })).toBeNull();
14 expect(getSharedInboxReturnTo({ blandSharedInboxReturnTo: "workspace/page" })).toBeNull();
15 });
16 
17 it("preserves existing router state when adding a return target", () => {
18 expect(withSharedInboxReturnTo({ __TSR_index: 3, foo: "bar" }, "/shared")).toEqual({
19 __TSR_index: 3,
20 blandSharedInboxReturnTo: "/shared",
21 foo: "bar",
22 });
23 });
24});