Elffuss BraidHub

kikocis/continue public

main · 2.3 KiBRawPermalink
1import { Text } from "ink";
2import { render } from "ink-testing-library";
3import React from "react";
4import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
5
6import { IntroMessage } from "./IntroMessage.js";
7
8// Mock the TipsDisplay module
9vi.mock("./TipsDisplay.js", () => ({
10 TipsDisplay: () => React.createElement(Text, null, "Mocked TipsDisplay"),
11 shouldShowTip: vi.fn(),
12}));
13
14// Mock other dependencies
15vi.mock("../asciiArt.js", () => ({
16 getDisplayableAsciiArt: () => "MOCK ASCII ART",
17}));
18
19vi.mock("../utils/modelCapability.js", () => ({
20 isModelCapable: () => true,
21}));
22
23describe("IntroMessage", () => {
24 beforeEach(() => {
25 vi.clearAllMocks();
26 });
27
28 afterEach(() => {
29 vi.restoreAllMocks();
30 });
31
32 it("renders ASCII art and basic structure", () => {
33 const { lastFrame } = render(<IntroMessage />);
34
35 expect(lastFrame()).toContain("MOCK ASCII ART");
36 });
37
38 it("shows tips when shouldShowTip returns true", async () => {
39 const { shouldShowTip } = await import("./TipsDisplay.js");
40 vi.mocked(shouldShowTip).mockReturnValue(true);
41
42 const { lastFrame } = render(<IntroMessage />);
43
44 expect(lastFrame()).toContain("Mocked TipsDisplay");
45 });
46
47 it("does not show tips when shouldShowTip returns false", async () => {
48 const { shouldShowTip } = await import("./TipsDisplay.js");
49 vi.mocked(shouldShowTip).mockReturnValue(false);
50
51 const { lastFrame } = render(<IntroMessage />);
52
53 expect(lastFrame()).not.toContain("Mocked TipsDisplay");
54 });
55
56 it("renders agent name when config is provided", () => {
57 const config = { name: "Test Agent", version: "1.0.0", rules: [] };
58
59 const { lastFrame } = render(<IntroMessage config={config} />);
60
61 expect(lastFrame()).toContain("Agent:");
62 expect(lastFrame()).toContain("Test Agent");
63 });
64
65 it("renders model information when model is provided", () => {
66 const model = {
67 name: "provider/model-name",
68 provider: "test-provider",
69 model: "test-model",
70 };
71
72 const { lastFrame } = render(<IntroMessage model={model} />);
73
74 expect(lastFrame()).toContain("Model:");
75 expect(lastFrame()).toContain("model-name");
76 });
77
78 it("shows loading state when model is not provided", () => {
79 const { lastFrame } = render(<IntroMessage />);
80
81 expect(lastFrame()).toContain("Model:");
82 expect(lastFrame()).toContain("Loading...");
83 });
84});