fix(ui): 完善界面交互与开发配置

This commit is contained in:
zhanjunhao
2026-11-18 19:09:00 +08:00
parent b9eae439ba
commit 001fbac538
87 changed files with 2212 additions and 2823 deletions
+109
View File
@@ -106,6 +106,30 @@ test('normal fields keep Ant Form automatic IDs and unnamed slots retain child I
assert.equal(slot.props.children, child);
});
test('radio group labels target an enabled input and preserve value callbacks', () => {
const values = [];
const item = Form.RadioGroup.render(
{
field: 'mode',
label: 'Mode',
onChange: (value) => values.push(value),
options: [
{ label: 'Disabled', value: 'disabled', disabled: true },
{ label: 'Observe', value: 'observe' },
],
},
null,
);
const control = item.props.children;
const group = control.type.render({ ...control.props, id: 'mode' }, null);
assert.equal(group.props.id, 'mode-group');
assert.equal(group.props.options[1].id, 'mode');
assert.equal(group.props.options[0].id, undefined);
assert.equal(group.props['aria-label'], 'Mode');
group.props.onChange({ target: { value: 'observe' } });
assert.deepEqual(values, ['observe']);
});
test('single filter labels preserve existing control IDs', () => {
for (const id of [undefined, 'existing-input']) {
const element = ConsoleFilterField({
@@ -134,3 +158,88 @@ test('composite filters use an accessible group instead of labeling a container'
assert.equal(control, children);
}
});
test('static forms rely on field subscriptions while render props receive updates', async () => {
for (const renderProp of [false, true]) {
let renders = 0;
let api;
let store = {};
const updates = [];
const effects = [];
const form = {
getFieldsValue: () => store,
getFieldValue: (path) => store[path[0]],
setFieldsValue: (next) => {
store = { ...store, ...next };
},
resetFields: () => {
store = {};
},
};
const { Form: TestForm } = await load('../../src/components/ui/form.jsx', {
react: {
...React,
useContext: () => null,
useReducer: () => [
0,
() => {
renders++;
},
],
useRef: (current) => ({ current }),
useMemo: (factory) => factory(),
useEffect: (effect) => effects.push(effect),
useImperativeHandle: () => {},
},
antd: {
Form: Object.assign(() => null, { useForm: () => [form] }),
Checkbox: { Group: Input },
},
'./controls': Object.fromEntries(
[
'Input',
'TextArea',
'InputNumber',
'Select',
'DatePicker',
'TimePicker',
'RadioGroup',
'TagInput',
'TreeSelect',
'AutoComplete',
'Upload',
'Switch',
].map((name) => [name, Input]),
),
'../console/ConsoleContext': { useConsolePage: () => null },
'../console/ConsolePrimitives': {},
});
const tree = TestForm.render(
{
children: renderProp ? () => null : React.createElement('span'),
values: { initial: true },
getFormApi: (next) => {
api = next;
},
onValueChange: (values) => updates.push(values),
labelAlign: 'left',
},
null,
);
effects.forEach((effect) => effect());
assert.equal(tree.props.children.props.labelAlign, 'start');
assert.deepEqual(api.getValues(), { initial: true });
api.setValue('name', 'first');
api.setValues({ name: 'second' });
assert.equal(api.getValue('name'), 'second');
api.reset();
tree.props.children.props.onValuesChange({}, { name: 'typed' });
assert.deepEqual(updates, [
{ initial: true, name: 'first' },
{ initial: true, name: 'second' },
{},
{ name: 'typed' },
]);
assert.equal(renders, renderProp ? 6 : 0);
}
});