aaa943a86d
menu-manage-model.ts 增 createMenuForm/flattenMenuNodes/nextSiblingSort;menu-manage-api.ts 增 createMenu POST /api/admin/permission-menus(unwrap+解析落库节点);MenusPage 新增菜单 Dialog(名称/标识/父菜单/路由/排序)校验后提交并刷新。8 用例全过,403 单测 + build 绿。
80 lines
3.1 KiB
TypeScript
80 lines
3.1 KiB
TypeScript
import test from 'node:test'
|
||
import assert from 'node:assert/strict'
|
||
import { readSource } from './helpers.ts'
|
||
import {
|
||
ADMIN_MENU_TYPE,
|
||
buildMenuManageTree,
|
||
createMenuForm,
|
||
flattenMenuNodes,
|
||
nextSiblingSort,
|
||
parseMenuManageList,
|
||
} from '../src/pages/account/menu-manage-model.ts'
|
||
|
||
test('test_task_055_menu_create_form_normal_primary_path', () => {
|
||
// 正常主路径:根菜单表单默认 menuType=admin、排序可给。
|
||
const form = createMenuForm(null, 0)
|
||
assert.equal(form.parentId, null)
|
||
assert.equal(form.menuType, ADMIN_MENU_TYPE)
|
||
assert.equal(form.sortOrder, 0)
|
||
assert.equal(form.name, '')
|
||
})
|
||
|
||
test('test_task_055_menu_create_form_normal_variant_input', () => {
|
||
// 正常变体:子菜单挂到指定父节点;排序按同级建议。
|
||
const form = createMenuForm(3, 4)
|
||
assert.equal(form.parentId, 3)
|
||
assert.equal(form.sortOrder, 4)
|
||
})
|
||
|
||
test('test_task_055_menu_create_form_normal_repeated_operation_is_idempotent', () => {
|
||
// 正常重复:表单工厂稳定、不改输入。
|
||
assert.deepEqual(createMenuForm(1, 2), createMenuForm(1, 2))
|
||
})
|
||
|
||
test('test_task_055_menu_create_form_boundary_empty_input', () => {
|
||
// 边界空值:空树无同级 → 建议排序 0;flatten 空树为空。
|
||
assert.equal(nextSiblingSort([], null), 0)
|
||
assert.deepEqual(flattenMenuNodes([]), [])
|
||
})
|
||
|
||
test('test_task_055_menu_create_form_boundary_single_item', () => {
|
||
// 边界单元素:单个同级 sort=2 → 建议 3。
|
||
const items = parseMenuManageList([{ id: 1, name: 'A', column_key: 'a', parent_id: null, sort_order: 2 }])
|
||
assert.equal(nextSiblingSort(items, null), 3)
|
||
})
|
||
|
||
test('test_task_055_menu_create_form_boundary_limit_or_missing_field', () => {
|
||
// 边界上限:同级含多节点取最大+1;不同父互不影响。
|
||
const items = parseMenuManageList([
|
||
{ id: 1, name: 'A', column_key: 'a', parent_id: null, sort_order: 5 },
|
||
{ id: 2, name: 'B', column_key: 'b', parent_id: 1, sort_order: 1 },
|
||
])
|
||
assert.equal(nextSiblingSort(items, null), 6)
|
||
assert.equal(nextSiblingSort(items, 1), 2)
|
||
})
|
||
|
||
test('test_task_055_menu_create_form_invalid_input_rejected', () => {
|
||
// 异常输入:flatten 递归含全部后代;排序缺省按 0 参与建议。
|
||
const tree = buildMenuManageTree(
|
||
parseMenuManageList([
|
||
{ id: 1, name: '根', column_key: 'root', parent_id: null },
|
||
{ id: 2, name: '子', column_key: 'sub', parent_id: 1 },
|
||
{ id: 3, name: '孙', column_key: 'leaf', parent_id: 2 },
|
||
]),
|
||
)
|
||
const flat = flattenMenuNodes(tree)
|
||
assert.deepEqual(flat.map((n) => n.id).sort((a, b) => a - b), [1, 2, 3])
|
||
})
|
||
|
||
test('test_task_055_menu_create_form_dependency_failure_returns_actionable_message', () => {
|
||
// 依赖失败/创建走 adapter:POST /permission-menus,页面用模型校验 + createMenu,不内联 http。
|
||
const api = readSource('src/pages/account/menu-manage-api.ts')
|
||
assert.match(api, /createMenu/)
|
||
assert.match(api, /http\.post/)
|
||
assert.match(api, /permission-menus/)
|
||
const page = readSource('src/pages/account/MenusPage.vue')
|
||
assert.match(page, /createMenu/)
|
||
assert.match(page, /menu-manage-model/)
|
||
assert.equal(/http\.(get|post)|unwrap\(/.test(page), false, '页面不内联请求')
|
||
})
|