import { test, expect } from '@playwright/test' import { mockSchoolApi } from './_helpers' /** * E2E tests for the Phase 8 export functionality on /stundenplan. * Split into its own file so stundenplan.spec.ts stays under the 500 LOC * budget enforced by the pre-commit hook. */ const exportOpts = () => ({ solutions: [ { id: 's1', created_by_user_id: 'u', name: 'Plan A', status: 'completed', hard_score: 0, soft_score: 0, created_at: '2026-05-22T10:00:00Z' }, ], lessons: [ { id: 'l1', solution_id: 's1', class_id: 'c1', subject_id: 'sub1', teacher_id: 't1', room_id: 'r1', day_of_week: 1, period_index: 1, pinned: false, created_at: '', class_name: '5a', subject_name: 'Mathe', teacher_name: 'Schmidt, Anna', room_name: 'A101' }, ], }) test.describe('Stundenplan — Export buttons', () => { test('export buttons are rendered on the PlanView', async ({ page }) => { await mockSchoolApi(page, exportOpts()) await page.goto('/stundenplan') await page.waitForLoadState('networkidle') await page.getByRole('button', { name: 'Anzeigen' }).click() await expect(page.getByTestId('export-csv')).toBeVisible() await expect(page.getByTestId('export-ics')).toBeVisible() await expect(page.getByTestId('export-print')).toBeVisible() }) test('CSV download triggers a fetch to export.csv', async ({ page }) => { await mockSchoolApi(page, exportOpts()) await page.goto('/stundenplan') await page.waitForLoadState('networkidle') await page.getByRole('button', { name: 'Anzeigen' }).click() const downloadPromise = page.waitForEvent('download') await page.getByTestId('export-csv').click() const download = await downloadPromise expect(download.suggestedFilename()).toContain('.csv') }) test('ICS download triggers a fetch to export.ics', async ({ page }) => { await mockSchoolApi(page, exportOpts()) await page.goto('/stundenplan') await page.waitForLoadState('networkidle') await page.getByRole('button', { name: 'Anzeigen' }).click() const downloadPromise = page.waitForEvent('download') await page.getByTestId('export-ics').click() const download = await downloadPromise expect(download.suggestedFilename()).toContain('.ics') }) })