linkify.spec.ts

 1import { test, expect } from "@playwright/test";
 2
 3// Test that URLs in agent responses are properly linkified
 4// This test requires the shelley server to be running with predictable model
 5
 6test("URLs in agent responses should be linkified", async ({ page }) => {
 7  // Navigate to the app
 8  await page.goto("http://localhost:8002");
 9
10  // Wait for the app to load
11  await expect(page.locator("[data-testid='message-input']")).toBeVisible();
12
13  // Type a message that will trigger a predictable response with URLs
14  await page.locator("[data-testid='message-input']").fill("echo: Check https://example.com and https://test.com");
15  
16  // Click send
17  await page.getByRole("button", { name: "Send message" }).click();
18  
19  // Wait for response
20  await page.waitForSelector(".message-agent", { timeout: 5000 });
21  
22  // Check that URLs are linkified
23  const agentMessage = page.locator(".message-agent .text-link").first();
24  await expect(agentMessage).toBeVisible();
25  await expect(agentMessage).toHaveAttribute("href", "https://example.com/");
26  await expect(agentMessage).toHaveAttribute("target", "_blank");
27  await expect(agentMessage).toHaveAttribute("rel", "noopener noreferrer");
28  
29  // Check second URL
30  const secondLink = page.locator(".message-agent .text-link").nth(1);
31  await expect(secondLink).toBeVisible();
32  await expect(secondLink).toHaveAttribute("href", "https://test.com/");
33});
34
35test("URLs should not be linkified in user messages", async ({ page }) => {
36  // Navigate to the app
37  await page.goto("http://localhost:8002");
38
39  // Wait for the app to load
40  await expect(page.locator("[data-testid='message-input']")).toBeVisible();
41
42  // Type a message with URLs
43  await page.locator("[data-testid='message-input']").fill("echo: Visit https://example.com");
44  
45  // Click send
46  await page.getByRole("button", { name: "Send message" }).click();
47  
48  // Wait for response
49  await page.waitForSelector(".message-user", { timeout: 5000 });
50  
51  // User messages should show raw text, not linkified
52  const userMessage = page.locator(".message-user");
53  await expect(userMessage).toContainText("echo: Visit https://example.com");
54  
55  // But should not have link elements
56  await expect(userMessage.locator("a.text-link")).toHaveCount(0);
57});