178 lines
8.0 KiB
TypeScript
178 lines
8.0 KiB
TypeScript
import { test, expect } from "@playwright/test";
|
|
test("真实 API 驱动首页、出摊和主理人视觉槽位", async ({ page }) => {
|
|
const errors: string[] = [];
|
|
page.on("pageerror", (error) => errors.push(error.message));
|
|
await page.goto("/");
|
|
await expect(page.locator(".food-home .name")).toContainText("阿成");
|
|
await expect(page.locator(".food-home .actions button")).toHaveCount(2);
|
|
const actionBounds = await page.locator(".food-home .actions button").evaluateAll((buttons) => {
|
|
const parent = buttons[0].parentElement!.getBoundingClientRect();
|
|
return buttons.map((button) => button.getBoundingClientRect().right - parent.right);
|
|
});
|
|
expect(Math.max(...actionBounds)).toBeLessThanOrEqual(1);
|
|
const actionStyles = await page
|
|
.locator(".food-home .actions button")
|
|
.first()
|
|
.evaluate((button) => {
|
|
const style = getComputedStyle(button);
|
|
return { margin: style.margin, borderWidth: style.borderWidth, padding: style.padding };
|
|
});
|
|
expect(actionStyles.margin).toBe("0px");
|
|
expect(actionStyles.borderWidth).toBe("0px");
|
|
const widths = await page.locator(".scene").evaluate((element) => ({
|
|
image: element.getBoundingClientRect().width,
|
|
parent: element.parentElement!.getBoundingClientRect().width,
|
|
}));
|
|
expect(Math.abs(widths.image - widths.parent)).toBeLessThan(2);
|
|
await page.getByText("出摊服务", { exact: true }).click();
|
|
await expect(page.locator(".schedule")).toHaveCount(2);
|
|
await expect(page.locator(".process-action")).toHaveCount(1);
|
|
const processAction = await page.locator(".process-action").boundingBox();
|
|
const processFoot = await page.locator(".process-foot").boundingBox();
|
|
expect(processAction!.x + processAction!.width).toBeLessThanOrEqual(
|
|
processFoot!.x + processFoot!.width + 1,
|
|
);
|
|
await expect(page.locator(".delivery-item")).toHaveCount(2);
|
|
await expect(page.locator(".step")).toHaveCount(4);
|
|
await page.screenshot({
|
|
path: "../../.codex-tasks/taro-migration/raw/food-service.png",
|
|
fullPage: true,
|
|
});
|
|
await page.getByText("主理人", { exact: true }).click();
|
|
await expect(page.locator(".standard")).toHaveCount(3);
|
|
await expect(page.locator(".case-row")).toHaveCount(3);
|
|
await expect(page.locator(".commitment")).toHaveCount(2);
|
|
await page.screenshot({
|
|
path: "../../.codex-tasks/taro-migration/raw/food-profile.png",
|
|
fullPage: true,
|
|
});
|
|
expect(errors).toEqual([]);
|
|
});
|
|
test("餐品搜索、详情和咨询目标传递", async ({ page }) => {
|
|
await page.goto("/#/pages/offerings/index");
|
|
await expect(page.locator(".offering-card").first()).toBeVisible();
|
|
await page.locator("input").fill("不存在的餐品名称");
|
|
await expect(page.getByText("没有找到相关餐品,换个词试试")).toBeVisible();
|
|
await page.locator("input").fill("");
|
|
const name = await page.locator(".dish-name").first().textContent();
|
|
await page.locator(".offering-card").first().click();
|
|
await expect(page.locator(".hero-copy")).toContainText(name!);
|
|
await page.locator(".bar taro-button-core").click();
|
|
await expect(page.locator(".inquiry-form")).toBeVisible();
|
|
await expect(page.locator(".half-field")).toHaveCount(4);
|
|
});
|
|
test("失败和未登录不清空表单,不伪造提交成功", async ({ page }) => {
|
|
await page.goto("/#/pages/inquiry/index");
|
|
await expect(page.locator(".inquiry-form")).toBeVisible();
|
|
await page.locator(".submit-button").click();
|
|
await expect(page.locator(".form-error")).toContainText("请填写");
|
|
const input = page.locator("input:not([type=hidden])").last();
|
|
await input.fill("13800138000");
|
|
await page.locator(".submit-button").click();
|
|
await expect(input).toHaveValue("13800138000");
|
|
await expect(page).not.toHaveURL(/success/);
|
|
});
|
|
test("加载失败提供重试", async ({ page }) => {
|
|
await page.route("**/public/workspace**", (route) =>
|
|
route.fulfill({
|
|
status: 503,
|
|
contentType: "application/json",
|
|
body: JSON.stringify({ error: { message: "测试服务暂不可用" } }),
|
|
}),
|
|
);
|
|
await page.goto("/");
|
|
await expect(page.getByText("测试服务暂不可用")).toBeVisible();
|
|
await expect(page.getByText("重试")).toBeVisible();
|
|
});
|
|
|
|
test("林境模板使用真实品牌数据与独立路由", async ({ page }) => {
|
|
const errors: string[] = [];
|
|
page.on("pageerror", (error) => errors.push(error.message));
|
|
await page.goto("http://localhost:3003/");
|
|
await expect(page.locator(".founder-name")).toContainText("林");
|
|
await expect(page.locator(".stat-value")).toHaveCount(4);
|
|
await page.getByText("主理人与我", { exact: true }).click();
|
|
await expect(page.locator(".editorial-profile .founder")).toBeVisible();
|
|
await expect(page.locator(".trust-card").first()).toBeVisible();
|
|
await page.screenshot({
|
|
path: "../../.codex-tasks/taro-migration/raw/linjing-profile.png",
|
|
fullPage: true,
|
|
});
|
|
expect(errors).toEqual([]);
|
|
});
|
|
|
|
for (const width of [375, 430, 768, 1280]) {
|
|
test(`预览宽度 ${width}:页面与导航对齐且无横向溢出`, async ({ page }) => {
|
|
await page.setViewportSize({ width, height: 900 });
|
|
await page.goto("/");
|
|
await expect(page.locator(".food-home .name")).toBeVisible();
|
|
const expectedWidth = Math.min(width, 430);
|
|
const bounds = await page.evaluate(() => {
|
|
const rect = (selector: string) => {
|
|
const box = document.querySelector(selector)!.getBoundingClientRect();
|
|
return { width: box.width, left: box.left };
|
|
};
|
|
return {
|
|
page: rect(".food-home .page"),
|
|
tab: rect(".taro-tabbar__tabbar"),
|
|
overflow: document.documentElement.scrollWidth > window.innerWidth,
|
|
};
|
|
});
|
|
expect(bounds.page.width).toBeCloseTo(expectedWidth, 0);
|
|
expect(bounds.tab.width).toBeCloseTo(expectedWidth, 0);
|
|
expect(bounds.tab.left).toBeCloseTo(bounds.page.left, 0);
|
|
expect(bounds.overflow).toBe(false);
|
|
await page.goto("/#/pages/offerings/index");
|
|
await page.locator(".offering-card").first().click();
|
|
await expect(page.locator(".bar")).toBeVisible();
|
|
await expect
|
|
.poll(async () => {
|
|
const bar = await page.locator(".bar").boundingBox();
|
|
return Math.abs(bar!.x - (width - expectedWidth) / 2);
|
|
})
|
|
.toBeLessThan(1);
|
|
const bar = await page.locator(".bar").boundingBox();
|
|
expect(bar!.width).toBeCloseTo(expectedWidth, 0);
|
|
});
|
|
}
|
|
|
|
for (const width of [375, 1280]) {
|
|
test(`餐饮控件与底部避让 ${width}`, async ({ page }) => {
|
|
await page.setViewportSize({ width, height: 812 });
|
|
const scrollToBottom = async () => {
|
|
await page.evaluate(() => {
|
|
document.querySelectorAll("*").forEach((element) => {
|
|
if (/auto|scroll/.test(getComputedStyle(element).overflowY))
|
|
element.scrollTop = element.scrollHeight;
|
|
});
|
|
window.scrollTo(0, document.body.scrollHeight);
|
|
});
|
|
};
|
|
const aboveNavigation = async (selector: string) => {
|
|
const bottom = await page.locator(selector).last().boundingBox();
|
|
const nav = await page.locator(".taro-tabbar__tabbar").boundingBox();
|
|
expect(bottom!.y + bottom!.height).toBeLessThan(nav!.y - 8);
|
|
};
|
|
await page.goto("/");
|
|
await expect(page.locator(".food-home .promise").last()).toBeAttached();
|
|
await scrollToBottom();
|
|
await aboveNavigation(".food-home .promise");
|
|
await page.goto("/#/pages/offerings/index");
|
|
await expect(page.locator(".filter").first()).toBeVisible();
|
|
const filters = await page
|
|
.locator(".filter")
|
|
.evaluateAll((elements) => elements.map((element) => element.getBoundingClientRect().width));
|
|
expect(filters[0]).toBeLessThan(200);
|
|
await page.locator(".filter").nth(1).click();
|
|
await expect(page.locator(".filter").nth(1)).toHaveClass(/active/);
|
|
await page.goto("/#/pages/inquiry/index");
|
|
await expect(page.locator(".submit-button")).toBeVisible();
|
|
await scrollToBottom();
|
|
await aboveNavigation(".history-link");
|
|
const button = await page.locator(".submit-button").boundingBox();
|
|
expect(button!.height).toBeGreaterThanOrEqual(44);
|
|
await page.locator(".submit-button").click();
|
|
await expect(page.locator(".form-error")).toContainText("请填写");
|
|
});
|
|
}
|