Files
crawler-plugin/admin-frontend-vue/tests/task-58.test.ts
T
huangzd1997 aeb226a0e6 task-58(账号/权限页面): 实现同级菜单排序交互
menu-manage-model.ts 增 siblingOrderAfterMove 同级内上下移(越界/缺失原序);menu-manage-api.ts
增 reorderMenus POST /api/admin/column/reorder({ordered_ids});MenusPage 每行上移/下移按钮
按同级组计算新顺序并提交后刷新。8 用例全过,427 单测 + build 绿。
2026-09-05 15:21:56 +08:00

57 lines
2.4 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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', () => {
// 依赖失败/排序走 adapterPOST /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, '页面不内联排序请求')
})