align(商品类目): el-tree 节点补来源(内置/自定义)/排序/备注展示、行内编辑删除(有子禁用)、按需懒加载子级+加载更多(已加载x/y)、搜索表格补来源列、按钮名/占位对齐(对齐 admin.js renderProductCategoryRows/loadProductCategoryChildren)
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
import test from 'node:test'
|
||||
import assert from 'node:assert/strict'
|
||||
import { readSource } from './helpers.ts'
|
||||
import {
|
||||
appendCategoryChildren,
|
||||
isCategoryLoadMoreNode,
|
||||
makeCategoryLoadMoreNode,
|
||||
productCategoryNodeMeta,
|
||||
productCategorySourceLabel,
|
||||
type ProductCategoryNode,
|
||||
} from '../src/pages/asin/product-category-model.ts'
|
||||
|
||||
/** 对齐 admin.js:5998-6012/6077-6120:树节点带来源/排序/备注、按需懒加载 + 加载更多(已加载 x/y)。 */
|
||||
|
||||
function node(id: number, overrides: Partial<ProductCategoryNode> = {}): ProductCategoryNode {
|
||||
return {
|
||||
id,
|
||||
parentId: null,
|
||||
name: `类目${id}`,
|
||||
categoryKey: `k${id}`,
|
||||
sortOrder: id,
|
||||
description: '',
|
||||
isBuiltin: false,
|
||||
childCount: 0,
|
||||
level: 0,
|
||||
path: `类目${id}`,
|
||||
children: [],
|
||||
...overrides,
|
||||
}
|
||||
}
|
||||
|
||||
test('align_category_source_label', () => {
|
||||
assert.equal(productCategorySourceLabel({ isBuiltin: true } as ProductCategoryNode), '内置')
|
||||
assert.equal(productCategorySourceLabel({ isBuiltin: false } as ProductCategoryNode), '自定义')
|
||||
assert.equal(productCategorySourceLabel(null), '自定义')
|
||||
})
|
||||
|
||||
test('align_category_node_meta_contains_source_and_sort', () => {
|
||||
assert.equal(productCategoryNodeMeta({ isBuiltin: true, sortOrder: 3 } as ProductCategoryNode), '内置 · 排序 3')
|
||||
assert.equal(productCategoryNodeMeta({ isBuiltin: false, sortOrder: null } as ProductCategoryNode), '自定义 · 排序 0')
|
||||
})
|
||||
|
||||
test('align_category_load_more_node_factory', () => {
|
||||
const more = makeCategoryLoadMoreNode(5, 20, 45)
|
||||
assert.equal(isCategoryLoadMoreNode(more), true)
|
||||
assert.equal(more.parentId, 5)
|
||||
assert.equal(more.loadedCount, 20)
|
||||
assert.equal(more.totalCount, 45)
|
||||
assert.equal(isCategoryLoadMoreNode(node(1)), false)
|
||||
})
|
||||
|
||||
test('align_category_append_children_keeps_more_until_done', () => {
|
||||
const current = [node(1), makeCategoryLoadMoreNode(null, 20, 45)]
|
||||
const next = appendCategoryChildren(current, [node(2), node(3)], null, 40, 45, true)
|
||||
assert.deepEqual(next.filter((n) => !isCategoryLoadMoreNode(n)).map((n) => n.id), [1, 2, 3])
|
||||
const tail = next[next.length - 1]
|
||||
assert.equal(isCategoryLoadMoreNode(tail), true)
|
||||
assert.equal((tail as ReturnType<typeof makeCategoryLoadMoreNode>).loadedCount, 40)
|
||||
})
|
||||
|
||||
test('align_category_append_children_drops_more_when_complete', () => {
|
||||
const current = [node(1), makeCategoryLoadMoreNode(9, 20, 22)]
|
||||
const next = appendCategoryChildren(current, [node(2), node(3)], 9, 22, 22, false)
|
||||
assert.deepEqual(next.map((n) => n.id), [1, 2, 3])
|
||||
assert.equal(next.some((n) => isCategoryLoadMoreNode(n)), false)
|
||||
})
|
||||
|
||||
test('align_category_children_api_wiring', () => {
|
||||
const api = readSource('src/pages/asin/product-category-api.ts')
|
||||
assert.match(api, /children/, '懒加载走 children 端点')
|
||||
assert.match(api, /parent_id|parentId/, '带父级参数')
|
||||
assert.match(api, /page_size|pageSize/, '分页参数')
|
||||
})
|
||||
|
||||
test('align_category_page_tree_and_search_wiring', () => {
|
||||
const page = readSource('src/pages/asin/ProductCategoryPage.vue')
|
||||
assert.doesNotMatch(page, /default-expand-all/, '树不再全量展开,改按需懒加载')
|
||||
assert.match(page, /加载更多/, '节点带加载更多')
|
||||
assert.match(page, /已加载/, '显示已加载 x/y')
|
||||
assert.match(page, /productCategorySourceLabel/, '节点展示来源')
|
||||
assert.match(page, /排序/, '节点展示排序')
|
||||
assert.doesNotMatch(page, /新增根类目/, '按钮名对齐参考“新增类目”')
|
||||
assert.match(page, /新增类目/, '顶部新增类目按钮')
|
||||
assert.match(page, /搜索类目名称、编码或备注/, '搜索占位对齐参考')
|
||||
assert.match(page, /来源/, '搜索表格补来源列')
|
||||
assert.match(page, /childCount/, '删除按钮按有子禁用')
|
||||
})
|
||||
@@ -28,7 +28,8 @@ test('test_task_256_category_normal_repeated_operation_is_idempotent', () => {
|
||||
|
||||
test('test_task_256_category_boundary_empty_input', () => {
|
||||
const page = readSource('src/pages/asin/ProductCategoryPage.vue')
|
||||
assert.match(page, /新增根类目/, '需保留新增根类目')
|
||||
// 对齐 admin.html:顶部按钮名「新增类目」;选中节点后仍可新增子类目。
|
||||
assert.match(page, /新增类目/, '顶部新增类目入口')
|
||||
assert.match(page, /新增子类目/, '需保留新增子类目')
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user