Files
monkey-ai-web/test/unit/action-icons.test.js
zhanjunhao 2aa9d73325 chore(repo): 移除重复版权文件头并纳入共享单测
集中保留原版权声明,移除文件头检查和全局测试忽略规则。验证:全量单测、受影响用例复测及静态检查通过。
2026-11-20 11:23:49 +08:00

140 lines
4.1 KiB
JavaScript

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);
}
});