import React from "react"; import { describe, it, expect, vi } from "vitest"; import RelatedArticles from "../../app/components/sections/RelatedArticles"; import type { BlogPost } from "../../lib/content"; import { renderWithProviders as render, screen, } from "../utils/test-utils"; vi.mock("next/link", () => ({ default: ({ children, href, ...props }: { children?: React.ReactNode; href?: string; [key: string]: unknown; }) => ( {children} ), })); vi.mock("../../app/components/content/ContentThumbnailTemplate", () => ({ default: ({ post }: { post: BlogPost }) => (

{post.frontmatter.title}

), })); vi.mock("../../app/hooks", () => ({ useIsMobile: () => false, })); const mockPosts: BlogPost[] = [ { slug: "article-1", frontmatter: { title: "Article 1", description: "Description 1", author: "Author", date: "2025-04-10", }, content: "", htmlContent: "", filePath: "article-1.md", lastModified: new Date("2025-04-10"), }, { slug: "article-2", frontmatter: { title: "Article 2", description: "Description 2", author: "Author", date: "2025-04-11", }, content: "", htmlContent: "", filePath: "article-2.md", lastModified: new Date("2025-04-11"), }, ]; // MessagesProvider required — container uses useMessages(). describe("RelatedArticles", () => { it("renders without crashing", () => { render( , ); }); it("renders related articles", () => { render( , ); expect(screen.getByTestId("thumbnail-article-1")).toBeInTheDocument(); expect(screen.getByTestId("thumbnail-article-2")).toBeInTheDocument(); }); it("filters out current post", () => { render( , ); expect(screen.queryByTestId("thumbnail-article-1")).not.toBeInTheDocument(); expect(screen.getByTestId("thumbnail-article-2")).toBeInTheDocument(); }); it("useCases variant shows localized stacked title", () => { render( , ); expect( screen.getByRole("heading", { level: 2, name: /Tools to set your group up for success/, }), ).toBeInTheDocument(); }); });