forked from CopilotKit/CopilotKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMarkdown.test.tsx
More file actions
106 lines (90 loc) · 3.78 KB
/
Copy pathMarkdown.test.tsx
File metadata and controls
106 lines (90 loc) · 3.78 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import React from "react";
import { render } from "@testing-library/react";
import { describe, it, expect, vi, beforeEach } from "vitest";
// ─── Mocks ────────────────────────────────────────────────────────────────────
// Mock react-native since we're in jsdom
vi.mock("react-native", () => ({
StyleSheet: {
create: <T extends Record<string, any>>(styles: T): T => styles,
flatten: (style: any) => style,
},
View: "View",
Text: "Text",
}));
// Capture the props passed to StreamdownText
let lastStreamdownProps: any = null;
vi.mock("react-native-streamdown", () => ({
StreamdownText: function MockStreamdownText(props: any) {
lastStreamdownProps = props;
return React.createElement(
"div",
{ "data-testid": "markdown" },
props.markdown,
);
},
}));
// Import after mocks
import { CopilotMarkdown, defaultMarkdownStyles } from "../Markdown";
// ─── Tests ────────────────────────────────────────────────────────────────────
describe("CopilotMarkdown", () => {
beforeEach(() => {
lastStreamdownProps = null;
});
it("renders without crashing", () => {
const { container } = render(<CopilotMarkdown content="Hello world" />);
expect(container).toBeTruthy();
});
it("passes content as markdown prop to StreamdownText", () => {
render(<CopilotMarkdown content="# Title" />);
expect(lastStreamdownProps).not.toBeNull();
expect(lastStreamdownProps.markdown).toBe("# Title");
});
it("uses default styles when no custom style is provided", () => {
render(<CopilotMarkdown content="test" />);
expect(lastStreamdownProps.markdownStyle).toBe(defaultMarkdownStyles);
});
it("merges custom styles with defaults", () => {
const customStyle = { paragraph: { fontSize: 20, color: "#000" } };
render(<CopilotMarkdown content="test" style={customStyle} />);
// Custom should override the paragraph style
expect(lastStreamdownProps.markdownStyle.paragraph).toEqual({
fontSize: 20,
color: "#000",
});
// Other defaults should still be present
expect(lastStreamdownProps.markdownStyle.h1).toEqual(
defaultMarkdownStyles.h1,
);
expect(lastStreamdownProps.markdownStyle.codeBlock).toEqual(
defaultMarkdownStyles.codeBlock,
);
});
it("renders safely with empty content", () => {
const { container } = render(<CopilotMarkdown content="" />);
expect(container).toBeTruthy();
expect(lastStreamdownProps.markdown).toBe("");
});
it("enables streamingAnimation by default", () => {
render(<CopilotMarkdown content="test" />);
expect(lastStreamdownProps.streamingAnimation).toBe(true);
});
it("allows disabling streamingAnimation", () => {
render(<CopilotMarkdown content="test" streamingAnimation={false} />);
expect(lastStreamdownProps.streamingAnimation).toBe(false);
});
});
describe("defaultMarkdownStyles", () => {
it("exports a style object with expected keys", () => {
expect(defaultMarkdownStyles.paragraph).toBeDefined();
expect(defaultMarkdownStyles.h1).toBeDefined();
expect(defaultMarkdownStyles.h2).toBeDefined();
expect(defaultMarkdownStyles.h3).toBeDefined();
expect(defaultMarkdownStyles.strong).toBeDefined();
expect(defaultMarkdownStyles.em).toBeDefined();
expect(defaultMarkdownStyles.link).toBeDefined();
expect(defaultMarkdownStyles.blockquote).toBeDefined();
expect(defaultMarkdownStyles.code).toBeDefined();
expect(defaultMarkdownStyles.codeBlock).toBeDefined();
expect(defaultMarkdownStyles.list).toBeDefined();
});
});