2aa9d73325
集中保留原版权声明,移除文件头检查和全局测试忽略规则。验证:全量单测、受影响用例复测及静态检查通过。
126 lines
4.4 KiB
JavaScript
126 lines
4.4 KiB
JavaScript
import assert from 'node:assert/strict';
|
|
import test from 'node:test';
|
|
import i18next from 'i18next';
|
|
import {
|
|
isActionColumn,
|
|
isCenterTableScope,
|
|
prepareCenterColumns,
|
|
} from '../../src/components/ui/centerTablePolicy.js';
|
|
|
|
test('center operation policy includes system settings and excludes unrelated routes', () => {
|
|
for (const path of [
|
|
'/user-center/usage-record',
|
|
'/org/tokens',
|
|
'/console/user',
|
|
'/console/setting',
|
|
'/console/setting/theme',
|
|
])
|
|
assert.equal(isCenterTableScope(path), true);
|
|
for (const path of ['/market', '/organization'])
|
|
assert.equal(isCenterTableScope(path), false);
|
|
});
|
|
|
|
test('pins operations and detail callbacks without changing data, renderers or input columns', () => {
|
|
const render = () => null;
|
|
const columns = [
|
|
{ key: 'name', width: 240, fixed: 'left' },
|
|
{ title: '类型', dataIndex: 'action', render },
|
|
{ title: '操作', key: 'actions', width: 160, render },
|
|
];
|
|
const result = prepareCenterColumns(columns, 1200);
|
|
assert.deepEqual(result[0], columns[0]);
|
|
assert.deepEqual(result[1], columns[1]);
|
|
assert.equal(result[2].fixed, 'right');
|
|
assert.equal(result[2].render, render);
|
|
assert.equal(columns[2].fixed, undefined);
|
|
assert.equal(isActionColumn(columns[1]), false);
|
|
assert.equal(
|
|
isActionColumn({ key: 'fail_reason', title: '详情', render }),
|
|
true,
|
|
);
|
|
assert.equal(isActionColumn({ title: '详情', dataIndex: 'detail' }), false);
|
|
assert.equal(
|
|
isActionColumn({ title: '操作人', dataIndex: 'operator' }),
|
|
false,
|
|
);
|
|
});
|
|
|
|
test('narrow containers release colliding left columns and bound the operation area', () => {
|
|
const columns = [
|
|
{ key: 'name', width: 240, fixed: 'left' },
|
|
{ title: '说明', width: 300, fixed: 'right' },
|
|
{ key: 'result', width: 300, render: () => null },
|
|
];
|
|
const result = prepareCenterColumns(columns, 300);
|
|
assert.equal(result[0].fixed, 'right');
|
|
assert.equal(result[1].fixed, 'right');
|
|
assert.equal(result[2].fixed, 'right');
|
|
assert.equal(result[2].width, 300);
|
|
assert.equal(columns[0].fixed, 'left');
|
|
});
|
|
|
|
test('renames interactive detail headers and sizes action columns from controls', () => {
|
|
const renderDetail = function renderDetail() {
|
|
return { onClick: true, Button: true };
|
|
};
|
|
const result = prepareCenterColumns(
|
|
[
|
|
{ key: 'name', width: 180 },
|
|
{ title: '详情', dataIndex: 'detail', render: renderDetail },
|
|
],
|
|
900,
|
|
);
|
|
assert.equal(result[1].title, '操作');
|
|
assert.equal(result[1].fixed, 'right');
|
|
assert.ok(result[1].width >= 120);
|
|
});
|
|
|
|
test('supports grouped headers and keeps ordinary tables intact', () => {
|
|
const render = () => null;
|
|
const grouped = [{ title: '记录', children: [{ title: '操作', render }] }];
|
|
assert.equal(
|
|
prepareCenterColumns(grouped, 800)[0].children[0].fixed,
|
|
'right',
|
|
);
|
|
const ordinary = [{ title: '金额', dataIndex: 'amount' }];
|
|
assert.deepEqual(prepareCenterColumns(ordinary, 300), ordinary);
|
|
});
|
|
|
|
test('recognizes translated operation headers without requiring a key', async () => {
|
|
await i18next.init({
|
|
lng: 'en',
|
|
resources: { en: { translation: { 操作: 'Actions' } } },
|
|
});
|
|
assert.equal(isActionColumn({ title: 'Actions', render: () => null }), true);
|
|
});
|
|
|
|
test('releases competing fixed columns when the operation area would overlap them', () => {
|
|
const columns = [
|
|
{ key: 'name', width: 180, fixed: 'left' },
|
|
{ key: 'description', width: 300 },
|
|
{ title: '操作', key: 'actions', render: () => null },
|
|
];
|
|
const narrow = prepareCenterColumns(columns, 321, { 2: 240 });
|
|
assert.equal(narrow[0].fixed, undefined);
|
|
assert.equal(narrow[0].width, 180);
|
|
assert.equal(narrow[2].fixed, 'right');
|
|
assert.equal(narrow[2].width, 240);
|
|
const wide = prepareCenterColumns(columns, 900, { 2: 240 });
|
|
assert.equal(wide[0].fixed, 'left');
|
|
assert.equal(wide[2].width, 240);
|
|
assert.equal(columns[0].fixed, 'left');
|
|
});
|
|
|
|
test('bounds measured operation widths to the viewport and restores them after resize', () => {
|
|
const render = () => null;
|
|
const columns = [
|
|
{ key: 'name', width: 200 },
|
|
{ title: '操作', render },
|
|
];
|
|
const narrow = prepareCenterColumns(columns, 280, { 1: 350 });
|
|
assert.equal(narrow[1].width, 280);
|
|
assert.equal(narrow[1].render, render);
|
|
assert.equal(prepareCenterColumns(columns, 900, { 1: 350 })[1].width, 350);
|
|
assert.equal(prepareCenterColumns(columns, 0, { 1: 350 })[1].width, 350);
|
|
});
|