feat: secure and document book reviews system
Some checks failed
Dev Deployment (Zero Downtime) / deploy-dev (push) Failing after 10m3s
Some checks failed
Dev Deployment (Zero Downtime) / deploy-dev (push) Failing after 10m3s
Added rate limiting to APIs, cleaned up docs, implemented fallback logic for reviews without text, and added comprehensive n8n guide.
This commit is contained in:
53
app/__tests__/components/ThemeToggle.test.tsx
Normal file
53
app/__tests__/components/ThemeToggle.test.tsx
Normal file
@@ -0,0 +1,53 @@
|
||||
import React from "react";
|
||||
import { render, screen, fireEvent, waitFor } from "@testing-library/react";
|
||||
import { ThemeToggle } from "@/app/components/ThemeToggle";
|
||||
import { useTheme } from "next-themes";
|
||||
|
||||
// Mock next-themes
|
||||
jest.mock("next-themes", () => ({
|
||||
useTheme: jest.fn(),
|
||||
}));
|
||||
|
||||
describe("ThemeToggle Component", () => {
|
||||
const setThemeMock = jest.fn();
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
(useTheme as jest.Mock).mockReturnValue({
|
||||
theme: "light",
|
||||
setTheme: setThemeMock,
|
||||
});
|
||||
});
|
||||
|
||||
it("renders a placeholder initially (to avoid hydration mismatch)", () => {
|
||||
const { container } = render(<ThemeToggle />);
|
||||
// Initial render should be the loading div
|
||||
expect(container.firstChild).toHaveClass("w-9 h-9");
|
||||
});
|
||||
|
||||
it("toggles to dark mode when clicked", async () => {
|
||||
render(<ThemeToggle />);
|
||||
|
||||
// Wait for effect to set mounted=true
|
||||
const button = await screen.findByRole("button", { name: /toggle theme/i });
|
||||
|
||||
fireEvent.click(button);
|
||||
|
||||
expect(setThemeMock).toHaveBeenCalledWith("dark");
|
||||
});
|
||||
|
||||
it("toggles to light mode when clicked if currently dark", async () => {
|
||||
(useTheme as jest.Mock).mockReturnValue({
|
||||
theme: "dark",
|
||||
setTheme: setThemeMock,
|
||||
});
|
||||
|
||||
render(<ThemeToggle />);
|
||||
|
||||
const button = await screen.findByRole("button", { name: /toggle theme/i });
|
||||
|
||||
fireEvent.click(button);
|
||||
|
||||
expect(setThemeMock).toHaveBeenCalledWith("light");
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user