mirror of
https://github.com/hanzoai/calendar.git
synced 2026-09-24 22:42:24 +00:00
* refactor: apply biome formatting to small packages + packages/lib Format packages/sms, packages/prisma, packages/platform/libraries, packages/platform/examples, packages/platform/types, packages/emails, and packages/lib. Excludes packages/platform/examples/base/src/pages/[bookingUid].tsx due to pre-existing lint errors. Co-Authored-By: Claude Opus 4.6 <[email protected]> * revert: remove packages/platform formatting changes Revert biome formatting for packages/platform as requested. Co-Authored-By: Claude Opus 4.6 <[email protected]> --------- Co-authored-by: Claude Opus 4.6 <[email protected]>
70 lines
2.6 KiB
TypeScript
70 lines
2.6 KiB
TypeScript
import { renderHook } from "@testing-library/react-hooks";
|
|
import { vi } from "vitest";
|
|
import { describe, expect, it } from "vitest";
|
|
|
|
import { useCompatSearchParams } from "./useCompatSearchParams";
|
|
|
|
vi.mock("next/navigation", () => ({
|
|
ReadonlyURLSearchParams: vi.fn().mockImplementation(function (a) {
|
|
return a;
|
|
}),
|
|
}));
|
|
|
|
describe("useCompatSearchParams hook", () => {
|
|
it("should return the searchParams in [email protected] Pages Router, SSR", async () => {
|
|
const navigation = await import("next/navigation");
|
|
|
|
navigation.useSearchParams = vi.fn().mockReturnValue(new URLSearchParams("a=a&b=b"));
|
|
navigation.useParams = vi.fn().mockReturnValue(null);
|
|
|
|
const { result } = renderHook(() => useCompatSearchParams());
|
|
|
|
expect(result.current.toString()).toEqual("a=a&b=b");
|
|
});
|
|
|
|
it("should return both searchParams and params in [email protected] App Router, SSR", async () => {
|
|
const navigation = await import("next/navigation");
|
|
|
|
navigation.useSearchParams = vi.fn().mockReturnValue(new URLSearchParams("a=a"));
|
|
navigation.useParams = vi.fn().mockReturnValue({ b: "b" });
|
|
|
|
const { result } = renderHook(() => useCompatSearchParams());
|
|
|
|
expect(result.current.toString()).toEqual("a=a&b=b");
|
|
});
|
|
|
|
it("params should always override searchParams in case of conflicting keys", async () => {
|
|
const navigation = await import("next/navigation");
|
|
|
|
navigation.useSearchParams = vi.fn().mockReturnValue(new URLSearchParams("a=a"));
|
|
navigation.useParams = vi.fn().mockReturnValue({ a: "b" });
|
|
|
|
const { result } = renderHook(() => useCompatSearchParams());
|
|
|
|
expect(result.current.toString()).toEqual("a=b");
|
|
});
|
|
|
|
it("should split paramsseparated with '/' (catch-all segments) in [email protected] App Router, SSR", async () => {
|
|
const navigation = await import("next/navigation");
|
|
|
|
navigation.useSearchParams = vi.fn().mockReturnValue(new URLSearchParams());
|
|
// in [email protected] useParams will return params separated by `/`
|
|
navigation.useParams = vi.fn().mockReturnValue({ a: "a/b/c" });
|
|
|
|
const { result } = renderHook(() => useCompatSearchParams());
|
|
|
|
expect(result.current.getAll("a")).toEqual(["a", "b", "c"]);
|
|
});
|
|
|
|
it("should include params and searchParams in [email protected], Pages/App Router, SSR", async () => {
|
|
const navigation = await import("next/navigation");
|
|
|
|
navigation.useSearchParams = vi.fn().mockReturnValue(new URLSearchParams("a=a"));
|
|
navigation.useParams = vi.fn().mockReturnValue({ b: "b" });
|
|
|
|
const { result } = renderHook(() => useCompatSearchParams());
|
|
|
|
expect(result.current.toString()).toEqual("a=a&b=b");
|
|
});
|
|
});
|