Files
gitea/web_src/js/features/admin/config.test.ts
Sebastian Ertz 3f3bebda0d Update go js dependencies (#37312)
| go | from | to |
| --- | --- | --- |
| github.com/aws/aws-sdk-go-v2/credentials | `1.19.14` | `1.19.15` |
| github.com/aws/aws-sdk-go-v2/service/codecommit | `1.33.12` |
`1.33.13` |
| github.com/dlclark/regexp2 | `1.11.5` | `1.12.0` |
| github.com/go-co-op/gocron/v2 | `2.20.0` | `2.21.0` |
| github.com/go-webauthn/webauthn | `0.16.4` | `0.16.5` |

| js | from | to |
| --- | --- | --- |
| @codemirror/view | `6.41.0` | `6.41.1` |
| @primer/octicons | `19.24.0` | `19.24.1` |
| clippie | `4.1.10` | `4.1.14` |
| postcss | `8.5.9` | `8.5.10` |
| rolldown-license-plugin | `2.2.5` | `3.0.1` |
| swagger-ui-dist | `5.32.2` | `5.32.4` |
| vite | `8.0.8` | `8.0.9` |
| @typescript-eslint/parser | `8.58.2` | `8.59.0` |
| @vitest/eslint-plugin | `1.6.15` | `1.6.16` |
| eslint | `10.2.0` | `10.2.1` |
| eslint-plugin-playwright | `2.10.1` | `2.10.2` |
| eslint-plugin-sonarjs | `4.0.2` | `4.0.3` |
| happy-dom | `20.8.9` | `20.9.0` |
| stylelint | `17.7.0` | `17.8.0` |
| typescript | `6.0.2` | `6.0.3` |
| typescript-eslint | `8.58.2` | `8.59.0` |
| updates | `17.15.3` | `17.15.5` |
| vue-tsc | `3.2.6` | `3.2.7` |

Co-authored-by: Nicolas <bircni@icloud.com>
Co-authored-by: silverwind <me@silverwind.io>
Co-authored-by: silverwind <silv3rwind@gmail.com>
Co-authored-by: Claude (Opus 4.7) <noreply@anthropic.com>
2026-04-20 22:32:45 +00:00

49 lines
2.0 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>
</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"}',
});
});