diff --git a/tests/fmt.test.js b/tests/fmt.test.js index 9aa4b59f..d39616ca 100644 --- a/tests/fmt.test.js +++ b/tests/fmt.test.js @@ -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 + }); }); diff --git a/tests/utils.test.js b/tests/utils.test.js index 92b12f7c..0b37e45a 100644 --- a/tests/utils.test.js +++ b/tests/utils.test.js @@ -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 - }); -});