Files
buzz-sheet/lib/guides/percent-input.test.ts
gunshiz 51e74eee04
CI / Verify (push) Successful in 1m1s
CI / Build immutable images and deploy (push) Successful in 2m4s
fix(admin) : clarify validation and normalize percent input
2026-09-02 21:21:03 +07:00

18 lines
674 B
TypeScript

import { describe, expect, it } from "vitest";
import { finalizePercentInput, normalizePercentInput } from "@/lib/guides/percent-input";
describe("percentage input", () => {
it("turns only a lone dash into zero when editing finishes", () => {
expect(normalizePercentInput("-")).toBe("-");
expect(finalizePercentInput("-")).toBe("0");
expect(finalizePercentInput("-20")).toBe("-20");
});
it("keeps positive and negative decimal input and ignores other text", () => {
expect(normalizePercentInput("12.5")).toBe("12.5");
expect(normalizePercentInput("-12.5")).toBe("-12.5");
expect(normalizePercentInput("invalid", "12")).toBe("12");
});
});