import { test, expect } from '@playwright/test'; const API_BASE = 'http://localhost:8000'; test.describe('API Endpoints', () => { test('health check', async ({ request }) => { const response = await request.get(`${API_BASE}/health`); expect(response.ok()).toBeTruthy(); expect(await response.json()).toHaveProperty('status'); }); test('historical aggregation API', async ({ request }) => { const response = await request.get( `${API_BASE}/api/history/aggregated?start_date=2022-12-01&end_date=2022-12-31` ); expect(response.ok()).toBeTruthy(); const data = await response.json(); expect(data).toHaveProperty('aggregations'); expect(data).toHaveProperty('total_records'); }); test('grids geojson API', async ({ request }) => { const response = await request.get( `${API_BASE}/api/grids/geojson?date=2022-12-15` ); expect(response.ok()).toBeTruthy(); const data = await response.json(); expect(data).toHaveProperty('type', 'FeatureCollection'); expect(data).toHaveProperty('features'); }); test('multi-day prediction API', async ({ request }) => { const response = await request.post(`${API_BASE}/api/predict/multi-day`, { data: { date: '2022-12-15', days: 3 }, headers: { 'Content-Type': 'application/json' }, }); expect(response.ok()).toBeTruthy(); const data = await response.json(); expect(data).toHaveProperty('predictions'); expect(data).toHaveProperty('date_range'); }); test('grid history API', async ({ request }) => { const response = await request.get( `${API_BASE}/api/grids/r100_c200/history?days=7` ); expect(response.ok()).toBeTruthy(); const data = await response.json(); expect(data).toHaveProperty('grid_id'); expect(data).toHaveProperty('history'); }); }); test.describe('Frontend Pages', () => { test.beforeEach(async ({ page }) => { await page.goto('http://localhost:3000'); }); test('home page loads', async ({ page }) => { await expect(page).toHaveTitle(/CBPOA|监测|预警/); }); test('monitoring dashboard has timeline', async ({ page }) => { await page.goto('http://localhost:3000/monitoring'); await expect(page.locator('text=累计病例')).toBeVisible({ timeout: 10000 }); }); test('no console errors on load', async ({ page }) => { const errors: string[] = []; page.on('console', (msg) => { if (msg.type() === 'error') { errors.push(msg.text()); } }); await page.goto('http://localhost:3000'); await page.waitForTimeout(2000); const filteredErrors = errors.filter( (e) => !e.includes('favicon') && !e.includes('404') ); expect(filteredErrors).toHaveLength(0); }); });