refactor(e2e): organize fixtures by feature

This commit is contained in:
2026-07-16 11:49:58 +08:00
parent 764bb5a862
commit e730799aa5
28 changed files with 521 additions and 1335 deletions
+30
View File
@@ -0,0 +1,30 @@
import { expect, type Page } from "@playwright/test";
export async function completeVipPayment(page: Page) {
const createOrderRequestPromise = page.waitForRequest("**/api/payment/create-order");
const orderStatusRequestPromise = page.waitForRequest("**/api/payment/order-status**");
await page.getByRole("button", { name: /Pay and Activ/i }).click();
const createOrderRequest = await createOrderRequestPromise;
expect(createOrderRequest.postDataJSON()).toMatchObject({ planId: "vip_monthly", payChannel: "stripe" });
await orderStatusRequestPromise;
const paymentSuccessDialog = page.getByRole("alertdialog", { name: "Payment successful" });
await expect(paymentSuccessDialog).toBeVisible();
await paymentSuccessDialog.getByRole("button", { name: "OK" }).click();
}
export async function expectVipChatSubscriptionUrl(page: Page) {
await expect(page).toHaveURL(/\/subscription\?/);
const url = new URL(page.url());
expect(url.pathname).toBe("/subscription");
expect(url.searchParams.get("type")).toBe("vip");
expect(url.searchParams.get("returnTo")).toBe("chat");
}
export function expectAuthRedirectToVipChatSubscription(page: Page) {
const redirect = new URL(page.url()).searchParams.get("redirect");
expect(redirect).not.toBeNull();
const redirectUrl = new URL(redirect ?? "", "http://e2e.local");
expect(redirectUrl.pathname).toBe("/subscription");
expect(redirectUrl.searchParams.get("type")).toBe("vip");
expect(redirectUrl.searchParams.get("returnTo")).toBe("chat");
}