diff --git a/src/shared/truncate-description.test.ts b/src/shared/truncate-description.test.ts index f6e6039c..7645de1c 100644 --- a/src/shared/truncate-description.test.ts +++ b/src/shared/truncate-description.test.ts @@ -21,9 +21,9 @@ describe("truncateDescription", () => { const result = truncateDescription(description) // then - expect(result.length).toBe(123) // 120 + "..." + expect(result.length).toBe(120) // 117 chars + "..." expect(result).toEndWith("...") - expect(result).toBe(description.slice(0, 120) + "...") + expect(result).toBe(description.slice(0, 117) + "...") }) it("respects custom max length parameter", () => { @@ -35,9 +35,9 @@ describe("truncateDescription", () => { const result = truncateDescription(description, maxLength) // then - expect(result.length).toBe(53) // 50 + "..." + expect(result.length).toBe(50) // 47 chars + "..." expect(result).toEndWith("...") - expect(result).toBe(description.slice(0, 50) + "...") + expect(result).toBe(description.slice(0, 47) + "...") }) it("handles empty string", () => { @@ -71,7 +71,7 @@ describe("truncateDescription", () => { const result = truncateDescription(description) // then - expect(result.length).toBe(123) // 120 + "..." + expect(result.length).toBe(120) expect(result).toContain("First sentence. Second sentence.") expect(result).toEndWith("...") }) @@ -84,7 +84,7 @@ describe("truncateDescription", () => { const result = truncateDescription(description) // then - expect(result.length).toBe(123) // 120 + "..." + expect(result.length).toBe(120) expect(result).toStartWith("Check out https://example.com") expect(result).toEndWith("...") }) @@ -97,7 +97,7 @@ describe("truncateDescription", () => { const result = truncateDescription(description) // then - expect(result.length).toBe(123) // 120 + "..." + expect(result.length).toBe(120) expect(result).toStartWith("Version 1.2.3") expect(result).toEndWith("...") }) diff --git a/src/shared/truncate-description.ts b/src/shared/truncate-description.ts index 6fe3c453..72fa3d08 100644 --- a/src/shared/truncate-description.ts +++ b/src/shared/truncate-description.ts @@ -1,11 +1,3 @@ -/** - * Truncates a description string to a maximum character length. - * If truncated, appends "..." to indicate continuation. - * - * @param description - The description string to truncate - * @param maxLength - Maximum character length (default: 120) - * @returns Truncated description with "..." appended if it was truncated - */ export function truncateDescription(description: string, maxLength: number = 120): string { if (!description) { return description @@ -15,5 +7,5 @@ export function truncateDescription(description: string, maxLength: number = 120 return description } - return description.slice(0, maxLength) + "..." + return description.slice(0, maxLength - 3) + "..." }