TidGi-Desktop/features/editWorkspace.feature
linonetwo cdb496961c Improve shutdown DB cleanup and edit workspace UI
Add end-to-end test for editing workspace and improve shutdown/database cleanup and edit-workspace behavior.

Key changes:
- features/editWorkspace.feature: new E2E scenario to verify save button behavior when enabling HTTP API and restarting a wiki.
- src/main.ts: wrap before-quit cleanup in try/catch/finally, call databaseService.closeAllDatabases() early, and add logging to make shutdown order explicit.
- src/services/database/*: add prepareDatabase pragmas (busy_timeout, synchronous) to SQLite config, make closeAppDatabase more robust with safer dataSource.destroy() handling, and add closeAllDatabases() to close all connections and backup stream to avoid better-sqlite3 crashes.
- src/services/database/interface.ts: expose closeAllDatabases() in the service interface and IPC descriptor.
- src/services/workspaces/interface.ts: mark runtime-only fields as non-config (add lastUrl, homeUrl, hibernated, active), move port to localOnlyFields and remove it from syncableConfigFields to avoid spurious save prompts.
- src/services/workspacesView/index.ts: emit a test log marker ([test-id-WIKI_WORKER_RESTARTING]) when a workspace restart is initiated to help tests detect restart events.
- src/windows/EditWorkspace/server.tsx: add data-testid attributes to server options accordion and HTTP API switch to support the new test selectors.
- src/windows/EditWorkspace/useForm.ts: tighten effect dependencies and adjust originalWorkspace change handling to avoid unnecessary form resets during user edits.

Why: fixes intermittent crashes on app quit related to better-sqlite3 by closing DBs first and finalizing resources, and stabilizes edit-workspace UI and tests by preventing runtime-only field changes from triggering save UI and by adding testable hooks.
2026-02-09 00:04:26 +08:00

34 lines
2.3 KiB
Gherkin

@edit-workspace-save
Feature: Edit Workspace
As a user
I want to edit workspace settings
Background:
Given I cleanup test wiki so it could create a new one on start
When 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')"
# Open edit workspace window
When I open edit workspace window for workspace with name "wiki"
And I switch to "editWorkspace" window
@edit-workspace-save-http-api
Scenario: Save button disappears after enabling HTTP API and restarting wiki
# Enable HTTP API (this requires restart, so save button will show a restart snackbar)
When I click on "server options accordion and enableHTTPAPI switch and save button" elements with selectors:
| element description | selector |
| server options accordion | [data-testid='preference-section-serverOptions'] |
| enableHTTPAPI switch | [data-testid='enable-http-api-switch'] |
| save button | [data-testid='edit-workspace-save-button'] |
Then I should not see a "save button" element with selector "[data-testid='edit-workspace-save-button']"
Then I should see a "restart snackbar with restart button" element with selector "button:has-text('')"
# Clear RESTARTING marker to catch the new restart event
And I clear log lines containing "[test-id-WIKI_WORKER_RESTARTING]"
# Click the restart button in the snackbar (still in editWorkspace window)
When I click on a "restart now button in snackbar" element with selector "button:has-text('')"
# Wait for wiki worker restart to begin - RESTARTING marker is logged immediately when restart starts
Then I wait for "wiki worker restart initiated" log marker "[test-id-WIKI_WORKER_RESTARTING]"
# Save button should STILL be hidden after restart completes
# This tests that the workspace state doesn't diverge after restart, not triggered by fields like `lastUrl`
Then I should not see a "save button after restart" element with selector "[data-testid='edit-workspace-save-button']"
Then settings.json should have workspace "wiki" with "enableHTTPAPI" set to "true"