diff --git a/src/cards/gist.js b/src/cards/gist.js index 3c3d059d07ae5..2deaf448dcce8 100644 --- a/src/cards/gist.js +++ b/src/cards/gist.js @@ -2,7 +2,6 @@ import { parseEmojis, - wrapTextMultiline, encodeHTML, measureText, flexLayout, @@ -11,7 +10,7 @@ import { } from "../common/utils.js"; import Card from "../common/Card.js"; import { getCardColors } from "../common/color.js"; -import { kFormatter } from "../common/fmt.js"; +import { kFormatter, wrapTextMultiline } from "../common/fmt.js"; import { icons } from "../common/icons.js"; /** Import language colors. diff --git a/src/cards/repo.js b/src/cards/repo.js index 6ebabeab07963..ccf42645e898c 100644 --- a/src/cards/repo.js +++ b/src/cards/repo.js @@ -2,7 +2,7 @@ import { Card } from "../common/Card.js"; import { getCardColors } from "../common/color.js"; -import { kFormatter } from "../common/fmt.js"; +import { kFormatter, wrapTextMultiline } from "../common/fmt.js"; import { I18n } from "../common/I18n.js"; import { icons } from "../common/icons.js"; import { @@ -10,7 +10,6 @@ import { flexLayout, measureText, parseEmojis, - wrapTextMultiline, iconWithLabel, createLanguageNode, clampValue, diff --git a/src/cards/stats.js b/src/cards/stats.js index 7737fe22b0afe..9e6725b0bc7cd 100644 --- a/src/cards/stats.js +++ b/src/cards/stats.js @@ -16,6 +16,36 @@ const RANK_CARD_DEFAULT_WIDTH = 450; const RANK_ONLY_CARD_MIN_WIDTH = 290; const RANK_ONLY_CARD_DEFAULT_WIDTH = 290; +/** + * Long locales that need more space for text. Keep sorted alphabetically. + * + * @type {(keyof typeof wakatimeCardLocales["wakatimecard.title"])[]} + */ +const LONG_LOCALES = [ + "az", + "bg", + "cs", + "de", + "es", + "fil", + "fr", + "id", + "ml", + "my", + "nl", + "pl", + "pt-br", + "pt-pt", + "ru", + "sr", + "sr-latn", + "sw", + "ta", + "uk-ua", + "uz", + "zh-tw", +]; + /** * Create a stats card text item. * @@ -374,30 +404,8 @@ const renderStatsCard = (stats, options = {}) => { id: "contribs", }; - const longLocales = [ - "az", - "bg", - "de", - "es", - "fil", - "fr", - "id", - "ml", - "my", - "nl", - "pl", - "pt-br", - "pt-pt", - "ru", - "sr", - "sr-latn", - "sw", - "ta", - "uk-ua", - "uz", - "zh-tw", - ]; - const isLongLocale = locale ? longLocales.includes(locale) : false; + // @ts-ignore + const isLongLocale = locale ? LONG_LOCALES.includes(locale) : false; // filter out hidden stats defined by user & create the text nodes const statItems = Object.keys(STATS) diff --git a/src/common/fmt.js b/src/common/fmt.js index 2d40378a88108..ca86f3cf59cae 100644 --- a/src/common/fmt.js +++ b/src/common/fmt.js @@ -1,3 +1,8 @@ +// @ts-check + +import wrap from "word-wrap"; +import { encodeHTML } from "./utils.js"; + /** * Retrieves num with suffix k(thousands) precise to given decimal places. * @@ -47,4 +52,39 @@ const formatBytes = (bytes) => { return `${(bytes / Math.pow(base, i)).toFixed(1)} ${sizes[i]}`; }; -export { kFormatter, formatBytes }; +/** + * Split text over multiple lines based on the card width. + * + * @param {string} text Text to split. + * @param {number} width Line width in number of characters. + * @param {number} maxLines Maximum number of lines. + * @returns {string[]} Array of lines. + */ +const wrapTextMultiline = (text, width = 59, maxLines = 3) => { + const fullWidthComma = ","; + const encoded = encodeHTML(text); + const isChinese = encoded.includes(fullWidthComma); + + let wrapped = []; + + if (isChinese) { + wrapped = encoded.split(fullWidthComma); // Chinese full punctuation + } else { + wrapped = wrap(encoded, { + width, + }).split("\n"); // Split wrapped lines to get an array of lines + } + + const lines = wrapped.map((line) => line.trim()).slice(0, maxLines); // Only consider maxLines lines + + // Add "..." to the last line if the text exceeds maxLines + if (wrapped.length > maxLines) { + lines[maxLines - 1] += "..."; + } + + // Remove empty lines if text fits in less than maxLines lines + const multiLineText = lines.filter(Boolean); + return multiLineText; +}; + +export { kFormatter, formatBytes, wrapTextMultiline }; diff --git a/src/common/index.js b/src/common/index.js index 93b50cc07f016..3a61fead40c02 100644 --- a/src/common/index.js +++ b/src/common/index.js @@ -15,7 +15,6 @@ export { clampValue, request, flexLayout, - wrapTextMultiline, logger, measureText, lowercaseTrim, diff --git a/src/common/utils.js b/src/common/utils.js index 2d8659981641f..6ce2741cce3b2 100644 --- a/src/common/utils.js +++ b/src/common/utils.js @@ -2,7 +2,6 @@ import axios from "axios"; import toEmoji from "emoji-name-map"; -import wrap from "word-wrap"; import { SECONDARY_ERROR_MESSAGES, TRY_AGAIN_LATER } from "./error.js"; import { getCardColors } from "./color.js"; @@ -234,41 +233,6 @@ const renderError = ({ `; }; -/** - * Split text over multiple lines based on the card width. - * - * @param {string} text Text to split. - * @param {number} width Line width in number of characters. - * @param {number} maxLines Maximum number of lines. - * @returns {string[]} Array of lines. - */ -const wrapTextMultiline = (text, width = 59, maxLines = 3) => { - const fullWidthComma = ","; - const encoded = encodeHTML(text); - const isChinese = encoded.includes(fullWidthComma); - - let wrapped = []; - - if (isChinese) { - wrapped = encoded.split(fullWidthComma); // Chinese full punctuation - } else { - wrapped = wrap(encoded, { - width, - }).split("\n"); // Split wrapped lines to get an array of lines - } - - const lines = wrapped.map((line) => line.trim()).slice(0, maxLines); // Only consider maxLines lines - - // Add "..." to the last line if the text exceeds maxLines - if (wrapped.length > maxLines) { - lines[maxLines - 1] += "..."; - } - - // Remove empty lines if text fits in less than maxLines lines - const multiLineText = lines.filter(Boolean); - return multiLineText; -}; - const noop = () => {}; // return console instance based on the environment const logger = @@ -388,7 +352,6 @@ export { clampValue, request, flexLayout, - wrapTextMultiline, logger, measureText, lowercaseTrim, diff --git a/src/fetchers/stats.js b/src/fetchers/stats.js index f22dfaf65f7c0..37ce591f51458 100644 --- a/src/fetchers/stats.js +++ b/src/fetchers/stats.js @@ -5,9 +5,10 @@ import * as dotenv from "dotenv"; import githubUsernameRegex from "github-username-regex"; import { calculateRank } from "../calculateRank.js"; import { retryer } from "../common/retryer.js"; -import { logger, request, wrapTextMultiline } from "../common/utils.js"; +import { logger, request } from "../common/utils.js"; import { excludeRepositories } from "../common/envs.js"; import { CustomError, MissingParamError } from "../common/error.js"; +import { wrapTextMultiline } from "../common/fmt.js"; dotenv.config(); diff --git a/src/fetchers/top-languages.js b/src/fetchers/top-languages.js index 9542678e581b0..9e711b0d1157a 100644 --- a/src/fetchers/top-languages.js +++ b/src/fetchers/top-languages.js @@ -1,9 +1,10 @@ // @ts-check import { retryer } from "../common/retryer.js"; -import { logger, request, wrapTextMultiline } from "../common/utils.js"; +import { logger, request } from "../common/utils.js"; import { excludeRepositories } from "../common/envs.js"; import { CustomError, MissingParamError } from "../common/error.js"; +import { wrapTextMultiline } from "../common/fmt.js"; /** * @typedef {import("axios").AxiosRequestHeaders} AxiosRequestHeaders Axios request headers. diff --git a/src/translations.js b/src/translations.js index f62294628bb77..a5d522cd53d39 100644 --- a/src/translations.js +++ b/src/translations.js @@ -48,7 +48,7 @@ const statCardLocales = ({ name, apostrophe }) => { "uk-ua": `Статистика GitHub користувача ${encodedName}`, id: `Statistik GitHub ${encodedName}`, ml: `${encodedName}'${apostrophe} ഗിറ്റ്ഹബ് സ്ഥിതിവിവരക്കണക്കുകൾ`, - my: `Statistik GitHub ${encodedName}`, + my: `${encodedName} ရဲ့ GitHub အခြေအနေများ`, ta: `${encodedName} கிட்ஹப் புள்ளிவிவரங்கள்`, sk: `GitHub štatistiky používateľa ${encodedName}`, tr: `${encodedName} Hesabının GitHub İstatistikleri`, @@ -96,7 +96,7 @@ const statCardLocales = ({ name, apostrophe }) => { "uk-ua": `Рейтинг GitHub користувача ${encodedName}`, id: `Statistik GitHub ${encodedName}`, ml: `${encodedName}'${apostrophe} ഗിറ്റ്ഹബ് സ്ഥിതിവിവരക്കണക്കുകൾ`, - my: `Statistik GitHub ${encodedName}`, + my: `${encodedName} ရဲ့ GitHub အဆင့်`, ta: `${encodedName} கிட்ஹப் தரவரிசை`, sk: `GitHub štatistiky používateľa ${encodedName}`, tr: `${encodedName} Hesabının GitHub Yıldızları`, @@ -144,7 +144,7 @@ const statCardLocales = ({ name, apostrophe }) => { "uk-ua": "Всього зірок", id: "Total Bintang", ml: "ആകെ നക്ഷത്രങ്ങൾ", - my: "Jumlah Bintang", + my: "စုစုပေါင်းကြယ်များ", ta: "சம்பாதித்த மொத்த நட்சத்திரங்கள்", sk: "Hviezdy", tr: "Toplam Yıldız", @@ -192,7 +192,7 @@ const statCardLocales = ({ name, apostrophe }) => { "uk-ua": "Всього комітів", id: "Total Komitmen", ml: "ആകെ കമ്മിറ്റുകൾ", - my: "Jumlah Komitmen", + my: "စုစုပေါင်း Commit များ", ta: `மொத்த கமிட்கள்`, sk: "Všetky commity", tr: "Toplam Commit", @@ -240,7 +240,7 @@ const statCardLocales = ({ name, apostrophe }) => { "uk-ua": "Всього запитів на злиття", id: "Total Permintaan Tarik", ml: "ആകെ പുൾ അഭ്യർത്ഥനകൾ", - my: "Jumlah PR", + my: "စုစုပေါင်း PR များ", ta: `மொத்த இழுக்கும் கோரிக்கைகள்`, sk: "Všetky PR", tr: "Toplam PR", @@ -288,7 +288,7 @@ const statCardLocales = ({ name, apostrophe }) => { "uk-ua": "Всього питань", id: "Total Masalah Dilaporkan", ml: "ആകെ പ്രശ്നങ്ങൾ", - my: "Jumlah Isu Dilaporkan", + my: "စုစုပေါင်းပြဿနာများ", ta: `மொத்த சிக்கல்கள்`, sk: "Všetky problémy", tr: "Toplam Hata", @@ -336,7 +336,7 @@ const statCardLocales = ({ name, apostrophe }) => { "uk-ua": "Зроблено внесок (за минулий рік)", id: "Berkontribusi ke (tahun lalu)", ml: "(കഴിഞ്ഞ വർഷത്തെ)ആകെ സംഭാവനകൾ ", - my: "Menyumbang kepada (tahun lepas)", + my: "အကူအညီပေးခဲ့သည် (ပြီးခဲ့သည့်နှစ်)", ta: "(கடந்த ஆண்டு) பங்களித்தது", sk: "Účasti (minulý rok)", tr: "Katkı Verildi (geçen yıl)", @@ -384,7 +384,7 @@ const statCardLocales = ({ name, apostrophe }) => { "uk-ua": "Всього запитів перевірено", id: "Total PR yang Direview", ml: "ആകെ പുൾ അവലോകനങ്ങൾ", - my: "Jumlah PR Dikaji Semula", + my: "စုစုပေါင်း PR များကို ပြန်လည်သုံးသပ်ခဲ့မှု", ta: "மதிப்பாய்வு செய்யப்பட்ட மொத்த இழுத்தல் கோரிக்கைகள்", sk: "Celkový počet PR", tr: "İncelenen toplam PR", @@ -432,7 +432,7 @@ const statCardLocales = ({ name, apostrophe }) => { "uk-ua": "Всього розпочатих дискусій", id: "Total Diskusi Dimulai", ml: "ആരംഭിച്ച ആലോചനകൾ", - my: "Jumlah Perbincangan Bermula", + my: "စုစုပေါင်း စတင်ခဲ့သော ဆွေးနွေးမှုများ", ta: "மொத்த விவாதங்கள் தொடங்கின", sk: "Celkový počet začatých diskusií", tr: "Başlatılan Toplam Tartışma", @@ -480,7 +480,7 @@ const statCardLocales = ({ name, apostrophe }) => { "uk-ua": "Всього відповідей на дискусії", id: "Total Diskusi Dibalas", ml: "ഉത്തരം നൽകിയ ആലോചനകൾ", - my: "Jumlah Perbincangan Dijawab", + my: "စုစုပေါင်း ပြန်လည်ဖြေကြားခဲ့သော ဆွေးနွေးမှုများ", ta: "பதிலளிக்கப்பட்ட மொத்த விவாதங்கள்", sk: "Celkový počet zodpovedaných diskusií", tr: "Toplam Cevaplanan Tartışma", @@ -527,7 +527,7 @@ const statCardLocales = ({ name, apostrophe }) => { ru: "Всего объединённых запросов", "uk-ua": "Всього об'єднаних запитів", id: "Total PR Digabungkan", - my: "Jumlah PR Digabungkan", + my: "စုစုပေါင်း ပေါင်းစည်းခဲ့သော PR များ", ta: "இணைக்கப்பட்ட மொத்த PRகள்", sk: "Celkový počet zlúčených PR", tr: "Toplam Birleştirilmiş PR", @@ -574,7 +574,7 @@ const statCardLocales = ({ name, apostrophe }) => { ru: "Процент объединённых запросов", "uk-ua": "Відсоток об'єднаних запитів", id: "Persentase PR Digabungkan", - my: "Peratus PR Digabungkan", + my: "PR များကို ပေါင်းစည်းခဲ့သော ရာခိုင်နှုန်း", ta: "இணைக்கப்பட்ட PRகள் சதவீதம்", sk: "Percento zlúčených PR", tr: "Birleştirilmiş PR Yüzdesi", @@ -626,7 +626,7 @@ const repoCardLocales = { "uk-ua": "Шаблон", id: "Pola", ml: "ടെംപ്ലേറ്റ്", - my: "Templat", + my: "ပုံစံ", ta: `டெம்ப்ளேட்`, sk: "Šablóna", tr: "Şablon", @@ -674,7 +674,7 @@ const repoCardLocales = { "uk-ua": "Архивований", id: "Arsip", ml: "ശേഖരിച്ചത്", - my: "Arkib", + my: "သိုလှောင်ပြီး", ta: `காப்பகப்படுத்தப்பட்டது`, sk: "Archivované", tr: "Arşiv", @@ -725,7 +725,7 @@ const langCardLocales = { "uk-ua": "Найбільш використовувані мови", id: "Bahasa Yang Paling Banyak Digunakan", ml: "കൂടുതൽ ഉപയോഗിച്ച ഭാഷകൾ", - my: "Bahasa Paling Digunakan", + my: "အများဆုံးအသုံးပြုသောဘာသာစကားများ", ta: `அதிகம் பயன்படுத்தப்படும் மொழிகள்`, sk: "Najviac používané jazyky", tr: "En Çok Kullanılan Diller", @@ -773,7 +773,7 @@ const langCardLocales = { "uk-ua": "Немає даних про мови.", id: "Tidak ada data bahasa.", ml: "ഭാഷാ ഡാറ്റയില്ല.", - my: "Tiada data bahasa.", + my: "ဒေတာ မရှိပါ။", ta: `மொழி தரவு இல்லை.`, sk: "Žiadne údaje o jazykoch.", tr: "Dil verisi yok.", @@ -824,7 +824,7 @@ const wakatimeCardLocales = { "uk-ua": "Статистика WakaTime", id: "Status WakaTime", ml: "വാകടൈം സ്ഥിതിവിവരക്കണക്കുകൾ", - my: "Statistik WakaTime", + my: "WakaTime အချက်အလက်များ", ta: `WakaTime புள்ளிவிவரங்கள்`, sk: "WakaTime štatistika", tr: "WakaTime İstatistikler", @@ -872,7 +872,7 @@ const wakatimeCardLocales = { "uk-ua": "За минулий рік", id: "Tahun lalu", ml: "കഴിഞ്ഞ വർഷം", - my: "Tahun lepas", + my: "မနှစ်က", ta: `கடந்த ஆண்டு`, sk: "Minulý rok", tr: "Geçen yıl", @@ -920,7 +920,7 @@ const wakatimeCardLocales = { "uk-ua": "Останні 7 днів", id: "7 hari terakhir", ml: "കഴിഞ്ഞ 7 ദിവസം", - my: "7 hari lepas", + my: "7 ရက်အတွင်း", ta: `கடந்த 7 நாட்கள்`, sk: "Posledných 7 dní", tr: "Son 7 gün", @@ -968,7 +968,7 @@ const wakatimeCardLocales = { "uk-ua": "Профіль користувача WakaTime не публічний", id: "Profil pengguna WakaTime tidak publik", ml: "WakaTime ഉപയോക്തൃ പ്രൊഫൈൽ പൊതുവായി പ്രസിദ്ധീകരിക്കപ്പെടാത്തതാണ്", - my: "Profil pengguna WakaTime tidak awam", + my: "Public Profile မဟုတ်ပါ။", ta: `WakaTime பயனர் சுயவிவரம் பொதுவில் இல்லை.`, sk: "Profil používateľa WakaTime nie je verejný", tr: "WakaTime kullanıcı profili herkese açık değil", @@ -1018,7 +1018,7 @@ const wakatimeCardLocales = { "uk-ua": "Користувач не публікує детальну статистику коду", id: "Pengguna tidak membagikan statistik kode terperinci secara publik", ml: "ഉപയോക്താവ് പൊതുവായി വിശദീകരിച്ച കോഡ് സ്റ്റാറ്റിസ്റ്റിക്സ് പങ്കിടുന്നില്ല", - my: "Pengguna tidak berkongsi statistik kod terperinci secara awam", + my: "အသုံးပြုသူသည် အသေးစိတ် ကုဒ် စာရင်းအင်းများကို အများသို့ မမျှဝေပါ။", ta: `பயனர் விரிவான குறியீட்டு புள்ளிவிவரங்களைப் பொதுவில் பகிர்வதில்லை.`, sk: "Používateľ neposkytuje verejne podrobné štatistiky kódu", tr: "Kullanıcı ayrıntılı kod istatistiklerini herkese açık olarak paylaşmıyor", @@ -1066,7 +1066,7 @@ const wakatimeCardLocales = { "uk-ua": "Цього тижня не було активності", id: "Tidak ada aktivitas perkodingan minggu ini", ml: "ഈ ആഴ്ച കോഡിംഗ് പ്രവർത്തനങ്ങളൊന്നുമില്ല", - my: "Tiada aktiviti pengekodan minggu ini", + my: "ဒီအပတ်မှာ ကုဒ်ရေးခြင်း မရှိပါ။", ta: `இந்த வாரம் குறியீட்டு செயல்பாடு இல்லை.`, sk: "Žiadna kódovacia aktivita tento týždeň", tr: "Bu hafta herhangi bir kod yazma aktivitesi olmadı", diff --git a/tests/fmt.test.js b/tests/fmt.test.js index 9aa4b59f1e637..857221f25073b 100644 --- a/tests/fmt.test.js +++ b/tests/fmt.test.js @@ -1,8 +1,12 @@ 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", () => { + it("kFormatter: should format numbers correctly by default", () => { expect(kFormatter(1)).toBe(1); expect(kFormatter(-1)).toBe(-1); expect(kFormatter(500)).toBe(500); @@ -14,7 +18,7 @@ describe("Test fmt.js", () => { expect(kFormatter(9900000)).toBe("9900k"); }); - it("should test kFormatter with 0 decimal precision", () => { + it("kFormatter: should format numbers correctly with 0 decimal precision", () => { expect(kFormatter(1, 0)).toBe("0k"); expect(kFormatter(-1, 0)).toBe("-0k"); expect(kFormatter(500, 0)).toBe("1k"); @@ -27,7 +31,7 @@ describe("Test fmt.js", () => { expect(kFormatter(9900000, 0)).toBe("9900k"); }); - it("should test kFormatter with 1 decimal precision", () => { + it("kFormatter: should format numbers correctly with 1 decimal precision", () => { expect(kFormatter(1, 1)).toBe("0.0k"); expect(kFormatter(-1, 1)).toBe("-0.0k"); expect(kFormatter(500, 1)).toBe("0.5k"); @@ -39,7 +43,7 @@ describe("Test fmt.js", () => { expect(kFormatter(9900000, 1)).toBe("9900.0k"); }); - it("should test kFormatter with 2 decimal precision", () => { + it("kFormatter: should format numbers correctly with 2 decimal precision", () => { expect(kFormatter(1, 2)).toBe("0.00k"); expect(kFormatter(-1, 2)).toBe("-0.00k"); expect(kFormatter(500, 2)).toBe("0.50k"); @@ -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 9be0ae2f1f568..0b37e45acbd07 100644 --- a/tests/utils.test.js +++ b/tests/utils.test.js @@ -3,12 +3,7 @@ import { describe, expect, it } from "@jest/globals"; import { queryByTestId } from "@testing-library/dom"; import "@testing-library/jest-dom"; -import { - encodeHTML, - parseBoolean, - renderError, - wrapTextMultiline, -} from "../src/common/utils.js"; +import { encodeHTML, parseBoolean, renderError } from "../src/common/utils.js"; describe("Test utils.js", () => { it("should test parseBoolean", () => { @@ -25,6 +20,7 @@ describe("Test utils.js", () => { expect(parseBoolean("1")).toBe(undefined); expect(parseBoolean("0")).toBe(undefined); expect(parseBoolean("")).toBe(undefined); + // @ts-ignore expect(parseBoolean(undefined)).toBe(undefined); }); @@ -53,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 - }); -});