feat: 1.统一右侧抽屉关闭按钮布局 2.统一 UI 组件为 Ant Design 移除 radix-ui、floating-ui 组件 3. 修复 ESLint 文件格式错误的问题

This commit is contained in:
zhanjunhao
2026-11-10 14:08:10 +08:00
parent 5713d541b0
commit d224d5b6fa
202 changed files with 29195 additions and 12732 deletions
+141
View File
@@ -0,0 +1,141 @@
/*
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 { setImmediate } from 'node:timers/promises';
import React from 'react';
import { createHookRuntime } from './helpers/hookRuntime.js';
import { loadFrontendModule } from './helpers/frontendModule.js';
async function harness() {
const runtime = createHookRuntime();
const { useEffectEvent } = await loadFrontendModule(
new URL('../../src/hooks/common/useEffectEvent.js', import.meta.url),
{ react: runtime.react },
);
return { runtime, useEffectEvent };
}
test('effect events keep identity and only expose the latest committed callback', async () => {
const { runtime, useEffectEvent } = await harness();
const Component = ({ value }) => useEffectEvent((extra) => value + extra);
const first = runtime.render(Component, { value: 1 });
runtime.commit();
assert.equal(first(2), 3);
const updated = runtime.render(Component, { value: 10 });
assert.equal(updated, first);
assert.equal(
first(2),
3,
'An uncommitted render must not leak to external handlers',
);
runtime.commit();
assert.equal(first(2), 12);
});
test('explicit scope changes run once and cleanup keeps its original resource', async () => {
const { runtime, useEffectEvent } = await harness();
const calls = [];
const cleanups = [];
const Component = ({ scope, draft }) => {
const onChange = useEffectEvent(() => {
calls.push([scope, draft]);
return () => cleanups.push(scope);
});
runtime.react.useEffect(() => onChange(), [onChange, scope]);
};
runtime.render(Component, { scope: 1, draft: 'a' });
runtime.flush();
runtime.render(Component, { scope: 1, draft: 'b' });
runtime.flush();
assert.deepEqual(
calls,
[[1, 'a']],
'Editing a draft must not reinitialize the form',
);
runtime.render(Component, { scope: 2, draft: 'b' });
runtime.flush();
assert.deepEqual(calls, [
[1, 'a'],
[2, 'b'],
]);
assert.deepEqual(cleanups, [1]);
runtime.unmount();
assert.deepEqual(cleanups, [1, 2]);
});
test('event callbacks preserve return values, async results, and errors', async () => {
const { runtime, useEffectEvent } = await harness();
const AsyncComponent = () => useEffectEvent(async (value) => value * 2);
const asyncEvent = runtime.render(AsyncComponent);
runtime.commit();
assert.equal(await asyncEvent(4), 8);
const ThrowingComponent = () =>
useEffectEvent(() => {
throw new Error('expected failure');
});
runtime.render(ThrowingComponent);
runtime.commit();
assert.throws(asyncEvent, /expected failure/);
});
test('settings mount and manual refresh settle without repeated option requests', async () => {
const { runtime, useEffectEvent } = await harness();
const requests = [];
const { default: Settings } = await loadFrontendModule(
new URL('../../src/components/settings/ChatsSetting.jsx', import.meta.url),
{
react: runtime.react,
'../../hooks/common/useEffectEvent': { useEffectEvent },
'@/components/ui': { Card: 'Card', Spin: 'Spin' },
'../../pages/Setting/Chat/SettingsChats': {
default: 'SettingsChats',
__esModule: true,
},
'../../helpers': {
API: {
get: async (url) => {
requests.push(url);
return {
data: { success: true, data: [{ key: 'Chats', value: '[]' }] },
};
},
},
showError: assert.fail,
toBoolean: (value) => value === 'true',
},
},
);
runtime.render(Settings);
runtime.flush();
await setImmediate();
let tree = runtime.flush();
assert.deepEqual(requests, ['/api/option/']);
const find = (node) =>
React.isValidElement(node)
? node.type === 'SettingsChats'
? node
: React.Children.toArray(node.props.children).map(find).find(Boolean)
: undefined;
await find(tree).props.refresh();
tree = runtime.flush();
assert.deepEqual(requests, ['/api/option/', '/api/option/']);
assert.equal(find(tree).props.options.Chats, '[]');
});