diff --git a/e2e/layout/tab_bar.spec.ts b/e2e/layout/tab_bar.spec.ts index e6df6f328..ccaff3876 100644 --- a/e2e/layout/tab_bar.spec.ts +++ b/e2e/layout/tab_bar.spec.ts @@ -57,3 +57,28 @@ test("Can drag tab to new window", async ({ page, context }) => { const popupApp = new App(popup, context); await expect(popupApp.getActiveTab()).toHaveText(NOTE_TITLE); }); + +test("Tabs are restored in right order", async ({ page, context }) => { + const app = new App(page, context); + await app.goto(); + + // Open three tabs. + await app.closeAllTabs(); + await app.goToNoteInNewTab("Code notes"); + await app.addNewTab(); + await app.goToNoteInNewTab("Text notes"); + await app.addNewTab(); + await app.goToNoteInNewTab("Mermaid"); + + // Select the mid one. + await app.getTab(1).click(); + + // Refresh the page and check the order. + await app.goto( { preserveTabs: true }); + await expect(app.getTab(0)).toContainText("Code notes"); + await expect(app.getTab(1)).toContainText("Text notes"); + await expect(app.getTab(2)).toContainText("Mermaid"); + + // Check the note tree has the right active node. + await expect(app.noteTreeActiveNote).toContainText("Text notes"); +}); diff --git a/e2e/support/app.ts b/e2e/support/app.ts index d6b3d231a..8ae430f1b 100644 --- a/e2e/support/app.ts +++ b/e2e/support/app.ts @@ -4,6 +4,7 @@ import type { BrowserContext } from "@playwright/test"; interface GotoOpts { url?: string; isMobile?: boolean; + preserveTabs?: boolean; } const BASE_URL = "http://127.0.0.1:8082"; @@ -14,6 +15,7 @@ export default class App { readonly tabBar: Locator; readonly noteTree: Locator; + readonly noteTreeActiveNote: Locator; readonly noteTreeHoistedNote: Locator; readonly launcherBar: Locator; readonly currentNoteSplit: Locator; @@ -27,6 +29,7 @@ export default class App { this.tabBar = page.locator(".tab-row-widget-container"); this.noteTree = page.locator(".tree-wrapper"); + this.noteTreeActiveNote = this.noteTree.locator(".fancytree-node.fancytree-active"); 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)"); @@ -35,7 +38,7 @@ export default class App { this.sidebar = page.locator("#right-pane"); } - async goto({ url, isMobile }: GotoOpts = {}) { + async goto({ url, isMobile, preserveTabs }: GotoOpts = {}) { await this.context.addCookies([ { url: BASE_URL, @@ -53,7 +56,9 @@ export default class App { // Wait for the page to load. if (url === "/") { await expect(this.page.locator(".tree")).toContainText("Trilium Integration Test"); - await this.closeAllTabs(); + if (!preserveTabs) { + await this.closeAllTabs(); + } } } diff --git a/src/public/app/widgets/note_context_aware_widget.ts b/src/public/app/widgets/note_context_aware_widget.ts index cadd77c49..df04b35b2 100644 --- a/src/public/app/widgets/note_context_aware_widget.ts +++ b/src/public/app/widgets/note_context_aware_widget.ts @@ -82,7 +82,6 @@ class NoteContextAwareWidget extends BasicWidget { async refreshWithNote(note: FNote | null | undefined) {} async noteSwitchedEvent({ noteContext, notePath }: EventData<"noteSwitched">) { - this.noteContext = noteContext; // if notePath does not match, then the noteContext has been switched to another note in the meantime if (noteContext.notePath === notePath) { await this.noteSwitched();