Skip to content
Source
Sign inSign up
TanStack/ai
Open History to see the last commit

abort.spec.ts

52 lines1.6 KB

1import { test, expect } from './fixtures'
2import { featureUrl } from './helpers'
3​
4// Fixture is loaded from fixtures/abort/basic.json (static, shared across workers)
5​
6test.describe('Abort/Cancellation', () => {
7 test('stop button appears during loading and stops generation', async ({
8 page,
9 testId,
10 aimockPort,
11 }) => {
12 await page.goto(featureUrl('openai', 'chat', testId, aimockPort))
13​
14 // Type and send
15 const input = page.getByTestId('chat-input')
16 await input.click()
17 await input.fill('[abort-test] tell me a long story')
18 await input.dispatchEvent('input', { bubbles: true })
19 await page
20 .getByTestId('send-button')
21 .click({ timeout: 5000 })
22 .catch(async () => {
23 const isDisabled = await page.getByTestId('send-button').isDisabled()
24 if (!isDisabled) throw new Error('Send button click failed')
25 await input.clear()
26 await input.pressSequentially('[abort-test] tell me a long story', {
27 delay: 30,
28 })
29 await page.getByTestId('send-button').click()
30 })
31​
32 // Wait for loading to start (proves the request was sent)
33 await expect(page.getByTestId('loading-indicator')).toBeVisible({
34 timeout: 10000,
35 })
36​
37 // Stop button should be visible during loading
38 const stopButton = page.getByTestId('stop-button')
39 await expect(stopButton).toBeVisible({ timeout: 5000 })
40​
41 // Click stop
42 await stopButton.click()
43​
44 // Loading should stop
45 await expect(page.getByTestId('loading-indicator')).not.toBeVisible({
46 timeout: 10000,
47 })
48​
49 // Stop button should disappear
50 await expect(stopButton).not.toBeVisible()
51 })
52})