| 1 | import { describe, expect, it } from "vite-plus/test"; |
| 2 | |
| 3 | import { middleTruncateAttachmentName } from "./composerInlineChip"; |
| 4 | |
| 5 | describe("middleTruncateAttachmentName", () => { |
| 6 | it("leaves short names unchanged", () => { |
| 7 | expect(middleTruncateAttachmentName("notes.txt")).toBe("notes.txt"); |
| 8 | }); |
| 9 | |
| 10 | it("keeps the start and filename extension", () => { |
| 11 | const result = middleTruncateAttachmentName( |
| 12 | "a-very-long-customer-reproduction-screenshot.final.png", |
| 13 | ); |
| 14 | expect(result).toHaveLength(36); |
| 15 | expect(result).toMatch(/^a-very-long-customer/); |
| 16 | expect(result).toMatch(/final\.png$/); |
| 17 | expect(result).toContain("…"); |
| 18 | }); |
| 19 | |
| 20 | it("truncates Unicode names without splitting a character", () => { |
| 21 | expect(middleTruncateAttachmentName("😀😀😀😀😀😀.png", 8)).toBe("😀😀😀….png"); |
| 22 | }); |
| 23 | |
| 24 | it("honours very small limits", () => { |
| 25 | expect(middleTruncateAttachmentName("notes.txt", 0)).toBe(""); |
| 26 | expect(middleTruncateAttachmentName("notes.txt", 1)).toBe("…"); |
| 27 | expect(middleTruncateAttachmentName("notes.txt", 2)).toBe("n…"); |
| 28 | }); |
| 29 | |
| 30 | it("keeps useful ends for multi-dot names and names without extensions", () => { |
| 31 | expect(middleTruncateAttachmentName("customer.export.final.very-long-name.json", 24)).toMatch( |
| 32 | /long-name\.json$/, |
| 33 | ); |
| 34 | expect(middleTruncateAttachmentName("a-very-long-filename-without-an-extension", 20)).toMatch( |
| 35 | /^a-ver.*extension$/, |
| 36 | ); |
| 37 | }); |
| 38 | }); |