Skip to content

armgit / lyftr

Public Imported from GitHub
0

Self-hosted fitness tracker. Log workouts, track nutrition, and monitor progress. Docker deployment, mobile-friendly.

feat(settings): editable API server in-app (closes #17) (#43)

Carter95a56b2dbd70
diff --git a/web/e2e/settings.spec.ts b/web/e2e/settings.spec.ts
new file mode 100644
index 0000000..4f7bac3
--- /dev/null
+++ b/web/e2e/settings.spec.ts
@@ -0,0 +1,31 @@
+import { test, expect } from '@playwright/test'
+
+// Authenticated spec — relies on the shared storage state from auth.setup.ts
+// (no test.use override), since Settings is only reachable when logged in.
+//
+// #17: the in-app Settings "Self-Hosted Instance" panel now embeds the reusable
+// ServerSettings editor (previously the API server was read-only here). This is
+// the ONE thing #17 added — the integration. The editor's own validation /
+// connect / warn-but-save behaviour is location-independent and already covered
+// by auth.spec.ts on the sign-in screen, so we don't re-test it here.
+
+test('Settings exposes an editable API server: change persists and resets in-app (#17)', async ({ page }) => {
+ await page.goto('/settings')
+ await expect(page.getByText('Self-Hosted Instance')).toBeVisible()
+
+ // The editor is wired into the page (it used to be read-only text).
+ await page.getByRole('button', { name: /server settings/i }).click()
+ const field = page.getByPlaceholder('Leave blank to use this site')
+ await expect(field).toBeVisible()
+
+ // A change made in-app takes effect (127.0.0.1:9 is a valid absolute URL).
+ await field.fill('http://127.0.0.1:9')
+ await page.getByRole('button', { name: /test & save/i }).click()
+ await expect.poll(() => page.evaluate(() => localStorage.getItem('server_url'))).toBe('http://127.0.0.1:9')
+
+ // Reset to blank recovers from a bad URL without signing out — the point of #17.
+ await field.fill('')
+ await page.getByRole('button', { name: /test & save/i }).click()
+ await expect.poll(() => page.evaluate(() => localStorage.getItem('server_url'))).toBeNull()
+ await expect(page.getByText('This site (reverse proxy)')).toBeVisible()
+})
diff --git a/web/src/pages/Settings.tsx b/web/src/pages/Settings.tsx
index dcd8a4e..3309306 100644
--- a/web/src/pages/Settings.tsx
+++ b/web/src/pages/Settings.tsx
@@ -8,6 +8,7 @@ import { exerciseAPI } from '../services/api'
import * as types from '../types'
import { HelpTip } from '../components/Tooltip'
import PageHeader from '../components/ui/PageHeader'
+import ServerSettings from '../components/ServerSettings'
import {
User, Shield, Target, Moon, Sun, Server, LogOut, Trash2, ChevronRight, Check, AlertCircle, Loader,
Dumbbell, RefreshCw,
@@ -299,6 +300,11 @@ export default function Settings() {
<span className="text-xs font-mono text-tx-muted">{serverUrl || 'This site (reverse proxy)'}</span>
</div>
</SettingRow>
+ {/* #17: same Server Settings editor as the sign-in screens, so a logged-in
+ user can repoint the client (or recover from a bad URL) without signing out. */}
+ <div className="py-2">
+ <ServerSettings />
+ </div>
<SettingRow label="Database" description="Storage backend">
<span className="badge-dim">SQLite</span>
</SettingRow>