Open History to see the last commit
1import { describe, expect, it } from "vite-plus/test";
2
3import { splitForMiddleTruncate } from "./middle-truncate";
4
5describe("splitForMiddleTruncate", () => {
6 it("keeps a short last path segment whole", () => {
7 expect(splitForMiddleTruncate("feature/ui-polish")).toEqual({
8 head: "feature/",
9 tail: "ui-polish",
10 });
11 });
12
13 it("starts a long segment's tail on a word, not mid-word", () => {
14 expect(splitForMiddleTruncate("t3/clone-repo-to-other-machine")?.tail).toBe("machine");
15 expect(splitForMiddleTruncate("t3/investigate-release-build-times")?.tail).toBe("times");
16 });
17
18 it("falls back to an earlier word when the last one is too short", () => {
19 expect(splitForMiddleTruncate("t3/compare-long-featurenames-ab")?.tail).toBe("featurenames-ab");
20 });
21
22 it("keeps the fixed tail when no word break is near", () => {
23 expect(splitForMiddleTruncate("t3/abcdefghijklmnopqrstuvwxyz")?.tail).toBe("qrstuvwxyz");
24 });
25
26 it("respects an explicit tail length", () => {
27 expect(splitForMiddleTruncate("t3/clone-repo-to-other-machine", 6)?.tail).toBe("achine");
28 });
29
30 it("keeps combining marks with their base letter", () => {
31 expect(splitForMiddleTruncate("t3/abcdefghijklmnopqrstuvwxye\u0301abcdefghi")?.tail).toBe(
32 "e\u0301abcdefghi",
33 );
34 expect(splitForMiddleTruncate("t3/परीक्षणशाखानयापेजबदलावक")?.tail).toBe("यापेजबदलावक");
35 });
36
37 it("keeps a flag together when the cut falls between its indicators", () => {
38 const flag = "\uD83C\uDDEF\uD83C\uDDF5";
39 const value = `${"a".repeat(11)}${flag}${"b".repeat(9)}`;
40 const whole = {
41 head: "a".repeat(11),
42 tail: `${flag}${"b".repeat(9)}`,
43 };
44 // Default tail: branch labels and the project breadcrumb pass no tail length.
45 expect(splitForMiddleTruncate(value)).toEqual(whole);
46 expect(splitForMiddleTruncate(value, 10)).toEqual(whole);
47 });
48
49 it("keeps a flag that already sits wholly in the head", () => {
50 const flag = "\uD83C\uDDEF\uD83C\uDDF5";
51 const split = splitForMiddleTruncate(`${"a".repeat(10)}${flag}${"b".repeat(10)}`, 10);
52 expect(split).toEqual({
53 head: `${"a".repeat(10)}${flag}`,
54 tail: "b".repeat(10),
55 });
56 });
57});