Files
HiveGrid-Wireframes/03 Quellen und Referenzen/hivegrid-cloud/apps/web/app/ui/components/StatsCard/StatsCard.zero-value.test.tsx
T

48 lines
1.8 KiB
TypeScript

// @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(<StatsCard label="Kritisch" value={0} />);
expect(screen.getByText("Kritisch")).toBeInTheDocument();
expect(screen.getByText("0")).toBeInTheDocument();
});
it("renders zero percentages and zero comparison text", () => {
render(<StatsCard label="Überfällig" value={0} percentage={0} comparisonText={0} />);
expect(screen.getAllByText("0")).toHaveLength(3);
});
it("still omits slots that carry no content", () => {
const { container } = render(<StatsCard label="Unklar" value={undefined} percentage={null} comparisonText={false} />);
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(<StatsCard label="Kritisch" value={0} percentage="" comparisonText="" />);
expect(container.querySelectorAll("span:empty")).toHaveLength(0);
expect(container.textContent).toBe("Kritisch0");
});
it("keeps rendering formatted string values", () => {
render(<StatsCard label="Umsatz" value="19,99 €" />);
expect(screen.getByText("19,99 €")).toBeInTheDocument();
});
});