import { test, expect } from '@playwright/test'; import { openApp } from '../fixtures/app.js'; import { SIXTY_MP4 } from '../fixtures/media.js'; test.describe('generate flow', () => { test('uploads a file, posts it to /api/process and renders the clips', async ({ page }) => { await openApp(page, { mocks: { statusSequence: ['processing', 'completed'] } }); await page.setInputFiles('input[type="file"][accept="video/*"]', SIXTY_MP4); await page.locator('form input[type="checkbox"]').first().check(); const requestPromise = page.waitForRequest( (r) => r.method() === 'POST' && r.url().includes('/api/process'), ); await page.getByRole('button', { name: /generate clips/i }).click(); const request = await requestPromise; expect(request.headers()['x-gemini-key']).toBe('e2e-gemini-key'); expect(request.headers()['content-type']).toContain('multipart/form-data'); // The multipart body carries the chosen file and the attestation. const body = request.postDataBuffer().toString('latin1'); expect(body).toContain('sixty.mp4'); expect(body).toContain('acknowledged'); // Polling is driven by the app's own 2s interval; auto-wait absorbs it. await expect(page.getByRole('heading', { name: 'First viral clip' })).toBeVisible(); await expect(page.getByRole('heading', { name: 'Second viral clip' })).toBeVisible(); await expect(page.getByText('2 Clips')).toBeVisible(); }); test('submits a YouTube URL as JSON with the Gemini header', async ({ page }) => { await openApp(page); await page.getByRole('button', { name: /video url/i }).click(); await page.getByPlaceholder(/paste a video link/i).fill('https://www.youtube.com/watch?v=dQw4w9WgXcQ'); await page.locator('form input[type="checkbox"]').first().check(); const requestPromise = page.waitForRequest( (r) => r.method() === 'POST' && r.url().includes('/api/process'), ); await page.getByRole('button', { name: /generate clips/i }).click(); const request = await requestPromise; expect(request.postDataJSON()).toMatchObject({ url: 'https://www.youtube.com/watch?v=dQw4w9WgXcQ', acknowledged: true, force_low_quality: false, }); await expect(page.getByRole('heading', { name: 'First viral clip' })).toBeVisible(); }); });