import "@testing-library/jest-dom"; import { render, screen, within } from "@testing-library/react"; import { MemoryRouter } from "react-router"; import { describe, expect, it, vi } from "vitest"; import { DashboardStats } from "./DashboardStats"; vi.mock("react-i18next", () => ({ useTranslation: () => ({ t: (key: string, options?: Record) => { if (key === "shared.statComparison") { return `translated from ${options?.[0]}`; } return key; }, }), })); function renderDashboardStats() { return render( ); } describe("DashboardStats", () => { it("renders translated comparison copy when previousStat is present", () => { renderDashboardStats(); expect(screen.getByText("translated from 9")).toBeInTheDocument(); }); it("does not render comparison copy for cards without previousStat", () => { renderDashboardStats(); const activeUsersCard = screen.getByText("admin.kpi.activeUsers.name").closest(".truncate")?.parentElement; expect(activeUsersCard).not.toBeNull(); expect(within(activeUsersCard as HTMLElement).queryByText(/translated from/i)).not.toBeInTheDocument(); }); });