4-26 树rust-2
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,276 @@
|
||||
"use strict";
|
||||
|
||||
// 说明:
|
||||
// - 这份 smoke 只验证 rust_family picker 的键盘高亮与 Enter 选中。
|
||||
// - 这里刻意使用 fresh-open 的最短链路,避免把空态/多轮搜索切换的抖动混进同一条回归里。
|
||||
|
||||
const { chromium } = require("playwright");
|
||||
const {
|
||||
UI_TIMEOUT_MS,
|
||||
createTempDocument,
|
||||
ensureAuthenticated,
|
||||
ensurePageOptionsVisible,
|
||||
openDocument,
|
||||
purgeDocument,
|
||||
renameDocument,
|
||||
} = require("./tree-shell-smoke-helpers");
|
||||
|
||||
async function main() {
|
||||
const headless =
|
||||
process.env.MNOTE_SMOKE_HEADLESS === "1"
|
||||
? true
|
||||
: process.env.MNOTE_SMOKE_HEADLESS === "0"
|
||||
? false
|
||||
: !process.env.DISPLAY;
|
||||
const browser = await chromium.launch({ headless });
|
||||
const context = await browser.newContext({
|
||||
viewport: { width: 1440, height: 960 },
|
||||
});
|
||||
const page = await context.newPage();
|
||||
|
||||
let fixture = null;
|
||||
let caughtError = null;
|
||||
|
||||
try {
|
||||
await ensureAuthenticated(page, context.request);
|
||||
const uniqueSuffix = Date.now().toString();
|
||||
const parent = await createTempDocument(context.request, null);
|
||||
const childA = await createTempDocument(context.request, parent.documentId);
|
||||
const target = await createTempDocument(context.request, null);
|
||||
|
||||
fixture = {
|
||||
workspaceId: parent.workspaceId,
|
||||
parentId: parent.documentId,
|
||||
childAId: childA.documentId,
|
||||
targetId: target.documentId,
|
||||
parentTitle: `task113-parent-${uniqueSuffix}`,
|
||||
childATitle: `task113-child-a-${uniqueSuffix}`,
|
||||
targetTitle: `task113-target-${uniqueSuffix}`,
|
||||
createdIds: [parent.documentId, childA.documentId, target.documentId],
|
||||
};
|
||||
|
||||
await renameDocument(context.request, fixture.workspaceId, fixture.parentId, fixture.parentTitle);
|
||||
await renameDocument(context.request, fixture.workspaceId, fixture.childAId, fixture.childATitle);
|
||||
await renameDocument(context.request, fixture.workspaceId, fixture.targetId, fixture.targetTitle);
|
||||
|
||||
await openDocument(page, fixture.workspaceId, fixture.childAId);
|
||||
await ensurePageOptionsVisible(page);
|
||||
const openButton = page.getByRole("button", { name: "移动/嵌入到..." });
|
||||
await openButton.waitFor({ state: "visible", timeout: UI_TIMEOUT_MS });
|
||||
await openButton.click({ timeout: UI_TIMEOUT_MS });
|
||||
|
||||
const dialog = page.getByRole("dialog");
|
||||
await dialog.waitFor({ state: "visible", timeout: UI_TIMEOUT_MS });
|
||||
const searchInput = dialog.getByPlaceholder("移动到...");
|
||||
const keyboardQuery = `task113-keyboard-${Date.now()}`;
|
||||
|
||||
await page.route("**/api/search/documents", async (route) => {
|
||||
const payload = route.request().postDataJSON();
|
||||
if (payload?.query !== keyboardQuery) {
|
||||
await route.continue();
|
||||
return;
|
||||
}
|
||||
await route.fulfill({
|
||||
status: 200,
|
||||
contentType: "application/json",
|
||||
body: JSON.stringify({
|
||||
results: [
|
||||
{
|
||||
id: fixture.parentId,
|
||||
title: fixture.parentTitle,
|
||||
matchField: "title",
|
||||
},
|
||||
{
|
||||
id: fixture.targetId,
|
||||
title: fixture.targetTitle,
|
||||
matchField: "title",
|
||||
},
|
||||
],
|
||||
}),
|
||||
});
|
||||
});
|
||||
|
||||
try {
|
||||
await searchInput.fill(keyboardQuery, { timeout: UI_TIMEOUT_MS });
|
||||
await page.waitForFunction(
|
||||
(nodeId) => {
|
||||
const frame = Array.from(
|
||||
document.querySelectorAll('[data-testid="tree-picker-surface-rust-iframe"]'),
|
||||
)
|
||||
.reverse()
|
||||
.find((element) => element instanceof HTMLIFrameElement) ?? null;
|
||||
if (!(frame instanceof HTMLIFrameElement)) {
|
||||
return false;
|
||||
}
|
||||
return Boolean(frame.contentDocument?.querySelector(`.tree-row[data-node-id="${nodeId}"]`));
|
||||
},
|
||||
fixture.targetId,
|
||||
{ timeout: UI_TIMEOUT_MS },
|
||||
);
|
||||
|
||||
await searchInput.focus();
|
||||
await page.waitForFunction(
|
||||
() => {
|
||||
const active = document.activeElement;
|
||||
return active instanceof HTMLInputElement && active.placeholder === "移动到...";
|
||||
},
|
||||
undefined,
|
||||
{ timeout: UI_TIMEOUT_MS },
|
||||
);
|
||||
|
||||
const readFocusedPickerItemKey = async () =>
|
||||
page.evaluate(() => {
|
||||
const frame = Array.from(
|
||||
document.querySelectorAll('[data-testid="tree-picker-surface-rust-iframe"]'),
|
||||
)
|
||||
.reverse()
|
||||
.find((element) => element instanceof HTMLIFrameElement) ?? null;
|
||||
if (!(frame instanceof HTMLIFrameElement)) {
|
||||
return "";
|
||||
}
|
||||
const rootButton = frame.contentDocument?.querySelector(
|
||||
'.tree-row[data-testid="tree-picker-root"][data-focused="true"]',
|
||||
);
|
||||
if (rootButton) {
|
||||
return "__root__";
|
||||
}
|
||||
const row = frame.contentDocument?.querySelector('.tree-row[data-focused="true"]');
|
||||
return row ? row.getAttribute("data-node-id") || "" : "";
|
||||
});
|
||||
|
||||
const moveHighlightTo = async (targetNodeId, maxSteps = 4) => {
|
||||
await page.waitForFunction(
|
||||
() => {
|
||||
const frame = Array.from(
|
||||
document.querySelectorAll('[data-testid="tree-picker-surface-rust-iframe"]'),
|
||||
)
|
||||
.reverse()
|
||||
.find((element) => element instanceof HTMLIFrameElement) ?? null;
|
||||
if (!(frame instanceof HTMLIFrameElement)) {
|
||||
return false;
|
||||
}
|
||||
const rootButton = frame.contentDocument?.querySelector(
|
||||
'.tree-row[data-testid="tree-picker-root"][data-focused="true"]',
|
||||
);
|
||||
if (rootButton) {
|
||||
return true;
|
||||
}
|
||||
return Boolean(frame.contentDocument?.querySelector('.tree-row[data-focused="true"]'));
|
||||
},
|
||||
undefined,
|
||||
{ timeout: UI_TIMEOUT_MS },
|
||||
);
|
||||
|
||||
for (let index = 0; index < maxSteps; index += 1) {
|
||||
const currentKey = await readFocusedPickerItemKey();
|
||||
if (currentKey === targetNodeId) {
|
||||
return;
|
||||
}
|
||||
await page.keyboard.press("ArrowDown");
|
||||
await page.waitForFunction(
|
||||
(previousKey) => {
|
||||
const frame = Array.from(
|
||||
document.querySelectorAll('[data-testid="tree-picker-surface-rust-iframe"]'),
|
||||
)
|
||||
.reverse()
|
||||
.find((element) => element instanceof HTMLIFrameElement) ?? null;
|
||||
if (!(frame instanceof HTMLIFrameElement)) {
|
||||
return false;
|
||||
}
|
||||
const rootButton = frame.contentDocument?.querySelector(
|
||||
'.tree-row[data-testid="tree-picker-root"][data-focused="true"]',
|
||||
);
|
||||
const row = frame.contentDocument?.querySelector('.tree-row[data-focused="true"]');
|
||||
const currentKey = rootButton
|
||||
? "__root__"
|
||||
: row
|
||||
? row.getAttribute("data-node-id") || ""
|
||||
: "";
|
||||
return currentKey !== previousKey;
|
||||
},
|
||||
currentKey,
|
||||
{ timeout: UI_TIMEOUT_MS },
|
||||
);
|
||||
await page.waitForFunction(
|
||||
() => {
|
||||
const active = document.activeElement;
|
||||
return active instanceof HTMLInputElement && active.placeholder === "移动到...";
|
||||
},
|
||||
undefined,
|
||||
{ timeout: UI_TIMEOUT_MS },
|
||||
);
|
||||
}
|
||||
|
||||
const finalKey = await readFocusedPickerItemKey();
|
||||
if (finalKey !== targetNodeId) {
|
||||
throw new Error(`picker 键盘高亮未落到目标节点:当前=${finalKey || "<empty>"} 目标=${targetNodeId}`);
|
||||
}
|
||||
};
|
||||
|
||||
await moveHighlightTo(fixture.targetId);
|
||||
|
||||
const moveRequest = page.waitForResponse(
|
||||
async (response) => {
|
||||
if (
|
||||
!response.url().includes("/api/tree/commands") ||
|
||||
response.request().method() !== "POST" ||
|
||||
!response.ok()
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
const payload = response.request().postDataJSON();
|
||||
return payload?.action === "move" && payload?.documentId === fixture.childAId && payload?.parentId === fixture.targetId;
|
||||
},
|
||||
{ timeout: UI_TIMEOUT_MS },
|
||||
);
|
||||
|
||||
await searchInput.focus();
|
||||
await page.keyboard.press("Enter");
|
||||
await moveRequest;
|
||||
await dialog.waitFor({ state: "hidden", timeout: UI_TIMEOUT_MS });
|
||||
} finally {
|
||||
await page.unroute("**/api/search/documents").catch(() => undefined);
|
||||
}
|
||||
|
||||
console.log(
|
||||
JSON.stringify(
|
||||
{
|
||||
ok: true,
|
||||
workspaceId: fixture.workspaceId,
|
||||
sourceId: fixture.childAId,
|
||||
targetId: fixture.targetId,
|
||||
searchQuery: keyboardQuery,
|
||||
pickerKeyboardHighlight: true,
|
||||
pickerKeyboardSelect: true,
|
||||
},
|
||||
null,
|
||||
2,
|
||||
),
|
||||
);
|
||||
} catch (error) {
|
||||
caughtError = error;
|
||||
} finally {
|
||||
if (fixture) {
|
||||
for (const documentId of [...fixture.createdIds].reverse()) {
|
||||
try {
|
||||
await purgeDocument(context.request, documentId);
|
||||
} catch {
|
||||
// 说明:移动后父级与目标级的清理顺序可能变化,这里忽略重复清理错误。
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
await page.close().catch(() => undefined);
|
||||
await context.close().catch(() => undefined);
|
||||
await browser.close().catch(() => undefined);
|
||||
}
|
||||
|
||||
if (caughtError) {
|
||||
throw caughtError;
|
||||
}
|
||||
}
|
||||
|
||||
main().catch((error) => {
|
||||
console.error(error instanceof Error ? error.stack || error.message : String(error));
|
||||
process.exit(1);
|
||||
});
|
||||
@@ -6,6 +6,8 @@ const REQUEST_TIMEOUT_MS = Number(process.env.MNOTE_SMOKE_TIMEOUT_MS || 20_000);
|
||||
const UI_TIMEOUT_MS = Number(process.env.MNOTE_SMOKE_UI_TIMEOUT_MS || 30_000);
|
||||
const TEST_LOGIN_BUTTON_NAME = "测试账号快速登录";
|
||||
const TEST_USERNAME_PREFIX = "测试用户";
|
||||
const TEST_EMAIL = "test@example.com";
|
||||
const TEST_PASSWORD = "Test123456";
|
||||
|
||||
function assert(condition, message) {
|
||||
if (!condition) {
|
||||
@@ -65,15 +67,33 @@ async function requestJson(requestContext, path, init = {}) {
|
||||
}
|
||||
|
||||
async function createTempDocument(requestContext, parentId = null) {
|
||||
const payload = await requestJson(requestContext, "/api/documents/create", {
|
||||
const payload = await requestJson(requestContext, "/api/tree/commands", {
|
||||
method: "POST",
|
||||
data: { parentId },
|
||||
data: {
|
||||
action: "create",
|
||||
parentId,
|
||||
},
|
||||
});
|
||||
assert(payload && typeof payload.id === "string", "创建临时页面失败:缺少 id");
|
||||
assert(payload && typeof payload.workspace_id === "string", "创建临时页面失败:缺少 workspace_id");
|
||||
const result = payload && typeof payload.result === "object" ? payload.result : null;
|
||||
const documentId =
|
||||
result && typeof result.documentId === "string"
|
||||
? result.documentId
|
||||
: payload && typeof payload.id === "string"
|
||||
? payload.id
|
||||
: "";
|
||||
const workspaceId =
|
||||
result && typeof result.workspaceId === "string"
|
||||
? result.workspaceId
|
||||
: payload && typeof payload.workspace_id === "string"
|
||||
? payload.workspace_id
|
||||
: payload && typeof payload.workspaceId === "string"
|
||||
? payload.workspaceId
|
||||
: "";
|
||||
assert(documentId, "创建临时页面失败:缺少 documentId/id");
|
||||
assert(workspaceId, "创建临时页面失败:缺少 workspaceId/workspace_id");
|
||||
return {
|
||||
documentId: payload.id,
|
||||
workspaceId: payload.workspace_id,
|
||||
documentId,
|
||||
workspaceId,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -101,6 +121,23 @@ async function getViewerIdentity(requestContext) {
|
||||
return payload;
|
||||
}
|
||||
|
||||
async function tryApiQuickLogin(requestContext) {
|
||||
await requestJson(requestContext, "/api/auth", {
|
||||
method: "POST",
|
||||
data: {
|
||||
action: "auth:signIn",
|
||||
args: {
|
||||
provider: "password",
|
||||
params: {
|
||||
email: TEST_EMAIL,
|
||||
password: TEST_PASSWORD,
|
||||
flow: "signIn",
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async function waitForAuthenticatedRedirect(page, timeout = 8_000) {
|
||||
await page.waitForURL((url) => !url.toString().includes("/auth"), {
|
||||
timeout,
|
||||
@@ -110,7 +147,16 @@ async function waitForAuthenticatedRedirect(page, timeout = 8_000) {
|
||||
|
||||
async function isVisible(locator) {
|
||||
try {
|
||||
return await locator.isVisible();
|
||||
return await locator.evaluateAll((elements) =>
|
||||
elements.some((element) => {
|
||||
if (!(element instanceof HTMLElement)) {
|
||||
return false;
|
||||
}
|
||||
const style = window.getComputedStyle(element);
|
||||
const rect = element.getBoundingClientRect();
|
||||
return style.display !== "none" && style.visibility !== "hidden" && rect.width > 0 && rect.height > 0;
|
||||
}),
|
||||
);
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
@@ -139,11 +185,11 @@ async function registerTestAccountIfNeeded(page) {
|
||||
}
|
||||
|
||||
await switchButton.click({ timeout: UI_TIMEOUT_MS });
|
||||
await page.locator('input[name="email"]').fill("test@example.com", { timeout: UI_TIMEOUT_MS });
|
||||
await page.locator('input[name="email"]').fill(TEST_EMAIL, { timeout: UI_TIMEOUT_MS });
|
||||
await page.locator('input[name="username"]').fill(`${TEST_USERNAME_PREFIX}${Date.now().toString().slice(-6)}`, {
|
||||
timeout: UI_TIMEOUT_MS,
|
||||
});
|
||||
await page.locator('input[name="password"]').fill("Test123456", { timeout: UI_TIMEOUT_MS });
|
||||
await page.locator('input[name="password"]').fill(TEST_PASSWORD, { timeout: UI_TIMEOUT_MS });
|
||||
await page.getByRole("button", { name: "注册" }).click({ timeout: UI_TIMEOUT_MS });
|
||||
try {
|
||||
await waitForAuthenticatedRedirect(page, UI_TIMEOUT_MS);
|
||||
@@ -166,21 +212,37 @@ async function waitForViewerIdentity(requestContext, attempts = 6) {
|
||||
throw lastError instanceof Error ? lastError : new Error("获取当前用户失败");
|
||||
}
|
||||
|
||||
async function ensureAuthenticated(page, requestContext) {
|
||||
async function ensureAuthenticatedViaUi(page, requestContext) {
|
||||
await page.goto(`${BASE_URL}/auth`, { waitUntil: "commit", timeout: UI_TIMEOUT_MS });
|
||||
|
||||
if (page.url().includes("/auth")) {
|
||||
const quickLoginButton = page.getByRole("button", { name: TEST_LOGIN_BUTTON_NAME });
|
||||
await Promise.race([
|
||||
page.waitForURL((url) => !url.toString().includes("/auth"), {
|
||||
timeout: UI_TIMEOUT_MS,
|
||||
waitUntil: "commit",
|
||||
}),
|
||||
quickLoginButton.waitFor({ state: "visible", timeout: UI_TIMEOUT_MS }),
|
||||
]);
|
||||
const deadline = Date.now() + UI_TIMEOUT_MS;
|
||||
while (page.url().includes("/auth") && Date.now() < deadline) {
|
||||
if (await isVisible(quickLoginButton)) {
|
||||
break;
|
||||
}
|
||||
await page.waitForTimeout(200);
|
||||
}
|
||||
if (!page.url().includes("/auth")) {
|
||||
return await waitForViewerIdentity(requestContext);
|
||||
}
|
||||
if (!(await isVisible(quickLoginButton))) {
|
||||
await page.reload({ waitUntil: "commit", timeout: UI_TIMEOUT_MS }).catch(() => undefined);
|
||||
const retryDeadline = Date.now() + Math.min(8_000, UI_TIMEOUT_MS);
|
||||
while (page.url().includes("/auth") && Date.now() < retryDeadline) {
|
||||
if (await isVisible(quickLoginButton)) {
|
||||
break;
|
||||
}
|
||||
await page.waitForTimeout(200);
|
||||
}
|
||||
}
|
||||
if (!page.url().includes("/auth")) {
|
||||
return await waitForViewerIdentity(requestContext);
|
||||
}
|
||||
if (!(await isVisible(quickLoginButton))) {
|
||||
throw new Error("认证页未出现测试账号快速登录按钮");
|
||||
}
|
||||
await quickLoginButton.click({ timeout: UI_TIMEOUT_MS });
|
||||
try {
|
||||
await waitForAuthenticatedRedirect(page, UI_TIMEOUT_MS);
|
||||
@@ -198,6 +260,36 @@ async function ensureAuthenticated(page, requestContext) {
|
||||
return await waitForViewerIdentity(requestContext);
|
||||
}
|
||||
|
||||
async function ensureAuthenticated(page, requestContext) {
|
||||
const existingViewer = await waitForViewerIdentity(requestContext, 1).catch(() => null);
|
||||
if (existingViewer) {
|
||||
return existingViewer;
|
||||
}
|
||||
|
||||
const preferUiAuth = Boolean(process.env.DISPLAY);
|
||||
if (preferUiAuth) {
|
||||
try {
|
||||
return await ensureAuthenticatedViaUi(page, requestContext);
|
||||
} catch {
|
||||
// 说明:有图形环境时优先走真实 UI 登录;如果异常,再回退到 API 登录。
|
||||
}
|
||||
}
|
||||
|
||||
const apiViewer = await (async () => {
|
||||
try {
|
||||
await tryApiQuickLogin(requestContext);
|
||||
return await waitForViewerIdentity(requestContext, 3);
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
})();
|
||||
if (apiViewer) {
|
||||
return apiViewer;
|
||||
}
|
||||
|
||||
return await ensureAuthenticatedViaUi(page, requestContext);
|
||||
}
|
||||
|
||||
async function prepareTempTreeFixture(requestContext) {
|
||||
const uniqueSuffix = Date.now().toString();
|
||||
const parentTitle = `task-tree-parent-${uniqueSuffix}`;
|
||||
@@ -228,28 +320,121 @@ async function cleanupDocuments(requestContext, createdIds) {
|
||||
|
||||
async function openDocument(page, workspaceId, documentId) {
|
||||
const url = `${BASE_URL}/documents/${documentId}?workspaceId=${encodeURIComponent(workspaceId)}`;
|
||||
await page.goto(url, { waitUntil: "commit", timeout: UI_TIMEOUT_MS });
|
||||
const hasSidebarControls = async () => {
|
||||
const groupButton = page.getByRole("button", { name: "分组" });
|
||||
const fileButton = page.getByRole("button", { name: "文件" });
|
||||
return (await isVisible(groupButton)) || (await isVisible(fileButton));
|
||||
};
|
||||
|
||||
const gotoDocument = async () => {
|
||||
try {
|
||||
await page.goto(url, { waitUntil: "commit", timeout: UI_TIMEOUT_MS });
|
||||
} catch (error) {
|
||||
const message = error instanceof Error ? error.message : String(error);
|
||||
if (!message.includes("ERR_ABORTED")) {
|
||||
throw error;
|
||||
}
|
||||
await page.waitForTimeout(500);
|
||||
await page.goto(url, { waitUntil: "commit", timeout: UI_TIMEOUT_MS });
|
||||
}
|
||||
};
|
||||
|
||||
await gotoDocument();
|
||||
const firstDeadline = Date.now() + Math.min(UI_TIMEOUT_MS, 10_000);
|
||||
while (Date.now() < firstDeadline) {
|
||||
if (await hasSidebarControls()) {
|
||||
return url;
|
||||
}
|
||||
await page.waitForTimeout(250);
|
||||
}
|
||||
|
||||
await page.reload({ waitUntil: "commit", timeout: UI_TIMEOUT_MS }).catch(() => undefined);
|
||||
const secondDeadline = Date.now() + Math.min(UI_TIMEOUT_MS, 10_000);
|
||||
while (Date.now() < secondDeadline) {
|
||||
if (await hasSidebarControls()) {
|
||||
return url;
|
||||
}
|
||||
await page.waitForTimeout(250);
|
||||
}
|
||||
|
||||
return url;
|
||||
}
|
||||
|
||||
async function openSectionView(page) {
|
||||
const button = page.getByRole("button", { name: "分组" });
|
||||
await button.waitFor({ state: "visible", timeout: UI_TIMEOUT_MS });
|
||||
await button.click({ timeout: UI_TIMEOUT_MS });
|
||||
const waitForHost = () =>
|
||||
page.waitForFunction(
|
||||
() => {
|
||||
const pageHost = document.querySelector('[data-testid="sidebar-page-tree-shell"]');
|
||||
return pageHost instanceof HTMLElement && pageHost.getClientRects().length > 0;
|
||||
},
|
||||
undefined,
|
||||
{ timeout: UI_TIMEOUT_MS },
|
||||
);
|
||||
|
||||
for (let attempt = 0; attempt < 2; attempt += 1) {
|
||||
await button.click({ timeout: UI_TIMEOUT_MS });
|
||||
try {
|
||||
await waitForHost();
|
||||
return;
|
||||
} catch (error) {
|
||||
if (attempt === 1) {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function openFilesystemView(page) {
|
||||
const button = page.getByRole("button", { name: "文件" });
|
||||
await button.waitFor({ state: "visible", timeout: UI_TIMEOUT_MS });
|
||||
await button.click({ timeout: UI_TIMEOUT_MS });
|
||||
const waitForHost = () =>
|
||||
page.waitForFunction(
|
||||
() => {
|
||||
const fileHost = document.querySelector('[data-testid="sidebar-file-tree-shell"]');
|
||||
return fileHost instanceof HTMLElement && fileHost.getClientRects().length > 0;
|
||||
},
|
||||
undefined,
|
||||
{ timeout: UI_TIMEOUT_MS },
|
||||
);
|
||||
|
||||
for (let attempt = 0; attempt < 2; attempt += 1) {
|
||||
await button.click({ timeout: UI_TIMEOUT_MS });
|
||||
try {
|
||||
await waitForHost();
|
||||
return;
|
||||
} catch (error) {
|
||||
if (attempt === 1) {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function ensurePageOptionsVisible(page) {
|
||||
const toggle = page.getByRole("button", { name: /显示页面选项|隐藏页面选项/ });
|
||||
await toggle.waitFor({ state: "visible", timeout: UI_TIMEOUT_MS });
|
||||
const label = (await toggle.getAttribute("aria-label")) || "";
|
||||
const readLabel = async () => (await toggle.getAttribute("aria-label")) || "";
|
||||
const waitUntilExpanded = async () => {
|
||||
await page.waitForFunction(
|
||||
() => {
|
||||
const buttons = Array.from(document.querySelectorAll("button"));
|
||||
return buttons.some((button) => (button.getAttribute("aria-label") || "").includes("隐藏页面选项"));
|
||||
},
|
||||
undefined,
|
||||
{ timeout: UI_TIMEOUT_MS },
|
||||
);
|
||||
};
|
||||
const label = await readLabel();
|
||||
if (label.includes("显示")) {
|
||||
await toggle.click({ timeout: UI_TIMEOUT_MS });
|
||||
try {
|
||||
await waitUntilExpanded();
|
||||
} catch {
|
||||
await toggle.click({ timeout: UI_TIMEOUT_MS });
|
||||
await waitUntilExpanded();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user