forked from CopilotKit/CopilotKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshared-state-write.spec.ts
More file actions
113 lines (97 loc) · 3.94 KB
/
Copy pathshared-state-write.spec.ts
File metadata and controls
113 lines (97 loc) · 3.94 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
import { test, expect } from "@playwright/test";
test.describe("Shared State (Writing)", () => {
test.beforeEach(async ({ page }) => {
await page.goto("/demos/shared-state-write");
});
test("page loads with Sales Pipeline dashboard", async ({ page }) => {
await expect(page.getByText("Sales Pipeline")).toBeVisible({
timeout: 10000,
});
});
test("sidebar is open with Sales Pipeline Assistant title", async ({
page,
}) => {
await expect(page.getByText("Sales Pipeline Assistant")).toBeVisible({
timeout: 10000,
});
});
test("dashboard shows pipeline summary with Total Pipeline metric", async ({
page,
}) => {
await expect(page.getByText("Total Pipeline")).toBeVisible({
timeout: 10000,
});
});
test("can send message through sidebar and get response", async ({
page,
}) => {
const input = page.locator('textarea, [placeholder*="message"]').first();
await input.fill("Add a new deal for Acme Corp worth $50,000");
await input.press("Enter");
await expect(page.locator('[data-role="assistant"]').first()).toBeVisible({
timeout: 30000,
});
});
test("deal list shows empty state or active deals with interactive elements", async ({
page,
}) => {
// Dashboard should show either deals or the empty state with an "Add a deal" button
const addButton = page.getByRole("button", { name: /add a deal/i });
const activeDealsList = page.getByText("Active Deals");
await expect(addButton.or(activeDealsList).first()).toBeVisible({
timeout: 10000,
});
});
test("agent can modify dashboard state through chat", async ({ page }) => {
const input = page.locator('textarea, [placeholder*="message"]').first();
await input.fill(
"Create three sample deals: Widget Co for $10,000, Gadget Inc for $25,000, and Tech LLC for $50,000",
);
await input.press("Enter");
// Wait for agent to respond
await expect(page.locator('[data-role="assistant"]').first()).toBeVisible({
timeout: 45000,
});
// After the agent writes state, the dashboard should reflect deals
// Either "Active Deals" heading appears or the pipeline values change
await expect(
page.getByText("Active Deals").or(page.getByText(/\$\d{1,3}(,\d{3})*/)),
).toBeVisible({ timeout: 30000 });
});
test("can add a deal via UI button", async ({ page }) => {
// Look for an "Add" or "+" button on the dashboard
const addBtn = page.locator('button:has-text("Add"), button:has-text("+")');
await expect(addBtn.first()).toBeVisible({ timeout: 5000 });
const initialCount = await page
.locator('[data-testid="todo-card"], .todo-card')
.count();
await addBtn.first().click();
// New item should appear
await expect(
page.locator('[data-testid="todo-card"], .todo-card'),
).toHaveCount(initialCount + 1, { timeout: 5000 });
});
test("can toggle a deal completion via checkbox", async ({ page }) => {
// First create some deals via chat so checkboxes exist
const input = page.locator('textarea, [placeholder*="message"]').first();
await input.fill("Add a deal for Demo Corp worth $20,000");
await input.press("Enter");
await expect(page.locator('[data-role="assistant"]').first()).toBeVisible({
timeout: 30000,
});
const toggleBtn = page.locator('[data-testid="toggle-completed"]').first();
await expect(toggleBtn).toBeVisible({ timeout: 5000 });
// The toggle is a styled button, not a native checkbox.
// Check whether the card has the completed opacity class before/after click.
const card = page.locator('[data-testid="todo-card"]').first();
const hadOpacity = await card.evaluate((el) =>
el.classList.contains("opacity-60"),
);
await toggleBtn.click();
if (hadOpacity) {
await expect(card).not.toHaveClass(/opacity-60/, { timeout: 3000 });
} else {
await expect(card).toHaveClass(/opacity-60/, { timeout: 3000 });
}
});
});