import { describe, expect, it } from "vitest"; import { generateExcerpt } from "@/lib/excerpt"; describe("generateExcerpt (HTML bodies)", () => { it("strips tags but keeps the visible text", () => { const html = "

Heading

Some bold text with a link. And more.

"; expect(generateExcerpt(html, 100)).toBe("Heading Some bold text with a link. And more."); }); it("caps the excerpt at the word limit and appends an ellipsis", () => { expect(generateExcerpt("

one two three four five six

", 3)).toBe("one two three…"); }); it("adds no ellipsis when the text fits exactly", () => { expect(generateExcerpt("

one two three

", 3)).toBe("one two three"); }); it("skips code blocks entirely", () => { const html = "
const hidden = true;

After the code.

"; expect(generateExcerpt(html, 50)).toBe("After the code."); }); it("contributes nothing from images (alt text is not visible text)", () => { const html = '

decorative alt

Caption text.

'; expect(generateExcerpt(html, 50)).toBe("Caption text."); }); it("keeps inline code as text", () => { expect(generateExcerpt("

Run npm test daily.

", 50)).toBe( "Run npm test daily.", ); }); it("separates list items and table cells with whitespace", () => { expect(generateExcerpt("", 50)).toBe( "first item second item", ); expect( generateExcerpt("
cell onecell two
", 50), ).toBe("cell one cell two"); }); it("returns an empty string for empty or non-textual bodies", () => { expect(generateExcerpt("", 40)).toBe(""); expect(generateExcerpt('

x

', 40)).toBe(""); }); it("tolerates a nonsensical word limit", () => { expect(generateExcerpt("

alpha beta

", 0)).toBe("alpha…"); }); });