AppShell.test.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /* @vitest-environment node */
  2. import { describe, it, expect, vi } from "vitest";
  3. import React from "react";
  4. import { renderToString } from "react-dom/server";
  5. /**
  6. * We mock `next/link` so this unit test does not depend on the Next.js runtime.
  7. * For a server-render smoke test, a minimal <a href="..."> replacement is enough.
  8. */
  9. vi.mock("next/link", async () => {
  10. const ReactNs = await import("react");
  11. const React = ReactNs.default ?? ReactNs;
  12. function LinkMock({ href, children, ...props }) {
  13. const resolvedHref =
  14. typeof href === "string"
  15. ? href
  16. : href?.pathname
  17. ? String(href.pathname)
  18. : "";
  19. return React.createElement("a", { href: resolvedHref, ...props }, children);
  20. }
  21. return { default: LinkMock };
  22. });
  23. import AppShell from "./AppShell";
  24. describe("components/app-shell/AppShell", () => {
  25. it("renders the shell without crashing and includes key areas", () => {
  26. const element = React.createElement(
  27. AppShell,
  28. null,
  29. React.createElement("div", null, "Child content")
  30. );
  31. const html = renderToString(element);
  32. // TopNav brand
  33. expect(html).toContain("RHL Lieferscheine");
  34. // Sidebar placeholder heading (German)
  35. expect(html).toContain("Seitenleiste");
  36. // Rendered children
  37. expect(html).toContain("Child content");
  38. });
  39. });