efb0433412
Universal: PR Check / Branch Policy (pull_request) Failing after 1s
Generic: Repo Health / Site Health (pull_request) Has been skipped
Generic: Repo Health / Access control (pull_request) Successful in 2s
Universal: PR Check / Validate PR (pull_request) Failing after 11s
Generic: Project CI / Lint & Validate (pull_request) Successful in 37s
PR RC Release / Build RC Release (pull_request) Failing after 1m3s
Universal: Pre-Release / Build Pre-Release (${{ inputs.stability || github.ref_name }}) (push) Failing after 1m5s
Universal: Build & Release / Promote to RC (pull_request) Has been skipped
Universal: Build & Release / Build & Release Pipeline (pull_request) Has been skipped
Universal: PR Check / Secret Scan (pull_request) Successful in 1m9s
Generic: Project CI / Tests (pull_request) Has been cancelled
Universal: PR Check / Build RC Package (pull_request) Has been cancelled
Universal: PR Check / Report Issues (pull_request) Has been cancelled
Generic: Repo Health / Scripts governance (pull_request) Has been cancelled
Generic: Repo Health / Repository health (pull_request) Has been cancelled
Generic: Repo Health / Report: Scripts Governance (pull_request) Has been cancelled
Generic: Repo Health / Report: Repository Health (pull_request) Has been cancelled
LandingPageType.Mode defaults to "" (Go zero value), and the template renders the home radio as checked for an empty Mode. The initial radio fill would evaluate home.checked = ("home" === "") = false, unchecking the default on a fresh install. Skip assignment when the config value is empty so the server-rendered selection is preserved. Adds a test for the empty-value case.
62 lines
2.8 KiB
TypeScript
62 lines
2.8 KiB
TypeScript
import {ConfigFormValueMapper} from './config.ts';
|
|
|
|
test('ConfigFormValueMapper', () => {
|
|
document.body.innerHTML = `
|
|
<form>
|
|
<input id="checkbox-unrelated" type="checkbox" value="v-unrelated" checked>
|
|
|
|
<!-- top-level key -->
|
|
<input name="k1" type="checkbox" value="v-key-only" data-config-dyn-key="k1" data-config-value-json="true" data-config-value-type="boolean">
|
|
|
|
<input type="hidden" data-config-dyn-key="k2" data-config-value-json='"k2-val"'>
|
|
<input name="k2">
|
|
|
|
<textarea name="repository.open-with.editor-apps"> a = b\n</textarea>
|
|
|
|
<input name="k-flipped-true" type="checkbox" data-config-value-type="flipped">
|
|
<input name="k-flipped-false" type="checkbox" checked data-config-value-type="flipped">
|
|
|
|
<!-- sub key -->
|
|
<input type="hidden" data-config-dyn-key="struct" data-config-value-json='{"SubBoolean": true, "SubTimestamp": 123456789, "OtherKey": "other-value"}'>
|
|
<input name="struct.SubBoolean" type="checkbox" data-config-value-type="boolean">
|
|
<input name="struct.SubTimestamp" type="datetime-local" data-config-value-type="timestamp">
|
|
<textarea name="struct.NewKey">new-value</textarea>
|
|
|
|
<!-- radio group (sub key): only the option matching the config value should be checked and collected -->
|
|
<input type="hidden" data-config-dyn-key="landing" data-config-value-json='{"Mode": "explore"}'>
|
|
<input name="landing.Mode" type="radio" value="home">
|
|
<input name="landing.Mode" type="radio" value="explore">
|
|
<input name="landing.Mode" type="radio" value="login">
|
|
|
|
<!-- radio group with empty value: the server-rendered default (home) must be preserved, not unchecked -->
|
|
<input type="hidden" data-config-dyn-key="landingDefault" data-config-value-json='{"Mode": ""}'>
|
|
<input name="landingDefault.Mode" type="radio" value="home" checked>
|
|
<input name="landingDefault.Mode" type="radio" value="explore">
|
|
</form>
|
|
`;
|
|
|
|
const form = document.querySelector('form')!;
|
|
const mapper = new ConfigFormValueMapper(form);
|
|
mapper.fillFromSystemConfig();
|
|
const formData = mapper.collectToFormData();
|
|
const result: Record<string, string> = {};
|
|
const keys: string[] = [], values: string[] = [];
|
|
for (const [key, value] of formData.entries()) {
|
|
if (key === 'key') keys.push(value as string);
|
|
if (key === 'value') values.push(value as string);
|
|
}
|
|
for (let i = 0; i < keys.length; i++) {
|
|
result[keys[i]] = values[i];
|
|
}
|
|
expect(result).toEqual({
|
|
'k1': 'true',
|
|
'k2': '"k2-val"',
|
|
'k-flipped-false': 'false',
|
|
'k-flipped-true': 'true',
|
|
'repository.open-with.editor-apps': '[{"DisplayName":"a","OpenURL":"b"}]', // TODO: OPEN-WITH-EDITOR-APP-JSON: it must match backend
|
|
'struct': '{"SubBoolean":true,"SubTimestamp":123456780,"OtherKey":"other-value","NewKey":"new-value"}',
|
|
'landing': '{"Mode":"explore"}',
|
|
'landingDefault': '{"Mode":"home"}',
|
|
});
|
|
});
|