From db66d86bc2df387fb3148b4f863b67694df29245 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Wed, 2 Apr 2025 16:39:16 +0300 Subject: [PATCH] fix(in-app-help): help not rendering in other languages (fixes #1600) --- e2e/help.spec.ts | 37 +++++++++++++++++++++++++ e2e/support/app.ts | 6 ++++ src/public/app/services/doc_renderer.ts | 6 ++-- 3 files changed, 47 insertions(+), 2 deletions(-) diff --git a/e2e/help.spec.ts b/e2e/help.spec.ts index 4402ffa30..6416afb6f 100644 --- a/e2e/help.spec.ts +++ b/e2e/help.spec.ts @@ -25,3 +25,40 @@ test("Complete help in search", async ({ page, context }) => { const popup = await popupPromise; expect(popup.url()).toBe("https://triliumnext.github.io/Docs/Wiki/search.html"); }); + +test("In-app-help works in English", async ({ page, context }) => { + const app = new App(page, context); + await app.goto(); + + await app.currentNoteSplit.press("F1"); + const title = "User Guide"; + await expect(app.noteTreeHoistedNote).toContainText(title); + await expect(app.currentNoteSplitTitle).toHaveValue(title); + + app.noteTree.getByText("Troubleshooting").click(); + await expect(app.currentNoteSplitTitle).toHaveValue("Troubleshooting"); + await app.currentNoteSplitContent.locator("p").first().waitFor({ state: "visible" }); + expect(await app.currentNoteSplitContent.locator("p").count()).toBeGreaterThan(10); +}); + +test("In-app-help works in other languages", async ({ page, context }) => { + const app = new App(page, context); + try { + await app.goto(); + await app.setOption("locale", "cn"); + await app.goto(); + + await app.currentNoteSplit.press("F1"); + const title = "用户指南"; + await expect(app.noteTreeHoistedNote).toContainText(title); + await expect(app.currentNoteSplitTitle).toHaveValue(title); + + app.noteTree.getByText("Troubleshooting").click(); + await expect(app.currentNoteSplitTitle).toHaveValue("Troubleshooting"); + await app.currentNoteSplitContent.locator("p").first().waitFor({ state: "visible" }); + expect(await app.currentNoteSplitContent.locator("p").count()).toBeGreaterThan(10); + } finally { + // Ensure English is set after each locale change to avoid any leaks to other tests. + await app.setOption("locale", "en"); + } +}); diff --git a/e2e/support/app.ts b/e2e/support/app.ts index b526638d9..d6b3d231a 100644 --- a/e2e/support/app.ts +++ b/e2e/support/app.ts @@ -14,8 +14,11 @@ export default class App { readonly tabBar: Locator; readonly noteTree: Locator; + readonly noteTreeHoistedNote: Locator; readonly launcherBar: Locator; readonly currentNoteSplit: Locator; + readonly currentNoteSplitTitle: Locator; + readonly currentNoteSplitContent: Locator; readonly sidebar: Locator; constructor(page: Page, context: BrowserContext) { @@ -24,8 +27,11 @@ export default class App { this.tabBar = page.locator(".tab-row-widget-container"); this.noteTree = page.locator(".tree-wrapper"); + this.noteTreeHoistedNote = this.noteTree.locator(".fancytree-node", { has: page.locator(".unhoist-button") }); this.launcherBar = page.locator("#launcher-container"); this.currentNoteSplit = page.locator(".note-split:not(.hidden-ext)"); + this.currentNoteSplitTitle = this.currentNoteSplit.locator(".note-title"); + this.currentNoteSplitContent = this.currentNoteSplit.locator(".note-detail-printable.visible"); this.sidebar = page.locator("#right-pane"); } diff --git a/src/public/app/services/doc_renderer.ts b/src/public/app/services/doc_renderer.ts index ac1560d4c..290adbb72 100644 --- a/src/public/app/services/doc_renderer.ts +++ b/src/public/app/services/doc_renderer.ts @@ -14,8 +14,10 @@ export default function renderDoc(note: FNote) { // fallback to english doc if no translation available if (status === "error") { const fallbackUrl = getUrl(docName, "en"); - $content.load(fallbackUrl, () => processContent(fallbackUrl, $content)); - resolve($content); + $content.load(fallbackUrl, () => { + processContent(fallbackUrl, $content) + resolve($content); + }); return; }