- Move components/ to src/ and compile to dist/ with tsc - Add root barrel export plus deep-import subpath exports and base.css export - Post-compile step: copy base.css, add .js import extensions, mark client modules - Add publish.sh and .npmrc for the Gitea npm registry - Fix type errors, guard TinyMCE env access, drop ace-builds type dependency - Rename clashing props type names, remove Next.js scaffolding and unused deps Co-Authored-By: Claude Opus 5.5 <[email protected]>
86 lines
2.3 KiB
TypeScript
86 lines
2.3 KiB
TypeScript
import { describe, expect, test } from "bun:test";
|
|
import twuiNumberfy from "./numberfy";
|
|
|
|
describe("twuiNumberfy", () => {
|
|
test("converts a number to number", () => {
|
|
expect(twuiNumberfy(42)).toBe(42);
|
|
});
|
|
|
|
test("converts a numeric string to number", () => {
|
|
expect(twuiNumberfy("42")).toBe(42);
|
|
});
|
|
|
|
test("strips non-numeric characters", () => {
|
|
expect(twuiNumberfy("$1,234.56")).toBe(1234.56);
|
|
});
|
|
|
|
test("returns 0 for non-numeric string", () => {
|
|
expect(twuiNumberfy("hello")).toBe(0);
|
|
});
|
|
|
|
test("returns 0 for undefined input", () => {
|
|
expect(twuiNumberfy(undefined)).toBe(0);
|
|
});
|
|
|
|
test("returns 0 for null input", () => {
|
|
expect(twuiNumberfy(null)).toBe(0);
|
|
});
|
|
|
|
test("rounds with decimals=0", () => {
|
|
expect(twuiNumberfy(3.7, 0)).toBe(4);
|
|
});
|
|
|
|
test("rounds with decimals=0 (floor case)", () => {
|
|
expect(twuiNumberfy(3.2, 0)).toBe(3);
|
|
});
|
|
|
|
test("limits decimal places", () => {
|
|
expect(twuiNumberfy(3.14159, 2)).toBe(3.14);
|
|
});
|
|
|
|
test("preserves existing decimals when no decimals param", () => {
|
|
expect(twuiNumberfy("3.14")).toBe(3.14);
|
|
});
|
|
|
|
test("rounds integers when no decimals param and no existing decimals", () => {
|
|
expect(twuiNumberfy("42")).toBe(42);
|
|
});
|
|
|
|
test("strips minus sign (does not support negatives)", () => {
|
|
expect(twuiNumberfy("-5")).toBe(5);
|
|
});
|
|
|
|
test("handles string with currency symbol", () => {
|
|
expect(twuiNumberfy("₦50,000")).toBe(50000);
|
|
});
|
|
|
|
test("handles empty string", () => {
|
|
expect(twuiNumberfy("")).toBe(0);
|
|
});
|
|
|
|
test("handles boolean true", () => {
|
|
expect(twuiNumberfy(true)).toBe(0);
|
|
});
|
|
|
|
test("handles boolean false", () => {
|
|
expect(twuiNumberfy(false)).toBe(0);
|
|
});
|
|
|
|
test("handles string with percentage", () => {
|
|
expect(twuiNumberfy("75%")).toBe(75);
|
|
});
|
|
|
|
test("handles multiple decimal points (results in NaN -> 0)", () => {
|
|
const result = twuiNumberfy("1.2.3");
|
|
expect(result).toBe(0);
|
|
});
|
|
|
|
test("handles zero", () => {
|
|
expect(twuiNumberfy(0)).toBe(0);
|
|
});
|
|
|
|
test("handles very large numbers", () => {
|
|
expect(twuiNumberfy("9999999999")).toBe(9999999999);
|
|
});
|
|
});
|