fix: 修复 Web 预览宽度及底部操作栏对齐
This commit is contained in:
1 parent
7e8fc01fba
commit
e5a1a60eee
3 files changed
+52
-7
No files matched your search
@@ -79,3 +79,38 @@ test("林境模板使用真实品牌数据与独立路由", async ({ page }) =>
|
||||
});
|
||||
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);
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user