@copilotkit/react-native 1.57.3 → 1.58.0

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.
Files changed (48) hide show
  1. package/USAGE.md +116 -0
  2. package/dist/RenderToolContext-CBNKcJqz.cjs +126 -0
  3. package/dist/RenderToolContext-CBNKcJqz.cjs.map +1 -0
  4. package/dist/RenderToolContext-CszHyes6.mjs +75 -0
  5. package/dist/RenderToolContext-CszHyes6.mjs.map +1 -0
  6. package/dist/components/index.cjs +722 -0
  7. package/dist/components/index.cjs.map +1 -0
  8. package/dist/components/index.d.cts +203 -0
  9. package/dist/components/index.d.mts +203 -0
  10. package/dist/components/index.mjs +714 -0
  11. package/dist/components/index.mjs.map +1 -0
  12. package/dist/index.cjs +53 -38
  13. package/dist/index.cjs.map +1 -1
  14. package/dist/index.d.cts +102 -6
  15. package/dist/index.d.mts +100 -4
  16. package/dist/index.mjs +49 -3
  17. package/dist/index.mjs.map +1 -1
  18. package/dist/polyfills/encoding.cjs +1 -1
  19. package/dist/polyfills/streams.cjs +1 -1
  20. package/package.json +24 -4
  21. package/src/CopilotKitProvider.tsx +2 -1
  22. package/src/__mocks__/react-native-streamdown.ts +16 -0
  23. package/src/__mocks__/react-native.ts +52 -0
  24. package/src/__tests__/headless-integration.test.tsx +16 -0
  25. package/src/components/CopilotChat.tsx +465 -0
  26. package/src/components/CopilotModal.tsx +210 -0
  27. package/src/components/Markdown.tsx +124 -0
  28. package/src/components/__tests__/CopilotChat-edge-cases.test.tsx +418 -0
  29. package/src/components/__tests__/CopilotChat.test.tsx +390 -0
  30. package/src/components/__tests__/CopilotModal.test.tsx +257 -0
  31. package/src/components/__tests__/Markdown.test.tsx +106 -0
  32. package/src/components/index.ts +18 -0
  33. package/src/components/messages/AssistantMessage.tsx +73 -0
  34. package/src/components/messages/TypingIndicator.tsx +103 -0
  35. package/src/components/messages/UserMessage.tsx +68 -0
  36. package/src/components/messages/__tests__/messages-edge-cases.test.tsx +179 -0
  37. package/src/components/messages/__tests__/messages.test.tsx +189 -0
  38. package/src/components/messages/__tests__/utils.test.ts +39 -0
  39. package/src/components/messages/index.ts +8 -0
  40. package/src/components/messages/utils.ts +11 -0
  41. package/src/hooks/RenderToolContext.tsx +150 -0
  42. package/src/hooks/__tests__/RenderToolContext.test.tsx +264 -0
  43. package/src/hooks/__tests__/useRenderTool.test.tsx +334 -0
  44. package/src/hooks/index.ts +9 -0
  45. package/src/hooks/useRenderTool.ts +96 -0
  46. package/src/index.ts +10 -3
  47. package/tsdown.config.ts +9 -0
  48. package/vitest.config.mjs +10 -0
