it("returns description unchanged when under max length",()=>{
// given
constdescription="This is a short description"
// when
constresult=truncateDescription(description)
// then
expect(result).toBe(description)
})
it("truncates to 120 characters by default and appends ellipsis",()=>{
// given
constdescription="This is a very long description that exceeds the default maximum length of 120 characters and should be truncated with an ellipsis at the end"
it("handles exactly max length without truncation",()=>{
// given
constdescription="a".repeat(120)
// when
constresult=truncateDescription(description)
// then
expect(result).toBe(description)
expect(result).not.toEndWith("...")
})
it("handles description with periods correctly",()=>{
// given
constdescription="First sentence. Second sentence. Third sentence that is very long and continues beyond the normal truncation point with even more text to ensure it exceeds 120 characters."
expect(result).toContain("First sentence. Second sentence.")
expect(result).toEndWith("...")
})
it("handles description with URLs correctly",()=>{
// given
constdescription="Check out https://example.com/very/long/path/that/contains/many/segments for more information about this feature and its capabilities"
expect(result).toStartWith("Check out https://example.com")
expect(result).toEndWith("...")
})
it("handles description with version numbers correctly",()=>{
// given
constdescription="Version 1.2.3 of the library includes many improvements and bug fixes that make it more stable and performant with additional enhancements"