import { expect, test } from '@playwright/test' // A previously installed PWA worker can bypass the API mocks used by this test. test.use({ serviceWorkers: 'block' }) const routes: Record = { SuperAdmin: ['/teaching-monitoring', '/campus-registrations', '/plugins', '/official-documents'], Teacher: ['/dashboard', '/account', '/teaching-preferences', '/my-timetable', '/teacher-roster', '/teacher-attendance', '/classroom-reservations', '/experiments', '/experiment-grades', '/grades', '/grade-analytics', '/exams', '/makeup-exams', '/course-adjustments', '/notifications', '/academic-calendar', '/approvals', '/evaluations'], Student: ['/dashboard', '/account', '/my-profile', '/my-curriculum', '/academic-planning', '/my-timetable', '/my-attendance', '/free-classrooms', '/classroom-reservations', '/campus-registrations', '/tuition', '/dormitory-services', '/dormitory-hygiene', '/experiments', '/experiment-grades', '/course-selections', '/grades', '/academic-overview', '/other-exams', '/physical-fitness', '/comprehensive-assessments', '/exams', '/makeup-exams', '/notifications', '/academic-calendar', '/approvals', '/warnings', '/student-status-changes', '/official-documents', '/graduation-audits', '/degree-awards', '/graduation-clearance', '/evaluations'], } const plugins = ['statistics', 'experiments', 'campus-services', 'evaluations', 'examinations', 'physical-fitness', 'comprehensive-assessment', 'student-services', 'graduation'] for (const [role, paths] of Object.entries(routes)) { test(`${role} routes fit mobile and desktop with unavailable business data`, async ({ page }) => { test.setTimeout(240_000) const user = { id: 'layout-user', userName: 'layout-user', displayName: '测试用户', roles: [role], permissions: role === 'SuperAdmin' ? ['system.plugins.manage'] : [], effectiveDataScope: role === 'SuperAdmin' ? 'All' : 'Self' } await page.addInitScript(savedUser => { localStorage.setItem('jiaowu_token', 'layout-test-token') localStorage.setItem('jiaowu_user', JSON.stringify(savedUser)) localStorage.setItem('jiaowu_access_expires_at', '2099-01-01T00:00:00Z') localStorage.setItem('jiaowu_session_expires_at', '2099-01-01T00:00:00Z') }, user) await page.route(url => url.pathname.startsWith('/api/'), route => { const path = new URL(route.request().url()).pathname if (path === '/api/auth/me') return route.fulfill({ json: user }) if (path === '/api/plugins/runtime') return route.fulfill({ json: plugins.map(id => ({ id: `mingxu.${id}`, isEnabled: true, navigationPaths: [], capabilities: [] })) }) if (path === '/api/licenses/status') return route.fulfill({ json: { isLicensed: true } }) if (path === '/api/dashboard') return route.fulfill({ json: { greeting: { title: '测试教师', subtitle: '测试学期', narrative: '页面布局检查', label: '概览', insights: [] } } }) if (path === '/api/grades/sheets') return route.fulfill({ json: { items: [], total: 0 } }) return route.fulfill({ status: 503, json: { message: 'Test data unavailable' } }) }) const failures: string[] = [] for (const width of [390, 1024]) { await page.setViewportSize({ width, height: 844 }) for (const path of paths) { await page.goto(path, { waitUntil: 'domcontentloaded' }) try { await expect(page.locator('h1, h2').first()).toBeVisible({ timeout: 8000 }) if (new URL(page.url()).pathname !== path) failures.push(`${width} ${path}: redirected to ${page.url()}`) const overflow = await page.evaluate(() => document.documentElement.scrollWidth - window.innerWidth) if (overflow > 1) failures.push(`${width} ${path}: horizontal overflow ${overflow}px`) } catch { failures.push(`${width} ${path}: heading did not render (${page.url()})`) } } } expect(failures).toEqual([]) }) }