Răsfoiți Sursa

RHL-019 feat(tests): add unit tests for AppShell component

Code_Uwe 1 lună în urmă
părinte
comite
676890efc8
1 a modificat fișierele cu 50 adăugiri și 0 ștergeri
  1. 50 0
      components/app-shell/AppShell.test.js

+ 50 - 0
components/app-shell/AppShell.test.js

@@ -0,0 +1,50 @@
+/* @vitest-environment node */
+
+import { describe, it, expect, vi } from "vitest";
+import React from "react";
+import { renderToString } from "react-dom/server";
+
+/**
+ * We mock `next/link` so this unit test does not depend on the Next.js runtime.
+ * For a server-render smoke test, a minimal <a href="..."> replacement is enough.
+ */
+vi.mock("next/link", async () => {
+	const ReactNs = await import("react");
+	const React = ReactNs.default ?? ReactNs;
+
+	function LinkMock({ href, children, ...props }) {
+		const resolvedHref =
+			typeof href === "string"
+				? href
+				: href?.pathname
+				? String(href.pathname)
+				: "";
+
+		return React.createElement("a", { href: resolvedHref, ...props }, children);
+	}
+
+	return { default: LinkMock };
+});
+
+import AppShell from "./AppShell";
+
+describe("components/app-shell/AppShell", () => {
+	it("renders the shell without crashing and includes key areas", () => {
+		const element = React.createElement(
+			AppShell,
+			null,
+			React.createElement("div", null, "Child content")
+		);
+
+		const html = renderToString(element);
+
+		// TopNav brand
+		expect(html).toContain("RHL Lieferscheine");
+
+		// Sidebar placeholder content
+		expect(html).toContain("Sidebar");
+
+		// Rendered children
+		expect(html).toContain("Child content");
+	});
+});