9cb89162ab
CI Pipeline / test (pull_request) Successful in 7m5s
CI Pipeline / lint (pull_request) Has been cancelled
CI Pipeline / build (pull_request) Has been cancelled
CI Pipeline / e2e (webkit) (pull_request) Has been cancelled
CI Pipeline / e2e (chromium) (pull_request) Successful in 54m11s
CI Pipeline / e2e (firefox) (pull_request) Failing after 22m9s
CI Pipeline / visual-regression (pull_request) Successful in 11m50s
CI Pipeline / performance (pull_request) Successful in 13m59s
73 lines
1.9 KiB
TypeScript
73 lines
1.9 KiB
TypeScript
import React from "react";
|
|
import { render, screen } from "@testing-library/react";
|
|
import { describe, it, expect, vi } from "vitest";
|
|
import RelatedArticles from "../../app/components/RelatedArticles";
|
|
import type { BlogPost } from "../../lib/content";
|
|
|
|
vi.mock("next/link", () => ({
|
|
default: ({ children, href, ...props }: any) => (
|
|
<a href={href} {...props}>
|
|
{children}
|
|
</a>
|
|
),
|
|
}));
|
|
|
|
vi.mock("../../app/components/ContentThumbnailTemplate", () => ({
|
|
default: ({ post }: { post: BlogPost }) => (
|
|
<div data-testid={`thumbnail-${post.slug}`}>
|
|
<a href={`/blog/${post.slug}`}>
|
|
<h3>{post.frontmatter.title}</h3>
|
|
</a>
|
|
</div>
|
|
),
|
|
}));
|
|
|
|
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",
|
|
},
|
|
},
|
|
{
|
|
slug: "article-2",
|
|
frontmatter: {
|
|
title: "Article 2",
|
|
description: "Description 2",
|
|
author: "Author",
|
|
date: "2025-04-11",
|
|
},
|
|
},
|
|
];
|
|
|
|
describe("RelatedArticles", () => {
|
|
it("renders without crashing", () => {
|
|
render(
|
|
<RelatedArticles relatedPosts={mockPosts} currentPostSlug="current" />,
|
|
);
|
|
});
|
|
|
|
it("renders related articles", () => {
|
|
render(
|
|
<RelatedArticles relatedPosts={mockPosts} currentPostSlug="current" />,
|
|
);
|
|
expect(screen.getByTestId("thumbnail-article-1")).toBeInTheDocument();
|
|
expect(screen.getByTestId("thumbnail-article-2")).toBeInTheDocument();
|
|
});
|
|
|
|
it("filters out current post", () => {
|
|
render(
|
|
<RelatedArticles relatedPosts={mockPosts} currentPostSlug="article-1" />,
|
|
);
|
|
expect(screen.queryByTestId("thumbnail-article-1")).not.toBeInTheDocument();
|
|
expect(screen.getByTestId("thumbnail-article-2")).toBeInTheDocument();
|
|
});
|
|
});
|