fix(client): note context not correctly define (closes #1193)

This commit is contained in:
Elian Doran 2025-04-02 20:08:18 +03:00
parent db66d86bc2
commit 69b2824f9c
No known key found for this signature in database
3 changed files with 32 additions and 3 deletions

View File

@ -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");
});

View File

@ -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();
}
}
}

View File

@ -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();