Files
monkey-ai-web/test/unit/action-icons.test.js
T
zhanjunhao 3297cca457 feat: 还原统一icon之后的尺寸 但复用ant design icon
fix: 修复底部客服按钮 收缩起来的样式bug
2026-11-10 22:08:00 +08:00

159 lines
4.9 KiB
JavaScript

/*
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, /--action-icon-width:18px/);
assert.match(html, /--action-icon-height: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['--action-icon-width'], '20px');
assert.equal(node.props.style['--action-icon-height'], '20px');
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, /--action-icon-width:14px/);
assert.match(html, /anticon-search/);
assert.doesNotMatch(html, /lucide/);
assert.match(
renderToStaticMarkup(React.createElement(legacy.IconPulse)),
/lucide/,
);
});
test('action icons preserve SVG dimensions independently of font size and retain width overrides', () => {
assert.equal(
icons.Search.render({}, null).props.style['--action-icon-width'],
'24px',
);
const node = icons.Copy.render(
{
size: 16,
width: 20,
height: '1.5em',
style: { fontSize: 48, width: 12 },
},
null,
);
assert.equal(node.props.style['--action-icon-width'], '20px');
assert.equal(node.props.style['--action-icon-height'], '1.5em');
assert.equal(node.props.style.fontSize, 48);
assert.equal(node.props.style.width, 12);
assert.equal(node.props.width, undefined);
assert.equal(node.props.height, undefined);
assert.equal(
icons.Plus.render({ size: 0 }, null).props.style['--action-icon-width'],
'0px',
);
});
test('Ant chevrons keep the compact original glyph proportions without changing their layout box', () => {
for (const name of [
'ChevronDown',
'ChevronUp',
'ChevronLeft',
'ChevronRight',
]) {
const node = icons[name].render({ size: 16 }, null);
assert.equal(node.props.style['--action-icon-width'], '16px');
assert.equal(node.props.style['--action-icon-height'], '16px');
assert.equal(node.props.style['--action-icon-scale'], 0.65);
}
});