Andrey Epifancev 2cb454af8b refactor(web): модуль jira и оболочка из списка модулей (#87)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-23 23:05:02 +04:00

48 lines
2.0 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { describe, expect, it } from "vitest";
import { JIRA_URL } from "../../board/constants.ts";
import { fileKind, fmtSize, isTooBig, jiraAttachmentUrl } from "./format.ts";
describe("fmtSize", () => {
it("как в хабе: Б, КБ, МБ с запятой", () => {
expect(fmtSize(500)).toBe("500 Б");
expect(fmtSize(1023)).toBe("1023 Б");
expect(fmtSize(1024)).toBe("1,0 КБ");
expect(fmtSize(240000)).toBe("234,4 КБ");
expect(fmtSize(1024 ** 2)).toBe("1,0 МБ");
expect(fmtSize(25 * 1024 ** 2)).toBe("25,0 МБ");
expect(fmtSize(1280)).toBe("1,3 КБ");
expect(fmtSize(1048575)).toBe("1,0 МБ");
expect(fmtSize(1310720)).toBe("1,3 МБ");
expect(fmtSize(25_000_000)).toBe("23,8 МБ");
expect(fmtSize(null)).toBe("размер неизвестен");
});
});
describe("jiraAttachmentUrl", () => {
it("имя в URL-кодировке", () => {
expect(jiraAttachmentUrl("31337", "скрин 1.png")).toBe(`${JIRA_URL}/secure/attachment/31337/%D1%81%D0%BA%D1%80%D0%B8%D0%BD%201.png`);
});
});
describe("isTooBig", () => {
it("больше 10 МБ — только в Jira; ровно 10 МБ и неизвестный размер — нет", () => {
expect(isTooBig(10 * 1024 * 1024)).toBe(false);
expect(isTooBig(10 * 1024 * 1024 + 1)).toBe(true);
expect(isTooBig(null)).toBe(false);
});
});
describe("fileKind", () => {
it("тип по mime, иначе по расширению", () => {
expect(fileKind("image/png", "a.bin")).toBe("image");
expect(fileKind(null, "Скрин.PNG")).toBe("image");
expect(fileKind("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "x")).toBe("sheet");
expect(fileKind(null, "ОСВ 60.xlsx")).toBe("sheet");
expect(fileKind("text/csv", "d.txt")).toBe("sheet");
expect(fileKind("application/pdf", "x")).toBe("pdf");
expect(fileKind(null, "отчёт.pdf")).toBe("pdf");
expect(fileKind("video/mp4", "запись.mp4")).toBe("other");
expect(fileKind(null, "без расширения")).toBe("other");
});
});