- Remove duplicate app/projects/ route (was causing 5xx and soft 404) - Fix nginx: redirect www.dk0.dev → dk0.dev (non-www canonical) - Fix not-found.tsx: locale-prefixed links, remove framer-motion dependency - Add fetchPriority='high' and will-change to Hero LCP image - Add preconnect hints for hardcover.app and cms.dk0.dev - Reduce background blur from 100px to 80px (LCP rendering delay) - Remove boneyard-js (~20 KiB), replace with custom Skeleton component - Remove react-icons (~10 KiB), replace with inline SVGs - Conditionally render mobile menu (saves ~20 DOM nodes) - Add /books to sitemap - Optimize image config with explicit deviceSizes/imageSizes
50 lines
1.3 KiB
TypeScript
50 lines
1.3 KiB
TypeScript
import { render, screen, waitFor } from "@testing-library/react";
|
|
import CurrentlyReadingComp from "@/app/components/CurrentlyReading";
|
|
import React from "react";
|
|
|
|
jest.mock("next-intl", () => ({
|
|
useTranslations: () => (key: string) => key,
|
|
useLocale: () => "en",
|
|
}));
|
|
|
|
jest.mock("next/image", () => ({
|
|
__esModule: true,
|
|
default: (props: React.ImgHTMLAttributes<HTMLImageElement>) => <img {...props} alt={props.alt || ""} />,
|
|
}));
|
|
|
|
describe("CurrentlyReading Component", () => {
|
|
beforeEach(() => {
|
|
global.fetch = jest.fn();
|
|
});
|
|
|
|
it("renders loading skeleton when loading", () => {
|
|
(global.fetch as jest.Mock).mockReturnValue(new Promise(() => {}));
|
|
render(<CurrentlyReadingComp />);
|
|
expect(screen.getAllByText).toBeDefined();
|
|
});
|
|
|
|
it("renders a book when data is fetched", async () => {
|
|
const mockBooks = [
|
|
{
|
|
title: "Test Book",
|
|
authors: ["Test Author"],
|
|
image: "/test.jpg",
|
|
progress: 50,
|
|
startedAt: "2024-01-01"
|
|
},
|
|
];
|
|
|
|
(global.fetch as jest.Mock).mockResolvedValue({
|
|
ok: true,
|
|
json: async () => ({ currentlyReading: mockBooks }),
|
|
});
|
|
|
|
render(<CurrentlyReadingComp />);
|
|
|
|
await waitFor(() => {
|
|
expect(screen.getByText("Test Book")).toBeInTheDocument();
|
|
expect(screen.getByText("Test Author")).toBeInTheDocument();
|
|
});
|
|
});
|
|
});
|