refactor(web): the admin settings cards share one load-and-save cycle (DRY W3)

Five settings cards (Fingerprinting, Loudness, Public address, Proxies,
Notification email) each hand-rolled the same cycle: load into a stored copy
and an editable one, say when they differ, save, adopt what the server
stored, toast. lib/settings/settingsForm.svelte.ts now runs it once
(createSettingsForm), and SettingsLoadStatus draws the "Loading…" / "Couldn't
load … Try again" line for those five and for Library folders and AcoustID.

The Proxies card dropped the server's reason when a save was refused and
toasted a fixed "Couldn't save proxy depth."; it now says why, as the other
cards do. Two cards' "Loading <thing>…" lines now read "Loading…" like the
rest.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-27 03:13:32 -05:00
co-authored by Claude Opus 5.5
parent dae46ea980
commit 87c650aca1
10 changed files with 245 additions and 274 deletions
@@ -1,6 +1,7 @@
import { describe, expect, test, vi, beforeEach } from 'vitest';
import { render, screen, fireEvent, waitFor } from '@testing-library/svelte';
import NetworkSettingsCard from './NetworkSettingsCard.svelte';
import { pushToast } from '#lib/stores/toast.svelte.js';
const getNetworkSettings = vi.fn();
const updateNetworkSettings = vi.fn();
@@ -97,6 +98,26 @@ describe('NetworkSettingsCard', () => {
expect(await screen.findByText(/Count your proxies/)).toBeTruthy();
});
test('a refused save says why, in the server\'s words', async () => {
getNetworkSettings.mockResolvedValue(settings());
updateNetworkSettings.mockRejectedValue({
code: 'invalid_setting',
message: 'trusted proxy hops must be from 0 to 10'
});
render(NetworkSettingsCard);
const input = await screen.findByRole('spinbutton');
await fireEvent.input(input, { target: { value: '2' } });
const save = screen.getByRole('button', { name: /Save/ });
await waitFor(() => expect(save).not.toBeDisabled());
await fireEvent.click(save);
await waitFor(() => expect(pushToast).toHaveBeenCalled());
const [text, kind] = vi.mocked(pushToast).mock.calls[0];
expect(kind).toBe('error');
expect(text).toContain('trusted proxy hops must be from 0 to 10');
});
test('offers a retry when loading fails', async () => {
getNetworkSettings.mockRejectedValue(new Error('boom'));
render(NetworkSettingsCard);