18 lines
674 B
TypeScript
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");
|
|
});
|
|
});
|