Files
prowler/ui/lib/utils.test.ts
T
Alan Buscaglia 587187419f feat(ui): add findings triage (#11704)
Co-authored-by: alejandrobailo <alejandrobailo94@gmail.com>
2026-07-01 17:55:33 +02:00

36 lines
1.1 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { calculatePercentage, getOptionalText } from "@/lib/utils";
describe("calculatePercentage", () => {
it("rounds the percentage to the nearest integer", () => {
expect(calculatePercentage(1, 3)).toBe(33);
expect(calculatePercentage(2, 3)).toBe(67);
});
it("returns 0 when the total is 0", () => {
expect(calculatePercentage(5, 0)).toBe(0);
});
});
describe("getOptionalText", () => {
it("returns the string when it has usable content", () => {
expect(getOptionalText("my-resource")).toBe("my-resource");
});
it("returns undefined for the '-' placeholder", () => {
expect(getOptionalText("-")).toBeUndefined();
});
it("returns undefined for empty or whitespace-only strings", () => {
expect(getOptionalText("")).toBeUndefined();
expect(getOptionalText(" ")).toBeUndefined();
});
it("returns undefined for non-string values", () => {
expect(getOptionalText(undefined)).toBeUndefined();
expect(getOptionalText(null)).toBeUndefined();
expect(getOptionalText(42)).toBeUndefined();
});
});