Files
plainleaf/e2e/plainleaf-mobile-workspace.test.ts
T
wushenghuaandCodex 645c04ed01 feat: 优化移动端笔记与编辑体验
手机端改用抽屉侧栏并移除底部导航,补充 Markdown 编辑工具栏,收拢开发者选项并改善社区扩展下载错误反馈。

Co-Authored-By: Codex <noreply@anthropic.com>
2026-08-13 06:42:18 +08:00

76 lines
2.5 KiB
TypeScript

import { expect, mod, test } from "./fixtures.ts";
test.use({
spaceFiles: {
"index.md": "# 首页\n",
"手机编辑.md": "用手机记录 Markdown",
},
});
test("mobile workspace stays within the viewport and exposes Markdown tools", async ({
sbPage,
sbServer,
}) => {
await sbPage.setViewportSize({ width: 390, height: 844 });
await sbPage.goto(
`${sbServer.url}/${encodeURIComponent("手机编辑")}?headless=1`,
);
await sbPage.locator("#sb-editor .cm-editor").waitFor({ state: "visible" });
const editor = sbPage.locator("#sb-editor .cm-content");
await expect(editor).toContainText("用手机记录 Markdown");
await expect(
sbPage.getByRole("toolbar", { name: "Markdown 编辑工具" }),
).toBeVisible();
await expect(
sbPage.getByRole("navigation", { name: "手机导航" }),
).toHaveCount(0);
await editor.click();
await sbPage.keyboard.press(`${mod}+a`);
await sbPage.getByRole("button", { name: "粗体" }).click();
await expect(editor).toContainText("**用手机记录 Markdown**");
const viewportOverflow = await sbPage.evaluate(
() =>
document.documentElement.scrollWidth -
document.documentElement.clientWidth,
);
expect(viewportOverflow).toBeLessThanOrEqual(1);
await sbPage.getByRole("button", { name: "打开导航" }).click();
const sidebar = sbPage.locator(".pl-sidebar.is-mobile-open");
await expect(sidebar).toBeVisible();
const sidebarMetrics = await sidebar.evaluate((element) => ({
width: element.getBoundingClientRect().width,
scrollWidth: element.scrollWidth,
clientWidth: element.clientWidth,
}));
expect(sidebarMetrics.width).toBeLessThanOrEqual(320);
expect(sidebarMetrics.scrollWidth).toBeLessThanOrEqual(
sidebarMetrics.clientWidth + 1,
);
await sidebar.getByRole("button", { name: "设置" }).click();
await expect(sidebar).not.toBeVisible();
await expect(sbPage.locator(".pl-settings-surface")).toBeVisible();
await expect(
sbPage.getByText("Markdown 编辑器", { exact: true }),
).toBeVisible();
await expect(
sbPage.getByText("启用开发者选项", { exact: true }),
).toBeVisible();
await expect(sbPage.getByText("命令面板", { exact: true })).toHaveCount(0);
const settingsOverflow = await sbPage.evaluate(
() =>
document.documentElement.scrollWidth -
document.documentElement.clientWidth,
);
expect(settingsOverflow).toBeLessThanOrEqual(1);
await sbPage.screenshot({
path: "/tmp/plainleaf-mobile-settings.png",
fullPage: true,
});
});