fix: stabilize local attachment icons and office proxy urls
This commit is contained in:
@@ -177,6 +177,24 @@ async function waitForPrimaryAttachment(page, fileName) {
|
||||
return link;
|
||||
}
|
||||
|
||||
async function waitForPrimaryAttachmentClass(page, fileName, className) {
|
||||
await page.waitForFunction(
|
||||
({ name, className }) => {
|
||||
const editor = document.querySelector('.document-pane[data-pane-role="primary"] .editor-surface .ProseMirror');
|
||||
const link = Array.from(editor?.querySelectorAll('a[href*="/api/local-folder/files/open"]') || [])
|
||||
.find((node) => node instanceof HTMLAnchorElement && (node.textContent || "").includes(name));
|
||||
return link instanceof HTMLAnchorElement && link.classList.contains(className);
|
||||
},
|
||||
{ name: fileName, className },
|
||||
{ timeout: UI_TIMEOUT_MS },
|
||||
);
|
||||
return await waitForPrimaryAttachment(page, fileName)
|
||||
.then((link) => link.evaluate((node) => {
|
||||
const badgeColor = getComputedStyle(node, "::before").backgroundColor;
|
||||
return `${node.getAttribute("class") || ""} ${badgeColor}`.trim();
|
||||
}));
|
||||
}
|
||||
|
||||
async function selectPrimaryAttachmentLink(page, fileName) {
|
||||
await page.evaluate((name) => {
|
||||
const editor = document.querySelector('.document-pane[data-pane-role="primary"] .editor-surface .ProseMirror');
|
||||
@@ -348,13 +366,34 @@ async function main() {
|
||||
assert.equal(uploadAsset.markdownRelativePath, "README/uploaded-one.md", "主编辑区上传响应应返回 markdownRelativePath");
|
||||
assert.equal(uploadAsset.ownerDocumentId, "local-md:README.md", "主编辑区上传响应应返回 ownerDocumentId");
|
||||
await assertNoPrimaryConflictPanel(page, "主编辑区上传附件后");
|
||||
const uploadedClassBeforeReload = await waitForPrimaryAttachmentClass(
|
||||
page,
|
||||
"uploaded-one.md",
|
||||
"mnote-uploaded-attachment-code",
|
||||
);
|
||||
assert(
|
||||
uploadedClassBeforeReload.includes("mnote-uploaded-attachment-code"),
|
||||
`上传后的 md 附件应使用 code/markdown 黑色图标 class,实际 class=${uploadedClassBeforeReload}`,
|
||||
);
|
||||
await page.reload({ waitUntil: "domcontentloaded", timeout: UI_TIMEOUT_MS });
|
||||
const uploadedClassAfterReload = await waitForPrimaryAttachmentClass(
|
||||
page,
|
||||
"uploaded-one.md",
|
||||
"mnote-uploaded-attachment-code",
|
||||
);
|
||||
assert(
|
||||
uploadedClassAfterReload.includes("mnote-uploaded-attachment-code"),
|
||||
`刷新后的 md 附件应保持 code/markdown 黑色图标 class,实际 class=${uploadedClassAfterReload}`,
|
||||
);
|
||||
|
||||
checks[checkId] = {
|
||||
ok: true,
|
||||
message: `上传文件落在资源目录 ${correctPath}`,
|
||||
message: `上传文件落在资源目录 ${correctPath},刷新后仍保持 md 附件图标 class`,
|
||||
landedInResourceDir,
|
||||
landedInRoot,
|
||||
uploadAsset,
|
||||
uploadedClassBeforeReload,
|
||||
uploadedClassAfterReload,
|
||||
};
|
||||
} catch (err) {
|
||||
overallOk = false;
|
||||
|
||||
Reference in New Issue
Block a user