|
1 | 1 | // SPDX-License-Identifier: MIT |
2 | | -import { test, expect, type Locator } from '@playwright/test'; |
3 | | - |
4 | | -async function sendPrompt(page: Awaited<ReturnType<typeof import('@playwright/test').test.step>> extends never ? never : Parameters<Parameters<typeof test>[1]>[0]['page'], prompt: string): Promise<Locator> { |
5 | | - await page.goto('/embed'); |
6 | | - const input = page.getByRole('textbox', { name: /message|prompt/i }); |
7 | | - await input.fill(prompt); |
8 | | - await page.getByRole('button', { name: /send/i }).click(); |
9 | | - |
10 | | - const assistantBubble = page.locator('chat-message').filter({ hasNotText: prompt }).last(); |
11 | | - await expect(assistantBubble).toBeVisible({ timeout: 30_000 }); |
12 | | - await expect |
13 | | - .poll(async () => ((await assistantBubble.innerText()) ?? '').trim().length, { timeout: 30_000 }) |
14 | | - .toBeGreaterThan(0); |
15 | | - return assistantBubble; |
16 | | -} |
| 2 | +import { test, expect } from '@playwright/test'; |
| 3 | +import { sendPromptAndWait } from './test-helpers'; |
17 | 4 |
|
18 | 5 | test('heading: assistant bubble renders an <h1>', async ({ page }) => { |
19 | | - const bubble = await sendPrompt(page, 'respond with a heading'); |
| 6 | + const bubble = await sendPromptAndWait(page, 'respond with a heading'); |
20 | 7 | await expect(bubble.locator('h1')).toBeVisible(); |
21 | 8 | await expect(bubble.locator('h1')).toContainText(/heading one/i); |
22 | 9 | }); |
23 | 10 |
|
24 | 11 | test('code fence: assistant bubble renders <pre><code>', async ({ page }) => { |
25 | | - const bubble = await sendPrompt(page, 'respond with a code fence'); |
| 12 | + const bubble = await sendPromptAndWait(page, 'respond with a code fence'); |
26 | 13 | const codeBlock = bubble.locator('pre code'); |
27 | 14 | await expect(codeBlock).toBeVisible(); |
28 | 15 | await expect(codeBlock).toContainText('const answer = 42'); |
29 | 16 | }); |
30 | 17 |
|
31 | 18 | test('bullet list: assistant bubble renders <ul> with three <li>', async ({ page }) => { |
32 | | - const bubble = await sendPrompt(page, 'respond with a bullet list'); |
| 19 | + const bubble = await sendPromptAndWait(page, 'respond with a bullet list'); |
33 | 20 | const list = bubble.locator('ul'); |
34 | 21 | await expect(list).toBeVisible(); |
35 | 22 | await expect(list.locator('li')).toHaveCount(3); |
|
0 commit comments