/ opencodehub / tests / unit / suggested-changes.test.ts
Swadhin Biswas test(qa): add e2e, integration, unit, and load coverage · 3/6/2026
1c29e63
69 lines · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import { parseSuggestionFromComment } from "@/lib/suggested-changes";
import { describe, expect, it } from "vitest";

describe("parseSuggestionFromComment", () => {
  it("extracts suggestion from a comment body", () => {
    const body = `
Some text before.

\`\`\`suggestion
const x = 42;
\`\`\`

Some text after.
    `.trim();

    const result = parseSuggestionFromComment(body);
    expect(result).toBeDefined();
    expect(result).toContain("const x = 42;");
  });

  it("returns null for comment without suggestion", () => {
    const body = "This is a regular comment without any suggestion block.";
    const result = parseSuggestionFromComment(body);
    expect(result).toBeNull();
  });

  it("returns null for empty string", () => {
    expect(parseSuggestionFromComment("")).toBeNull();
  });

  it("extracts multi-line suggestion", () => {
    const body = `
Review comment.

\`\`\`suggestion
function hello() {
  return "world";
}
\`\`\`
    `.trim();

    const result = parseSuggestionFromComment(body);
    expect(result).toBeDefined();
    expect(result).toContain("function hello()");
    expect(result).toContain('return "world"');
  });

  it("handles suggestion at start of body", () => {
    const body = `\`\`\`suggestion
fix this
\`\`\``;

    const result = parseSuggestionFromComment(body);
    expect(result).toBeDefined();
    expect(result).toContain("fix this");
  });

  it("does not confuse regular code blocks", () => {
    const body = `
\`\`\`javascript
const x = 1;
\`\`\`
    `.trim();

    const result = parseSuggestionFromComment(body);
    expect(result).toBeNull();
  });
});