feat: add bytes stats format option for top-languages card (#3708)

* feat: add `display_bytes` option to top-languages.

* docs: add description about display bytes in top-languages

* feat: add `stats_format` option instead of `display_bytes`

* docs: add description about stats format in top-languages

* refactor: rewrite with function to determine display value

* docs: add `stats_format`to table of parameter

* fix: remove unnecessary decimal part from format of bytes

* tests: add tests of stats_format in top-langs card

* Update tests/renderTopLanguagesCard.test.js

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update readme.md

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* prettier

* jsdoc

---------

Co-authored-by: Alexandr <qwerty541zxc@gmail.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
abap34
2025-09-16 21:41:46 +03:00
committed by GitHub
co-authored by Copilot Alexandr
parent 485c2247f8
commit 078040d26e
7 changed files with 203 additions and 21 deletions
+36
View File
@@ -849,4 +849,40 @@ describe("Test renderTopLanguages", () => {
"No languages data.",
);
});
it("should show proper stats format", () => {
document.body.innerHTML = renderTopLanguages(langs, {
layout: "compact",
stats_format: "percentages",
});
expect(queryAllByTestId(document.body, "lang-name")[0]).toHaveTextContent(
"HTML 40.00%",
);
expect(queryAllByTestId(document.body, "lang-name")[1]).toHaveTextContent(
"javascript 40.00%",
);
expect(queryAllByTestId(document.body, "lang-name")[2]).toHaveTextContent(
"css 20.00%",
);
document.body.innerHTML = renderTopLanguages(langs, {
layout: "compact",
stats_format: "bytes",
});
expect(queryAllByTestId(document.body, "lang-name")[0]).toHaveTextContent(
"HTML 200.0 B",
);
expect(queryAllByTestId(document.body, "lang-name")[1]).toHaveTextContent(
"javascript 200.0 B",
);
expect(queryAllByTestId(document.body, "lang-name")[2]).toHaveTextContent(
"css 100.0 B",
);
});
});