feat: 合并代码后 系统设置 ui样式优化、bug修复、全局统一图标对齐等
This commit is contained in:
@@ -0,0 +1,115 @@
|
||||
/*
|
||||
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 React from 'react';
|
||||
import { renderToStaticMarkup } from 'react-dom/server';
|
||||
import * as ant from '@ant-design/icons';
|
||||
import * as icons from '../../src/components/common/icons/ActionIcons.js';
|
||||
import { loadFrontendModule } from './helpers/frontendModule.js';
|
||||
|
||||
test('common action glyphs render Ant Design icons with their existing accessible props', () => {
|
||||
for (const name of [
|
||||
'Search',
|
||||
'Plus',
|
||||
'RefreshCw',
|
||||
'Copy',
|
||||
'Trash2',
|
||||
'X',
|
||||
'Save',
|
||||
'Eye',
|
||||
'EyeOff',
|
||||
'Download',
|
||||
'Settings',
|
||||
'GitCompare',
|
||||
'TestTube2',
|
||||
'Eraser',
|
||||
'PanelLeftOpen',
|
||||
'Bold',
|
||||
'Moon',
|
||||
'Sun',
|
||||
]) {
|
||||
const html = renderToStaticMarkup(
|
||||
React.createElement(icons[name], {
|
||||
size: 18,
|
||||
'aria-label': name,
|
||||
'data-testid': name,
|
||||
}),
|
||||
);
|
||||
assert.match(html, /app-action-icon/);
|
||||
assert.match(html, /anticon/);
|
||||
assert.match(html, /font-size:18px/);
|
||||
assert.ok(html.includes(`aria-label="${name}"`));
|
||||
assert.doesNotMatch(html, /lucide/);
|
||||
}
|
||||
});
|
||||
|
||||
test('action icons preserve refs, class names, explicit style, symbolic size and color', () => {
|
||||
const ref = React.createRef();
|
||||
const node = icons.Copy.render(
|
||||
{
|
||||
size: 'large',
|
||||
color: 'currentColor',
|
||||
className: 'custom',
|
||||
style: { fontSize: 22 },
|
||||
strokeWidth: 1.5,
|
||||
},
|
||||
ref,
|
||||
);
|
||||
assert.equal(node.type, ant.CopyOutlined);
|
||||
assert.equal(node.ref, ref);
|
||||
assert.equal(node.props.style.fontSize, 22);
|
||||
assert.equal(node.props.style.color, 'currentColor');
|
||||
assert.match(node.props.className, /custom/);
|
||||
assert.equal(node.props.strokeWidth, undefined);
|
||||
assert.equal(icons.ArrowUpRight.render({}, null).props.rotate, 45);
|
||||
});
|
||||
|
||||
test('favorite toggles retain filled stars and an unmatched heartbeat retains its original glyph', () => {
|
||||
assert.equal(
|
||||
icons.Star.render({ fill: 'currentColor' }, null).type,
|
||||
ant.StarFilled,
|
||||
);
|
||||
assert.equal(
|
||||
icons.Star.render({ fill: 'none' }, null).type,
|
||||
ant.StarOutlined,
|
||||
);
|
||||
assert.match(
|
||||
renderToStaticMarkup(React.createElement(icons.Activity)),
|
||||
/lucide/,
|
||||
);
|
||||
});
|
||||
|
||||
test('legacy icon names retain size presets and now resolve to Ant Design', async () => {
|
||||
const legacy = await loadFrontendModule(
|
||||
new URL('../../src/components/ui/icons.jsx', import.meta.url),
|
||||
{ react: React },
|
||||
);
|
||||
const html = renderToStaticMarkup(
|
||||
React.createElement(legacy.IconSearch, { size: 'small' }),
|
||||
);
|
||||
assert.match(html, /font-size:14px/);
|
||||
assert.match(html, /anticon-search/);
|
||||
assert.doesNotMatch(html, /lucide/);
|
||||
assert.match(
|
||||
renderToStaticMarkup(React.createElement(legacy.IconPulse)),
|
||||
/lucide/,
|
||||
);
|
||||
});
|
||||
@@ -0,0 +1,159 @@
|
||||
/*
|
||||
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 { readFile } from 'node:fs/promises';
|
||||
import test from 'node:test';
|
||||
import React from 'react';
|
||||
import { parse } from '@babel/parser';
|
||||
import { runInNewContext } from 'node:vm';
|
||||
import { transformWithEsbuild } from 'vite';
|
||||
import { loadFrontendModule } from './frontend-module.js';
|
||||
|
||||
const react = {
|
||||
...React,
|
||||
useMemo: (callback) => callback(),
|
||||
useEffect: () => {},
|
||||
useState: (initial) => [initial, () => {}],
|
||||
useContext: (context) => context,
|
||||
};
|
||||
const userState = { user: { quota: 100, used_quota: 20, request_count: 8 } };
|
||||
async function loadStats(filename, mocks) {
|
||||
const { code } = await transformWithEsbuild(
|
||||
await readFile(filename, 'utf8'),
|
||||
filename.pathname,
|
||||
{
|
||||
loader: 'jsx',
|
||||
format: 'cjs',
|
||||
},
|
||||
);
|
||||
const module = { exports: {} };
|
||||
runInNewContext(code, {
|
||||
React,
|
||||
module,
|
||||
exports: module.exports,
|
||||
require: (name) => mocks[name],
|
||||
});
|
||||
return module.exports;
|
||||
}
|
||||
const stats = await loadStats(
|
||||
new URL('../../src/hooks/dashboard/useDashboardStats.jsx', import.meta.url),
|
||||
{
|
||||
react,
|
||||
'lucide-react': {
|
||||
Wallet: 'Wallet',
|
||||
Activity: 'Activity',
|
||||
Gauge: 'Gauge',
|
||||
Cpu: 'Cpu',
|
||||
},
|
||||
'@/components/ui/icons': Object.fromEntries(
|
||||
[
|
||||
'IconMoneyExchangeStroked',
|
||||
'IconHistogram',
|
||||
'IconPulse',
|
||||
'IconStopwatchStroked',
|
||||
'IconTypograph',
|
||||
'IconSend',
|
||||
].map((name) => [name, name]),
|
||||
),
|
||||
'../../helpers': { renderNumber: String, renderQuota: String },
|
||||
'../../helpers/dashboard': { createSectionTitle: (_, title) => title },
|
||||
},
|
||||
);
|
||||
|
||||
function descendants(node) {
|
||||
if (Array.isArray(node)) return node.flatMap(descendants);
|
||||
if (!node || typeof node !== 'object') return [];
|
||||
return [node, ...descendants(node.props?.children)];
|
||||
}
|
||||
|
||||
for (const path of [
|
||||
'pages/UserCenter/UserDashboard.jsx',
|
||||
'components/dashboard/index.jsx',
|
||||
]) {
|
||||
test(`${path} renders real statistics without navigating during render`, async () => {
|
||||
const filename = new URL(`../../src/${path}`, import.meta.url);
|
||||
const source = await readFile(filename, 'utf8');
|
||||
const ast = parse(source, { sourceType: 'module', plugins: ['jsx'] });
|
||||
// Only data fetching and presentation children are stubbed; execute the page
|
||||
// and the real statistics hook together to catch positional argument drift.
|
||||
const mocks = Object.fromEntries(
|
||||
ast.program.body
|
||||
.filter((node) => node.type === 'ImportDeclaration')
|
||||
.map((node) => [
|
||||
node.source.value,
|
||||
Object.fromEntries([
|
||||
['__esModule', true],
|
||||
...node.specifiers.map((specifier) => [
|
||||
specifier.imported?.name || 'default',
|
||||
specifier.local.name,
|
||||
]),
|
||||
]),
|
||||
]),
|
||||
);
|
||||
const navigation = [];
|
||||
Object.assign(mocks, {
|
||||
react,
|
||||
'../../context/User': { UserContext: [userState, () => {}] },
|
||||
'../../context/Status': { StatusContext: [{}] },
|
||||
'../../hooks/common/useEffectEvent': {
|
||||
useEffectEvent: (callback) => callback,
|
||||
},
|
||||
'../../hooks/common/useIsMobile': { useIsMobile: () => false },
|
||||
'../../hooks/dashboard/useDashboardStats': stats,
|
||||
'../../hooks/dashboard/useDashboardCharts': {
|
||||
useDashboardCharts: () => ({}),
|
||||
},
|
||||
'../../hooks/dashboard/useDashboardData': {
|
||||
useDashboardData: () => ({
|
||||
times: 7,
|
||||
trendData: [{ deliberately: 'different from metrics' }],
|
||||
performanceMetrics: { avgRPM: 12, avgTPM: 345 },
|
||||
tokenUsage: {
|
||||
input_tokens: 10,
|
||||
output_tokens: 20,
|
||||
cache_tokens: 30,
|
||||
cache_creation_tokens: 40,
|
||||
},
|
||||
navigate: (...args) => navigation.push(args),
|
||||
t: (value) => value,
|
||||
}),
|
||||
},
|
||||
'../../constants/dashboard.constants': { UPTIME_STATUS_MAP: {} },
|
||||
});
|
||||
const Page = (await loadFrontendModule(filename, mocks)).default;
|
||||
const tree = Page();
|
||||
assert.deepEqual(navigation, []);
|
||||
const groups = descendants(tree).find((node) => node.type === 'StatsCards')
|
||||
.props.groupedStatsData;
|
||||
assert.deepEqual(
|
||||
Array.from(groups.at(-1).items, (item) => item.value),
|
||||
[12, 345],
|
||||
);
|
||||
const tokens = groups.find((group) => group.title === 'Token 流量');
|
||||
if (path.startsWith('pages/')) {
|
||||
assert.deepEqual(
|
||||
Array.from(tokens.items, (item) => item.value),
|
||||
['10', '20', '30', '40'],
|
||||
);
|
||||
} else {
|
||||
assert.equal(tokens, undefined);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,136 @@
|
||||
/*
|
||||
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 { readFile } from 'node:fs/promises';
|
||||
import test from 'node:test';
|
||||
import React from 'react';
|
||||
import { transformWithEsbuild } from 'vite';
|
||||
|
||||
async function load(relativePath, mocks) {
|
||||
const filename = new URL(relativePath, import.meta.url);
|
||||
const { code } = await transformWithEsbuild(
|
||||
await readFile(filename, 'utf8'),
|
||||
filename.pathname,
|
||||
{ loader: 'jsx', format: 'cjs' },
|
||||
);
|
||||
const module = { exports: {} };
|
||||
new Function('require', 'module', 'exports', code)(
|
||||
(name) => {
|
||||
assert.ok(Object.hasOwn(mocks, name), `Missing dependency: ${name}`);
|
||||
return mocks[name];
|
||||
},
|
||||
module,
|
||||
module.exports,
|
||||
);
|
||||
return module.exports;
|
||||
}
|
||||
|
||||
const Input = React.forwardRef(function Input() {
|
||||
return null;
|
||||
});
|
||||
const { Form } = await load('../../src/components/ui/form.jsx', {
|
||||
react: { ...React, useContext: () => null },
|
||||
antd: { Form: { Item: 'form-item' }, Checkbox: { Group: Input } },
|
||||
'./controls': Object.fromEntries(
|
||||
[
|
||||
'Input',
|
||||
'TextArea',
|
||||
'InputNumber',
|
||||
'Select',
|
||||
'DatePicker',
|
||||
'TimePicker',
|
||||
'RadioGroup',
|
||||
'TagInput',
|
||||
'TreeSelect',
|
||||
'AutoComplete',
|
||||
'Upload',
|
||||
'Switch',
|
||||
].map((name) => [name, Input]),
|
||||
),
|
||||
'../console/ConsoleContext': {},
|
||||
'../console/ConsolePrimitives': {},
|
||||
});
|
||||
const { ConsoleFilterField } = await load(
|
||||
'../../src/components/console/ConsoleModuleFilters.jsx',
|
||||
{
|
||||
react: { ...React, useId: () => 'generated-filter-id' },
|
||||
antd: {},
|
||||
'react-i18next': {},
|
||||
'../common/table/FilterSearchButton': {},
|
||||
'./module-alignment.css': {},
|
||||
},
|
||||
);
|
||||
|
||||
test('form labels and controls share explicit IDs and legacy label names', () => {
|
||||
for (const props of [
|
||||
{ field: 'name', label: 'Name', id: 'custom-name' },
|
||||
{ field: 'name', label: { text: 'Name', name: 'legacy-name' } },
|
||||
{
|
||||
field: 'name',
|
||||
label: { text: 'Name', name: 'legacy-name' },
|
||||
id: 'explicit-name',
|
||||
},
|
||||
]) {
|
||||
const item = Form.Input.render(props, null);
|
||||
assert.equal(item.props.htmlFor, props.id ?? props.label.name);
|
||||
assert.equal(item.props.children.props.id, item.props.htmlFor);
|
||||
assert.deepEqual(item.props.name, ['name']);
|
||||
}
|
||||
});
|
||||
|
||||
test('normal fields keep Ant Form automatic IDs and unnamed slots retain child IDs', () => {
|
||||
const normal = Form.Input.render({ field: 'name', label: 'Name' }, null);
|
||||
assert.equal(normal.props.htmlFor, undefined);
|
||||
assert.equal(Object.hasOwn(normal.props, 'htmlFor'), false);
|
||||
assert.equal(normal.props.children.props.id, undefined);
|
||||
const child = React.createElement(Input, { id: 'slot-input' });
|
||||
const slot = Form.Input.render({ label: 'Slot', children: child }, null);
|
||||
assert.equal(slot.props.htmlFor, 'slot-input');
|
||||
assert.equal(slot.props.children, child);
|
||||
});
|
||||
|
||||
test('single filter labels preserve existing control IDs', () => {
|
||||
for (const id of [undefined, 'existing-input']) {
|
||||
const element = ConsoleFilterField({
|
||||
label: 'Search',
|
||||
children: React.createElement(Input, { id }),
|
||||
});
|
||||
const [label, control] = element.props.children;
|
||||
assert.equal(label.type, 'label');
|
||||
assert.equal(label.props.htmlFor, id ?? 'generated-filter-id');
|
||||
assert.equal(control.props.id, label.props.htmlFor);
|
||||
}
|
||||
});
|
||||
|
||||
test('composite filters use an accessible group instead of labeling a container', () => {
|
||||
for (const type of ['div', React.Fragment]) {
|
||||
const children = React.createElement(type, null, [
|
||||
React.createElement(Input, { key: 'min' }),
|
||||
React.createElement(Input, { key: 'max' }),
|
||||
]);
|
||||
const element = ConsoleFilterField({ label: 'Amount', children });
|
||||
assert.equal(element.props.role, 'group');
|
||||
const [label, control] = element.props.children;
|
||||
assert.equal(label.type, 'span');
|
||||
assert.equal(label.props.htmlFor, undefined);
|
||||
assert.equal(element.props['aria-labelledby'], label.props.id);
|
||||
assert.equal(control, children);
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
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 { readFile } from 'node:fs/promises';
|
||||
import { runInNewContext } from 'node:vm';
|
||||
import { transformWithEsbuild } from 'vite';
|
||||
import * as actionIcons from '../../src/components/common/icons/ActionIcons.js';
|
||||
|
||||
export async function loadFrontendModule(filename, mocks) {
|
||||
const { code } = await transformWithEsbuild(
|
||||
await readFile(filename, 'utf8'),
|
||||
filename.pathname,
|
||||
{ loader: 'jsx', format: 'cjs', define: { 'import.meta.env': '{}' } },
|
||||
);
|
||||
const module = { exports: {} };
|
||||
runInNewContext(code, {
|
||||
module,
|
||||
exports: module.exports,
|
||||
URLSearchParams,
|
||||
TextEncoder,
|
||||
FormData,
|
||||
File,
|
||||
Uint8Array,
|
||||
atob,
|
||||
require(name) {
|
||||
if (name.endsWith('/common/icons/ActionIcons')) return actionIcons;
|
||||
assert.ok(Object.hasOwn(mocks, name), `Missing test dependency: ${name}`);
|
||||
return mocks[name];
|
||||
},
|
||||
});
|
||||
return module.exports;
|
||||
}
|
||||
@@ -20,6 +20,7 @@ For commercial licensing, please contact support@quantumnous.com
|
||||
import assert from 'node:assert/strict';
|
||||
import { readFile } from 'node:fs/promises';
|
||||
import { transformWithEsbuild } from 'vite';
|
||||
import * as actionIcons from '../../../src/components/common/icons/ActionIcons.js';
|
||||
|
||||
export async function loadFrontendModule(filename, mocks) {
|
||||
const { code } = await transformWithEsbuild(
|
||||
@@ -35,6 +36,7 @@ export async function loadFrontendModule(filename, mocks) {
|
||||
const module = { exports: {} };
|
||||
new Function('require', 'module', 'exports', code)(
|
||||
(name) => {
|
||||
if (name.endsWith('/common/icons/ActionIcons')) return actionIcons;
|
||||
assert.ok(Object.hasOwn(mocks, name), 'Missing test dependency: ' + name);
|
||||
return mocks[name];
|
||||
},
|
||||
|
||||
@@ -0,0 +1,181 @@
|
||||
/*
|
||||
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 { readFile, readdir } from 'node:fs/promises';
|
||||
import test from 'node:test';
|
||||
import React from 'react';
|
||||
import { parse } from '@babel/parser';
|
||||
import { transformWithEsbuild } from 'vite';
|
||||
|
||||
let pageKey = 'setting';
|
||||
const token = {
|
||||
colorInfoBg: 'info-background',
|
||||
colorInfoBorder: 'info-border',
|
||||
colorInfo: 'info-icon',
|
||||
colorWarningBg: 'warning-background',
|
||||
colorWarningBorder: 'warning-border',
|
||||
};
|
||||
const filename = new URL(
|
||||
'../../src/components/console/ConsolePrimitives.jsx',
|
||||
import.meta.url,
|
||||
);
|
||||
const { code } = await transformWithEsbuild(
|
||||
await readFile(filename, 'utf8'),
|
||||
filename.pathname,
|
||||
{ loader: 'jsx', format: 'cjs' },
|
||||
);
|
||||
const module = { exports: {} };
|
||||
const mocks = {
|
||||
react: React,
|
||||
antd: {
|
||||
Alert: 'alert',
|
||||
Table: 'table',
|
||||
Empty: Object.assign(() => null, { PRESENTED_IMAGE_SIMPLE: 'simple' }),
|
||||
theme: { useToken: () => ({ token }) },
|
||||
},
|
||||
'react-i18next': {},
|
||||
'../common/table/TableEmpty': () => null,
|
||||
'./ConsoleContext': { useConsolePage: () => ({ page: { key: pageKey } }) },
|
||||
};
|
||||
new Function('require', 'module', 'exports', code)(
|
||||
(name) => {
|
||||
assert.ok(Object.hasOwn(mocks, name), name);
|
||||
return mocks[name];
|
||||
},
|
||||
module,
|
||||
module.exports,
|
||||
);
|
||||
const { ConsoleAlert, ConsoleTable } = module.exports;
|
||||
|
||||
test('settings alerts share the reference surface while retaining their semantic type', () => {
|
||||
pageKey = 'setting';
|
||||
for (const type of ['info', 'warning', 'error', 'success']) {
|
||||
const element = ConsoleAlert({ type, description: 'Existing message' });
|
||||
assert.equal(element.props.type, type);
|
||||
assert.equal(element.props.description, 'Existing message');
|
||||
assert.equal(element.props.style.background, token.colorInfoBg);
|
||||
assert.equal(element.props.style.borderColor, token.colorInfoBorder);
|
||||
assert.equal(
|
||||
element.props.style['--settings-alert-icon-color'],
|
||||
token.colorInfo,
|
||||
);
|
||||
}
|
||||
pageKey = 'token';
|
||||
const element = ConsoleAlert({ type: 'warning' });
|
||||
assert.equal(element.props.style.background, token.colorWarningBg);
|
||||
assert.equal(element.props.style.borderColor, token.colorWarningBorder);
|
||||
});
|
||||
|
||||
test('settings tables use token-list density and keep columns and callbacks intact', () => {
|
||||
const columns = [{ dataIndex: 'value', render: (value) => value }];
|
||||
const onChange = () => {};
|
||||
const props = { columns, onChange, size: 'small' };
|
||||
pageKey = 'setting';
|
||||
const element = ConsoleTable.render(props, null);
|
||||
assert.equal(element.props.size, 'middle');
|
||||
assert.equal(element.props.columns, columns);
|
||||
assert.equal(element.props.onChange, onChange);
|
||||
pageKey = 'token';
|
||||
assert.equal(ConsoleTable.render(props, null).props.size, 'small');
|
||||
});
|
||||
|
||||
function walk(node, visit) {
|
||||
if (!node || typeof node !== 'object') return;
|
||||
visit(node);
|
||||
for (const [key, value] of Object.entries(node)) {
|
||||
if (key === 'loc') continue;
|
||||
if (Array.isArray(value)) value.forEach((child) => walk(child, visit));
|
||||
else if (value && typeof value === 'object') walk(value, visit);
|
||||
}
|
||||
}
|
||||
|
||||
async function sourceFiles(directory) {
|
||||
const entries = await readdir(directory, { withFileTypes: true });
|
||||
const files = [];
|
||||
for (const entry of entries) {
|
||||
const child = new URL(
|
||||
entry.name + (entry.isDirectory() ? '/' : ''),
|
||||
directory,
|
||||
);
|
||||
if (entry.isDirectory()) files.push(...(await sourceFiles(child)));
|
||||
else if (entry.name.endsWith('.jsx')) files.push(child);
|
||||
}
|
||||
return files;
|
||||
}
|
||||
|
||||
test('every settings action column uses labeled links instead of icon buttons', async () => {
|
||||
const files = [
|
||||
...(await sourceFiles(
|
||||
new URL('../../src/pages/Setting/', import.meta.url),
|
||||
)),
|
||||
...(await sourceFiles(
|
||||
new URL('../../src/components/settings/', import.meta.url),
|
||||
)),
|
||||
];
|
||||
let count = 0;
|
||||
for (const file of files) {
|
||||
const source = await readFile(file, 'utf8');
|
||||
const ast = parse(source, { sourceType: 'module', plugins: ['jsx'] });
|
||||
walk(ast, (node) => {
|
||||
if (node.type !== 'ObjectExpression') return;
|
||||
const title = node.properties.find(
|
||||
(property) => property.key?.name === 'title',
|
||||
);
|
||||
const render = node.properties.find(
|
||||
(property) => property.key?.name === 'render',
|
||||
);
|
||||
if (
|
||||
!title ||
|
||||
!render ||
|
||||
!/t\(['"]\u64cd\u4f5c['"]\)/.test(
|
||||
source.slice(title.value.start, title.value.end),
|
||||
)
|
||||
)
|
||||
return;
|
||||
walk(render, (child) => {
|
||||
if (
|
||||
child.type !== 'JSXElement' ||
|
||||
!['Button', 'AntButton'].includes(child.openingElement.name.name)
|
||||
)
|
||||
return;
|
||||
const attributes = child.openingElement.attributes;
|
||||
const type = attributes.find(
|
||||
(attribute) => attribute.name?.name === 'type',
|
||||
);
|
||||
const location = `${file.pathname}:${child.loc.start.line}`;
|
||||
assert.equal(type?.value?.value, 'link', location);
|
||||
assert.ok(
|
||||
!attributes.some((attribute) =>
|
||||
['icon', 'theme'].includes(attribute.name?.name),
|
||||
),
|
||||
location,
|
||||
);
|
||||
assert.ok(
|
||||
child.children.some(
|
||||
(content) => content.type !== 'JSXText' || content.value.trim(),
|
||||
),
|
||||
location,
|
||||
);
|
||||
count++;
|
||||
});
|
||||
});
|
||||
}
|
||||
assert.ok(count > 0);
|
||||
});
|
||||
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
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 * as model from '../../src/pages/WebsiteSettings/model.js';
|
||||
import * as richTextImages from '../../src/components/common/ui/richTextImages.js';
|
||||
import { loadFrontendModule } from './frontend-module.js';
|
||||
|
||||
function validValues() {
|
||||
return {
|
||||
paidCustomers: '200+',
|
||||
dailyTokens: '10亿',
|
||||
costReduction: '30%',
|
||||
teamMembers: '100+',
|
||||
researchRatio: '70%',
|
||||
headquarters: '珠海',
|
||||
serviceNetwork: '全国',
|
||||
businessPhone: '13800138000',
|
||||
businessEmail: 'demo@example.com',
|
||||
wechatQrCode: 'https://cdn.example.com/qr.png',
|
||||
address: '示例地址',
|
||||
insights: {
|
||||
categories: [{ id: 'news', name: '新闻' }],
|
||||
articles: [
|
||||
{
|
||||
id: 'a',
|
||||
title: '标题',
|
||||
category: 'news',
|
||||
date: '2026-11-10',
|
||||
summary: '摘要',
|
||||
body: '<p>正文</p>',
|
||||
related: [],
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
test('save validation requires an article even when default categories exist', () => {
|
||||
assert.deepEqual(model.validateSettings(validValues()), {});
|
||||
for (const insights of [
|
||||
model.emptySettings().insights,
|
||||
{ categories: [], articles: [] },
|
||||
]) {
|
||||
assert.deepEqual(model.validateSettings({ ...validValues(), insights }), {
|
||||
insights: '请完善动态与洞察的配置',
|
||||
});
|
||||
}
|
||||
const invalid = validValues();
|
||||
invalid.insights.articles[0].body = '';
|
||||
assert.ok(model.validateSettings(invalid).insights);
|
||||
});
|
||||
|
||||
test('saving incomplete insights cannot send uploads or a configuration write', async () => {
|
||||
const requests = [];
|
||||
const api = await loadFrontendModule(
|
||||
new URL('../../src/pages/WebsiteSettings/settingsApi.js', import.meta.url),
|
||||
{
|
||||
'../../helpers/websiteApi': {
|
||||
requestWebsite: async (...args) => requests.push(args),
|
||||
},
|
||||
'./model': model,
|
||||
'../../components/common/ui/richTextImages': richTextImages,
|
||||
},
|
||||
);
|
||||
await assert.rejects(
|
||||
api.saveWebsiteSettings(
|
||||
model.serializeSettings({
|
||||
...validValues(),
|
||||
insights: model.emptySettings().insights,
|
||||
}),
|
||||
),
|
||||
/请完整填写并检查官网设置/,
|
||||
);
|
||||
assert.deepEqual(requests, []);
|
||||
await api.saveWebsiteSettings(model.serializeSettings(validValues()));
|
||||
assert.equal(requests.length, 1);
|
||||
assert.equal(requests[0][0], 'post');
|
||||
assert.equal(requests[0][1], '/api/website/page-config');
|
||||
});
|
||||
Reference in New Issue
Block a user