mirror of
https://github.com/tiddly-gittly/TidGi-Desktop.git
synced 2026-03-07 06:20:50 -08:00
Add step to restart workspace in wiki tests
Introduces a new step definition 'I restart workspace {string}' to programmatically restart a wiki workspace during tests. Updates the root tiddler scenario to use this step for verifying lazy-load behavior after workspace restart, improving test reliability and clarity.
This commit is contained in:
parent
0aacfb91ab
commit
cce7152a2e
2 changed files with 67 additions and 21 deletions
|
|
@ -61,33 +61,28 @@ Feature: TidGi Default Wiki
|
|||
Then I should see "我的 TiddlyWiki" in the browser view content
|
||||
|
||||
@wiki @root-tiddler
|
||||
Scenario: Configure root tiddler and verify content loads after restart
|
||||
# First, modify Index tiddler with unique test content before configuring root tiddler
|
||||
Scenario: Configure root tiddler to use lazy-load and verify content still loads
|
||||
# Wait for browser view to be fully loaded first
|
||||
And the browser view should be loaded and visible
|
||||
And I should see "我的 TiddlyWiki" in the browser view content
|
||||
# Now modify Index tiddler with unique test content before configuring root tiddler
|
||||
When I modify file "wiki-test/wiki/tiddlers/Index.tid" to contain "Test content for lazy-all verification after restart"
|
||||
# Verify the test content is displayed in browser view (no need to wait for watch-fs since it's disabled by default)
|
||||
And I should see "Test content for lazy-all verification after restart" in the browser view content
|
||||
# Update rootTiddler setting via API to use lazy-all
|
||||
# before restart, should not see the new content from fs yet (watch-fs is off by default)
|
||||
And I should not see "Test content for lazy-all verification after restart" in the browser view content
|
||||
# Update rootTiddler setting via API to use lazy-all, and ensure watch-fs is disabled
|
||||
When I update workspace "wiki" settings:
|
||||
| property | value |
|
||||
| rootTiddler | $:/core/save/lazy-all |
|
||||
| property | value |
|
||||
| rootTiddler | $:/core/save/lazy-all |
|
||||
| enableFileSystemWatch | false |
|
||||
# Wait for config to be written
|
||||
Then I wait for "config file written" log marker "[test-id-TIDGI_CONFIG_WRITTEN]"
|
||||
# Clear log markers before restart
|
||||
And I clear test-id markers from logs
|
||||
# Restart the workspace to apply the configuration by toggling enableFileSystemWatch
|
||||
When I update workspace "wiki" settings:
|
||||
| property | value |
|
||||
| enableFileSystemWatch | true |
|
||||
# Wait for workspace to fully restart and load
|
||||
Then I wait for log markers:
|
||||
| description | marker |
|
||||
| watch-fs stabilized | [test-id-WATCH_FS_STABILIZED] |
|
||||
| view loaded | [test-id-VIEW_LOADED] |
|
||||
# Verify browser view is loaded and visible
|
||||
# Restart the workspace to apply the rootTiddler configuration
|
||||
When I restart workspace "wiki"
|
||||
# Verify browser view is loaded and visible after restart
|
||||
And the browser view should be loaded and visible
|
||||
# Verify Index tiddler content is loaded with our test content (not just the title)
|
||||
# This confirms lazy-all is working and loading full tiddler content
|
||||
# Verify Index tiddler element exists (confirms rootTiddler=lazy-all config is applied)
|
||||
Then I should see a "Index tiddler" element in browser view with selector "div[data-tiddler-title='Index']"
|
||||
# Verify the actual content is displayed (confirms lazy-all loaded the file content on restart)
|
||||
And I should see "Test content for lazy-all verification after restart" in the browser view content
|
||||
|
||||
@wiki @move-workspace
|
||||
|
|
|
|||
|
|
@ -937,6 +937,57 @@ When('I create a new wiki workspace with name {string}', async function(this: Ap
|
|||
});
|
||||
});
|
||||
|
||||
/**
|
||||
* Restart a workspace wiki worker
|
||||
*/
|
||||
When('I restart workspace {string}', { timeout: STEP_TIMEOUT }, async function(this: ApplicationWorld, workspaceName: string) {
|
||||
if (!this.app) throw new Error('Application is not available');
|
||||
|
||||
const settingsPath = getSettingsPath(this);
|
||||
const settings = JSON.parse(await fs.readFile(settingsPath, 'utf-8')) as { workspaces?: Record<string, IWorkspace> };
|
||||
if (!settings.workspaces) throw new Error('No workspaces found');
|
||||
|
||||
let targetWorkspaceId: string | undefined;
|
||||
for (const [id, workspace] of Object.entries(settings.workspaces)) {
|
||||
if ('name' in workspace && workspace.name === workspaceName) {
|
||||
targetWorkspaceId = id;
|
||||
break;
|
||||
}
|
||||
if ('wikiFolderLocation' in workspace && workspace.wikiFolderLocation) {
|
||||
const folderName = path.basename(workspace.wikiFolderLocation);
|
||||
if (folderName === workspaceName) {
|
||||
targetWorkspaceId = id;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!targetWorkspaceId) throw new Error(`No workspace found: ${workspaceName}`);
|
||||
|
||||
const result = await this.app.evaluate(async ({ BrowserWindow }, workspaceId: string) => {
|
||||
const windows = BrowserWindow.getAllWindows();
|
||||
const mainWindow = windows.find(win => !win.isDestroyed() && win.webContents?.getURL().includes('index.html'));
|
||||
if (!mainWindow) throw new Error('Main window not found');
|
||||
|
||||
return await mainWindow.webContents.executeJavaScript(`
|
||||
(async () => {
|
||||
const workspace = await window.service.workspace.get(${JSON.stringify(workspaceId)});
|
||||
if (!workspace) return { success: false, error: 'Workspace not found' };
|
||||
try {
|
||||
await window.service.wiki.restartWiki(workspace);
|
||||
// Reload view to show fresh content from disk after wiki restart
|
||||
await window.service.view.reloadViewsWebContents(${JSON.stringify(workspaceId)});
|
||||
return { success: true };
|
||||
} catch (error) {
|
||||
return { success: false, error: error.message };
|
||||
}
|
||||
})();
|
||||
`) as Promise<{ success: boolean; error?: string }>;
|
||||
}, targetWorkspaceId);
|
||||
|
||||
if (!result.success) throw new Error(`Failed to restart: ${result.error ?? 'Unknown error'}`);
|
||||
});
|
||||
|
||||
/**
|
||||
* Update workspace settings dynamically after app launch
|
||||
* This is useful for enabling features like enableFileSystemWatch in tests
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue