83 lines
2.8 KiB
JavaScript
83 lines
2.8 KiB
JavaScript
/**
|
|
* 合作伙伴分类树的页面级纯函数(仍内联在 views/base/othercompany/index.vue)。
|
|
*
|
|
* 建树、位置派生、排序号重排、整树重建、拖拽移动等通用逻辑已收敛到 @/utils/tree
|
|
* (其测试在 tests/unit/utils.spec.js),选中「全部分类」的虚拟根约定收敛到 FmsTree。
|
|
* 本文件只覆盖留在页面里的业务判定,它们内联在页面中,
|
|
* 因此通过挂载页面组件访问 <script setup> 的内部绑定。
|
|
*/
|
|
import { describe, expect, it, beforeEach, vi } from 'vitest'
|
|
import { flushPromises } from '@vue/test-utils'
|
|
import Othercompany from '@/views/base/othercompany/index.vue'
|
|
import { mountPage } from '../helpers/app.js'
|
|
|
|
vi.mock('@/services/api', () => ({
|
|
loadDataApi: vi.fn(() => Promise.resolve({ data: [], code: 0, success: true })),
|
|
pageDataApi: vi.fn(() =>
|
|
Promise.resolve({ data: { rows: [], total: 0 }, code: 0, success: true }),
|
|
),
|
|
saveObjectApi: vi.fn(() => Promise.resolve({ code: 0, success: true })),
|
|
}))
|
|
|
|
function category(over = {}) {
|
|
return {
|
|
b_id: 'a',
|
|
b_parent_id: null,
|
|
b_depth: 0,
|
|
b_path: '/a/',
|
|
b_name: 'A',
|
|
b_xh: 10,
|
|
b_canuse: 1,
|
|
...over,
|
|
}
|
|
}
|
|
|
|
/** 页面实例(分类树纯函数与状态都在它的 setup 里) */
|
|
let vm
|
|
|
|
beforeEach(async () => {
|
|
const { wrapper } = await mountPage(Othercompany)
|
|
await flushPromises()
|
|
vm = wrapper.vm
|
|
})
|
|
|
|
describe('othercompany 分类树工具:排序号与子分类判定', () => {
|
|
it('同级最大 b_xh 加 10,无同级时取 10', () => {
|
|
const rows = [
|
|
category({ b_id: 'a', b_xh: 10 }),
|
|
category({ b_id: 'b', b_xh: 30 }),
|
|
category({ b_id: 'a1', b_parent_id: 'a', b_xh: 90 }),
|
|
]
|
|
|
|
expect(vm.nextSiblingXh(rows, null)).toBe(40)
|
|
expect(vm.nextSiblingXh(rows, 'a')).toBe(100)
|
|
expect(vm.nextSiblingXh(rows, 'not-exist')).toBe(10)
|
|
expect(vm.nextSiblingXh([], null)).toBe(10)
|
|
})
|
|
|
|
it('hasChildCategory 只看直接子分类', () => {
|
|
const rows = [
|
|
category({ b_id: 'a' }),
|
|
category({ b_id: 'a1', b_parent_id: 'a' }),
|
|
category({ b_id: 'a1x', b_parent_id: 'a1' }),
|
|
]
|
|
|
|
expect(vm.hasChildCategory(rows, 'a')).toBe(true)
|
|
expect(vm.hasChildCategory(rows, 'a1')).toBe(true)
|
|
expect(vm.hasChildCategory(rows, 'a1x')).toBe(false)
|
|
})
|
|
})
|
|
|
|
describe('othercompany 分类树工具:选中「全部分类」的约定', () => {
|
|
it('未选中任何分类时用空串表达「全部」,不再持有 rootKey', () => {
|
|
// FmsTree 内部消化虚拟根:页面侧传空选中键即代表选中根,
|
|
// 因此页面不应再暴露 ALL_CATEGORY_KEY 之类的魔法字符串。
|
|
expect(vm.selectedCategoryKey).toBe('')
|
|
expect(vm.ALL_CATEGORY_KEY).toBeUndefined()
|
|
})
|
|
|
|
it('未选中分类时不过滤右侧列表(不加固定条件)', () => {
|
|
expect(vm.categoryFilterCondition).toBe('')
|
|
})
|
|
})
|