feat(frontend): prefill demo credentials on login page + E2E test passed
This commit is contained in:
@@ -0,0 +1,24 @@
|
|||||||
|
/** 登录页预填测试账号验证。 */
|
||||||
|
|
||||||
|
import { test, expect, type Page } from "@playwright/test";
|
||||||
|
|
||||||
|
test.use({ viewport: { width: 1280, height: 720 } });
|
||||||
|
|
||||||
|
test("登录页预填演示账号并登录成功", async ({ page }: { page: Page }) => {
|
||||||
|
await page.goto("/login");
|
||||||
|
await page.waitForLoadState("networkidle");
|
||||||
|
|
||||||
|
// 验证邮箱和密码已预填
|
||||||
|
await expect(page.locator('input[id="email"]')).toHaveValue("gp@demo.com");
|
||||||
|
await expect(page.locator('input[id="password"]')).toHaveValue("demo123456");
|
||||||
|
|
||||||
|
// 验证演示账号提示存在
|
||||||
|
await expect(page.getByText("演示账号")).toBeVisible();
|
||||||
|
|
||||||
|
// 点击登录
|
||||||
|
await page.click('button[type="submit"]');
|
||||||
|
await expect(page).toHaveURL(/\/dashboard|\/today/);
|
||||||
|
|
||||||
|
// 验证已登录(侧边栏出现)
|
||||||
|
await expect(page.locator("aside")).toBeVisible();
|
||||||
|
});
|
||||||
@@ -11,8 +11,8 @@ import { useAuth } from "@/lib/auth-context";
|
|||||||
export default function LoginPage() {
|
export default function LoginPage() {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const { login } = useAuth();
|
const { login } = useAuth();
|
||||||
const [email, setEmail] = useState("");
|
const [email, setEmail] = useState("gp@demo.com");
|
||||||
const [password, setPassword] = useState("");
|
const [password, setPassword] = useState("demo123456");
|
||||||
const [error, setError] = useState("");
|
const [error, setError] = useState("");
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
|
|
||||||
@@ -102,6 +102,13 @@ export default function LoginPage() {
|
|||||||
{isLoading ? "登录中..." : "登录"}
|
{isLoading ? "登录中..." : "登录"}
|
||||||
</button>
|
</button>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
{/* 演示账号提示 */}
|
||||||
|
<div className="mt-4 rounded-md border border-indigo-100 bg-indigo-50/50 p-3 text-xs text-muted-foreground">
|
||||||
|
<p className="font-medium text-indigo-600">演示账号</p>
|
||||||
|
<p className="mt-1">邮箱:gp@demo.com</p>
|
||||||
|
<p>密码:demo123456</p>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user