Open History to see the last commit
1import { describe, expect, it } from "vite-plus/test";
2
3import { truncateProjectName } from "./DraftProjectName.logic";
4
5const measure = (text: string) => Array.from(text).length;
6
7describe("truncateProjectName", () => {
8 it("keeps distinguishing suffixes in one string without adding whitespace", () => {
9 expect(truncateProjectName("ExampleCompany-CustomerPortal-App", 19, measure)).toBe(
10 "ExampleCo…ortal-App",
11 );
12 expect(truncateProjectName("ExampleCompany-CustomerPortal-Env", 19, measure)).toBe(
13 "ExampleCo…ortal-Env",
14 );
15 });
16
17 it("leaves names that fit unchanged", () => {
18 expect(truncateProjectName("ShortRepo", 9, measure)).toBe("ShortRepo");
19 });
20
21 it("fits proportional character widths", () => {
22 const proportional = (text: string) =>
23 Array.from(text).reduce((width, character) => width + (character === "W" ? 3 : 1), 0);
24 expect(truncateProjectName("WWWW-project-App", 12, proportional)).toBe("WW…App");
25 });
26
27 it("keeps combining marks and emoji sequences intact", () => {
28 const value = "e\u0301👩💻-customer-portal-App";
29 const result = truncateProjectName(value, 18, measure);
30 expect(result.startsWith("e\u0301👩💻")).toBe(true);
31 expect(result.endsWith("App")).toBe(true);
32 expect(measure(result)).toBeLessThanOrEqual(18);
33 });
34
35 it("handles space for only the ellipsis or no text", () => {
36 expect(truncateProjectName("ExampleCompany", 1, measure)).toBe("…");
37 expect(truncateProjectName("ExampleCompany", 0, measure)).toBe("");
38 });
39});