test(e2e): cover chat send token refresh retry

This commit is contained in:
2026-07-02 12:53:42 +08:00
parent 51987882eb
commit d8a28bb438
8 changed files with 153 additions and 12 deletions
+44 -4
View File
@@ -72,10 +72,32 @@ export async function dismissChatInterruptions(page: Page) {
}
export async function switchToEmailSignIn(page: Page) {
await page.getByRole("button", { name: /Other Sign In Options/i }).click();
await expect(
page.getByRole("dialog", { name: /Other sign-in options/i }),
).toBeVisible();
const otherOptionsButton = page.getByRole("button", {
name: /Other Sign In Options/i,
});
const otherOptionsDialog = page.getByRole("dialog", {
name: /Other sign-in options/i,
});
await expect(otherOptionsButton).toBeVisible({ timeout: 10_000 });
await expect(otherOptionsButton).toBeEnabled();
for (let attempt = 0; attempt < 3; attempt += 1) {
await otherOptionsButton.click();
try {
await expect(otherOptionsDialog).toBeVisible({ timeout: 2_000 });
break;
} catch (error) {
if (attempt === 2) throw error;
await otherOptionsButton.evaluate((button) =>
(button as HTMLButtonElement).click(),
);
if (await otherOptionsDialog.isVisible().catch(() => false)) {
break;
}
await page.waitForTimeout(500);
}
}
await page.getByRole("button", { name: "Email Sign In" }).click();
await expect(page.getByPlaceholder("Email")).toHaveValue(
@@ -176,3 +198,21 @@ export async function expectInsufficientCreditsDialog(page: Page) {
return insufficientCreditsDialog;
}
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");
}