|
1 | 1 | import { describe, expect, it } from "vitest"; |
2 | 2 | import { readFileSync, existsSync } from "node:fs"; |
3 | 3 | import { resolve } from "node:path"; |
| 4 | +import { stripTitleFromPreview } from "../../apps/desktop/src/features/dashboard/lib/strip-title-from-preview"; |
4 | 5 |
|
5 | 6 | const utilPath = resolve( |
6 | 7 | __dirname, |
@@ -51,6 +52,54 @@ describe("strip-title-from-preview utility", () => { |
51 | 52 | }); |
52 | 53 | }); |
53 | 54 |
|
| 55 | +describe("stripTitleFromPreview — behavioral", () => { |
| 56 | + it("returns empty string for empty summary", () => { |
| 57 | + expect(stripTitleFromPreview("Some title", "")).toBe(""); |
| 58 | + }); |
| 59 | + |
| 60 | + it("strips title prefix from summary", () => { |
| 61 | + expect( |
| 62 | + stripTitleFromPreview( |
| 63 | + "Feature matrix", |
| 64 | + "Feature matrix with grouped rows by use case", |
| 65 | + ), |
| 66 | + ).toBe("with grouped rows by use case"); |
| 67 | + }); |
| 68 | + |
| 69 | + it("returns full summary when title is not a prefix", () => { |
| 70 | + expect( |
| 71 | + stripTitleFromPreview("Unrelated title", "Some preview text here"), |
| 72 | + ).toBe("Some preview text here"); |
| 73 | + }); |
| 74 | + |
| 75 | + it("strips leading numbering from preview before title comparison", () => { |
| 76 | + expect( |
| 77 | + stripTitleFromPreview( |
| 78 | + "Rewritten Free vs Pro feature matrix with grouped rows by", |
| 79 | + "1) Rewritten Free vs Pro feature matrix with grouped rows by use case > Important framing", |
| 80 | + ), |
| 81 | + ).toBe("use case > Important framing"); |
| 82 | + }); |
| 83 | + |
| 84 | + it("strips '2. ' numbering prefix from preview before title comparison", () => { |
| 85 | + expect( |
| 86 | + stripTitleFromPreview( |
| 87 | + "Updated homepage hero copy", |
| 88 | + "2. Updated homepage hero copy: new version with better CTA", |
| 89 | + ), |
| 90 | + ).toBe("new version with better CTA"); |
| 91 | + }); |
| 92 | + |
| 93 | + it("handles preview without numbering as before", () => { |
| 94 | + expect( |
| 95 | + stripTitleFromPreview( |
| 96 | + "SEO Audit Key Findings", |
| 97 | + "SEO Audit Key Findings — detailed breakdown follows", |
| 98 | + ), |
| 99 | + ).toBe("detailed breakdown follows"); |
| 100 | + }); |
| 101 | +}); |
| 102 | + |
54 | 103 | describe("ArtifactCard title-echo removal", () => { |
55 | 104 | it("ArtifactCard imports stripTitleFromPreview", () => { |
56 | 105 | const src = readFileSync(artifactCardPath, "utf-8"); |
|
0 commit comments