@copilotkit/react-core 1.54.1 → 1.55.0-next.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +117 -116
- package/dist/copilotkit-B3Mb1yVE.cjs +7975 -0
- package/dist/copilotkit-B3Mb1yVE.cjs.map +1 -0
- package/dist/copilotkit-DBzgOMby.d.cts +2182 -0
- package/dist/copilotkit-DBzgOMby.d.cts.map +1 -0
- package/dist/copilotkit-DNYSFuz5.mjs +7562 -0
- package/dist/copilotkit-DNYSFuz5.mjs.map +1 -0
- package/dist/copilotkit-Dy5w3qEV.d.mts +2182 -0
- package/dist/copilotkit-Dy5w3qEV.d.mts.map +1 -0
- package/dist/index.cjs +27 -28
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -3
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +3 -3
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +4 -5
- package/dist/index.mjs.map +1 -1
- package/dist/index.umd.js +1941 -35
- package/dist/index.umd.js.map +1 -1
- package/dist/v2/index.cjs +77 -7
- package/dist/v2/index.css +1 -2
- package/dist/v2/index.d.cts +6 -4
- package/dist/v2/index.d.mts +6 -4
- package/dist/v2/index.mjs +7 -4
- package/dist/v2/index.umd.js +5725 -24
- package/dist/v2/index.umd.js.map +1 -1
- package/package.json +37 -9
- package/scripts/scope-preflight.mjs +101 -0
- package/src/components/CopilotListeners.tsx +2 -6
- package/src/components/copilot-provider/copilot-messages.tsx +1 -1
- package/src/components/copilot-provider/copilotkit-props.tsx +1 -1
- package/src/components/copilot-provider/copilotkit.tsx +4 -4
- package/src/context/copilot-messages-context.tsx +1 -1
- package/src/hooks/__tests__/use-coagent-config.test.ts +2 -2
- package/src/hooks/__tests__/use-coagent-state-render.e2e.test.tsx +2 -2
- package/src/hooks/__tests__/use-copilot-chat-internal-connect.test.tsx +3 -7
- package/src/hooks/__tests__/use-frontend-tool-available.test.tsx +1 -1
- package/src/hooks/__tests__/use-frontend-tool-remount.e2e.test.tsx +4 -4
- package/src/hooks/use-agent-nodename.ts +1 -1
- package/src/hooks/use-coagent-state-render-bridge.tsx +1 -4
- package/src/hooks/use-coagent.ts +1 -1
- package/src/hooks/use-configure-chat-suggestions.tsx +2 -2
- package/src/hooks/use-copilot-chat-suggestions.tsx +2 -2
- package/src/hooks/use-copilot-chat_internal.ts +2 -2
- package/src/hooks/use-copilot-readable.ts +1 -1
- package/src/hooks/use-frontend-tool.ts +2 -2
- package/src/hooks/use-human-in-the-loop.ts +2 -2
- package/src/hooks/use-langgraph-interrupt.ts +2 -5
- package/src/hooks/use-lazy-tool-renderer.tsx +1 -1
- package/src/hooks/use-render-tool-call.ts +1 -1
- package/src/lib/copilot-task.ts +1 -1
- package/src/setupTests.ts +18 -14
- package/src/v2/__tests__/A2UIMessageRenderer.test.tsx +176 -0
- package/src/v2/__tests__/globalSetup.ts +14 -0
- package/src/v2/__tests__/setup.ts +93 -0
- package/src/v2/__tests__/utils/test-helpers.tsx +470 -0
- package/src/v2/a2ui/A2UIMessageRenderer.tsx +206 -0
- package/src/v2/components/CopilotKitInspector.tsx +50 -0
- package/src/v2/components/MCPAppsActivityRenderer.tsx +785 -0
- package/src/v2/components/WildcardToolCallRender.tsx +86 -0
- package/src/v2/components/__tests__/license-warning-banner.test.tsx +46 -0
- package/src/v2/components/chat/CopilotChat.tsx +431 -0
- package/src/v2/components/chat/CopilotChatAssistantMessage.tsx +375 -0
- package/src/v2/components/chat/CopilotChatAudioRecorder.tsx +350 -0
- package/src/v2/components/chat/CopilotChatInput.tsx +1302 -0
- package/src/v2/components/chat/CopilotChatMessageView.tsx +556 -0
- package/src/v2/components/chat/CopilotChatReasoningMessage.tsx +252 -0
- package/src/v2/components/chat/CopilotChatSuggestionPill.tsx +59 -0
- package/src/v2/components/chat/CopilotChatSuggestionView.tsx +133 -0
- package/src/v2/components/chat/CopilotChatToggleButton.tsx +171 -0
- package/src/v2/components/chat/CopilotChatToolCallsView.tsx +40 -0
- package/src/v2/components/chat/CopilotChatUserMessage.tsx +388 -0
- package/src/v2/components/chat/CopilotChatView.tsx +598 -0
- package/src/v2/components/chat/CopilotModalHeader.tsx +129 -0
- package/src/v2/components/chat/CopilotPopup.tsx +81 -0
- package/src/v2/components/chat/CopilotPopupView.tsx +317 -0
- package/src/v2/components/chat/CopilotSidebar.tsx +76 -0
- package/src/v2/components/chat/CopilotSidebarView.tsx +255 -0
- package/src/v2/components/chat/__tests__/CopilotChat.e2e.test.tsx +1113 -0
- package/src/v2/components/chat/__tests__/CopilotChat.onError.test.tsx +73 -0
- package/src/v2/components/chat/__tests__/CopilotChat.slots.e2e.test.tsx +432 -0
- package/src/v2/components/chat/__tests__/CopilotChatActivityRendering.e2e.test.tsx +150 -0
- package/src/v2/components/chat/__tests__/CopilotChatAssistantMessage.slots.e2e.test.tsx +624 -0
- package/src/v2/components/chat/__tests__/CopilotChatAssistantMessage.test.tsx +702 -0
- package/src/v2/components/chat/__tests__/CopilotChatCssClasses.test.tsx +107 -0
- package/src/v2/components/chat/__tests__/CopilotChatInput.slots.e2e.test.tsx +929 -0
- package/src/v2/components/chat/__tests__/CopilotChatInput.test.tsx +986 -0
- package/src/v2/components/chat/__tests__/CopilotChatMessageView.slots.e2e.test.tsx +1004 -0
- package/src/v2/components/chat/__tests__/CopilotChatMessageView.test.tsx +169 -0
- package/src/v2/components/chat/__tests__/CopilotChatSuggestionView.slots.e2e.test.tsx +530 -0
- package/src/v2/components/chat/__tests__/CopilotChatToolRendering.e2e.test.tsx +782 -0
- package/src/v2/components/chat/__tests__/CopilotChatToolRerenders.e2e.test.tsx +2413 -0
- package/src/v2/components/chat/__tests__/CopilotChatUserMessage.slots.e2e.test.tsx +621 -0
- package/src/v2/components/chat/__tests__/CopilotChatView.onClick.e2e.test.tsx +853 -0
- package/src/v2/components/chat/__tests__/CopilotChatView.slots.e2e.test.tsx +1050 -0
- package/src/v2/components/chat/__tests__/CopilotModalHeader.slots.e2e.test.tsx +484 -0
- package/src/v2/components/chat/__tests__/CopilotPopupView.slots.e2e.test.tsx +612 -0
- package/src/v2/components/chat/__tests__/CopilotSidebarView.slots.e2e.test.tsx +502 -0
- package/src/v2/components/chat/__tests__/MCPAppsActivityRenderer.e2e.test.tsx +1011 -0
- package/src/v2/components/chat/__tests__/setup.ts +1 -0
- package/src/v2/components/chat/index.ts +79 -0
- package/src/v2/components/index.ts +7 -0
- package/src/v2/components/license-warning-banner.tsx +198 -0
- package/src/v2/components/ui/button.tsx +123 -0
- package/src/v2/components/ui/dropdown-menu.tsx +258 -0
- package/src/v2/components/ui/tooltip.tsx +60 -0
- package/src/v2/hooks/__tests__/standard-schema-types.test.tsx +152 -0
- package/src/v2/hooks/__tests__/standard-schema.test.tsx +282 -0
- package/src/v2/hooks/__tests__/use-agent-context-timing.e2e.test.tsx +132 -0
- package/src/v2/hooks/__tests__/use-agent-context.test.tsx +401 -0
- package/src/v2/hooks/__tests__/use-agent-error-state.test.tsx +44 -0
- package/src/v2/hooks/__tests__/use-agent-stability.test.tsx +205 -0
- package/src/v2/hooks/__tests__/use-agent.e2e.test.tsx +148 -0
- package/src/v2/hooks/__tests__/use-component.test.tsx +123 -0
- package/src/v2/hooks/__tests__/use-configure-suggestions.e2e.test.tsx +696 -0
- package/src/v2/hooks/__tests__/use-default-render-tool.test.tsx +153 -0
- package/src/v2/hooks/__tests__/use-frontend-tool-available.test.tsx +167 -0
- package/src/v2/hooks/__tests__/use-frontend-tool.e2e.test.tsx +2129 -0
- package/src/v2/hooks/__tests__/use-human-in-the-loop.e2e.test.tsx +1261 -0
- package/src/v2/hooks/__tests__/use-interrupt.test.tsx +397 -0
- package/src/v2/hooks/__tests__/use-katex-styles.test.tsx +56 -0
- package/src/v2/hooks/__tests__/use-keyboard-height.test.tsx +192 -0
- package/src/v2/hooks/__tests__/use-render-tool.test.tsx +259 -0
- package/src/v2/hooks/__tests__/use-suggestions.e2e.test.tsx +524 -0
- package/src/v2/hooks/__tests__/use-threads.test.tsx +433 -0
- package/src/v2/hooks/__tests__/zod-regression.test.tsx +311 -0
- package/src/v2/hooks/index.ts +18 -0
- package/src/v2/hooks/use-agent-context.tsx +45 -0
- package/src/v2/hooks/use-agent.tsx +155 -0
- package/src/v2/hooks/use-component.tsx +89 -0
- package/src/v2/hooks/use-configure-suggestions.tsx +187 -0
- package/src/v2/hooks/use-default-render-tool.tsx +254 -0
- package/src/v2/hooks/use-frontend-tool.tsx +43 -0
- package/src/v2/hooks/use-human-in-the-loop.tsx +81 -0
- package/src/v2/hooks/use-interrupt.tsx +305 -0
- package/src/v2/hooks/use-keyboard-height.tsx +67 -0
- package/src/v2/hooks/use-render-activity-message.tsx +73 -0
- package/src/v2/hooks/use-render-custom-messages.tsx +93 -0
- package/src/v2/hooks/use-render-tool-call.tsx +175 -0
- package/src/v2/hooks/use-render-tool.tsx +181 -0
- package/src/v2/hooks/use-suggestions.tsx +91 -0
- package/src/v2/hooks/use-threads.tsx +256 -0
- package/src/v2/hooks/useKatexStyles.ts +27 -0
- package/src/v2/index.css +1 -1
- package/src/v2/index.ts +18 -2
- package/src/v2/lib/__tests__/completePartialMarkdown.test.ts +495 -0
- package/src/v2/lib/__tests__/renderSlot.test.tsx +588 -0
- package/src/v2/lib/react-core.ts +156 -0
- package/src/v2/lib/slots.tsx +143 -0
- package/src/v2/lib/transcription-client.ts +184 -0
- package/src/v2/lib/utils.ts +8 -0
- package/src/v2/providers/CopilotChatConfigurationProvider.tsx +162 -0
- package/src/v2/providers/CopilotKitProvider.tsx +600 -0
- package/src/v2/providers/__tests__/CopilotChatConfigurationProvider.test.tsx +546 -0
- package/src/v2/providers/__tests__/CopilotKitProvider.license.test.tsx +101 -0
- package/src/v2/providers/__tests__/CopilotKitProvider.onError.test.tsx +69 -0
- package/src/v2/providers/__tests__/CopilotKitProvider.renderCustomMessages.e2e.test.tsx +881 -0
- package/src/v2/providers/__tests__/CopilotKitProvider.stability.test.tsx +740 -0
- package/src/v2/providers/__tests__/CopilotKitProvider.test.tsx +642 -0
- package/src/v2/providers/__tests__/CopilotKitProvider.wildcard.test.tsx +294 -0
- package/src/v2/providers/index.ts +14 -0
- package/src/v2/styles/globals.css +230 -0
- package/src/v2/types/__tests__/defineToolCallRenderer.test.tsx +525 -0
- package/src/v2/types/defineToolCallRenderer.ts +65 -0
- package/src/v2/types/frontend-tool.ts +8 -0
- package/src/v2/types/human-in-the-loop.ts +33 -0
- package/src/v2/types/index.ts +7 -0
- package/src/v2/types/interrupt.ts +15 -0
- package/src/v2/types/react-activity-message-renderer.ts +27 -0
- package/src/v2/types/react-custom-message-renderer.ts +17 -0
- package/src/v2/types/react-tool-call-renderer.ts +32 -0
- package/tsdown.config.ts +34 -10
- package/vitest.config.mjs +4 -3
- package/LICENSE +0 -21
- package/dist/copilotkit-BRPQ2sqS.d.cts +0 -670
- package/dist/copilotkit-BRPQ2sqS.d.cts.map +0 -1
- package/dist/copilotkit-C94ayZbs.cjs +0 -2161
- package/dist/copilotkit-C94ayZbs.cjs.map +0 -1
- package/dist/copilotkit-CwZMFmSK.d.mts +0 -670
- package/dist/copilotkit-CwZMFmSK.d.mts.map +0 -1
- package/dist/copilotkit-Yh_Ld_FX.mjs +0 -2031
- package/dist/copilotkit-Yh_Ld_FX.mjs.map +0 -1
- package/dist/v2/index.css.map +0 -1
|
@@ -0,0 +1,624 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { render, screen, fireEvent } from "@testing-library/react";
|
|
3
|
+
import { describe, it, expect, vi } from "vitest";
|
|
4
|
+
import { CopilotChatAssistantMessage } from "../CopilotChatAssistantMessage";
|
|
5
|
+
import { CopilotKitProvider } from "../../../providers/CopilotKitProvider";
|
|
6
|
+
import { CopilotChatConfigurationProvider } from "../../../providers/CopilotChatConfigurationProvider";
|
|
7
|
+
import { AssistantMessage } from "@ag-ui/core";
|
|
8
|
+
|
|
9
|
+
// Wrapper to provide required context
|
|
10
|
+
const TestWrapper: React.FC<{ children: React.ReactNode }> = ({ children }) => (
|
|
11
|
+
<CopilotKitProvider>
|
|
12
|
+
<CopilotChatConfigurationProvider threadId="test-thread">
|
|
13
|
+
{children}
|
|
14
|
+
</CopilotChatConfigurationProvider>
|
|
15
|
+
</CopilotKitProvider>
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
const createAssistantMessage = (content: string): AssistantMessage => ({
|
|
19
|
+
id: "msg-1",
|
|
20
|
+
role: "assistant",
|
|
21
|
+
content,
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
describe("CopilotChatAssistantMessage Slot System E2E Tests", () => {
|
|
25
|
+
// ============================================================================
|
|
26
|
+
// 1. TAILWIND CLASS TESTS
|
|
27
|
+
// ============================================================================
|
|
28
|
+
describe("1. Tailwind Class Slot Override", () => {
|
|
29
|
+
describe("markdownRenderer slot", () => {
|
|
30
|
+
it("should apply tailwind class string to markdownRenderer", () => {
|
|
31
|
+
const message = createAssistantMessage("Hello world");
|
|
32
|
+
const { container } = render(
|
|
33
|
+
<TestWrapper>
|
|
34
|
+
<CopilotChatAssistantMessage
|
|
35
|
+
message={message}
|
|
36
|
+
markdownRenderer="bg-blue-100 rounded-lg p-4"
|
|
37
|
+
/>
|
|
38
|
+
</TestWrapper>,
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
const markdown = container.querySelector(".bg-blue-100");
|
|
42
|
+
expect(markdown).toBeDefined();
|
|
43
|
+
expect(markdown?.classList.contains("rounded-lg")).toBe(true);
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
describe("toolbar slot", () => {
|
|
48
|
+
it("should apply tailwind class string to toolbar", () => {
|
|
49
|
+
const message = createAssistantMessage("Hello world");
|
|
50
|
+
const { container } = render(
|
|
51
|
+
<TestWrapper>
|
|
52
|
+
<CopilotChatAssistantMessage
|
|
53
|
+
message={message}
|
|
54
|
+
toolbar="bg-gray-100 border-t"
|
|
55
|
+
/>
|
|
56
|
+
</TestWrapper>,
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
const toolbar = container.querySelector(".bg-gray-100");
|
|
60
|
+
expect(toolbar).toBeDefined();
|
|
61
|
+
expect(toolbar?.classList.contains("border-t")).toBe(true);
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
describe("copyButton slot", () => {
|
|
66
|
+
it("should apply tailwind class string to copyButton", () => {
|
|
67
|
+
const message = createAssistantMessage("Hello world");
|
|
68
|
+
const { container } = render(
|
|
69
|
+
<TestWrapper>
|
|
70
|
+
<CopilotChatAssistantMessage
|
|
71
|
+
message={message}
|
|
72
|
+
copyButton="text-green-500 hover:text-green-700"
|
|
73
|
+
/>
|
|
74
|
+
</TestWrapper>,
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
const copyBtn = container.querySelector(".text-green-500");
|
|
78
|
+
expect(copyBtn).toBeDefined();
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
describe("thumbsUpButton slot", () => {
|
|
83
|
+
it("should apply tailwind class string to thumbsUpButton", () => {
|
|
84
|
+
const onThumbsUp = vi.fn();
|
|
85
|
+
const message = createAssistantMessage("Hello world");
|
|
86
|
+
const { container } = render(
|
|
87
|
+
<TestWrapper>
|
|
88
|
+
<CopilotChatAssistantMessage
|
|
89
|
+
message={message}
|
|
90
|
+
onThumbsUp={onThumbsUp}
|
|
91
|
+
thumbsUpButton="text-blue-500"
|
|
92
|
+
/>
|
|
93
|
+
</TestWrapper>,
|
|
94
|
+
);
|
|
95
|
+
|
|
96
|
+
const thumbsUp = container.querySelector(".text-blue-500");
|
|
97
|
+
expect(thumbsUp).toBeDefined();
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
describe("thumbsDownButton slot", () => {
|
|
102
|
+
it("should apply tailwind class string to thumbsDownButton", () => {
|
|
103
|
+
const onThumbsDown = vi.fn();
|
|
104
|
+
const message = createAssistantMessage("Hello world");
|
|
105
|
+
const { container } = render(
|
|
106
|
+
<TestWrapper>
|
|
107
|
+
<CopilotChatAssistantMessage
|
|
108
|
+
message={message}
|
|
109
|
+
onThumbsDown={onThumbsDown}
|
|
110
|
+
thumbsDownButton="text-red-500"
|
|
111
|
+
/>
|
|
112
|
+
</TestWrapper>,
|
|
113
|
+
);
|
|
114
|
+
|
|
115
|
+
const thumbsDown = container.querySelector(".text-red-500");
|
|
116
|
+
expect(thumbsDown).toBeDefined();
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
describe("readAloudButton slot", () => {
|
|
121
|
+
it("should apply tailwind class string to readAloudButton", () => {
|
|
122
|
+
const onReadAloud = vi.fn();
|
|
123
|
+
const message = createAssistantMessage("Hello world");
|
|
124
|
+
const { container } = render(
|
|
125
|
+
<TestWrapper>
|
|
126
|
+
<CopilotChatAssistantMessage
|
|
127
|
+
message={message}
|
|
128
|
+
onReadAloud={onReadAloud}
|
|
129
|
+
readAloudButton="text-purple-500"
|
|
130
|
+
/>
|
|
131
|
+
</TestWrapper>,
|
|
132
|
+
);
|
|
133
|
+
|
|
134
|
+
const readAloud = container.querySelector(".text-purple-500");
|
|
135
|
+
expect(readAloud).toBeDefined();
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
describe("regenerateButton slot", () => {
|
|
140
|
+
it("should apply tailwind class string to regenerateButton", () => {
|
|
141
|
+
const onRegenerate = vi.fn();
|
|
142
|
+
const message = createAssistantMessage("Hello world");
|
|
143
|
+
const { container } = render(
|
|
144
|
+
<TestWrapper>
|
|
145
|
+
<CopilotChatAssistantMessage
|
|
146
|
+
message={message}
|
|
147
|
+
onRegenerate={onRegenerate}
|
|
148
|
+
regenerateButton="text-orange-500"
|
|
149
|
+
/>
|
|
150
|
+
</TestWrapper>,
|
|
151
|
+
);
|
|
152
|
+
|
|
153
|
+
const regenerate = container.querySelector(".text-orange-500");
|
|
154
|
+
expect(regenerate).toBeDefined();
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
describe("toolCallsView slot", () => {
|
|
159
|
+
it("should apply tailwind class string to toolCallsView", () => {
|
|
160
|
+
const message: AssistantMessage = {
|
|
161
|
+
...createAssistantMessage("Hello"),
|
|
162
|
+
toolCalls: [
|
|
163
|
+
{
|
|
164
|
+
id: "tc-1",
|
|
165
|
+
type: "function",
|
|
166
|
+
function: { name: "test_tool", arguments: "{}" },
|
|
167
|
+
},
|
|
168
|
+
],
|
|
169
|
+
};
|
|
170
|
+
const { container } = render(
|
|
171
|
+
<TestWrapper>
|
|
172
|
+
<CopilotChatAssistantMessage
|
|
173
|
+
message={message}
|
|
174
|
+
toolCallsView="bg-yellow-50 p-2"
|
|
175
|
+
/>
|
|
176
|
+
</TestWrapper>,
|
|
177
|
+
);
|
|
178
|
+
|
|
179
|
+
const toolCalls = container.querySelector(".bg-yellow-50");
|
|
180
|
+
// May not be visible if no tool calls rendered
|
|
181
|
+
if (toolCalls) {
|
|
182
|
+
expect(toolCalls.classList.contains("p-2")).toBe(true);
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
});
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
// ============================================================================
|
|
189
|
+
// 2. PROPERTY PASSING TESTS
|
|
190
|
+
// ============================================================================
|
|
191
|
+
describe("2. Property Passing (onClick, disabled, etc.)", () => {
|
|
192
|
+
describe("markdownRenderer slot", () => {
|
|
193
|
+
it("should pass custom props to markdownRenderer", () => {
|
|
194
|
+
const message = createAssistantMessage("Hello world");
|
|
195
|
+
const { container } = render(
|
|
196
|
+
<TestWrapper>
|
|
197
|
+
<CopilotChatAssistantMessage
|
|
198
|
+
message={message}
|
|
199
|
+
markdownRenderer={{ "data-testid": "custom-markdown" }}
|
|
200
|
+
/>
|
|
201
|
+
</TestWrapper>,
|
|
202
|
+
);
|
|
203
|
+
|
|
204
|
+
const markdown = screen.queryByTestId("custom-markdown");
|
|
205
|
+
expect(markdown).toBeDefined();
|
|
206
|
+
});
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
describe("toolbar slot", () => {
|
|
210
|
+
it("should pass custom onClick to toolbar", () => {
|
|
211
|
+
const onClick = vi.fn();
|
|
212
|
+
const message = createAssistantMessage("Hello world");
|
|
213
|
+
const { container } = render(
|
|
214
|
+
<TestWrapper>
|
|
215
|
+
<CopilotChatAssistantMessage
|
|
216
|
+
message={message}
|
|
217
|
+
toolbar={{ onClick, "data-testid": "custom-toolbar" }}
|
|
218
|
+
/>
|
|
219
|
+
</TestWrapper>,
|
|
220
|
+
);
|
|
221
|
+
|
|
222
|
+
const toolbar = screen.queryByTestId("custom-toolbar");
|
|
223
|
+
if (toolbar) {
|
|
224
|
+
fireEvent.click(toolbar);
|
|
225
|
+
expect(onClick).toHaveBeenCalled();
|
|
226
|
+
}
|
|
227
|
+
});
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
describe("copyButton slot", () => {
|
|
231
|
+
it("should pass custom onClick that wraps default behavior", () => {
|
|
232
|
+
const customOnClick = vi.fn();
|
|
233
|
+
const message = createAssistantMessage("Hello world");
|
|
234
|
+
const { container } = render(
|
|
235
|
+
<TestWrapper>
|
|
236
|
+
<CopilotChatAssistantMessage
|
|
237
|
+
message={message}
|
|
238
|
+
copyButton={{ onClick: customOnClick }}
|
|
239
|
+
/>
|
|
240
|
+
</TestWrapper>,
|
|
241
|
+
);
|
|
242
|
+
|
|
243
|
+
// Find copy button by aria-label
|
|
244
|
+
const copyBtn = container.querySelector('button[aria-label*="Copy"]');
|
|
245
|
+
if (copyBtn) {
|
|
246
|
+
fireEvent.click(copyBtn);
|
|
247
|
+
expect(customOnClick).toHaveBeenCalled();
|
|
248
|
+
}
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
it("should support disabled state on copyButton", () => {
|
|
252
|
+
const message = createAssistantMessage("Hello world");
|
|
253
|
+
const { container } = render(
|
|
254
|
+
<TestWrapper>
|
|
255
|
+
<CopilotChatAssistantMessage
|
|
256
|
+
message={message}
|
|
257
|
+
copyButton={{ disabled: true }}
|
|
258
|
+
/>
|
|
259
|
+
</TestWrapper>,
|
|
260
|
+
);
|
|
261
|
+
|
|
262
|
+
const copyBtn = container.querySelector('button[aria-label*="Copy"]');
|
|
263
|
+
if (copyBtn) {
|
|
264
|
+
expect(copyBtn.hasAttribute("disabled")).toBe(true);
|
|
265
|
+
}
|
|
266
|
+
});
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
describe("thumbsUpButton slot", () => {
|
|
270
|
+
it("should call custom onClick on thumbsUpButton", () => {
|
|
271
|
+
const customOnClick = vi.fn();
|
|
272
|
+
const onThumbsUp = vi.fn();
|
|
273
|
+
const message = createAssistantMessage("Hello world");
|
|
274
|
+
const { container } = render(
|
|
275
|
+
<TestWrapper>
|
|
276
|
+
<CopilotChatAssistantMessage
|
|
277
|
+
message={message}
|
|
278
|
+
onThumbsUp={onThumbsUp}
|
|
279
|
+
thumbsUpButton={{ onClick: customOnClick }}
|
|
280
|
+
/>
|
|
281
|
+
</TestWrapper>,
|
|
282
|
+
);
|
|
283
|
+
|
|
284
|
+
const thumbsUpBtn = container.querySelector(
|
|
285
|
+
'button[aria-label*="Thumbs up"]',
|
|
286
|
+
);
|
|
287
|
+
if (thumbsUpBtn) {
|
|
288
|
+
fireEvent.click(thumbsUpBtn);
|
|
289
|
+
expect(customOnClick).toHaveBeenCalled();
|
|
290
|
+
}
|
|
291
|
+
});
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
describe("thumbsDownButton slot", () => {
|
|
295
|
+
it("should call custom onClick on thumbsDownButton", () => {
|
|
296
|
+
const customOnClick = vi.fn();
|
|
297
|
+
const onThumbsDown = vi.fn();
|
|
298
|
+
const message = createAssistantMessage("Hello world");
|
|
299
|
+
const { container } = render(
|
|
300
|
+
<TestWrapper>
|
|
301
|
+
<CopilotChatAssistantMessage
|
|
302
|
+
message={message}
|
|
303
|
+
onThumbsDown={onThumbsDown}
|
|
304
|
+
thumbsDownButton={{ onClick: customOnClick }}
|
|
305
|
+
/>
|
|
306
|
+
</TestWrapper>,
|
|
307
|
+
);
|
|
308
|
+
|
|
309
|
+
const thumbsDownBtn = container.querySelector(
|
|
310
|
+
'button[aria-label*="Thumbs down"]',
|
|
311
|
+
);
|
|
312
|
+
if (thumbsDownBtn) {
|
|
313
|
+
fireEvent.click(thumbsDownBtn);
|
|
314
|
+
expect(customOnClick).toHaveBeenCalled();
|
|
315
|
+
}
|
|
316
|
+
});
|
|
317
|
+
});
|
|
318
|
+
|
|
319
|
+
describe("readAloudButton slot", () => {
|
|
320
|
+
it("should call custom onClick on readAloudButton", () => {
|
|
321
|
+
const customOnClick = vi.fn();
|
|
322
|
+
const onReadAloud = vi.fn();
|
|
323
|
+
const message = createAssistantMessage("Hello world");
|
|
324
|
+
const { container } = render(
|
|
325
|
+
<TestWrapper>
|
|
326
|
+
<CopilotChatAssistantMessage
|
|
327
|
+
message={message}
|
|
328
|
+
onReadAloud={onReadAloud}
|
|
329
|
+
readAloudButton={{ onClick: customOnClick }}
|
|
330
|
+
/>
|
|
331
|
+
</TestWrapper>,
|
|
332
|
+
);
|
|
333
|
+
|
|
334
|
+
const readAloudBtn = container.querySelector(
|
|
335
|
+
'button[aria-label*="Read"]',
|
|
336
|
+
);
|
|
337
|
+
if (readAloudBtn) {
|
|
338
|
+
fireEvent.click(readAloudBtn);
|
|
339
|
+
expect(customOnClick).toHaveBeenCalled();
|
|
340
|
+
}
|
|
341
|
+
});
|
|
342
|
+
});
|
|
343
|
+
|
|
344
|
+
describe("regenerateButton slot", () => {
|
|
345
|
+
it("should call custom onClick on regenerateButton", () => {
|
|
346
|
+
const customOnClick = vi.fn();
|
|
347
|
+
const onRegenerate = vi.fn();
|
|
348
|
+
const message = createAssistantMessage("Hello world");
|
|
349
|
+
const { container } = render(
|
|
350
|
+
<TestWrapper>
|
|
351
|
+
<CopilotChatAssistantMessage
|
|
352
|
+
message={message}
|
|
353
|
+
onRegenerate={onRegenerate}
|
|
354
|
+
regenerateButton={{ onClick: customOnClick }}
|
|
355
|
+
/>
|
|
356
|
+
</TestWrapper>,
|
|
357
|
+
);
|
|
358
|
+
|
|
359
|
+
const regenerateBtn = container.querySelector(
|
|
360
|
+
'button[aria-label*="Regenerate"]',
|
|
361
|
+
);
|
|
362
|
+
if (regenerateBtn) {
|
|
363
|
+
fireEvent.click(regenerateBtn);
|
|
364
|
+
expect(customOnClick).toHaveBeenCalled();
|
|
365
|
+
}
|
|
366
|
+
});
|
|
367
|
+
});
|
|
368
|
+
});
|
|
369
|
+
|
|
370
|
+
// ============================================================================
|
|
371
|
+
// 3. CUSTOM COMPONENT TESTS
|
|
372
|
+
// ============================================================================
|
|
373
|
+
describe("3. Custom Component Receiving Sub-components", () => {
|
|
374
|
+
it("should allow custom component for markdownRenderer", () => {
|
|
375
|
+
const CustomMarkdown: React.FC<{ content: string }> = ({ content }) => (
|
|
376
|
+
<div data-testid="custom-markdown-component">
|
|
377
|
+
{content.toUpperCase()}
|
|
378
|
+
</div>
|
|
379
|
+
);
|
|
380
|
+
|
|
381
|
+
const message = createAssistantMessage("hello");
|
|
382
|
+
render(
|
|
383
|
+
<TestWrapper>
|
|
384
|
+
<CopilotChatAssistantMessage
|
|
385
|
+
message={message}
|
|
386
|
+
markdownRenderer={CustomMarkdown as any}
|
|
387
|
+
/>
|
|
388
|
+
</TestWrapper>,
|
|
389
|
+
);
|
|
390
|
+
|
|
391
|
+
const custom = screen.queryByTestId("custom-markdown-component");
|
|
392
|
+
expect(custom).toBeDefined();
|
|
393
|
+
expect(custom?.textContent).toBe("HELLO");
|
|
394
|
+
});
|
|
395
|
+
|
|
396
|
+
it("should allow custom component for toolbar", () => {
|
|
397
|
+
const CustomToolbar: React.FC<React.PropsWithChildren> = ({
|
|
398
|
+
children,
|
|
399
|
+
}) => (
|
|
400
|
+
<div data-testid="custom-toolbar-component">
|
|
401
|
+
<span>Custom Toolbar:</span>
|
|
402
|
+
{children}
|
|
403
|
+
</div>
|
|
404
|
+
);
|
|
405
|
+
|
|
406
|
+
const message = createAssistantMessage("Hello");
|
|
407
|
+
render(
|
|
408
|
+
<TestWrapper>
|
|
409
|
+
<CopilotChatAssistantMessage
|
|
410
|
+
message={message}
|
|
411
|
+
toolbar={CustomToolbar as any}
|
|
412
|
+
/>
|
|
413
|
+
</TestWrapper>,
|
|
414
|
+
);
|
|
415
|
+
|
|
416
|
+
const custom = screen.queryByTestId("custom-toolbar-component");
|
|
417
|
+
expect(custom).toBeDefined();
|
|
418
|
+
expect(custom?.textContent).toContain("Custom Toolbar");
|
|
419
|
+
});
|
|
420
|
+
|
|
421
|
+
it("should allow custom component for copyButton", () => {
|
|
422
|
+
const CustomCopyButton: React.FC<
|
|
423
|
+
React.ButtonHTMLAttributes<HTMLButtonElement>
|
|
424
|
+
> = (props) => (
|
|
425
|
+
<button data-testid="custom-copy" {...props}>
|
|
426
|
+
Custom Copy
|
|
427
|
+
</button>
|
|
428
|
+
);
|
|
429
|
+
|
|
430
|
+
const message = createAssistantMessage("Hello");
|
|
431
|
+
render(
|
|
432
|
+
<TestWrapper>
|
|
433
|
+
<CopilotChatAssistantMessage
|
|
434
|
+
message={message}
|
|
435
|
+
copyButton={CustomCopyButton as any}
|
|
436
|
+
/>
|
|
437
|
+
</TestWrapper>,
|
|
438
|
+
);
|
|
439
|
+
|
|
440
|
+
const custom = screen.queryByTestId("custom-copy");
|
|
441
|
+
expect(custom).toBeDefined();
|
|
442
|
+
});
|
|
443
|
+
});
|
|
444
|
+
|
|
445
|
+
// ============================================================================
|
|
446
|
+
// 4. CHILDREN RENDER FUNCTION (DRILL-DOWN) TESTS
|
|
447
|
+
// ============================================================================
|
|
448
|
+
describe("4. Children Render Function for Drill-down", () => {
|
|
449
|
+
it("should provide all bound sub-components via children render function", () => {
|
|
450
|
+
const message = createAssistantMessage("Hello world");
|
|
451
|
+
const childrenFn = vi.fn((props) => (
|
|
452
|
+
<div data-testid="children-render">
|
|
453
|
+
<div data-testid="received-markdown">{props.markdownRenderer}</div>
|
|
454
|
+
<div data-testid="received-toolbar">{props.toolbar}</div>
|
|
455
|
+
<div data-testid="received-copy">{props.copyButton}</div>
|
|
456
|
+
<div data-testid="received-thumbs-up">{props.thumbsUpButton}</div>
|
|
457
|
+
<div data-testid="received-thumbs-down">{props.thumbsDownButton}</div>
|
|
458
|
+
<div data-testid="received-read-aloud">{props.readAloudButton}</div>
|
|
459
|
+
<div data-testid="received-regenerate">{props.regenerateButton}</div>
|
|
460
|
+
<div data-testid="received-tool-calls">{props.toolCallsView}</div>
|
|
461
|
+
</div>
|
|
462
|
+
));
|
|
463
|
+
|
|
464
|
+
render(
|
|
465
|
+
<TestWrapper>
|
|
466
|
+
<CopilotChatAssistantMessage
|
|
467
|
+
message={message}
|
|
468
|
+
onThumbsUp={vi.fn()}
|
|
469
|
+
onThumbsDown={vi.fn()}
|
|
470
|
+
onReadAloud={vi.fn()}
|
|
471
|
+
onRegenerate={vi.fn()}
|
|
472
|
+
>
|
|
473
|
+
{childrenFn}
|
|
474
|
+
</CopilotChatAssistantMessage>
|
|
475
|
+
</TestWrapper>,
|
|
476
|
+
);
|
|
477
|
+
|
|
478
|
+
expect(childrenFn).toHaveBeenCalled();
|
|
479
|
+
const callArgs = childrenFn.mock.calls[0][0];
|
|
480
|
+
expect(callArgs).toHaveProperty("markdownRenderer");
|
|
481
|
+
expect(callArgs).toHaveProperty("toolbar");
|
|
482
|
+
expect(callArgs).toHaveProperty("copyButton");
|
|
483
|
+
expect(callArgs).toHaveProperty("thumbsUpButton");
|
|
484
|
+
expect(callArgs).toHaveProperty("thumbsDownButton");
|
|
485
|
+
expect(callArgs).toHaveProperty("readAloudButton");
|
|
486
|
+
expect(callArgs).toHaveProperty("regenerateButton");
|
|
487
|
+
expect(callArgs).toHaveProperty("toolCallsView");
|
|
488
|
+
expect(callArgs).toHaveProperty("message");
|
|
489
|
+
|
|
490
|
+
expect(screen.queryByTestId("children-render")).toBeDefined();
|
|
491
|
+
});
|
|
492
|
+
|
|
493
|
+
it("should pass message and other props through children render function", () => {
|
|
494
|
+
const message = createAssistantMessage("Test message");
|
|
495
|
+
const childrenFn = vi.fn(() => <div />);
|
|
496
|
+
|
|
497
|
+
render(
|
|
498
|
+
<TestWrapper>
|
|
499
|
+
<CopilotChatAssistantMessage
|
|
500
|
+
message={message}
|
|
501
|
+
isRunning={true}
|
|
502
|
+
toolbarVisible={false}
|
|
503
|
+
>
|
|
504
|
+
{childrenFn}
|
|
505
|
+
</CopilotChatAssistantMessage>
|
|
506
|
+
</TestWrapper>,
|
|
507
|
+
);
|
|
508
|
+
|
|
509
|
+
const callArgs = childrenFn.mock.calls[0][0];
|
|
510
|
+
expect(callArgs.message).toBe(message);
|
|
511
|
+
expect(callArgs.isRunning).toBe(true);
|
|
512
|
+
expect(callArgs.toolbarVisible).toBe(false);
|
|
513
|
+
});
|
|
514
|
+
});
|
|
515
|
+
|
|
516
|
+
// ============================================================================
|
|
517
|
+
// 5. CLASSNAME OVERRIDE TESTS
|
|
518
|
+
// ============================================================================
|
|
519
|
+
describe("5. className Override with Tailwind Strings", () => {
|
|
520
|
+
it("should override root className while preserving default prose classes", () => {
|
|
521
|
+
const message = createAssistantMessage("Hello");
|
|
522
|
+
const { container } = render(
|
|
523
|
+
<TestWrapper>
|
|
524
|
+
<CopilotChatAssistantMessage
|
|
525
|
+
message={message}
|
|
526
|
+
className="custom-root-class bg-custom"
|
|
527
|
+
/>
|
|
528
|
+
</TestWrapper>,
|
|
529
|
+
);
|
|
530
|
+
|
|
531
|
+
const root = container.querySelector(".custom-root-class");
|
|
532
|
+
expect(root).toBeDefined();
|
|
533
|
+
// Prose classes are on an inner div wrapping the markdown content
|
|
534
|
+
const proseDiv = root?.querySelector(".cpk\\:prose");
|
|
535
|
+
expect(proseDiv).toBeDefined();
|
|
536
|
+
});
|
|
537
|
+
|
|
538
|
+
it("should allow tailwind utilities to override default styles", () => {
|
|
539
|
+
const message = createAssistantMessage("Hello");
|
|
540
|
+
const { container } = render(
|
|
541
|
+
<TestWrapper>
|
|
542
|
+
<CopilotChatAssistantMessage message={message} className="max-w-sm" />
|
|
543
|
+
</TestWrapper>,
|
|
544
|
+
);
|
|
545
|
+
|
|
546
|
+
// max-w-sm should override the default max-w-full
|
|
547
|
+
const root = container.querySelector(".max-w-sm");
|
|
548
|
+
expect(root).toBeDefined();
|
|
549
|
+
});
|
|
550
|
+
|
|
551
|
+
it("should merge multiple slot classNames correctly", () => {
|
|
552
|
+
const message = createAssistantMessage("Hello");
|
|
553
|
+
const { container } = render(
|
|
554
|
+
<TestWrapper>
|
|
555
|
+
<CopilotChatAssistantMessage
|
|
556
|
+
message={message}
|
|
557
|
+
className="root-custom"
|
|
558
|
+
toolbar="toolbar-custom"
|
|
559
|
+
copyButton="copy-custom"
|
|
560
|
+
/>
|
|
561
|
+
</TestWrapper>,
|
|
562
|
+
);
|
|
563
|
+
|
|
564
|
+
expect(container.querySelector(".root-custom")).toBeDefined();
|
|
565
|
+
expect(container.querySelector(".toolbar-custom")).toBeDefined();
|
|
566
|
+
expect(container.querySelector(".copy-custom")).toBeDefined();
|
|
567
|
+
});
|
|
568
|
+
});
|
|
569
|
+
|
|
570
|
+
// ============================================================================
|
|
571
|
+
// 6. INTEGRATION / RECURSIVE SLOT TESTS
|
|
572
|
+
// ============================================================================
|
|
573
|
+
describe("6. Integration and Recursive Slot Application", () => {
|
|
574
|
+
it("should correctly render all slots with mixed customization", () => {
|
|
575
|
+
const onThumbsUp = vi.fn();
|
|
576
|
+
const onThumbsDown = vi.fn();
|
|
577
|
+
const message = createAssistantMessage("Hello world");
|
|
578
|
+
|
|
579
|
+
const { container } = render(
|
|
580
|
+
<TestWrapper>
|
|
581
|
+
<CopilotChatAssistantMessage
|
|
582
|
+
message={message}
|
|
583
|
+
onThumbsUp={onThumbsUp}
|
|
584
|
+
onThumbsDown={onThumbsDown}
|
|
585
|
+
markdownRenderer="markdown-style"
|
|
586
|
+
toolbar="toolbar-style"
|
|
587
|
+
copyButton="copy-style"
|
|
588
|
+
thumbsUpButton="thumbs-up-style"
|
|
589
|
+
thumbsDownButton="thumbs-down-style"
|
|
590
|
+
/>
|
|
591
|
+
</TestWrapper>,
|
|
592
|
+
);
|
|
593
|
+
|
|
594
|
+
expect(container.querySelector(".markdown-style")).toBeDefined();
|
|
595
|
+
expect(container.querySelector(".toolbar-style")).toBeDefined();
|
|
596
|
+
expect(container.querySelector(".copy-style")).toBeDefined();
|
|
597
|
+
expect(container.querySelector(".thumbs-up-style")).toBeDefined();
|
|
598
|
+
expect(container.querySelector(".thumbs-down-style")).toBeDefined();
|
|
599
|
+
});
|
|
600
|
+
|
|
601
|
+
it("should work with property objects and class strings mixed", () => {
|
|
602
|
+
const onClick = vi.fn();
|
|
603
|
+
const message = createAssistantMessage("Hello world");
|
|
604
|
+
|
|
605
|
+
const { container } = render(
|
|
606
|
+
<TestWrapper>
|
|
607
|
+
<CopilotChatAssistantMessage
|
|
608
|
+
message={message}
|
|
609
|
+
markdownRenderer="text-lg"
|
|
610
|
+
toolbar={{ onClick, className: "flex gap-2" }}
|
|
611
|
+
/>
|
|
612
|
+
</TestWrapper>,
|
|
613
|
+
);
|
|
614
|
+
|
|
615
|
+
expect(container.querySelector(".text-lg")).toBeDefined();
|
|
616
|
+
|
|
617
|
+
const toolbar = container.querySelector(".flex.gap-2");
|
|
618
|
+
if (toolbar) {
|
|
619
|
+
fireEvent.click(toolbar);
|
|
620
|
+
expect(onClick).toHaveBeenCalled();
|
|
621
|
+
}
|
|
622
|
+
});
|
|
623
|
+
});
|
|
624
|
+
});
|