fix(system-role): 修复角色资源树联动授权提交
This commit is contained in:
78
tests/role-resource-tree.test.ts
Normal file
78
tests/role-resource-tree.test.ts
Normal file
@@ -0,0 +1,78 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import { describe, it } from 'node:test';
|
||||
import { resolveRoleMenuSubmitIds } from '../src/views/system/role/modules/role-resource-tree';
|
||||
|
||||
type MenuNode = {
|
||||
id: string;
|
||||
children?: MenuNode[];
|
||||
};
|
||||
|
||||
const menuTree: MenuNode[] = [
|
||||
{
|
||||
id: 'personal',
|
||||
children: [
|
||||
{
|
||||
id: 'weekly',
|
||||
children: [{ id: 'weeklyDetail' }]
|
||||
},
|
||||
{
|
||||
id: 'monthly',
|
||||
children: [{ id: 'monthlyDetail' }]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
id: 'infra',
|
||||
children: [{ id: 'stateMachine' }, { id: 'cmd' }]
|
||||
}
|
||||
];
|
||||
|
||||
describe('resolveRoleMenuSubmitIds', () => {
|
||||
it('keeps original ids when there is no user interaction', () => {
|
||||
const result = resolveRoleMenuSubmitIds({
|
||||
menuTree,
|
||||
baselineIds: ['weekly', 'monthly'],
|
||||
dirtyIds: [],
|
||||
checkedIds: ['personal', 'weekly', 'monthly'],
|
||||
halfCheckedIds: []
|
||||
});
|
||||
|
||||
assert.deepEqual(result, ['weekly', 'monthly']);
|
||||
});
|
||||
|
||||
it('preserves untouched branches when another branch changes', () => {
|
||||
const result = resolveRoleMenuSubmitIds({
|
||||
menuTree,
|
||||
baselineIds: ['weekly', 'monthly'],
|
||||
dirtyIds: ['stateMachine'],
|
||||
checkedIds: ['personal', 'weekly', 'monthly', 'stateMachine'],
|
||||
halfCheckedIds: ['infra']
|
||||
});
|
||||
|
||||
assert.deepEqual(result, ['weekly', 'monthly', 'stateMachine']);
|
||||
});
|
||||
|
||||
it('recomputes the whole dirty branch instead of expanding unrelated baseline ids', () => {
|
||||
const result = resolveRoleMenuSubmitIds({
|
||||
menuTree,
|
||||
baselineIds: ['personal'],
|
||||
dirtyIds: ['weekly'],
|
||||
checkedIds: ['personal', 'weekly', 'weeklyDetail'],
|
||||
halfCheckedIds: []
|
||||
});
|
||||
|
||||
assert.deepEqual(result, ['personal', 'weekly', 'weeklyDetail']);
|
||||
});
|
||||
|
||||
it('does not expand untouched sibling branches under the same ancestor', () => {
|
||||
const result = resolveRoleMenuSubmitIds({
|
||||
menuTree,
|
||||
baselineIds: ['monthly'],
|
||||
dirtyIds: ['weeklyDetail'],
|
||||
checkedIds: ['personal', 'weekly', 'weeklyDetail', 'monthly', 'monthlyDetail'],
|
||||
halfCheckedIds: []
|
||||
});
|
||||
|
||||
assert.deepEqual(result, ['weeklyDetail', 'monthly']);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user