import { expect, test } from "@playwright/test" /** * 成绩模块 E2E 测试。 * 未登录场景可独立运行;登录后场景需要 DATABASE_URL。 */ test.describe("Grades", () => { test("should redirect unauthenticated user to login from teacher grades", async ({ page }) => { await page.goto("/teacher/grades") await expect(page).toHaveURL(/\/login(?:$|[/?#])/) }) test("should redirect unauthenticated user to login from student grades", async ({ page }) => { await page.goto("/student/grades") await expect(page).toHaveURL(/\/login(?:$|[/?#])/) }) test("should display teacher grades page when authenticated", async ({ page }) => { test.skip(!process.env.DATABASE_URL, "requires DATABASE_URL for authenticated flow") const email = process.env.E2E_TEACHER_EMAIL ?? "teacher@e2e.local" const password = process.env.E2E_TEACHER_PASSWORD ?? "e2e-pass-123456" await page.goto("/login") await page.getByLabel("Email").fill(email) await page.getByLabel("Password").fill(password) await page.getByRole("button", { name: "Sign In with Email" }).click() await page.goto("/teacher/grades") await expect(page.locator("body")).toBeVisible() await expect(page).not.toHaveURL(/\/login(?:$|[/?#])/) }) })