refactor Setting

This commit is contained in:
Timi
2026-04-30 11:04:28 +08:00
parent 28f0eabff2
commit ff3297e879
15 changed files with 239 additions and 231 deletions
+17 -4
View File
@@ -46,20 +46,24 @@ describe("Text", () => {
describe("unit", () => {
it("should format number with fixed and unit", () => {
expect(Text.unitSpace(1.236, 2, "rem")).toBe("1.24 rem");
expect(Text.unitCompact(1.236, "rem", 2)).toBe("1.24rem");
});
it("should format number with fixed and unit not space", () => {
expect(Text.unit(1.236, "rem", 2)).toBe("1.24rem");
expect(Text.unit(1.236, "rem", 2)).toBe("1.24 rem");
});
it("should trim string and append unit", () => {
expect(Text.unit(" 12 ", "px")).toBe("12px");
expect(Text.unit(" 12 ", "px")).toBe("12 px");
});
it("test zero", () => {
expect(Text.unit(0, "毫秒")).toBe("0 毫秒");
});
it("should return empty string for nullish zero and NaN", () => {
expect(Text.unit(null, "px")).toBe("");
expect(Text.unit(undefined, "px")).toBe("");
expect(Text.unit(0, "px")).toBe("");
expect(Text.unit(0, "px")).toBe("0 px");
expect(Text.unit(Number.NaN, "px")).toBe("");
});
});
@@ -83,6 +87,15 @@ describe("Text", () => {
});
});
describe("displayBool", () => {
it("should show boolean text", () => {
expect(Text.displayBool(true)).toBe("true");
expect(Text.displayBool(false)).toBe("false");
expect(Text.displayBool(false, "开启", "关闭")).toBe("关闭");
expect(Text.displayBool(undefined)).toBe("");
});
});
describe("readableColor", () => {
it("should return #FFF for dark backgrounds", () => {
expect(Text.readableColor("#000")).toBe("#FFF");