feat: cut over rust web main shell
This commit is contained in:
@@ -1,6 +1,11 @@
|
||||
"use strict";
|
||||
|
||||
const BASE_URL = (process.env.MNOTE_UI_BASE_URL || "http://127.0.0.1:3000").replace(/\/+$/, "");
|
||||
const DOCUMENT_UI_BASE_URL = (
|
||||
process.env.MNOTE_TREE_SMOKE_DOCUMENT_BASE_URL ||
|
||||
process.env.MNOTE_LEGACY_UI_BASE_URL ||
|
||||
"http://127.0.0.1:3100"
|
||||
).replace(/\/+$/, "");
|
||||
const MNOTE_WEB_BASE_URL = (process.env.MNOTE_WEB_SMOKE_BASE_URL || "").replace(/\/+$/, "");
|
||||
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);
|
||||
@@ -162,6 +167,19 @@ async function isVisible(locator) {
|
||||
}
|
||||
}
|
||||
|
||||
async function clickButtonByExactText(page, text) {
|
||||
await page.evaluate((label) => {
|
||||
const button = Array.from(document.querySelectorAll("button")).find((candidate) => {
|
||||
const content = (candidate.textContent || "").trim();
|
||||
return content === label;
|
||||
});
|
||||
if (!(button instanceof HTMLButtonElement)) {
|
||||
throw new Error(`未找到按钮:${label}`);
|
||||
}
|
||||
button.click();
|
||||
}, text);
|
||||
}
|
||||
|
||||
async function completeUsernameSetupIfNeeded(page) {
|
||||
const saveButton = page.getByRole("button", { name: "保存并继续" });
|
||||
if (!(await isVisible(saveButton))) {
|
||||
@@ -319,7 +337,7 @@ async function cleanupDocuments(requestContext, createdIds) {
|
||||
}
|
||||
|
||||
async function openDocument(page, workspaceId, documentId) {
|
||||
const url = `${BASE_URL}/documents/${documentId}?workspaceId=${encodeURIComponent(workspaceId)}`;
|
||||
const url = `${DOCUMENT_UI_BASE_URL}/documents/${documentId}?workspaceId=${encodeURIComponent(workspaceId)}`;
|
||||
const hasSidebarControls = async () => {
|
||||
const groupButton = page.getByRole("button", { name: "分组" });
|
||||
const fileButton = page.getByRole("button", { name: "文件" });
|
||||
@@ -373,8 +391,15 @@ async function openSectionView(page) {
|
||||
{ timeout: UI_TIMEOUT_MS },
|
||||
);
|
||||
|
||||
try {
|
||||
await waitForHost();
|
||||
return;
|
||||
} catch {
|
||||
// 说明:未处于分组视图时才需要点击切换。
|
||||
}
|
||||
|
||||
for (let attempt = 0; attempt < 2; attempt += 1) {
|
||||
await button.click({ timeout: UI_TIMEOUT_MS });
|
||||
await clickButtonByExactText(page, "分组");
|
||||
try {
|
||||
await waitForHost();
|
||||
return;
|
||||
@@ -399,8 +424,15 @@ async function openFilesystemView(page) {
|
||||
{ timeout: UI_TIMEOUT_MS },
|
||||
);
|
||||
|
||||
try {
|
||||
await waitForHost();
|
||||
return;
|
||||
} catch {
|
||||
// 说明:未处于文件视图时才需要点击切换。
|
||||
}
|
||||
|
||||
for (let attempt = 0; attempt < 2; attempt += 1) {
|
||||
await button.click({ timeout: UI_TIMEOUT_MS });
|
||||
await clickButtonByExactText(page, "文件");
|
||||
try {
|
||||
await waitForHost();
|
||||
return;
|
||||
@@ -440,6 +472,7 @@ async function ensurePageOptionsVisible(page) {
|
||||
|
||||
module.exports = {
|
||||
BASE_URL,
|
||||
DOCUMENT_UI_BASE_URL,
|
||||
MNOTE_WEB_BASE_URL,
|
||||
REQUEST_TIMEOUT_MS,
|
||||
UI_TIMEOUT_MS,
|
||||
|
||||
Reference in New Issue
Block a user