Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
e2e(server): handle tab bar flakiness
Elian Doranfc16ab5d1909
diff --git a/packages/trilium-e2e/src/layout/tab_bar.spec.ts b/packages/trilium-e2e/src/layout/tab_bar.spec.tsindex 5bdebcfe24..31fa4755f5 100644--- a/packages/trilium-e2e/src/layout/tab_bar.spec.ts+++ b/packages/trilium-e2e/src/layout/tab_bar.spec.ts@@ -82,11 +82,13 @@ test("Tabs are restored in right order", async ({ page, context }) => {await expect(app.noteTreeActiveNote).toContainText("Text notes");await recentNotesSaved;- // Refresh the page and check the order.+ // Refresh the page and check the order. Asserting on the wrapper+ // collection (rather than each tab individually) waits for all three+ // titles to populate — restoration renders the active tab first and+ // fills in the others asynchronously.await app.goto( { preserveTabs: true });- await expect(await app.getTab(0)).toContainText("Code notes");- await expect(await app.getTab(1)).toContainText("Text notes");- await expect(await app.getTab(2)).toContainText("Mermaid");+ await expect(app.tabBar.locator(".note-tab-wrapper"))+ .toHaveText([/Code notes/, /Text notes/, /Mermaid/]);// Check the note tree has the right active node.await expect(app.noteTreeActiveNote).toContainText("Text notes");diff --git a/packages/trilium-e2e/src/support/app.ts b/packages/trilium-e2e/src/support/app.tsindex 834537f6d8..c3446edbe5 100644--- a/packages/trilium-e2e/src/support/app.ts+++ b/packages/trilium-e2e/src/support/app.ts@@ -96,12 +96,20 @@ export default class App {async goToNoteInNewTab(noteTitle: string) {const autocomplete = this.currentNoteSplit.locator(".note-autocomplete");await expect(autocomplete).toBeVisible();- await autocomplete.fill(noteTitle);-- const resultsSelector = this.currentNoteSplit.locator(".note-detail-empty-results");- await expect(resultsSelector).toContainText(noteTitle);- const suggestionSelector = resultsSelector.locator(".aa-suggestion")- .nth(1); // Select the second one (best candidate), as the first one is "Create a new note"+ // The algolia autocomplete listens to keyboard events. `fill()` only+ // dispatches `input`, which doesn't reliably open the dropdown — clear+ // and type with real key events instead.+ await autocomplete.click();+ await autocomplete.clear();+ await autocomplete.pressSequentially(noteTitle);++ // The second suggestion is the best candidate; the first is "Create a+ // new note". Asserting on the suggestion itself (instead of the parent+ // `.note-detail-empty-results`, which also contains the recent-notes+ // list) ensures the dropdown actually opened.+ const suggestionSelector = this.currentNoteSplit+ .locator(".note-detail-empty-results .aa-suggestion")+ .nth(1);await expect(suggestionSelector).toContainText(noteTitle);await suggestionSelector.click();}@@ -137,7 +145,12 @@ export default class App {* Adds a new tab by cliking on the + button near the tab bar.*/async addNewTab() {+ const tabs = this.tabBar.locator(".note-tab-wrapper");+ const before = await tabs.count();await this.page.locator('[data-trigger-command="openNewTab"]').click();+ // `openNewTabCommand` doesn't await tab creation, so wait until the+ // new tab is actually in the DOM before returning.+ await expect(tabs).toHaveCount(before + 1);}/**