Files

59 lines
2.6 KiB
TypeScript
Raw Permalink 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),页面不内联请求;
// 页面上移/下移已按产品决策移除,排序改由 sort_order 字段维护。
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.equal(/上移|下移/.test(page), false, '菜单页不再提供上移/下移按钮')
assert.equal(/http\.post/.test(page), false, '页面不内联排序请求')
assert.match(page, /sortOrder/, '排序通过 sort_order 字段维护')
})