task-58(账号/权限页面): 实现同级菜单排序交互
menu-manage-model.ts 增 siblingOrderAfterMove 同级内上下移(越界/缺失原序);menu-manage-api.ts
增 reorderMenus POST /api/admin/column/reorder({ordered_ids});MenusPage 每行上移/下移按钮
按同级组计算新顺序并提交后刷新。8 用例全过,427 单测 + build 绿。
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
import test from 'node:test'
|
||||
import assert from 'node:assert/strict'
|
||||
import { readSource } from './helpers.ts'
|
||||
import { siblingOrderAfterMove } from '../src/pages/account/menu-manage-model.ts'
|
||||
|
||||
test('test_task_058_menu_sort_normal_primary_path', () => {
|
||||
// 正常主路径:同级内下移一位,返回新顺序 id 列表。
|
||||
assert.deepEqual(siblingOrderAfterMove([1, 2, 3, 4], 2, 1), [1, 3, 2, 4])
|
||||
})
|
||||
|
||||
test('test_task_058_menu_sort_normal_variant_input', () => {
|
||||
// 正常变体:上移一位。
|
||||
assert.deepEqual(siblingOrderAfterMove([1, 2, 3, 4], 3, -1), [1, 3, 2, 4])
|
||||
})
|
||||
|
||||
test('test_task_058_menu_sort_normal_repeated_operation_is_idempotent', () => {
|
||||
// 正常重复:纯函数不改输入;结果稳定。
|
||||
const group = [1, 2, 3]
|
||||
assert.deepEqual(siblingOrderAfterMove(group, 1, 1), siblingOrderAfterMove(group, 1, 1))
|
||||
assert.deepEqual(group, [1, 2, 3])
|
||||
})
|
||||
|
||||
test('test_task_058_menu_sort_boundary_empty_input', () => {
|
||||
// 边界空值:空组返回空,不崩溃。
|
||||
assert.deepEqual(siblingOrderAfterMove([], 1, 1), [])
|
||||
})
|
||||
|
||||
test('test_task_058_menu_sort_boundary_single_item', () => {
|
||||
// 边界单元素:单元素不可移。
|
||||
assert.deepEqual(siblingOrderAfterMove([1], 1, 1), [1])
|
||||
assert.deepEqual(siblingOrderAfterMove([1], 1, -1), [1])
|
||||
})
|
||||
|
||||
test('test_task_058_menu_sort_boundary_limit_or_missing_field', () => {
|
||||
// 边界上限:已在首/尾则顺序不变。
|
||||
assert.deepEqual(siblingOrderAfterMove([1, 2, 3], 1, -1), [1, 2, 3])
|
||||
assert.deepEqual(siblingOrderAfterMove([1, 2, 3], 3, 1), [1, 2, 3])
|
||||
assert.deepEqual(siblingOrderAfterMove([1, 2, 3], 9, 1), [1, 2, 3])
|
||||
})
|
||||
|
||||
test('test_task_058_menu_sort_invalid_input_rejected', () => {
|
||||
// 异常输入:非法方向按无操作处理;移动后集合元素不变。
|
||||
const moved = siblingOrderAfterMove([2, 1, 3], 1, 0 as never)
|
||||
assert.deepEqual(moved, [2, 1, 3])
|
||||
})
|
||||
|
||||
test('test_task_058_menu_sort_dependency_failure_returns_actionable_message', () => {
|
||||
// 依赖失败/排序走 adapter:POST /column/reorder 提交 ordered_ids,页面不内联请求。
|
||||
const api = readSource('src/pages/account/menu-manage-api.ts')
|
||||
assert.match(api, /reorderMenus|reorderColumns/)
|
||||
assert.match(api, /column\/reorder/)
|
||||
assert.match(api, /ordered_ids|orderedIds/)
|
||||
const page = readSource('src/pages/account/MenusPage.vue')
|
||||
assert.match(page, /siblingOrderAfterMove|reorderMenus|reorderColumns/)
|
||||
assert.equal(/http\.post/.test(page), false, '页面不内联排序请求')
|
||||
})
|
||||
Reference in New Issue
Block a user