@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,621 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { render, screen, fireEvent } from "@testing-library/react";
|
|
3
|
+
import { describe, it, expect, vi } from "vitest";
|
|
4
|
+
import { CopilotChatUserMessage } from "../CopilotChatUserMessage";
|
|
5
|
+
import { CopilotKitProvider } from "../../../providers/CopilotKitProvider";
|
|
6
|
+
import { CopilotChatConfigurationProvider } from "../../../providers/CopilotChatConfigurationProvider";
|
|
7
|
+
import { UserMessage } 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 createUserMessage = (content: string): UserMessage => ({
|
|
19
|
+
id: "msg-1",
|
|
20
|
+
role: "user",
|
|
21
|
+
content,
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
describe("CopilotChatUserMessage Slot System E2E Tests", () => {
|
|
25
|
+
// ============================================================================
|
|
26
|
+
// 1. TAILWIND CLASS TESTS
|
|
27
|
+
// ============================================================================
|
|
28
|
+
describe("1. Tailwind Class Slot Override", () => {
|
|
29
|
+
describe("messageRenderer slot", () => {
|
|
30
|
+
it("should apply tailwind class string to messageRenderer", () => {
|
|
31
|
+
const message = createUserMessage("Hello");
|
|
32
|
+
const { container } = render(
|
|
33
|
+
<TestWrapper>
|
|
34
|
+
<CopilotChatUserMessage
|
|
35
|
+
message={message}
|
|
36
|
+
messageRenderer="bg-blue-500 text-white rounded-xl"
|
|
37
|
+
/>
|
|
38
|
+
</TestWrapper>,
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
const renderer = container.querySelector(".bg-blue-500");
|
|
42
|
+
expect(renderer).toBeDefined();
|
|
43
|
+
expect(renderer?.classList.contains("text-white")).toBe(true);
|
|
44
|
+
expect(renderer?.classList.contains("rounded-xl")).toBe(true);
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
describe("toolbar slot", () => {
|
|
49
|
+
it("should apply tailwind class string to toolbar", () => {
|
|
50
|
+
const message = createUserMessage("Hello");
|
|
51
|
+
const { container } = render(
|
|
52
|
+
<TestWrapper>
|
|
53
|
+
<CopilotChatUserMessage
|
|
54
|
+
message={message}
|
|
55
|
+
toolbar="bg-gray-50 border rounded"
|
|
56
|
+
/>
|
|
57
|
+
</TestWrapper>,
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
const toolbar = container.querySelector(".bg-gray-50");
|
|
61
|
+
expect(toolbar).toBeDefined();
|
|
62
|
+
expect(toolbar?.classList.contains("border")).toBe(true);
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
describe("copyButton slot", () => {
|
|
67
|
+
it("should apply tailwind class string to copyButton", () => {
|
|
68
|
+
const message = createUserMessage("Hello");
|
|
69
|
+
const { container } = render(
|
|
70
|
+
<TestWrapper>
|
|
71
|
+
<CopilotChatUserMessage
|
|
72
|
+
message={message}
|
|
73
|
+
copyButton="text-indigo-500 hover:text-indigo-700"
|
|
74
|
+
/>
|
|
75
|
+
</TestWrapper>,
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
const copyBtn = container.querySelector(".text-indigo-500");
|
|
79
|
+
expect(copyBtn).toBeDefined();
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
describe("editButton slot", () => {
|
|
84
|
+
it("should apply tailwind class string to editButton", () => {
|
|
85
|
+
const onEditMessage = vi.fn();
|
|
86
|
+
const message = createUserMessage("Hello");
|
|
87
|
+
const { container } = render(
|
|
88
|
+
<TestWrapper>
|
|
89
|
+
<CopilotChatUserMessage
|
|
90
|
+
message={message}
|
|
91
|
+
onEditMessage={onEditMessage}
|
|
92
|
+
editButton="text-yellow-500"
|
|
93
|
+
/>
|
|
94
|
+
</TestWrapper>,
|
|
95
|
+
);
|
|
96
|
+
|
|
97
|
+
const editBtn = container.querySelector(".text-yellow-500");
|
|
98
|
+
expect(editBtn).toBeDefined();
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
describe("branchNavigation slot", () => {
|
|
103
|
+
it("should apply tailwind class string to branchNavigation", () => {
|
|
104
|
+
const onSwitchToBranch = vi.fn();
|
|
105
|
+
const message = createUserMessage("Hello");
|
|
106
|
+
const { container } = render(
|
|
107
|
+
<TestWrapper>
|
|
108
|
+
<CopilotChatUserMessage
|
|
109
|
+
message={message}
|
|
110
|
+
branchIndex={0}
|
|
111
|
+
numberOfBranches={3}
|
|
112
|
+
onSwitchToBranch={onSwitchToBranch}
|
|
113
|
+
branchNavigation="bg-slate-100 px-2 py-1"
|
|
114
|
+
/>
|
|
115
|
+
</TestWrapper>,
|
|
116
|
+
);
|
|
117
|
+
|
|
118
|
+
const branchNav = container.querySelector(".bg-slate-100");
|
|
119
|
+
expect(branchNav).toBeDefined();
|
|
120
|
+
expect(branchNav?.classList.contains("px-2")).toBe(true);
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
// ============================================================================
|
|
126
|
+
// 2. PROPERTY PASSING TESTS
|
|
127
|
+
// ============================================================================
|
|
128
|
+
describe("2. Property Passing (onClick, disabled, etc.)", () => {
|
|
129
|
+
describe("messageRenderer slot", () => {
|
|
130
|
+
it("should pass custom props to messageRenderer", () => {
|
|
131
|
+
const message = createUserMessage("Hello");
|
|
132
|
+
render(
|
|
133
|
+
<TestWrapper>
|
|
134
|
+
<CopilotChatUserMessage
|
|
135
|
+
message={message}
|
|
136
|
+
messageRenderer={{ "data-testid": "custom-message-renderer" }}
|
|
137
|
+
/>
|
|
138
|
+
</TestWrapper>,
|
|
139
|
+
);
|
|
140
|
+
|
|
141
|
+
const renderer = screen.queryByTestId("custom-message-renderer");
|
|
142
|
+
expect(renderer).toBeDefined();
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
describe("toolbar slot", () => {
|
|
147
|
+
it("should pass custom onClick to toolbar", () => {
|
|
148
|
+
const onClick = vi.fn();
|
|
149
|
+
const message = createUserMessage("Hello");
|
|
150
|
+
render(
|
|
151
|
+
<TestWrapper>
|
|
152
|
+
<CopilotChatUserMessage
|
|
153
|
+
message={message}
|
|
154
|
+
toolbar={{ onClick, "data-testid": "custom-toolbar" }}
|
|
155
|
+
/>
|
|
156
|
+
</TestWrapper>,
|
|
157
|
+
);
|
|
158
|
+
|
|
159
|
+
const toolbar = screen.queryByTestId("custom-toolbar");
|
|
160
|
+
if (toolbar) {
|
|
161
|
+
fireEvent.click(toolbar);
|
|
162
|
+
expect(onClick).toHaveBeenCalled();
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
describe("copyButton slot", () => {
|
|
168
|
+
it("should pass custom onClick that wraps default behavior", () => {
|
|
169
|
+
const customOnClick = vi.fn();
|
|
170
|
+
const message = createUserMessage("Hello");
|
|
171
|
+
const { container } = render(
|
|
172
|
+
<TestWrapper>
|
|
173
|
+
<CopilotChatUserMessage
|
|
174
|
+
message={message}
|
|
175
|
+
copyButton={{ onClick: customOnClick }}
|
|
176
|
+
/>
|
|
177
|
+
</TestWrapper>,
|
|
178
|
+
);
|
|
179
|
+
|
|
180
|
+
const copyBtn = container.querySelector('button[aria-label*="Copy"]');
|
|
181
|
+
if (copyBtn) {
|
|
182
|
+
fireEvent.click(copyBtn);
|
|
183
|
+
expect(customOnClick).toHaveBeenCalled();
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
it("should support disabled state on copyButton", () => {
|
|
188
|
+
const message = createUserMessage("Hello");
|
|
189
|
+
const { container } = render(
|
|
190
|
+
<TestWrapper>
|
|
191
|
+
<CopilotChatUserMessage
|
|
192
|
+
message={message}
|
|
193
|
+
copyButton={{ disabled: true }}
|
|
194
|
+
/>
|
|
195
|
+
</TestWrapper>,
|
|
196
|
+
);
|
|
197
|
+
|
|
198
|
+
const copyBtn = container.querySelector('button[aria-label*="Copy"]');
|
|
199
|
+
if (copyBtn) {
|
|
200
|
+
expect(copyBtn.hasAttribute("disabled")).toBe(true);
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
describe("editButton slot", () => {
|
|
206
|
+
it("should call custom onClick on editButton", () => {
|
|
207
|
+
const customOnClick = vi.fn();
|
|
208
|
+
const onEditMessage = vi.fn();
|
|
209
|
+
const message = createUserMessage("Hello");
|
|
210
|
+
const { container } = render(
|
|
211
|
+
<TestWrapper>
|
|
212
|
+
<CopilotChatUserMessage
|
|
213
|
+
message={message}
|
|
214
|
+
onEditMessage={onEditMessage}
|
|
215
|
+
editButton={{ onClick: customOnClick }}
|
|
216
|
+
/>
|
|
217
|
+
</TestWrapper>,
|
|
218
|
+
);
|
|
219
|
+
|
|
220
|
+
const editBtn = container.querySelector('button[aria-label*="Edit"]');
|
|
221
|
+
if (editBtn) {
|
|
222
|
+
fireEvent.click(editBtn);
|
|
223
|
+
expect(customOnClick).toHaveBeenCalled();
|
|
224
|
+
}
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
it("should support disabled state on editButton", () => {
|
|
228
|
+
const onEditMessage = vi.fn();
|
|
229
|
+
const message = createUserMessage("Hello");
|
|
230
|
+
const { container } = render(
|
|
231
|
+
<TestWrapper>
|
|
232
|
+
<CopilotChatUserMessage
|
|
233
|
+
message={message}
|
|
234
|
+
onEditMessage={onEditMessage}
|
|
235
|
+
editButton={{ disabled: true }}
|
|
236
|
+
/>
|
|
237
|
+
</TestWrapper>,
|
|
238
|
+
);
|
|
239
|
+
|
|
240
|
+
const editBtn = container.querySelector('button[aria-label*="Edit"]');
|
|
241
|
+
if (editBtn) {
|
|
242
|
+
expect(editBtn.hasAttribute("disabled")).toBe(true);
|
|
243
|
+
}
|
|
244
|
+
});
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
describe("branchNavigation slot", () => {
|
|
248
|
+
it("should pass custom props to branchNavigation", () => {
|
|
249
|
+
const onSwitchToBranch = vi.fn();
|
|
250
|
+
const message = createUserMessage("Hello");
|
|
251
|
+
render(
|
|
252
|
+
<TestWrapper>
|
|
253
|
+
<CopilotChatUserMessage
|
|
254
|
+
message={message}
|
|
255
|
+
branchIndex={1}
|
|
256
|
+
numberOfBranches={3}
|
|
257
|
+
onSwitchToBranch={onSwitchToBranch}
|
|
258
|
+
branchNavigation={{ "data-testid": "custom-branch-nav" }}
|
|
259
|
+
/>
|
|
260
|
+
</TestWrapper>,
|
|
261
|
+
);
|
|
262
|
+
|
|
263
|
+
const branchNav = screen.queryByTestId("custom-branch-nav");
|
|
264
|
+
expect(branchNav).toBeDefined();
|
|
265
|
+
});
|
|
266
|
+
});
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
// ============================================================================
|
|
270
|
+
// 3. CUSTOM COMPONENT TESTS
|
|
271
|
+
// ============================================================================
|
|
272
|
+
describe("3. Custom Component Receiving Sub-components", () => {
|
|
273
|
+
it("should allow custom component for messageRenderer", () => {
|
|
274
|
+
const CustomRenderer: React.FC<{ content: string }> = ({ content }) => (
|
|
275
|
+
<div data-testid="custom-renderer">[{content}]</div>
|
|
276
|
+
);
|
|
277
|
+
|
|
278
|
+
const message = createUserMessage("Hello");
|
|
279
|
+
render(
|
|
280
|
+
<TestWrapper>
|
|
281
|
+
<CopilotChatUserMessage
|
|
282
|
+
message={message}
|
|
283
|
+
messageRenderer={CustomRenderer as any}
|
|
284
|
+
/>
|
|
285
|
+
</TestWrapper>,
|
|
286
|
+
);
|
|
287
|
+
|
|
288
|
+
const custom = screen.queryByTestId("custom-renderer");
|
|
289
|
+
expect(custom).toBeDefined();
|
|
290
|
+
expect(custom?.textContent).toBe("[Hello]");
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
it("should allow custom component for toolbar", () => {
|
|
294
|
+
const CustomToolbar: React.FC<React.PropsWithChildren> = ({
|
|
295
|
+
children,
|
|
296
|
+
}) => (
|
|
297
|
+
<div data-testid="custom-toolbar-component">
|
|
298
|
+
<span>Actions:</span>
|
|
299
|
+
{children}
|
|
300
|
+
</div>
|
|
301
|
+
);
|
|
302
|
+
|
|
303
|
+
const message = createUserMessage("Hello");
|
|
304
|
+
render(
|
|
305
|
+
<TestWrapper>
|
|
306
|
+
<CopilotChatUserMessage
|
|
307
|
+
message={message}
|
|
308
|
+
toolbar={CustomToolbar as any}
|
|
309
|
+
/>
|
|
310
|
+
</TestWrapper>,
|
|
311
|
+
);
|
|
312
|
+
|
|
313
|
+
const custom = screen.queryByTestId("custom-toolbar-component");
|
|
314
|
+
expect(custom).toBeDefined();
|
|
315
|
+
expect(custom?.textContent).toContain("Actions");
|
|
316
|
+
});
|
|
317
|
+
|
|
318
|
+
it("should allow custom component for copyButton", () => {
|
|
319
|
+
const CustomCopyButton: React.FC<
|
|
320
|
+
React.ButtonHTMLAttributes<HTMLButtonElement>
|
|
321
|
+
> = (props) => (
|
|
322
|
+
<button data-testid="custom-copy-btn" {...props}>
|
|
323
|
+
Copy It
|
|
324
|
+
</button>
|
|
325
|
+
);
|
|
326
|
+
|
|
327
|
+
const message = createUserMessage("Hello");
|
|
328
|
+
render(
|
|
329
|
+
<TestWrapper>
|
|
330
|
+
<CopilotChatUserMessage
|
|
331
|
+
message={message}
|
|
332
|
+
copyButton={CustomCopyButton as any}
|
|
333
|
+
/>
|
|
334
|
+
</TestWrapper>,
|
|
335
|
+
);
|
|
336
|
+
|
|
337
|
+
const custom = screen.queryByTestId("custom-copy-btn");
|
|
338
|
+
expect(custom).toBeDefined();
|
|
339
|
+
expect(custom?.textContent).toBe("Copy It");
|
|
340
|
+
});
|
|
341
|
+
|
|
342
|
+
it("should allow custom component for editButton", () => {
|
|
343
|
+
const CustomEditButton: React.FC<
|
|
344
|
+
React.ButtonHTMLAttributes<HTMLButtonElement>
|
|
345
|
+
> = (props) => (
|
|
346
|
+
<button data-testid="custom-edit-btn" {...props}>
|
|
347
|
+
Modify
|
|
348
|
+
</button>
|
|
349
|
+
);
|
|
350
|
+
|
|
351
|
+
const onEditMessage = vi.fn();
|
|
352
|
+
const message = createUserMessage("Hello");
|
|
353
|
+
render(
|
|
354
|
+
<TestWrapper>
|
|
355
|
+
<CopilotChatUserMessage
|
|
356
|
+
message={message}
|
|
357
|
+
onEditMessage={onEditMessage}
|
|
358
|
+
editButton={CustomEditButton as any}
|
|
359
|
+
/>
|
|
360
|
+
</TestWrapper>,
|
|
361
|
+
);
|
|
362
|
+
|
|
363
|
+
const custom = screen.queryByTestId("custom-edit-btn");
|
|
364
|
+
expect(custom).toBeDefined();
|
|
365
|
+
});
|
|
366
|
+
|
|
367
|
+
it("should allow custom component for branchNavigation", () => {
|
|
368
|
+
const CustomBranchNav: React.FC<{
|
|
369
|
+
currentBranch?: number;
|
|
370
|
+
numberOfBranches?: number;
|
|
371
|
+
}> = ({ currentBranch = 0, numberOfBranches = 1 }) => (
|
|
372
|
+
<div data-testid="custom-branch-nav">
|
|
373
|
+
Branch {currentBranch + 1} of {numberOfBranches}
|
|
374
|
+
</div>
|
|
375
|
+
);
|
|
376
|
+
|
|
377
|
+
const onSwitchToBranch = vi.fn();
|
|
378
|
+
const message = createUserMessage("Hello");
|
|
379
|
+
render(
|
|
380
|
+
<TestWrapper>
|
|
381
|
+
<CopilotChatUserMessage
|
|
382
|
+
message={message}
|
|
383
|
+
branchIndex={1}
|
|
384
|
+
numberOfBranches={3}
|
|
385
|
+
onSwitchToBranch={onSwitchToBranch}
|
|
386
|
+
branchNavigation={CustomBranchNav as any}
|
|
387
|
+
/>
|
|
388
|
+
</TestWrapper>,
|
|
389
|
+
);
|
|
390
|
+
|
|
391
|
+
const custom = screen.queryByTestId("custom-branch-nav");
|
|
392
|
+
expect(custom).toBeDefined();
|
|
393
|
+
expect(custom?.textContent).toBe("Branch 2 of 3");
|
|
394
|
+
});
|
|
395
|
+
});
|
|
396
|
+
|
|
397
|
+
// ============================================================================
|
|
398
|
+
// 4. CHILDREN RENDER FUNCTION (DRILL-DOWN) TESTS
|
|
399
|
+
// ============================================================================
|
|
400
|
+
describe("4. Children Render Function for Drill-down", () => {
|
|
401
|
+
it("should provide all bound sub-components via children render function", () => {
|
|
402
|
+
const message = createUserMessage("Hello");
|
|
403
|
+
const onEditMessage = vi.fn();
|
|
404
|
+
const onSwitchToBranch = vi.fn();
|
|
405
|
+
const childrenFn = vi.fn((props) => (
|
|
406
|
+
<div data-testid="children-render">
|
|
407
|
+
<div data-testid="received-renderer">{props.messageRenderer}</div>
|
|
408
|
+
<div data-testid="received-toolbar">{props.toolbar}</div>
|
|
409
|
+
<div data-testid="received-copy">{props.copyButton}</div>
|
|
410
|
+
<div data-testid="received-edit">{props.editButton}</div>
|
|
411
|
+
<div data-testid="received-branch">{props.branchNavigation}</div>
|
|
412
|
+
</div>
|
|
413
|
+
));
|
|
414
|
+
|
|
415
|
+
render(
|
|
416
|
+
<TestWrapper>
|
|
417
|
+
<CopilotChatUserMessage
|
|
418
|
+
message={message}
|
|
419
|
+
onEditMessage={onEditMessage}
|
|
420
|
+
branchIndex={0}
|
|
421
|
+
numberOfBranches={2}
|
|
422
|
+
onSwitchToBranch={onSwitchToBranch}
|
|
423
|
+
>
|
|
424
|
+
{childrenFn}
|
|
425
|
+
</CopilotChatUserMessage>
|
|
426
|
+
</TestWrapper>,
|
|
427
|
+
);
|
|
428
|
+
|
|
429
|
+
expect(childrenFn).toHaveBeenCalled();
|
|
430
|
+
const callArgs = childrenFn.mock.calls[0][0];
|
|
431
|
+
expect(callArgs).toHaveProperty("messageRenderer");
|
|
432
|
+
expect(callArgs).toHaveProperty("toolbar");
|
|
433
|
+
expect(callArgs).toHaveProperty("copyButton");
|
|
434
|
+
expect(callArgs).toHaveProperty("editButton");
|
|
435
|
+
expect(callArgs).toHaveProperty("branchNavigation");
|
|
436
|
+
expect(callArgs).toHaveProperty("message");
|
|
437
|
+
|
|
438
|
+
expect(screen.queryByTestId("children-render")).toBeDefined();
|
|
439
|
+
});
|
|
440
|
+
|
|
441
|
+
it("should pass message and branch info through children render function", () => {
|
|
442
|
+
const message = createUserMessage("Test message");
|
|
443
|
+
const childrenFn = vi.fn(() => <div />);
|
|
444
|
+
|
|
445
|
+
render(
|
|
446
|
+
<TestWrapper>
|
|
447
|
+
<CopilotChatUserMessage
|
|
448
|
+
message={message}
|
|
449
|
+
branchIndex={1}
|
|
450
|
+
numberOfBranches={3}
|
|
451
|
+
>
|
|
452
|
+
{childrenFn}
|
|
453
|
+
</CopilotChatUserMessage>
|
|
454
|
+
</TestWrapper>,
|
|
455
|
+
);
|
|
456
|
+
|
|
457
|
+
const callArgs = childrenFn.mock.calls[0][0];
|
|
458
|
+
expect(callArgs.message).toBe(message);
|
|
459
|
+
expect(callArgs.branchIndex).toBe(1);
|
|
460
|
+
expect(callArgs.numberOfBranches).toBe(3);
|
|
461
|
+
});
|
|
462
|
+
|
|
463
|
+
it("should allow reorganizing sub-components in children render", () => {
|
|
464
|
+
const message = createUserMessage("Hello");
|
|
465
|
+
const onEditMessage = vi.fn();
|
|
466
|
+
|
|
467
|
+
const { container } = render(
|
|
468
|
+
<TestWrapper>
|
|
469
|
+
<CopilotChatUserMessage
|
|
470
|
+
message={message}
|
|
471
|
+
onEditMessage={onEditMessage}
|
|
472
|
+
>
|
|
473
|
+
{({ messageRenderer, toolbar, copyButton, editButton }) => (
|
|
474
|
+
<div data-testid="custom-layout">
|
|
475
|
+
<div className="message-area">{messageRenderer}</div>
|
|
476
|
+
<div className="actions-row">
|
|
477
|
+
{editButton}
|
|
478
|
+
{copyButton}
|
|
479
|
+
</div>
|
|
480
|
+
<div className="toolbar-area">{toolbar}</div>
|
|
481
|
+
</div>
|
|
482
|
+
)}
|
|
483
|
+
</CopilotChatUserMessage>
|
|
484
|
+
</TestWrapper>,
|
|
485
|
+
);
|
|
486
|
+
|
|
487
|
+
const customLayout = screen.queryByTestId("custom-layout");
|
|
488
|
+
expect(customLayout).toBeDefined();
|
|
489
|
+
expect(container.querySelector(".message-area")).toBeDefined();
|
|
490
|
+
expect(container.querySelector(".actions-row")).toBeDefined();
|
|
491
|
+
expect(container.querySelector(".toolbar-area")).toBeDefined();
|
|
492
|
+
});
|
|
493
|
+
});
|
|
494
|
+
|
|
495
|
+
// ============================================================================
|
|
496
|
+
// 5. CLASSNAME OVERRIDE TESTS
|
|
497
|
+
// ============================================================================
|
|
498
|
+
describe("5. className Override with Tailwind Strings", () => {
|
|
499
|
+
it("should override root className while preserving default layout classes", () => {
|
|
500
|
+
const message = createUserMessage("Hello");
|
|
501
|
+
const { container } = render(
|
|
502
|
+
<TestWrapper>
|
|
503
|
+
<CopilotChatUserMessage
|
|
504
|
+
message={message}
|
|
505
|
+
className="custom-root-class bg-purple-50"
|
|
506
|
+
/>
|
|
507
|
+
</TestWrapper>,
|
|
508
|
+
);
|
|
509
|
+
|
|
510
|
+
const root = container.querySelector(".custom-root-class");
|
|
511
|
+
expect(root).toBeDefined();
|
|
512
|
+
expect(root?.classList.contains("bg-purple-50")).toBe(true);
|
|
513
|
+
});
|
|
514
|
+
|
|
515
|
+
it("should allow tailwind utilities to override default styles", () => {
|
|
516
|
+
const message = createUserMessage("Hello");
|
|
517
|
+
const { container } = render(
|
|
518
|
+
<TestWrapper>
|
|
519
|
+
<CopilotChatUserMessage message={message} className="pt-0" />
|
|
520
|
+
</TestWrapper>,
|
|
521
|
+
);
|
|
522
|
+
|
|
523
|
+
// pt-0 should override the default pt-10
|
|
524
|
+
const root = container.querySelector(".pt-0");
|
|
525
|
+
expect(root).toBeDefined();
|
|
526
|
+
});
|
|
527
|
+
|
|
528
|
+
it("should merge multiple slot classNames correctly", () => {
|
|
529
|
+
const onEditMessage = vi.fn();
|
|
530
|
+
const message = createUserMessage("Hello");
|
|
531
|
+
const { container } = render(
|
|
532
|
+
<TestWrapper>
|
|
533
|
+
<CopilotChatUserMessage
|
|
534
|
+
message={message}
|
|
535
|
+
onEditMessage={onEditMessage}
|
|
536
|
+
className="root-custom"
|
|
537
|
+
messageRenderer="renderer-custom"
|
|
538
|
+
toolbar="toolbar-custom"
|
|
539
|
+
copyButton="copy-custom"
|
|
540
|
+
editButton="edit-custom"
|
|
541
|
+
/>
|
|
542
|
+
</TestWrapper>,
|
|
543
|
+
);
|
|
544
|
+
|
|
545
|
+
expect(container.querySelector(".root-custom")).toBeDefined();
|
|
546
|
+
expect(container.querySelector(".renderer-custom")).toBeDefined();
|
|
547
|
+
expect(container.querySelector(".toolbar-custom")).toBeDefined();
|
|
548
|
+
expect(container.querySelector(".copy-custom")).toBeDefined();
|
|
549
|
+
expect(container.querySelector(".edit-custom")).toBeDefined();
|
|
550
|
+
});
|
|
551
|
+
});
|
|
552
|
+
|
|
553
|
+
// ============================================================================
|
|
554
|
+
// 6. INTEGRATION / RECURSIVE SLOT TESTS
|
|
555
|
+
// ============================================================================
|
|
556
|
+
describe("6. Integration and Recursive Slot Application", () => {
|
|
557
|
+
it("should correctly render all slots with mixed customization", () => {
|
|
558
|
+
const onEditMessage = vi.fn();
|
|
559
|
+
const onSwitchToBranch = vi.fn();
|
|
560
|
+
const message = createUserMessage("Hello world");
|
|
561
|
+
|
|
562
|
+
const { container } = render(
|
|
563
|
+
<TestWrapper>
|
|
564
|
+
<CopilotChatUserMessage
|
|
565
|
+
message={message}
|
|
566
|
+
onEditMessage={onEditMessage}
|
|
567
|
+
branchIndex={0}
|
|
568
|
+
numberOfBranches={2}
|
|
569
|
+
onSwitchToBranch={onSwitchToBranch}
|
|
570
|
+
messageRenderer="renderer-style"
|
|
571
|
+
toolbar="toolbar-style"
|
|
572
|
+
copyButton="copy-style"
|
|
573
|
+
editButton="edit-style"
|
|
574
|
+
branchNavigation="branch-style"
|
|
575
|
+
/>
|
|
576
|
+
</TestWrapper>,
|
|
577
|
+
);
|
|
578
|
+
|
|
579
|
+
expect(container.querySelector(".renderer-style")).toBeDefined();
|
|
580
|
+
expect(container.querySelector(".toolbar-style")).toBeDefined();
|
|
581
|
+
expect(container.querySelector(".copy-style")).toBeDefined();
|
|
582
|
+
expect(container.querySelector(".edit-style")).toBeDefined();
|
|
583
|
+
expect(container.querySelector(".branch-style")).toBeDefined();
|
|
584
|
+
});
|
|
585
|
+
|
|
586
|
+
it("should work with property objects and class strings mixed", () => {
|
|
587
|
+
const onClick = vi.fn();
|
|
588
|
+
const message = createUserMessage("Hello world");
|
|
589
|
+
|
|
590
|
+
const { container } = render(
|
|
591
|
+
<TestWrapper>
|
|
592
|
+
<CopilotChatUserMessage
|
|
593
|
+
message={message}
|
|
594
|
+
messageRenderer="text-lg font-bold"
|
|
595
|
+
toolbar={{ onClick, className: "flex gap-4" }}
|
|
596
|
+
/>
|
|
597
|
+
</TestWrapper>,
|
|
598
|
+
);
|
|
599
|
+
|
|
600
|
+
expect(container.querySelector(".text-lg")).toBeDefined();
|
|
601
|
+
|
|
602
|
+
const toolbar = container.querySelector(".flex.gap-4");
|
|
603
|
+
if (toolbar) {
|
|
604
|
+
fireEvent.click(toolbar);
|
|
605
|
+
expect(onClick).toHaveBeenCalled();
|
|
606
|
+
}
|
|
607
|
+
});
|
|
608
|
+
|
|
609
|
+
it("should correctly display user message content", () => {
|
|
610
|
+
const message = createUserMessage("This is my message content");
|
|
611
|
+
|
|
612
|
+
render(
|
|
613
|
+
<TestWrapper>
|
|
614
|
+
<CopilotChatUserMessage message={message} />
|
|
615
|
+
</TestWrapper>,
|
|
616
|
+
);
|
|
617
|
+
|
|
618
|
+
expect(screen.getByText("This is my message content")).toBeDefined();
|
|
619
|
+
});
|
|
620
|
+
});
|
|
621
|
+
});
|