From 307691fadf7b03ed47e3331fa15084e2e22689ca Mon Sep 17 00:00:00 2001 From: linonetwo Date: Fri, 26 Dec 2025 23:52:45 +0800 Subject: [PATCH] fix: test that requires enableFileSystemWatch use new step set to true --- features/aiCommitMessage.feature | 4 ++ features/defaultWiki.feature | 4 ++ features/filesystemPlugin.feature | 4 ++ features/gitLog.feature | 4 ++ features/stepDefinitions/wiki.ts | 80 +++++++++++++++++++++++++++++++ features/subWiki.feature | 4 ++ features/sync.feature | 4 ++ features/tiddler.feature | 2 +- 8 files changed, 105 insertions(+), 1 deletion(-) diff --git a/features/aiCommitMessage.feature b/features/aiCommitMessage.feature index 80a9ae97..f75af407 100644 --- a/features/aiCommitMessage.feature +++ b/features/aiCommitMessage.feature @@ -11,6 +11,10 @@ Feature: AI-Generated Git Commit Messages And I launch the TidGi application And I wait for the page to load completely Then I should see a "default wiki workspace" element with selector "div[data-testid^='workspace-']:has-text('wiki')" + # Enable file system watch for testing (default is false in production) + When I update workspace "wiki" settings: + | property | value | + | enableFileSystemWatch | true | When I click on a "default wiki workspace button" element with selector "div[data-testid^='workspace-']:has-text('wiki')" Then the browser view should be loaded and visible And I wait for SSE and watch-fs to be ready diff --git a/features/defaultWiki.feature b/features/defaultWiki.feature index 9fe59242..6c743ad5 100644 --- a/features/defaultWiki.feature +++ b/features/defaultWiki.feature @@ -24,6 +24,10 @@ Feature: TidGi Default Wiki @wiki @move-workspace Scenario: Move workspace to a new location + # Enable file system watch for testing (default is false in production) + When I update workspace "wiki" settings: + | property | value | + | enableFileSystemWatch | true | When I open edit workspace window for workspace with name "wiki" And I switch to "editWorkspace" window And I wait for the page to load completely diff --git a/features/filesystemPlugin.feature b/features/filesystemPlugin.feature index 31e8358a..3315d9b1 100644 --- a/features/filesystemPlugin.feature +++ b/features/filesystemPlugin.feature @@ -8,6 +8,10 @@ Feature: Filesystem Plugin And I launch the TidGi application And I wait for the page to load completely Then I should see a "default wiki workspace" element with selector "div[data-testid^='workspace-']:has-text('wiki')" + # Enable file system watch for testing (default is false in production) + When I update workspace "wiki" settings: + | property | value | + | enableFileSystemWatch | true | When I click on a "default wiki workspace button" element with selector "div[data-testid^='workspace-']:has-text('wiki')" Then the browser view should be loaded and visible And I wait for SSE and watch-fs to be ready diff --git a/features/gitLog.feature b/features/gitLog.feature index 6877553a..e5e1553a 100644 --- a/features/gitLog.feature +++ b/features/gitLog.feature @@ -8,6 +8,10 @@ Feature: Git Log Window And I launch the TidGi application And I wait for the page to load completely Then I should see a "default wiki workspace" element with selector "div[data-testid^='workspace-']:has-text('wiki')" + # Enable file system watch for testing (default is false in production) + When I update workspace "wiki" settings: + | property | value | + | enableFileSystemWatch | true | When I click on a "default wiki workspace button" element with selector "div[data-testid^='workspace-']:has-text('wiki')" Then the browser view should be loaded and visible And I wait for SSE and watch-fs to be ready diff --git a/features/stepDefinitions/wiki.ts b/features/stepDefinitions/wiki.ts index 59994a58..afedf604 100644 --- a/features/stepDefinitions/wiki.ts +++ b/features/stepDefinitions/wiki.ts @@ -714,6 +714,86 @@ When('I create a new wiki workspace with name {string}', async function(this: Ap }); }); +/** + * Update workspace settings dynamically after app launch + * This is useful for enabling features like enableFileSystemWatch in tests + * + * Usage: + * When I update workspace "wiki" settings: + * | property | value | + * | enableFileSystemWatch | true | + * | syncOnInterval | false | + */ +When('I update workspace {string} settings:', async function(this: ApplicationWorld, workspaceName: string, dataTable: DataTable) { + if (!this.app) { + throw new Error('Application is not available'); + } + + // Parse settings from DataTable + const rows = dataTable.hashes(); + const settingsUpdate: Record = {}; + + for (const row of rows) { + const { property, value } = row; + + // Convert value to appropriate type + let parsedValue: unknown = value; + if (value === 'true') parsedValue = true; + else if (value === 'false') parsedValue = false; + else if (value === 'null') parsedValue = null; + else if (!isNaN(Number(value))) parsedValue = Number(value); + // Try to parse as JSON array + else if (value.startsWith('[') && value.endsWith(']')) { + try { + parsedValue = JSON.parse(value); + } catch { + // Keep as string if JSON parse fails + } + } + + settingsUpdate[property] = parsedValue; + } + + // Read settings file to get workspace ID + const settings = await fs.readJson(settingsPath) as { workspaces?: Record }; + const workspaces: Record = settings.workspaces ?? {}; + + // Find workspace by name + let targetWorkspaceId: string | undefined; + for (const [id, workspace] of Object.entries(workspaces)) { + if (!workspace.pageType && workspace.name === workspaceName) { + targetWorkspaceId = id; + break; + } + } + + if (!targetWorkspaceId) { + throw new Error(`No workspace found with name: ${workspaceName}`); + } + + // Update workspace settings via main window + await this.app.evaluate(async ({ BrowserWindow }, { workspaceId, updates }: { workspaceId: string; updates: Record }) => { + const windows = BrowserWindow.getAllWindows(); + const mainWindow = windows.find(win => !win.isDestroyed() && win.webContents && win.webContents.getURL().includes('index.html')); + + if (!mainWindow) { + throw new Error('Main window not found'); + } + + // Call workspace service to update workspace settings + await mainWindow.webContents.executeJavaScript(` + (async () => { + await window.service.workspace.update(${JSON.stringify(workspaceId)}, ${JSON.stringify(updates)}); + })(); + `); + }, { workspaceId: targetWorkspaceId, updates: settingsUpdate }); + + // Wait for settings to propagate + await this.app.evaluate(async () => { + await new Promise(resolve => setTimeout(resolve, 500)); + }); +}); + /** * Clean up hibernation test data - remove wiki2 folder and its workspace config */ diff --git a/features/subWiki.feature b/features/subWiki.feature index 25292dda..5db55f35 100644 --- a/features/subWiki.feature +++ b/features/subWiki.feature @@ -17,6 +17,10 @@ Feature: Sub-Wiki Functionality Then I should see "page body and workspaces" elements with selectors: | div[data-testid^='workspace-']:has-text('wiki') | | div[data-testid^='workspace-']:has-text('SubWiki') | + # Enable file system watch for testing (default is false in production) + When I update workspace "wiki" settings: + | property | value | + | enableFileSystemWatch | true | When I click on a "default wiki workspace button" element with selector "div[data-testid^='workspace-']:has-text('wiki')" Then the browser view should be loaded and visible And I wait for SSE and watch-fs to be ready diff --git a/features/sync.feature b/features/sync.feature index 161bb58e..e0ba1fa8 100644 --- a/features/sync.feature +++ b/features/sync.feature @@ -8,6 +8,10 @@ Feature: Git Sync And I launch the TidGi application And I wait for the page to load completely Then I should see a "default wiki workspace" element with selector "div[data-testid^='workspace-']:has-text('wiki')" + # Enable file system watch for testing (default is false in production) + When I update workspace "wiki" settings: + | property | value | + | enableFileSystemWatch | true | Then the browser view should be loaded and visible And I wait for SSE and watch-fs to be ready And I wait for "git initialization" log marker "[test-id-git-init-complete]" diff --git a/features/tiddler.feature b/features/tiddler.feature index ccd54647..a3d3ec67 100644 --- a/features/tiddler.feature +++ b/features/tiddler.feature @@ -10,7 +10,7 @@ Feature: Tiddler Creation and Editing Then I should see a "default wiki workspace" element with selector "div[data-testid^='workspace-']:has-text('wiki')" When I click on a "default wiki workspace button" element with selector "div[data-testid^='workspace-']:has-text('wiki')" Then the browser view should be loaded and visible - And I wait for SSE and watch-fs to be ready + And I wait for "SSE backend ready" log marker "[test-id-SSE_READY]" @tiddler @tiddler-create Scenario: Create a new tiddler with tag and custom field via UI