26 lines
943 B
TypeScript
26 lines
943 B
TypeScript
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("ab123c4");
|
|
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();
|
|
});
|