// @vitest-environment jsdom import "@testing-library/jest-dom/vitest"; import { render, screen } from "@testing-library/react"; import { describe, expect, it } from "vitest"; import { StatsCard } from "."; describe("StatsCard slot rendering", () => { it("renders a zero metric instead of dropping it", () => { // Regression guard: the generated `{value ? … : null}` guard treated the // number 0 as absent, so cards such as "Kritisch" or "Überfällig" showed a // heading and a trend arrow with no figure at all. render(); expect(screen.getByText("Kritisch")).toBeInTheDocument(); expect(screen.getByText("0")).toBeInTheDocument(); }); it("renders zero percentages and zero comparison text", () => { render(); expect(screen.getAllByText("0")).toHaveLength(3); }); it("still omits slots that carry no content", () => { const { container } = render(); expect(screen.getByText("Unklar")).toBeInTheDocument(); expect(container.textContent).toBe("Unklar"); }); it("treats an empty string as an opt-out, not as content", () => { // Call sites pass `percentage=""` to hide that slot; rendering it would add // empty elements to every card. const { container } = render(); expect(container.querySelectorAll("span:empty")).toHaveLength(0); expect(container.textContent).toBe("Kritisch0"); }); it("keeps rendering formatted string values", () => { render(); expect(screen.getByText("19,99 €")).toBeInTheDocument(); }); });