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

image-gen.spec.ts

69 lines2.5 KB

1import { test, expect } from './fixtures'
2import {
3 fillPrompt,
4 clickGenerate,
5 waitForGenerationComplete,
6 featureUrl,
7} from './helpers'
8import { providersFor } from './test-matrix'
9​
10for (const provider of providersFor('image-gen')) {
11 test.describe(`${provider} -- image-gen`, () => {
12 test('sse -- generates images via SSE connection', async ({
13 page,
14 testId,
15 aimockPort,
16 }) => {
17 await page.goto(
18 featureUrl(provider, 'image-gen', testId, aimockPort, 'sse'),
19 )
20 await fillPrompt(page, 'a guitar in a music store')
21 await clickGenerate(page)
22 await waitForGenerationComplete(page)
23 await expect(page.getByTestId('active-run-id')).not.toHaveText('')
24 await expect(page.getByTestId('active-status')).toHaveText('generating')
25 await expect(page.getByTestId('active-loading')).toHaveText('true')
26 await expect(page.getByTestId('final-run-id')).toHaveText('')
27 const images = page.getByTestId('generated-image')
28 await expect(images).toHaveCount(1)
29 })
30​
31 test('http-stream -- generates images via HTTP stream', async ({
32 page,
33 testId,
34 aimockPort,
35 }) => {
36 await page.goto(
37 featureUrl(provider, 'image-gen', testId, aimockPort, 'http-stream'),
38 )
39 await fillPrompt(page, 'a guitar in a music store')
40 await clickGenerate(page)
41 await waitForGenerationComplete(page)
42 await expect(page.getByTestId('active-run-id')).not.toHaveText('')
43 await expect(page.getByTestId('active-status')).toHaveText('generating')
44 await expect(page.getByTestId('active-loading')).toHaveText('true')
45 await expect(page.getByTestId('final-run-id')).toHaveText('')
46 const images = page.getByTestId('generated-image')
47 await expect(images).toHaveCount(1)
48 })
49​
50 test('fetcher -- generates images via server function', async ({
51 page,
52 testId,
53 aimockPort,
54 }) => {
55 await page.goto(
56 featureUrl(provider, 'image-gen', testId, aimockPort, 'fetcher'),
57 )
58 await fillPrompt(page, 'a guitar in a music store')
59 await clickGenerate(page)
60 await waitForGenerationComplete(page)
61 await expect(page.getByTestId('active-run-id')).not.toHaveText('')
62 await expect(page.getByTestId('active-status')).toHaveText('generating')
63 await expect(page.getByTestId('active-loading')).toHaveText('true')
64 await expect(page.getByTestId('final-run-id')).toHaveText('')
65 const images = page.getByTestId('generated-image')
66 await expect(images).toHaveCount(1)
67 })
68 })