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

This commit is contained in:
zhanjunhao
2026-11-18 19:09:00 +08:00
parent 4147fac38f
commit 28fb53ceae
87 changed files with 2212 additions and 2823 deletions
+48 -1
View File
@@ -32,7 +32,12 @@ const context = {
};
const controls = await loadFrontendModule(
new URL('../../src/components/ui/controls.jsx', import.meta.url),
{ react: React, antd: Ant, dayjs, '../console/ConsoleContext': context },
{
react: { ...React, useId: () => 'generated-control-id' },
antd: Ant,
dayjs,
'../console/ConsoleContext': context,
},
);
const ui = await loadFrontendModule(
new URL('../../src/components/ui/index.jsx', import.meta.url),
@@ -82,6 +87,48 @@ test('legacy controls keep value callbacks and remote search behavior in v6', ()
assert.equal(Object.hasOwn(select.props, 'onSearch'), false);
});
test('settings secrets declare autocomplete without changing login fields', () => {
context.useConsolePage = () => ({ page: { key: 'setting' } });
try {
for (const props of [{ mode: 'password' }, { type: 'password' }]) {
assert.equal(
controls.Input.render(props, null).props.autoComplete,
'new-password',
);
assert.equal(
controls.Input.render({ ...props, autoComplete: 'off' }, null).props
.autoComplete,
'off',
);
}
assert.equal(controls.Input.render({}, null).props.autoComplete, 'off');
for (const Control of [
controls.Input,
controls.TextArea,
controls.InputNumber,
]) {
assert.equal(Control.render({}, null).props.id, 'generated-control-id');
assert.equal(
Control.render({ id: 'explicit-id' }, null).props.id,
'explicit-id',
);
}
} finally {
context.useConsolePage = () => null;
}
assert.equal(
controls.Input.render({ mode: 'password' }, null).props.autoComplete,
undefined,
);
assert.equal(
controls.Input.render(
{ type: 'password', autoComplete: 'current-password' },
null,
).props.autoComplete,
'current-password',
);
});
test('card semantic styles survive the legacy adapter without losing slots', () => {
const card = ui.Card.render(
{
+76
View File
@@ -0,0 +1,76 @@
/*
Copyright (C) 2025 QuantumNous
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
For commercial licensing, please contact support@quantumnous.com
*/
import assert from 'node:assert/strict';
import test from 'node:test';
import { createServer } from 'node:http';
import { mkdtemp, mkdir, writeFile, rm } from 'node:fs/promises';
import { tmpdir } from 'node:os';
import path from 'node:path';
import { findDevService, logAddresses } from '../../scripts/dev-service.mjs';
test('dev discovery reuses a matching project after a stale log and rejects a different source', async (t) => {
const root = await mkdtemp(path.join(tmpdir(), 'monkey-service-test-'));
t.after(() => rm(root, { recursive: true, force: true }));
await mkdir(path.join(root, 'src'));
await writeFile(path.join(root, 'src/index.jsx'), 'project-entry');
const servers = [];
const listen = async (source) => {
const server = createServer((req, res) => {
res.end(
'//# sourceMappingURL=data:application/json;base64,' +
Buffer.from(JSON.stringify({ sourcesContent: [source] })).toString(
'base64',
),
);
});
servers.push(server);
await new Promise((resolve) => server.listen(0, '127.0.0.1', resolve));
return server.address().port;
};
t.after(() =>
Promise.all(
servers.map((server) => new Promise((resolve) => server.close(resolve))),
),
);
const wrong = await listen('another-project');
const correct = await listen('project-entry');
await writeFile(
path.join(root, 'dev.log'),
'Local: http://127.0.0.1:' + wrong + '/',
);
assert.equal(
await findDevService({ root, getPorts: async () => [wrong, correct] }),
'http://127.0.0.1:' + correct + '/',
);
assert.equal(
await findDevService({ root, getPorts: async () => [wrong] }),
null,
);
});
test('logs support UTF-16LE and newest Local addresses first', () => {
const text = 'Local: http://127.0.0.1:5174/\nLocal: http://127.0.0.1:4176/';
const expected = ['http://127.0.0.1:4176/', 'http://127.0.0.1:5174/'];
assert.deepEqual(logAddresses(Buffer.from(text)), expected);
assert.deepEqual(
logAddresses(Buffer.from('\ufeff' + text, 'utf16le')),
expected,
);
});
+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);
}
});
+12 -2
View File
@@ -175,8 +175,13 @@ test('config isolates HTML, JUnit and traces and supports extended projects', ()
},
),
);
const base = read({}),
ci = read({ CI: '1', PW_EXTENDED_LAYOUT: '1', PW_WORKERS: '1' });
const base = read({ PW_TARGET: 'local-dev' }),
ci = read({
CI: '1',
PW_EXTENDED_LAYOUT: '1',
PW_WORKERS: '1',
PW_TARGET: 'local-dev',
});
assert.equal(base.projects.length, 2);
assert.equal(ci.projects.length, 8);
assert.equal(base.use.headless, false);
@@ -192,6 +197,11 @@ test('config isolates HTML, JUnit and traces and supports extended projects', ()
);
assert.ok(base.use.launchOptions.args.includes('--hide-scrollbars'));
assert.ok(base.webServer.command.includes('--strictPort'));
assert.equal(
read({ PW_TARGET: 'remote', PW_BASE_URL: 'http://127.0.0.1:5174/' })
.webServer,
undefined,
);
assert.deepEqual(read({}, ['--list']).reporter, [['list']]);
assert.throws(
() => read({ CI: '1' }, ['--headed']),
+67
View File
@@ -0,0 +1,67 @@
/*
Copyright (C) 2025 QuantumNous
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
For commercial licensing, please contact support@quantumnous.com
*/
import test from 'node:test';
import assert from 'node:assert/strict';
import { revealActiveSidebarItem } from '../../src/helpers/sidebarScroll.js';
function container(top, bottom, visible = true) {
return {
scrollHeight: 1200,
clientHeight: 500,
clientTop: 2,
scrollTop: 100,
getBoundingClientRect: () => ({ top: 100 }),
querySelector: () => ({
getClientRects: () => (visible ? [{}] : []),
getBoundingClientRect: () => ({ top, bottom }),
}),
};
}
test('reveals an item below the sidebar viewport with the minimum scroll', () => {
const node = container(650, 692);
revealActiveSidebarItem(node);
assert.equal(node.scrollTop, 190);
});
test('reveals an item above the sidebar viewport with the minimum scroll', () => {
const node = container(50, 92);
revealActiveSidebarItem(node);
assert.equal(node.scrollTop, 48);
});
test('preserves manual scrolling when the selected menu is already fully visible', () => {
const node = container(120, 162);
revealActiveSidebarItem(node);
assert.equal(node.scrollTop, 100);
});
test('does not force open a hidden group or scroll a menu without overflow', () => {
const hidden = container(650, 692, false);
revealActiveSidebarItem(hidden);
assert.equal(hidden.scrollTop, 100);
const short = container(650, 692);
short.scrollHeight = 500;
revealActiveSidebarItem(short);
assert.equal(short.scrollTop, 100);
revealActiveSidebarItem(null);
});
test('handles pending or unavailable active items without changing scroll', () => {
const node = container(650, 692);
node.querySelector = () => null;
revealActiveSidebarItem(node);
assert.equal(node.scrollTop, 100);
});