新增 E2E 测试配置与用例并更新测试补充文档
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
import { test, expect } from "@playwright/test";
|
||||
|
||||
test("首页模式卡片可正确导航", async ({ page }) => {
|
||||
await page.goto("/");
|
||||
await expect(page.getByRole("heading", { name: "NoWhatever" })).toBeVisible();
|
||||
|
||||
await page.getByRole("button", { name: /极速救场/ }).click();
|
||||
await expect(page).toHaveURL(/\/panic$/);
|
||||
|
||||
await page.getByRole("button", { name: "返回" }).click();
|
||||
await expect(page).toHaveURL(/\/$/);
|
||||
|
||||
await page.getByRole("button", { name: /周末契约/ }).click();
|
||||
await expect(page).toHaveURL(/\/blindbox$/);
|
||||
});
|
||||
@@ -0,0 +1,35 @@
|
||||
import { test, expect } from "@playwright/test";
|
||||
|
||||
test("邀请页可展示房间信息并完成加入", async ({ page }) => {
|
||||
const joinBodies: Array<{ userId?: string }> = [];
|
||||
|
||||
await page.route("**/api/room/ROOM01", async (route) => {
|
||||
if (route.request().method() !== "GET") {
|
||||
await route.fallback();
|
||||
return;
|
||||
}
|
||||
|
||||
await route.fulfill({
|
||||
status: 200,
|
||||
contentType: "application/json",
|
||||
body: JSON.stringify({ userCount: 2, scene: "eat" }),
|
||||
});
|
||||
});
|
||||
|
||||
await page.route("**/api/room/ROOM01/join", async (route) => {
|
||||
const body = route.request().postDataJSON() as { userId?: string } | null;
|
||||
joinBodies.push(body ?? {});
|
||||
await route.fulfill({ status: 200, contentType: "application/json", body: "{}" });
|
||||
});
|
||||
|
||||
await page.goto("/invite/ROOM01");
|
||||
|
||||
await expect(page.getByText("ROOM01")).toBeVisible();
|
||||
await expect(page.getByText("已有 2 人在房间")).toBeVisible();
|
||||
|
||||
await page.getByRole("button", { name: "加入房间" }).click();
|
||||
await expect(page).toHaveURL(/\/room\/ROOM01$/);
|
||||
|
||||
expect(joinBodies.length).toBeGreaterThan(0);
|
||||
expect(joinBodies[0]?.userId).toBeTruthy();
|
||||
});
|
||||
@@ -0,0 +1,25 @@
|
||||
import { test, expect } from "@playwright/test";
|
||||
|
||||
test("Panic 手动加入房间会规范化房间号并发起 join 请求", async ({ page }) => {
|
||||
const joinBodies: Array<{ userId?: string }> = [];
|
||||
|
||||
await page.route("**/api/room/*/join", async (route) => {
|
||||
const body = route.request().postDataJSON() as { userId?: string } | null;
|
||||
joinBodies.push(body ?? {});
|
||||
await route.fulfill({ status: 200, contentType: "application/json", body: "{}" });
|
||||
});
|
||||
|
||||
await page.goto("/panic");
|
||||
|
||||
const roomInput = page.getByPlaceholder("输入 6 位房间号");
|
||||
await roomInput.fill("ab-12@3c4");
|
||||
await expect(roomInput).toHaveValue("AB123C");
|
||||
|
||||
const joinButton = page.getByRole("button", { name: "加入房间" });
|
||||
await expect(joinButton).toBeEnabled();
|
||||
await joinButton.click();
|
||||
|
||||
await expect(page).toHaveURL(/\/room\/AB123C$/);
|
||||
expect(joinBodies.length).toBeGreaterThan(0);
|
||||
expect(joinBodies[0]?.userId).toBeTruthy();
|
||||
});
|
||||
Reference in New Issue
Block a user