The general and quota cards registered their react-hook-form fields under
the dotted settings keys. RHF treats dots as nested-path separators, so
the form DISPLAYED fine (its getter falls back to the literal flat key)
but typing nested the value ({ instance: { name } }) and the api's strict
PATCH schema rejected the body — none of these fields ever saved through
the UI, on any instance. Found by Stefan on a fresh self-hosted install.
- admin-settings-form.ts: dot-free form model with one explicit mapping
to the dotted settings keys and converters in both directions; the
submit now also carries ONLY the settings these cards edit, so the
internal branding metadata keys never ride along.
- Saving invalidates the branding query too — the TopBar reads the
instance name from it and kept the old name until its staleTime ran out.
- admin-settings.spec.ts (new e2e pack, registered in ci.yml): drives the
rename THROUGH THE FORM — success message, TopBar update without
reload, value survives reload, api returns it. Verified locally to fail
against the unfixed page and pass against the fix. Every existing
admin-settings test patched the api directly, which is why this bug was
invisible to CI.
- admin-settings-form.test.ts pins that no form field name contains a dot
and the mapping round-trips.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017aviRTgWCcAHUh1SBoxf6P
54 lines
1.8 KiB
TypeScript
54 lines
1.8 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
|
|
import {
|
|
GENERAL_FORM_FIELDS,
|
|
GeneralSettingsForm,
|
|
toFormValues,
|
|
toSettingsPatch,
|
|
} from './admin-settings-form';
|
|
|
|
describe('admin general settings form model (issue #322)', () => {
|
|
// The regression this file exists for: a dotted field name makes
|
|
// react-hook-form nest the typed value and the strict PATCH schema
|
|
// reject the body — the form then looks fine but never saves.
|
|
it('uses no dots in any form field name', () => {
|
|
for (const field of Object.keys(GENERAL_FORM_FIELDS)) {
|
|
expect(field).not.toContain('.');
|
|
}
|
|
});
|
|
|
|
it('round-trips settings through form values back to a flat patch', () => {
|
|
const settings = {
|
|
'instance.name': 'My Wiki',
|
|
'instance.defaultLocale': 'de',
|
|
'auth.registrationMode': 'closed',
|
|
'classification.newPageDefault': 'unclassified',
|
|
'classification.uploadPolicy': 'warn',
|
|
'quota.editorsPerPond': 5,
|
|
'quota.readersPerPond': 50,
|
|
'quota.additionalPonds': 0,
|
|
'quota.storageBytes': 1024,
|
|
'quota.maxFileBytes': 25,
|
|
};
|
|
expect(toSettingsPatch(toFormValues(settings))).toEqual(settings);
|
|
});
|
|
|
|
it('patches only the settings this form edits, under their dotted keys', () => {
|
|
const input: GeneralSettingsForm = {
|
|
instanceName: 'Renamed',
|
|
defaultLocale: 'en',
|
|
registrationMode: 'open',
|
|
newPageClassification: 'vs_nfd',
|
|
uploadPolicy: 'block',
|
|
quotaEditorsPerPond: 1,
|
|
quotaReadersPerPond: 2,
|
|
quotaAdditionalPonds: 3,
|
|
quotaStorageBytes: 4,
|
|
quotaMaxFileBytes: 5,
|
|
};
|
|
const patch = toSettingsPatch(input);
|
|
expect(patch['instance.name']).toBe('Renamed');
|
|
expect(Object.keys(patch).sort()).toEqual(Object.values(GENERAL_FORM_FIELDS).slice().sort());
|
|
});
|
|
});
|