56 lines
1.5 KiB
TypeScript
56 lines
1.5 KiB
TypeScript
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<string, string>) => {
|
|
if (key === "shared.statComparison") {
|
|
return `translated from ${options?.[0]}`;
|
|
}
|
|
return key;
|
|
},
|
|
}),
|
|
}));
|
|
|
|
function renderDashboardStats() {
|
|
return render(
|
|
<MemoryRouter>
|
|
<DashboardStats
|
|
items={[
|
|
{
|
|
name: "admin.kpi.accounts.name",
|
|
hint: "admin.kpi.accounts.hint",
|
|
stat: "12",
|
|
previousStat: "9",
|
|
},
|
|
{
|
|
name: "admin.kpi.activeUsers.name",
|
|
hint: "admin.kpi.activeUsers.hint",
|
|
stat: "48",
|
|
},
|
|
]}
|
|
/>
|
|
</MemoryRouter>
|
|
);
|
|
}
|
|
|
|
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();
|
|
});
|
|
});
|