forked from CopilotKit/CopilotKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchat-slots.spec.ts
More file actions
134 lines (118 loc) · 5.19 KB
/
Copy pathchat-slots.spec.ts
File metadata and controls
134 lines (118 loc) · 5.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import { test, expect } from "@playwright/test";
// Each custom slot wraps the default in a `SlotMarker` that emits
// `data-slot-label="<slot-path>"`. That attribute is the canonical
// signal that a slot override wired through end-to-end (the welcome
// screen + disclaimer also expose dedicated `data-testid` attributes
// for ergonomics).
const SLOT_LABEL_ASSISTANT = '[data-slot-label="MessageView.AssistantMessage"]';
test.describe("Chat Slots", () => {
test.beforeEach(async ({ page }) => {
await page.goto("/demos/chat-slots");
});
test("custom welcome screen slot renders on first load", async ({ page }) => {
// The custom welcomeScreen slot replaces the default welcome. Both its
// own testid and the nested welcomeMessage sub-slot's testid prove the
// override wired through end-to-end. Asserting both catches accidental
// fallback to the default CopilotChat welcome.
const welcome = page.locator('[data-testid="custom-welcome-screen"]');
await expect(welcome).toBeVisible();
await expect(
welcome.locator('[data-testid="custom-welcome-message"]'),
).toBeVisible();
});
test("both suggestion pills render with verbatim titles", async ({
page,
}) => {
// useConfigureSuggestions registers exactly two pills with available: "always".
// Both should be visible immediately on the welcome screen.
await expect(
page
.locator('[data-testid="copilot-suggestion"]')
.filter({ hasText: "Write a sonnet" }),
).toBeVisible({ timeout: 15000 });
await expect(
page
.locator('[data-testid="copilot-suggestion"]')
.filter({ hasText: "Tell me a joke" }),
).toBeVisible({ timeout: 15000 });
});
test('clicking "Tell me a joke" shows the custom assistant message slot', async ({
page,
}) => {
// Click the suggestion pill — this sends "Tell me a short joke." The
// assistant responds with text (neutral agent, no tools), and its
// bubble must be wrapped in the CustomAssistantMessage SlotMarker.
await page
.locator('[data-testid="copilot-suggestion"]')
.filter({ hasText: "Tell me a joke" })
.first()
.click();
// The MessageView.AssistantMessage slot-marker wraps every assistant
// bubble; its presence proves the slot override took effect rather
// than the default CopilotChatAssistantMessage rendering bare.
await expect(page.locator(SLOT_LABEL_ASSISTANT).first()).toBeVisible({
timeout: 45000,
});
});
test("custom disclaimer slot renders after the first user message", async ({
page,
}) => {
// Type and send via the send button — Enter-on-textarea was intermittently
// dropping the submit on this deployment. We assert the disclaimer +
// custom assistant wrapper appear once we transition out of the welcome
// state. Use exact aimock fixture messages to ensure deterministic responses.
const input = page.getByPlaceholder("Type a message");
await input.fill("Say hello in one short sentence");
await page.locator('[data-testid="copilot-send-button"]').first().click();
// Assistant replies and is wrapped in the custom slot.
await expect(page.locator(SLOT_LABEL_ASSISTANT).first()).toBeVisible({
timeout: 45000,
});
// The custom disclaimer slot lives below the input on the post-welcome
// chat view. The welcome-screen state hides it; once the assistant
// responds the welcome is gone and the disclaimer should be visible.
await expect(page.locator('[data-testid="custom-disclaimer"]')).toBeVisible(
{ timeout: 10000 },
);
});
test("second assistant turn is also wrapped in the custom slot", async ({
page,
}) => {
const input = page.getByPlaceholder("Type a message");
const sendBtn = () =>
page.locator('[data-testid="copilot-send-button"]').first();
// Turn 1 — use exact aimock fixture messages for deterministic responses.
await input.fill("Say hello in one short sentence");
await sendBtn().click();
await expect(page.locator(SLOT_LABEL_ASSISTANT).first()).toBeVisible({
timeout: 45000,
});
// Wait for the first turn's stream to fully complete. The assistant
// message becomes visible as soon as the first chunk arrives, but the
// chat input stays in "responding" state until the full stream ends.
// Rather than race with that, wait for the assistant text to stabilize
// (no new content for 2 seconds).
const firstAssistant = page.locator(SLOT_LABEL_ASSISTANT).first();
let previousText = "";
await expect
.poll(
async () => {
const text = (await firstAssistant.textContent()) ?? "";
const stable = text.length > 0 && text === previousText;
previousText = text;
return stable;
},
{ timeout: 30000, intervals: [2000] },
)
.toBe(true);
// Turn 2 — the slot should wrap every assistant turn, not just the first.
await input.fill("Give me a fun fact");
await sendBtn().click();
// Expect at least two custom-wrapped assistant messages.
await expect
.poll(async () => await page.locator(SLOT_LABEL_ASSISTANT).count(), {
timeout: 45000,
})
.toBeGreaterThanOrEqual(2);
});
});