forked from mirrored/github-readme-stats
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:
co-authored by
Alexandr
parent
ab53e3052d
commit
fda29161e8
+38
-1
@@ -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
|
||||
});
|
||||
});
|
||||
|
||||
@@ -4,7 +4,6 @@ import { describe, expect, it } from "@jest/globals";
|
||||
import { queryByTestId } from "@testing-library/dom";
|
||||
import "@testing-library/jest-dom";
|
||||
import { encodeHTML, parseBoolean, renderError } from "../src/common/utils.js";
|
||||
import { wrapTextMultiline } from "../src/common/fmt.js";
|
||||
|
||||
describe("Test utils.js", () => {
|
||||
it("should test parseBoolean", () => {
|
||||
@@ -50,35 +49,3 @@ describe("Test utils.js", () => {
|
||||
).toHaveTextContent(/Secondary Message/gim);
|
||||
});
|
||||
});
|
||||
|
||||
describe("wrapTextMultiline", () => {
|
||||
it("should not wrap small texts", () => {
|
||||
{
|
||||
let multiLineText = wrapTextMultiline("Small text should not wrap");
|
||||
expect(multiLineText).toEqual(["Small text should not wrap"]);
|
||||
}
|
||||
});
|
||||
it("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("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("should wrap chinese by punctuation", () => {
|
||||
let multiLineText = wrapTextMultiline(
|
||||
"专门为刚开始刷题的同学准备的算法基地,没有最细只有更细,立志用动画将晦涩难懂的算法说的通俗易懂!",
|
||||
);
|
||||
expect(multiLineText.length).toEqual(3);
|
||||
expect(multiLineText[0].length).toEqual(18 * 8); // &#xxxxx; x 8
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user