1import { describe, expect, it } from "vitest";
2import { blockText, stripHtml } from "../version-text";
3
4describe("version-text (T-150/T-151 preview extraction)", () => {
5 it("extracts the API canonical { text } shape", () => {
6 expect(blockText({ text: "Standup notes" })).toBe("Standup notes");
7 });
8
9 it("extracts the legacy { title } shape", () => {
10 expect(blockText({ title: "Legacy title" })).toBe("Legacy title");
11 });
12
13 it("strips tags from a raw HTML string payload (untrusted — never rendered)", () => {
14 expect(blockText("<p>Objectives</p>")).toBe("Objectives");
15
16 expect(blockText('<p><img src=x onerror="alert(1)">x</p>')).not.toContain("onerror=alert");
17 });
18
19 it("walks a serialized Tiptap doc object", () => {
20 expect(
21 blockText({
22 type: "doc",
23 content: [
24 { type: "paragraph", content: [{ type: "text", text: "hello " }] },
25 { type: "paragraph", content: [{ type: "text", text: "world" }] }
26 ]
27 })
28 ).toBe("hello world");
29 });
30
31 it("returns '' for empty / unknown content", () => {
32 expect(blockText(null)).toBe("");
33 expect(blockText(undefined)).toBe("");
34 expect(blockText({ databaseId: "db_123" })).toBe("");
35 expect(blockText(42)).toBe("");
36 });
37
38 it("stripHtml removes tags (regex fallback, jsdom-free)", () => {
39 expect(stripHtml("<b>bold</b> and <i>italic</i>")).toBe("bold and italic");
40 });
41});
42