fix(ui): unify table controls and organization layouts
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import React from 'react';
|
||||
import { loadFrontendModule } from './frontend-module.js';
|
||||
|
||||
const { default: TableStatusSwitch } = await loadFrontendModule(
|
||||
new URL(
|
||||
'../../src/components/common/table/TableStatusSwitch.jsx',
|
||||
import.meta.url,
|
||||
),
|
||||
{
|
||||
react: React,
|
||||
antd: { Switch: 'mock-switch' },
|
||||
'react-i18next': { useTranslation: () => ({ t: (key) => key }) },
|
||||
},
|
||||
);
|
||||
const { default: TableGroupTags, TableGroupTag } = await loadFrontendModule(
|
||||
new URL(
|
||||
'../../src/components/common/table/TableGroupTags.jsx',
|
||||
import.meta.url,
|
||||
),
|
||||
{ react: React, antd: { Tag: 'mock-tag' }, './table-group-tags.css': {} },
|
||||
);
|
||||
|
||||
test('table switches share a compact appearance without replacing row actions', () => {
|
||||
const onChange = () => {};
|
||||
const ref = React.createRef();
|
||||
const { props, ref: switchRef } = TableStatusSwitch.render(
|
||||
{
|
||||
checked: false,
|
||||
size: 'large',
|
||||
disabled: true,
|
||||
loading: true,
|
||||
onChange,
|
||||
},
|
||||
ref,
|
||||
);
|
||||
assert.equal(switchRef, ref);
|
||||
assert.equal(props.size, 'small');
|
||||
assert.equal(props.checkedChildren, '启用');
|
||||
assert.equal(props.unCheckedChildren, '禁用');
|
||||
assert.equal(props.checked, false);
|
||||
assert.equal(props.disabled, true);
|
||||
assert.equal(props.loading, true);
|
||||
assert.equal(props.onChange, onChange);
|
||||
assert.equal(
|
||||
TableStatusSwitch.render({ checkedChildren: '是' }, null).props
|
||||
.checkedChildren,
|
||||
'是',
|
||||
);
|
||||
});
|
||||
|
||||
test('single and multiple groups use one outlined color mapping', () => {
|
||||
const { props } = TableGroupTags({
|
||||
groups: ['default, svip', ' vip ', 'default', 'custom', ''],
|
||||
});
|
||||
const tags = Array.from(
|
||||
props.children,
|
||||
(child) => TableGroupTag(child.props).props,
|
||||
);
|
||||
assert.deepEqual(
|
||||
tags.map((tag) => tag.children),
|
||||
['default', 'svip', 'vip', 'custom'],
|
||||
);
|
||||
assert.deepEqual(
|
||||
tags.map((tag) => tag.color),
|
||||
['blue', 'red', 'yellow', 'default'],
|
||||
);
|
||||
assert.ok(tags.every((tag) => tag.variant === 'outlined'));
|
||||
assert.equal(TableGroupTag({ group: 'VIP' }).props.color, 'yellow');
|
||||
assert.equal(TableGroupTags({ groups: null, empty: 'fallback' }), 'fallback');
|
||||
});
|
||||
Reference in New Issue
Block a user