File size: 2,741 Bytes
3f76ff4
 
 
 
837e3ac
 
3f76ff4
837e3ac
 
 
3f76ff4
 
 
837e3ac
3f76ff4
 
 
 
837e3ac
 
 
3f76ff4
 
 
 
 
 
 
 
 
837e3ac
 
3f76ff4
 
 
 
 
 
 
 
 
837e3ac
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3f76ff4
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import { renderToStaticMarkup } from "react-dom/server";
import { describe, expect, it, vi } from "vitest";
import { DEFAULT_LLM_BASE_URL, DEFAULT_LLM_MODEL } from "@/lib/llm-config";
import { ChatPanel } from "./ChatPanel";
import seedWorkPackages from "../agentic_pm_demo_codex_plans/data/work-packages.seed.json";
import type { WorkPackage } from "@/lib/work-package-types";

const workPackages = seedWorkPackages as WorkPackage[];

function renderChatPanel(draft = "") {
  return renderToStaticMarkup(
    <ChatPanel
      messages={[]}
      draft={draft}
      setDraft={vi.fn()}
      busy={false}
      productTitle="Agentic PM Demo"
      currentActivity="Ready"
      workPackages={workPackages}
      selectedWorkPackageId="wp-srs"
      onSelectWorkPackage={vi.fn()}
      llmConfig={{
        apiKey: "",
        baseUrl: DEFAULT_LLM_BASE_URL,
        model: DEFAULT_LLM_MODEL,
      }}
      setLlmConfig={vi.fn()}
      isMockMode={true}
      connectionStatus="idle"
      connectionMessage="Add API key, base URL, and model to enable live automation."
      canTestConnection={true}
      onTestConnection={vi.fn()}
      onSend={vi.fn()}
    />,
  );
}

describe("ChatPanel", () => {
  it("keeps model settings folded by default in mock mode", () => {
    expect(renderChatPanel()).not.toContain("Paste your API key");
  });

  it("renders package suggestions when the draft ends with @ mention text", () => {
    const html = renderChatPanel("@sr");

    expect(html).toContain("@SRS");
    expect(html).toContain("System Requirements Specification");
  });

  it("renders slash command suggestions when the draft ends with slash text", () => {
    const html = renderChatPanel("/pl");

    expect(html).toContain("/plan");
    expect(html).toContain("Break a package into actionable work");
  });

  it("shows a test connection action when the model settings panel is open", () => {
    const html = renderToStaticMarkup(
      <ChatPanel
        messages={[]}
        draft=""
        setDraft={vi.fn()}
        busy={false}
        productTitle="Agentic PM Demo"
        currentActivity="Ready"
        workPackages={workPackages}
        selectedWorkPackageId="wp-srs"
        onSelectWorkPackage={vi.fn()}
        llmConfig={{
          apiKey: "",
          baseUrl: DEFAULT_LLM_BASE_URL,
          model: DEFAULT_LLM_MODEL,
        }}
        setLlmConfig={vi.fn()}
        isMockMode={true}
        connectionStatus="idle"
        connectionMessage="Add API key, base URL, and model to enable live automation."
        canTestConnection={true}
        onTestConnection={vi.fn()}
        onSend={vi.fn()}
        initialSettingsOpen={true}
      />,
    );

    expect(html).toContain("Test connection");
  });
});