- Vitest multi-project setup (unit / integration / component) - Real-Postgres integration harness via in-process PGlite (TEST_DATABASE_URL override), migrations applied per worker; production code untouched - Unit: routing, locale, validation/Zod schemas, metadata, mail, site-theme, marquee, media, portfolio helpers, plus architecture-rule tests - Integration: Prisma data layer, API routes, and all server actions - Component: UI primitives and form components (jsdom + Testing Library) - 371 tests passing
37 lines
1.3 KiB
TypeScript
37 lines
1.3 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
|
|
import { readFlash, withFlash } from "@/lib/admin-feedback";
|
|
|
|
describe("withFlash", () => {
|
|
it("returns the plain path when there are no messages", () => {
|
|
expect(withFlash("/admin/smtp", {})).toBe("/admin/smtp");
|
|
});
|
|
|
|
it("appends a success message", () => {
|
|
expect(withFlash("/admin/smtp", { success: "Saved." })).toBe("/admin/smtp?success=Saved.");
|
|
});
|
|
|
|
it("appends an error message", () => {
|
|
expect(withFlash("/admin/smtp", { error: "Nope." })).toBe("/admin/smtp?error=Nope.");
|
|
});
|
|
|
|
it("appends both and url-encodes values", () => {
|
|
const result = withFlash("/admin/smtp", { success: "a b", error: "x&y" });
|
|
const params = new URL(result, "http://local").searchParams;
|
|
expect(params.get("success")).toBe("a b");
|
|
expect(params.get("error")).toBe("x&y");
|
|
});
|
|
});
|
|
|
|
describe("readFlash", () => {
|
|
it("reads success and error from resolved search params", () => {
|
|
expect(readFlash({ success: "ok", error: "bad" })).toEqual({ success: "ok", error: "bad" });
|
|
});
|
|
|
|
it("returns undefined fields when params are missing", () => {
|
|
expect(readFlash(undefined)).toEqual({ success: undefined, error: undefined });
|
|
expect(readFlash(null)).toEqual({ success: undefined, error: undefined });
|
|
expect(readFlash({})).toEqual({ success: undefined, error: undefined });
|
|
});
|
|
});
|