@@ -0,0 +1,390 @@
1
+ import React from "react";
2
+ import { render, fireEvent, act } from "@testing-library/react";
3
+ import { describe, it, expect, beforeEach, vi } from "vitest";
4
+
5
+ // ─── Hoisted state ─────────────────────────────────────────────────────────────
6
+
7
+ const hoisted = vi.hoisted(() => {
8
+ return {
9
+ mockAgent: {
10
+ messages: [] as any[],
11
+ isRunning: false,
12
+ addMessage: vi.fn(),
13
+ },
14
+ mockRunAgent: vi.fn().mockResolvedValue(undefined),
15
+ mockToolRegistry: vi.fn(() => new Map()),
16
+ };
17
+ });
18
+
19
+ // ─── Mocks ────────────────────────────────────────────────────────────────────
20
+
21
+ vi.mock("@copilotkit/react-core/v2/headless", () => ({
22
+ useAgent: vi.fn(() => ({ agent: hoisted.mockAgent })),
23
+ }));
24
+
25
+ vi.mock("@copilotkit/react-core/v2/context", () => ({
26
+ useCopilotKit: vi.fn(() => ({
27
+ copilotkit: { runAgent: hoisted.mockRunAgent },
28
+ executingToolCallIds: new Set<string>(),
29
+ })),
30
+ }));
31
+
32
+ // Mock sub-components that B2 builds
33
+ vi.mock("../messages/AssistantMessage", () => ({
34
+ AssistantMessage: ({ content, isLoading }: any) => {
35
+ const React = require("react");
36
+ return React.createElement(
37
+ "div",
38
+ { "data-testid": "assistant-message" },
39
+ isLoading ? "Loading..." : content,
40
+ );
41
+ },
42
+ }));
43
+
44
+ vi.mock("../messages/UserMessage", () => ({
45
+ UserMessage: ({ content }: any) => {
46
+ const React = require("react");
47
+ return React.createElement(
48
+ "div",
49
+ { "data-testid": "user-message" },
50
+ content,
51
+ );
52
+ },
53
+ }));
54
+
55
+ // Mock RenderToolContext (B3)
56
+ vi.mock("../../hooks/RenderToolContext", () => ({
57
+ useRenderToolRegistry: (...args: any[]) => hoisted.mockToolRegistry(...args),
58
+ }));
59
+
60
+ // Mock react-native components with testable DOM elements
61
+ vi.mock("react-native", () => {
62
+ const React = require("react");
63
+ return {
64
+ FlatList: ({ data, renderItem, ListEmptyComponent, keyExtractor }: any) => {
65
+ if (!data || data.length === 0) {
66
+ return React.createElement(
67
+ "div",
68
+ { "data-testid": "flatlist" },
69
+ ListEmptyComponent,
70
+ );
71
+ }
72
+ return React.createElement(
73
+ "div",
74
+ { "data-testid": "flatlist" },
75
+ data.map((item: any, index: number) =>
76
+ React.createElement(
77
+ "div",
78
+ { key: keyExtractor?.(item, index) ?? index },
79
+ renderItem({ item, index }),
80
+ ),
81
+ ),
82
+ );
83
+ },
84
+ KeyboardAvoidingView: ({ children }: any) =>
85
+ React.createElement("div", { "data-testid": "keyboard-view" }, children),
86
+ Platform: { OS: "ios" },
87
+ Pressable: ({ children, onPress, ...props }: any) =>
88
+ React.createElement(
89
+ "button",
90
+ { onClick: onPress, "data-testid": "pressable", ...props },
91
+ children,
92
+ ),
93
+ StyleSheet: {
94
+ create: (styles: any) => styles,
95
+ hairlineWidth: 1,
96
+ },
97
+ Text: ({ children, ...props }: any) =>
98
+ React.createElement("span", props, children),
99
+ TextInput: ({ value, onChangeText, onSubmitEditing, ...props }: any) =>
100
+ React.createElement("input", {
101
+ value,
102
+ onChange: (e: any) => onChangeText?.(e.target.value),
103
+ onKeyDown: (e: any) => {
104
+ if (e.key === "Enter") onSubmitEditing?.();
105
+ },
106
+ "data-testid": "text-input",
107
+ ...props,
108
+ }),
109
+ TouchableOpacity: ({
110
+ children,
111
+ onPress,
112
+ disabled,
113
+ testID,
114
+ ...props
115
+ }: any) =>
116
+ React.createElement(
117
+ "button",
118
+ {
119
+ onClick: onPress,
120
+ disabled,
121
+ ...(testID ? { "data-testid": testID } : {}),
122
+ ...props,
123
+ },
124
+ children,
125
+ ),
126
+ View: ({ children, ...props }: any) =>
127
+ React.createElement("div", props, children),
128
+ };
129
+ });
130
+
131
+ // Import component under test AFTER mocks
132
+ import { CopilotChat } from "../CopilotChat";
133
+
134
+ // ─── Tests ────────────────────────────────────────────────────────────────────
135
+
136
+ describe("CopilotChat", () => {
137
+ beforeEach(() => {
138
+ vi.clearAllMocks();
139
+ hoisted.mockAgent.messages = [];
140
+ hoisted.mockAgent.isRunning = false;
141
+ hoisted.mockAgent.addMessage = vi.fn();
142
+ hoisted.mockRunAgent.mockResolvedValue(undefined);
143
+ hoisted.mockToolRegistry.mockReturnValue(new Map());
144
+ });
145
+
146
+ it("renders empty state when there are no messages", () => {
147
+ const { getByText } = render(<CopilotChat />);
148
+
149
+ expect(getByText("How can I help?")).toBeTruthy();
150
+ expect(
151
+ getByText("Ask me anything or try a suggestion below."),
152
+ ).toBeTruthy();
153
+ });
154
+
155
+ it("renders custom empty state title and subtitle", () => {
156
+ const { getByText } = render(
157
+ <CopilotChat
158
+ emptyStateTitle="Welcome!"
159
+ emptyStateSubtitle="Start chatting"
160
+ />,
161
+ );
162
+
163
+ expect(getByText("Welcome!")).toBeTruthy();
164
+ expect(getByText("Start chatting")).toBeTruthy();
165
+ });
166
+
167
+ it("renders suggestion pills when initialMessages provided", () => {
168
+ const suggestions = ["Hello", "Help me"];
169
+ const { getByText } = render(<CopilotChat initialMessages={suggestions} />);
170
+
171
+ expect(getByText("Hello")).toBeTruthy();
172
+ expect(getByText("Help me")).toBeTruthy();
173
+ });
174
+
175
+ it("renders user and assistant messages", () => {
176
+ hoisted.mockAgent.messages = [
177
+ { id: "1", role: "user", content: "Hi there" },
178
+ { id: "2", role: "assistant", content: "Hello! How can I help?" },
179
+ ];
180
+
181
+ const { getAllByTestId } = render(<CopilotChat />);
182
+
183
+ const userMessages = getAllByTestId("user-message");
184
+ const assistantMessages = getAllByTestId("assistant-message");
185
+
186
+ expect(userMessages).toHaveLength(1);
187
+ expect(assistantMessages).toHaveLength(1);
188
+ expect(userMessages[0].textContent).toBe("Hi there");
189
+ expect(assistantMessages[0].textContent).toBe("Hello! How can I help?");
190
+ });
191
+
192
+ it("shows loading indicator when agent is running", () => {
193
+ hoisted.mockAgent.messages = [{ id: "1", role: "user", content: "Hi" }];
194
+ hoisted.mockAgent.isRunning = true;
195
+
196
+ const { getAllByTestId } = render(<CopilotChat />);
197
+
198
+ const assistantMessages = getAllByTestId("assistant-message");
199
+ expect(assistantMessages.length).toBeGreaterThanOrEqual(1);
200
+
201
+ const loadingMsg = assistantMessages[assistantMessages.length - 1];
202
+ expect(loadingMsg.textContent).toBe("Loading...");
203
+ });
204
+
205
+ it("calls agent.addMessage and copilotkit.runAgent on send", async () => {
206
+ const { getByTestId } = render(<CopilotChat />);
207
+
208
+ const input = getByTestId("text-input");
209
+ const sendBtn = getByTestId("send-button");
210
+
211
+ await act(async () => {
212
+ fireEvent.change(input, { target: { value: "Test message" } });
213
+ });
214
+
215
+ await act(async () => {
216
+ fireEvent.click(sendBtn);
217
+ });
218
+
219
+ expect(hoisted.mockAgent.addMessage).toHaveBeenCalledWith(
220
+ expect.objectContaining({
221
+ role: "user",
222
+ content: "Test message",
223
+ }),
224
+ );
225
+ expect(hoisted.mockRunAgent).toHaveBeenCalledWith({
226
+ agent: hoisted.mockAgent,
227
+ });
228
+ });
229
+
230
+ it("disables send button when input is empty", () => {
231
+ const { getByTestId } = render(<CopilotChat />);
232
+
233
+ const sendBtn = getByTestId("send-button");
234
+ expect(sendBtn).toHaveProperty("disabled", true);
235
+ });
236
+
237
+ it("disables send button when agent is running", async () => {
238
+ hoisted.mockAgent.isRunning = true;
239
+
240
+ const { getByTestId } = render(<CopilotChat />);
241
+
242
+ const input = getByTestId("text-input");
243
+ await act(async () => {
244
+ fireEvent.change(input, { target: { value: "Test" } });
245
+ });
246
+
247
+ const sendBtn = getByTestId("send-button");
248
+ expect(sendBtn).toHaveProperty("disabled", true);
249
+ });
250
+
251
+ it("shows header when showHeader is true", () => {
252
+ const { getByText } = render(
253
+ <CopilotChat showHeader headerTitle="My Chat" />,
254
+ );
255
+
256
+ expect(getByText("My Chat")).toBeTruthy();
257
+ });
258
+
259
+ it("hides header when showHeader is false", () => {
260
+ const { queryByText } = render(
261
+ <CopilotChat showHeader={false} headerTitle="Hidden" />,
262
+ );
263
+
264
+ expect(queryByText("Hidden")).toBeNull();
265
+ });
266
+
267
+ it("calls onSendMessage callback when sending", async () => {
268
+ const onSend = vi.fn();
269
+ const { getByTestId } = render(<CopilotChat onSendMessage={onSend} />);
270
+
271
+ const input = getByTestId("text-input");
272
+ const sendBtn = getByTestId("send-button");
273
+
274
+ await act(async () => {
275
+ fireEvent.change(input, { target: { value: "Callback test" } });
276
+ });
277
+
278
+ await act(async () => {
279
+ fireEvent.click(sendBtn);
280
+ });
281
+
282
+ expect(onSend).toHaveBeenCalledWith("Callback test");
283
+ });
284
+
285
+ it("renders tool call indicator for unregistered tools", () => {
286
+ hoisted.mockAgent.messages = [
287
+ {
288
+ id: "1",
289
+ role: "assistant",
290
+ content: "",
291
+ toolCalls: [
292
+ {
293
+ id: "tc-1",
294
+ type: "function" as const,
295
+ function: { name: "myTool", arguments: "{}" },
296
+ },
297
+ ],
298
+ },
299
+ ];
300
+
301
+ const { getByText } = render(<CopilotChat />);
302
+
303
+ expect(getByText("Called: myTool")).toBeTruthy();
304
+ });
305
+
306
+ it("renders registered tool renderer with correct props", () => {
307
+ const receivedProps: any[] = [];
308
+ const mockRenderer = (props: any) => {
309
+ receivedProps.push(props);
310
+ const React = require("react");
311
+ return React.createElement(
312
+ "div",
313
+ { "data-testid": "tool-render" },
314
+ `rendered: ${JSON.stringify(props.args)}`,
315
+ );
316
+ };
317
+
318
+ const toolMap = new Map([["myTool", mockRenderer]]);
319
+ hoisted.mockToolRegistry.mockReturnValue(toolMap);
320
+
321
+ hoisted.mockAgent.messages = [
322
+ {
323
+ id: "1",
324
+ role: "assistant",
325
+ content: "",
326
+ toolCalls: [
327
+ {
328
+ id: "tc-1",
329
+ type: "function" as const,
330
+ function: {
331
+ name: "myTool",
332
+ arguments: '{"city":"Seattle"}',
333
+ },
334
+ },
335
+ ],
336
+ },
337
+ ];
338
+
339
+ const { getByTestId } = render(<CopilotChat />);
340
+
341
+ expect(getByTestId("tool-render")).toBeTruthy();
342
+ expect(receivedProps[0]).toEqual({
343
+ args: { city: "Seattle" },
344
+ status: "complete",
345
+ });
346
+ });
347
+
348
+ it("shows error message when runAgent fails", async () => {
349
+ hoisted.mockRunAgent.mockRejectedValueOnce(new Error("Network timeout"));
350
+
351
+ const { getByTestId, getByText } = render(<CopilotChat />);
352
+
353
+ const input = getByTestId("text-input");
354
+ const sendBtn = getByTestId("send-button");
355
+
356
+ await act(async () => {
357
+ fireEvent.change(input, { target: { value: "fail message" } });
358
+ });
359
+
360
+ await act(async () => {
361
+ fireEvent.click(sendBtn);
362
+ });
363
+
364
+ expect(getByText("Network timeout")).toBeTruthy();
365
+ });
366
+
367
+ it("uses incrementing message IDs instead of Date.now()", async () => {
368
+ const { getByTestId } = render(<CopilotChat />);
369
+ const input = getByTestId("text-input");
370
+ const sendBtn = getByTestId("send-button");
371
+
372
+ await act(async () => {
373
+ fireEvent.change(input, { target: { value: "first" } });
374
+ });
375
+ await act(async () => {
376
+ fireEvent.click(sendBtn);
377
+ });
378
+
379
+ await act(async () => {
380
+ fireEvent.change(input, { target: { value: "second" } });
381
+ });
382
+ await act(async () => {
383
+ fireEvent.click(sendBtn);
384
+ });
385
+
386
+ const calls = hoisted.mockAgent.addMessage.mock.calls;
387
+ expect(calls[0][0].id).toBe("user-1");
388
+ expect(calls[1][0].id).toBe("user-2");
389
+ });
390
+ });
@@ -0,0 +1,257 @@
1
+ import React, { createRef } from "react";
2
+ import { render, act } from "@testing-library/react";
3
+ import { describe, it, expect, beforeEach, vi } from "vitest";
4
+
5
+ // ---------------------------------------------------------------------------
6
+ // Mocks
7
+ // ---------------------------------------------------------------------------
8
+
9
+ const hoisted = vi.hoisted(() => {
10
+ const snapToIndex = vi.fn();
11
+ const close = vi.fn();
12
+
13
+ return {
14
+ snapToIndex,
15
+ close,
16
+ lastOnClose: null as (() => void) | null,
17
+ lastSnapPoints: null as (string | number)[] | null,
18
+ lastIndex: null as number | null,
19
+ };
20
+ });
21
+
22
+ // Mock react-native primitives used in CopilotModal
23
+ vi.mock("react-native", () => ({
24
+ StyleSheet: {
25
+ create: (s: Record<string, unknown>) => s,
26
+ },
27
+ View: "View",
28
+ }));
29
+
30
+ // Mock @gorhom/bottom-sheet
31
+ vi.mock("@gorhom/bottom-sheet", () => {
32
+ const React = require("react");
33
+
34
+ // BottomSheet stores its ref and captures props for assertions
35
+ const BottomSheet = React.forwardRef(function MockBottomSheet(
36
+ props: any,
37
+ ref: any,
38
+ ) {
39
+ React.useImperativeHandle(ref, () => ({
40
+ snapToIndex: hoisted.snapToIndex,
41
+ close: hoisted.close,
42
+ }));
43
+
44
+ hoisted.lastOnClose = props.onClose ?? null;
45
+ hoisted.lastSnapPoints = props.snapPoints ?? null;
46
+ hoisted.lastIndex = props.index ?? null;
47
+
48
+ return React.createElement(
49
+ "mock-bottom-sheet",
50
+ { "data-testid": "bottom-sheet" },
51
+ props.children,
52
+ );
53
+ });
54
+
55
+ const BottomSheetView = (props: any) =>
56
+ React.createElement(
57
+ "mock-bottom-sheet-view",
58
+ { "data-testid": "bottom-sheet-view" },
59
+ props.children,
60
+ );
61
+
62
+ const BottomSheetBackdrop = (props: any) =>
63
+ React.createElement("mock-backdrop", props);
64
+
65
+ const BottomSheetFlatList = (props: any) =>
66
+ React.createElement(
67
+ "mock-bottom-sheet-flatlist",
68
+ { "data-testid": "bottom-sheet-flatlist" },
69
+ props.children,
70
+ );
71
+
72
+ return {
73
+ __esModule: true,
74
+ default: BottomSheet,
75
+ BottomSheetView,
76
+ BottomSheetBackdrop,
77
+ BottomSheetFlatList,
78
+ };
79
+ });
80
+
81
+ // Mock CopilotChat (B4's component — may not exist yet in this worktree)
82
+ vi.mock("../CopilotChat", () => {
83
+ const React = require("react");
84
+ const CopilotChat = (props: any) =>
85
+ React.createElement("mock-copilot-chat", {
86
+ "data-testid": "copilot-chat",
87
+ ...props,
88
+ });
89
+ return { CopilotChat };
90
+ });
91
+
92
+ // Import after mocks
93
+ import { CopilotModal } from "../CopilotModal";
94
+ import type { CopilotModalRef } from "../CopilotModal";
95
+
96
+ // ---------------------------------------------------------------------------
97
+ // Tests
98
+ // ---------------------------------------------------------------------------
99
+
100
+ describe("CopilotModal", () => {
101
+ beforeEach(() => {
102
+ hoisted.snapToIndex.mockClear();
103
+ hoisted.close.mockClear();
104
+ hoisted.lastOnClose = null;
105
+ hoisted.lastSnapPoints = null;
106
+ hoisted.lastIndex = null;
107
+ });
108
+
109
+ // ── Rendering ───────────────────────────────────────────────────────────
110
+
111
+ describe("rendering", () => {
112
+ it("renders the bottom sheet with default snap points", () => {
113
+ render(<CopilotModal />);
114
+
115
+ expect(hoisted.lastSnapPoints).toEqual(["50%", "90%"]);
116
+ });
117
+
118
+ it("starts closed (index -1)", () => {
119
+ render(<CopilotModal />);
120
+
121
+ expect(hoisted.lastIndex).toBe(-1);
122
+ });
123
+
124
+ it("embeds CopilotChat inside the sheet", () => {
125
+ const { getByTestId } = render(<CopilotModal />);
126
+
127
+ expect(getByTestId("copilot-chat")).toBeTruthy();
128
+ });
129
+ });
130
+
131
+ // ── Controlled visibility ─────────────────────────────────────────────
132
+
133
+ describe("controlled visibility", () => {
134
+ it("opens the sheet when visible becomes true", () => {
135
+ const { rerender } = render(<CopilotModal visible={false} />);
136
+
137
+ rerender(<CopilotModal visible={true} />);
138
+
139
+ expect(hoisted.snapToIndex).toHaveBeenCalledWith(0);
140
+ });
141
+
142
+ it("closes the sheet when visible becomes false", () => {
143
+ const { rerender } = render(<CopilotModal visible={true} />);
144
+
145
+ hoisted.snapToIndex.mockClear();
146
+
147
+ rerender(<CopilotModal visible={false} />);
148
+
149
+ expect(hoisted.close).toHaveBeenCalled();
150
+ });
151
+ });
152
+
153
+ // ── onDismiss ─────────────────────────────────────────────────────────
154
+
155
+ describe("onDismiss", () => {
156
+ it("calls onDismiss when the sheet closes", () => {
157
+ const onDismiss = vi.fn();
158
+ render(<CopilotModal onDismiss={onDismiss} />);
159
+
160
+ // Simulate bottom-sheet calling onClose
161
+ act(() => {
162
+ hoisted.lastOnClose?.();
163
+ });
164
+
165
+ expect(onDismiss).toHaveBeenCalledTimes(1);
166
+ });
167
+
168
+ it("does not call onDismiss when enableDismissOnClose is false", () => {
169
+ const onDismiss = vi.fn();
170
+ render(
171
+ <CopilotModal onDismiss={onDismiss} enableDismissOnClose={false} />,
172
+ );
173
+
174
+ act(() => {
175
+ hoisted.lastOnClose?.();
176
+ });
177
+
178
+ expect(onDismiss).not.toHaveBeenCalled();
179
+ });
180
+ });
181
+
182
+ // ── Custom snap points ────────────────────────────────────────────────
183
+
184
+ describe("custom snap points", () => {
185
+ it("uses provided snap points", () => {
186
+ render(<CopilotModal snapPoints={["25%", "75%", "100%"]} />);
187
+
188
+ expect(hoisted.lastSnapPoints).toEqual(["25%", "75%", "100%"]);
189
+ });
190
+
191
+ it("opens at the specified initialSnapIndex", () => {
192
+ const ref = createRef<CopilotModalRef>();
193
+ render(<CopilotModal ref={ref} initialSnapIndex={1} />);
194
+
195
+ act(() => {
196
+ ref.current?.open();
197
+ });
198
+
199
+ expect(hoisted.snapToIndex).toHaveBeenCalledWith(1);
200
+ });
201
+ });
202
+
203
+ // ── Imperative API ────────────────────────────────────────────────────
204
+
205
+ describe("imperative API", () => {
206
+ it("exposes open() via ref", () => {
207
+ const ref = createRef<CopilotModalRef>();
208
+ render(<CopilotModal ref={ref} />);
209
+
210
+ act(() => {
211
+ ref.current?.open();
212
+ });
213
+
214
+ expect(hoisted.snapToIndex).toHaveBeenCalledWith(0);
215
+ });
216
+
217
+ it("exposes close() via ref", () => {
218
+ const ref = createRef<CopilotModalRef>();
219
+ render(<CopilotModal ref={ref} />);
220
+
221
+ act(() => {
222
+ ref.current?.close();
223
+ });
224
+
225
+ expect(hoisted.close).toHaveBeenCalled();
226
+ });
227
+ });
228
+
229
+ // ── CopilotChat pass-through ──────────────────────────────────────────
230
+
231
+ describe("CopilotChat integration", () => {
232
+ it("passes agentName to CopilotChat", () => {
233
+ const { getByTestId } = render(<CopilotModal agentName="test-agent" />);
234
+
235
+ const chat = getByTestId("copilot-chat");
236
+ expect(chat.getAttribute("agentName")).toBe("test-agent");
237
+ });
238
+
239
+ it("passes placeholder to CopilotChat", () => {
240
+ const { getByTestId } = render(
241
+ <CopilotModal placeholder="Ask me anything..." />,
242
+ );
243
+
244
+ const chat = getByTestId("copilot-chat");
245
+ expect(chat.getAttribute("placeholder")).toBe("Ask me anything...");
246
+ });
247
+
248
+ it("passes headerTitle to CopilotChat", () => {
249
+ const { getByTestId } = render(
250
+ <CopilotModal headerTitle="AI Assistant" />,
251
+ );
252
+
253
+ const chat = getByTestId("copilot-chat");
254
+ expect(chat.getAttribute("headerTitle")).toBe("AI Assistant");
255
+ });
256
+ });
257
+ });