refactor: move wrap text multiline function tests into fmt module (#4573)

* refactor: move wrap text multiline function tests into fmt module

* lints

---------

Co-authored-by: Alexandr <qwerty541zxc@gmail.com>
This commit is contained in:
Alexandr GarbuzovandAlexandr authored and GitHub committed 2025-10-14 21:19:54 +03:00
1 parent ab53e3052d
commit fda29161e8
2 files changed
+38 -34

No files matched your search

+38 -1
View File
@@ -1,5 +1,9 @@
import { describe, expect, it } from "@jest/globals";
import { formatBytes, kFormatter } from "../src/common/fmt.js";
import {
formatBytes,
kFormatter,
wrapTextMultiline,
} from "../src/common/fmt.js";
describe("Test fmt.js", () => {
it("should test kFormatter default behavior", () => {
@@ -64,4 +68,37 @@ describe("Test fmt.js", () => {
expect(formatBytes(1234 * 1024)).toBe("1.2 MB");
expect(formatBytes(123.4 * 1024)).toBe("123.4 KB");
});
it("wrapTextMultiline: should not wrap small texts", () => {
{
let multiLineText = wrapTextMultiline("Small text should not wrap");
expect(multiLineText).toEqual(["Small text should not wrap"]);
}
});
it("wrapTextMultiline: should wrap large texts", () => {
let multiLineText = wrapTextMultiline(
"Hello world long long long text",
20,
3,
);
expect(multiLineText).toEqual(["Hello world long", "long long text"]);
});
it("wrapTextMultiline: should wrap large texts and limit max lines", () => {
let multiLineText = wrapTextMultiline(
"Hello world long long long text",
10,
2,
);
expect(multiLineText).toEqual(["Hello", "world long..."]);
});
it("wrapTextMultiline: should wrap chinese by punctuation", () => {
let multiLineText = wrapTextMultiline(
"专门为刚开始刷题的同学准备的算法基地,没有最细只有更细,立志用动画将晦涩难懂的算法说的通俗易懂!",
);
expect(multiLineText.length).toEqual(3);
expect(multiLineText[0].length).toEqual(18 * 8); // &#xxxxx; x 8
});
});