test(e2e): add playwright smoke coverage

This commit is contained in:
2026-06-25 14:19:38 +08:00
parent 6081f2896a
commit 5879b7acf3
10 changed files with 402 additions and 8 deletions
+39
View File
@@ -0,0 +1,39 @@
import { expect, test } from "@playwright/test";
import { mockCoreApis } from "../../fixtures/api-mocks";
test.beforeEach(async ({ context, page }) => {
await context.clearCookies();
await mockCoreApis(page);
});
test("guest can skip splash, enter chat, and send a message", async ({ page }) => {
await page.goto("/splash");
await page.getByRole("button", { name: "Skip" }).click();
await expect(page).toHaveURL(/\/chat$/);
const messageInput = page.getByRole("textbox", { name: "Message" });
await expect(messageInput).toBeVisible();
await messageInput.fill("hello e2e");
await page.getByRole("button", { name: "Send message" }).click();
await expect(page.getByText("hello e2e")).toBeVisible();
await expect(page.getByText("Hello from the E2E boyfriend.")).toBeVisible();
});
test("subscription page renders mocked plans without touching real payment", async ({
page,
}) => {
await page.goto("/splash");
await page.getByRole("button", { name: "Skip" }).click();
await expect(page).toHaveURL(/\/chat$/);
await page.goto("/subscription?type=vip");
await expect(page.getByText("Subscribe to become the VIP Member")).toBeVisible();
await expect(page.getByText("Monthly")).toBeVisible();
await expect(page.getByText("Quarterly")).toBeVisible();
await expect(page.getByRole("button", { name: /Pay and Activiate/i })).toBeVisible();
});
+57
View File
@@ -0,0 +1,57 @@
import { expect, test } from "@playwright/test";
const apiBaseURL = process.env.E2E_API_BASE_URL;
test.describe("real backend smoke", () => {
test("splash page can be opened", async ({ page }) => {
await page.goto("/splash", { waitUntil: "domcontentloaded" });
await expect(page.getByRole("button", { name: "Skip" })).toBeVisible();
await expect(
page.getByRole("button", { name: "Login with Facebook" }),
).toBeVisible();
});
test("protected subscription page redirects anonymous visitors safely", async ({
page,
}) => {
await page.goto("/subscription?type=vip", {
waitUntil: "domcontentloaded",
});
await expect(page.getByRole("button", { name: "Skip" })).toBeVisible();
await expect(page).toHaveURL(/\/splash(?:\?.*)?$/);
});
test("real payment plans API returns a usable plan list", async ({
request,
}) => {
test.skip(!apiBaseURL, "Set E2E_API_BASE_URL to test real backend APIs.");
const response = await request.get(`${apiBaseURL}/api/payment/plans`);
expect(response.ok()).toBe(true);
const body = await response.json();
expect(body.success).toBe(true);
expect(Array.isArray(body.data?.plans)).toBe(true);
expect(body.data.plans.length).toBeGreaterThan(0);
expect(body.data.plans[0]).toEqual(
expect.objectContaining({
plan_id: expect.any(String),
plan_name: expect.any(String),
amount_cents: expect.any(Number),
currency: expect.any(String),
}),
);
});
test("auth page exposes the social login entry without completing OAuth", async ({
page,
}) => {
await page.goto("/auth", { waitUntil: "domcontentloaded" });
await expect(
page.getByRole("button", { name: /facebook/i }),
).toBeVisible();
});
});